namespace Tests.Pages.BuildCalculator;

public class BankComponent
{
    private readonly Website _website;

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

    public ILocator BankContainer => _website.Locator(".bankContainer");

    public ILocator DisplayValue(string label)
    {
        return BankContainer.Locator(".displayContainer").Filter(new LocatorFilterOptions { HasText = label })
            .Locator(".displayContent");
    }

    public async Task<string> GetTimeAsync()
    {
        return (await DisplayValue("Time").TextContentAsync())?.Trim() ?? "";
    }

    public async Task<string> GetAlloyAsync()
    {
        return (await DisplayValue("Alloy").TextContentAsync())?.Trim() ?? "";
    }

    public async Task<string> GetEtherAsync()
    {
        return (await DisplayValue("Ether").TextContentAsync())?.Trim() ?? "";
    }

    public async Task<string> GetPyreAsync()
    {
        return (await DisplayValue("Pyre").TextContentAsync())?.Trim() ?? "";
    }

    public async Task<string> GetSupplyAsync()
    {
        return (await DisplayValue("Supply").TextContentAsync())?.Trim() ?? "";
    }

    public async Task<string> GetWorkerCountAsync()
    {
        return (await BankContainer.Locator(".workerText").Locator(".displayContent").Nth(0).TextContentAsync())
            ?.Trim() ?? "";
    }

    public async Task<string> GetBusyWorkerCountAsync()
    {
        return (await BankContainer.Locator(".workerText").Locator(".displayContent").Nth(1).TextContentAsync())
            ?.Trim() ?? "";
    }

    public async Task<string> GetCreatingWorkerCountAsync()
    {
        return (await BankContainer.Locator(".workerText").Locator(".displayContent").Nth(2).TextContentAsync())
            ?.Trim() ?? "";
    }
}