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

export class PolicyVehiclesPage extends BasePage {
    readonly page: Page;
    issPageValue = 'policy-vehicles';

    constructor(page: Page) {
        super(page);
        this.page = page;
        // this.validateURL(this.url);
    }

    async validateVehicleIsOnPolicy(vehicleDetails: IVehicleDetails) {
        const vehicleRegExp = new RegExp(`${vehicleDetails.year} .+ ${vehicleDetails.model}`, 'i');
        await expect.soft(this.page.getByRole('radio', {name: vehicleRegExp})).toBeAttached();
    }

    async selectVehicle(vehicleDetails: IVehicleDetails){
        const vehicleRegExp = new RegExp(`${vehicleDetails.year} .+ ${vehicleDetails.model}`, 'i');
        await this.page.locator('label').filter({hasText: vehicleRegExp}).locator('div').click();
    }
    async selectVehicleNotListed(){
        await this.page.getByText('Vehicle not listed').click();
    }

    async assertNonServiceableAlertBehavior(){
        const nonServiceableWarning = this.page.getByText('Service not available for your vehicle');
        await expect(nonServiceableWarning).toBeVisible();
        await expect(this.continueButton).toBeDisabled();
    }
}
