import { type Locator, type Page } from '@playwright/test';
import { BasePage } from './BasePage';
import { ServicePackage } from '@business-logic/types/Enums';

export class ServicePackagesPage extends BasePage {
    readonly page: Page;
    readonly standardPackageButton: Locator;
    readonly premiumPackageButton: Locator;
    readonly glassOnlyPackageButton: Locator;
    readonly wiperModal: Locator;
    readonly wiperModalCloseButton: Locator;
    readonly continueButton: Locator;
    issPageValue = 'service-packages';

    constructor(page: Page) {
        super(page);
        this.page = page;
        this.standardPackageButton = this.page.locator('label[for="ServicePackageQuestion-TierTwo"]'); // standard package
        this.premiumPackageButton = this.page.locator('label[for="ServicePackageQuestion-TierThree"]'); // premium package
        this.glassOnlyPackageButton = this.page.locator('label[for="ServicePackageQuestion-TierOne"]'); // glass only package
        this.wiperModal = this.page.locator('#FrontWiperModal #modalbtn');
        this.wiperModalCloseButton = this.page.locator('#FrontWiperModal').getByLabel('Close')
        this.continueButton = this.page.getByRole('button', { name: 'Continue' });
        // this.validateURL(this.url);
    }

    async selectServicePackage(servicePackage: ServicePackage){
        if (servicePackage === ServicePackage.Standard) {
            await this.standardPackageButton.check();
        } else if (servicePackage === ServicePackage.Premium) {
            await this.premiumPackageButton.check();
            try {await this.wiperModal.waitFor({ state: 'visible', timeout: 5000 });
                await this.wiperModalCloseButton.click();
            } catch {
                await this.continueButton.click();
            }
        } else if (servicePackage === ServicePackage.GlassOnly) {
            await this.glassOnlyPackageButton.check();
        } 
        await this.continueButton.click();
    }
}