using Microsoft.Playwright;

namespace Books.E2E.Tests.Pages;

/// <summary>
/// Page object for the Dashboard page at /.
/// </summary>
public class DashboardPage : BasePage
{
    public DashboardPage(IPage page) : base(page)
    {
    }

    /// <summary>
    /// Waits for the dashboard to be fully loaded.
    /// </summary>
    public async Task WaitForDashboardToLoad()
    {
        // Wait for dashboard header or main content
        await Page.WaitForSelectorAsync(".ant-layout-content", new() { Timeout = 10000 });
        await WaitForNetworkIdleAsync();
    }

    /// <summary>
    /// Checks if the dashboard shows any KPI cards.
    /// </summary>
    public async Task<bool> HasKpiCards()
    {
        return await Page.Locator(".ant-statistic").CountAsync() > 0;
    }

    /// <summary>
    /// Gets the company name shown in the header.
    /// </summary>
    public async Task<string?> GetCurrentCompanyName()
    {
        var companySelector = Page.Locator("[data-testid='company-name'], .company-name");
        if (await companySelector.IsVisibleAsync())
        {
            return await companySelector.TextContentAsync();
        }
        return null;
    }
}
