namespace Tests.Pages.BuildCalculator;

public class OptionsComponent
{
    private readonly Website _website;

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

    public ILocator BuildingInputDelayInput => FormNumberInput("Building Input Delay");
    public ILocator WaitTimeInput => FormNumberInput("Wait Time");
    public ILocator WaitToInput => FormNumberInput("Wait To");
    public ILocator AddWaitButton => ButtonWithLabel("Add Wait").First;
    public ILocator AddWaitToButton => ButtonWithLabel("Add Wait").Last;

    private ILocator FormNumberInput(string label)
    {
        return _website.Locator(".formNumberContainer").Filter(new LocatorFilterOptions { HasText = label })
            .Locator("input[type='number']");
    }

    private ILocator ButtonWithLabel(string label)
    {
        return _website.Locator("button").Filter(new LocatorFilterOptions { HasText = label });
    }

    public async Task SetBuildingInputDelayAsync(int value)
    {
        await BuildingInputDelayInput.FillAsync(value.ToString());
        await BuildingInputDelayInput.PressAsync("Enter");
    }

    public async Task SetWaitTimeAsync(int value)
    {
        await WaitTimeInput.FillAsync(value.ToString());
    }

    public async Task SetWaitToAsync(int value)
    {
        await WaitToInput.FillAsync(value.ToString());
    }

    public async Task ClickAddWaitAsync()
    {
        await AddWaitButton.ClickAsync();
    }

    public async Task ClickAddWaitToAsync()
    {
        await AddWaitToButton.ClickAsync();
    }

    public async Task<string> GetBuildingInputDelayAsync()
    {
        return await BuildingInputDelayInput.InputValueAsync();
    }

    public async Task<string> GetWaitTimeAsync()
    {
        return await WaitTimeInput.InputValueAsync();
    }

    public async Task<string> GetWaitToAsync()
    {
        return await WaitToInput.InputValueAsync();
    }
}