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

export class PolicyVehiclesPage extends InsuranceBasePage {
    readonly page: Page;
    url = process.env['BASE_URL']! + '/FixMyGlass/PolicyVehicle.aspx';

    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 baseModel = vehicleDetails.model.split(' ').pop() || vehicleDetails.model;
        const vehicleRegExp = new RegExp(`${vehicleDetails.year}.*?${vehicleDetails.make}.*?${baseModel}`, 'i');
        await this.page.getByRole('radio', {name: vehicleRegExp}).click();
    }

    async selectVehicleNotListed(){
        await this.page.getByText('Vehicle not listed').click();
    }
}