namespace Tests.Pages.BuildCalculator;

public class FilterComponent
{
    private readonly Website _website;

    public FilterComponent(Website website)
    {
        _website = website;
    }

    private ILocator FactionSelect =>
        _website.Locator("select").Filter(new LocatorFilterOptions
            { Has = _website.Locator("option:has-text('Aru'), option:has-text(\"Q'Rath\")") });

    private ILocator ImmortalSelect =>
        _website.Locator("select").Filter(new LocatorFilterOptions
        {
            Has = _website.Locator(
                "option:has-text('Orzum'), option:has-text('Ajari'), option:has-text('Atzlan'), option:has-text('Mala'), option:has-text('Xol')")
        });

    public async Task SelectFactionAsync(string faction)
    {
        await FactionSelect.SelectOptionAsync(faction);
    }

    public async Task SelectImmortalAsync(string immortal)
    {
        await ImmortalSelect.SelectOptionAsync(immortal);
    }

    public async Task<string> GetSelectedFactionAsync()
    {
        return await FactionSelect.InputValueAsync();
    }

    public async Task<string> GetSelectedImmortalAsync()
    {
        return await ImmortalSelect.InputValueAsync();
    }

    public async Task<IReadOnlyList<string>> GetAvailableImmortalsAsync()
    {
        return await ImmortalSelect.Locator("option").AllTextContentsAsync();
    }
}