import { type Page, Locator } from '@playwright/test';
import { LookupPage } from './LookupPage';
import { AddressForm } from './forms/AddressForm';
import { VehicleSelectionForm } from './forms/VehicleSelectionForm';
import { ICustomerDetails, IVehicleDetails } from 'safelite-playwright-core';
import { step } from 'framework/localTypes/Step';
import { ITestData } from 'framework/TestData';
import { ProgressBarPercentages } from 'framework/localTypes/Enums';

export class VehicleLookupAddressPage extends LookupPage {
    readonly addressForm: AddressForm;
    readonly vehicleSelectionForm: VehicleSelectionForm;

    constructor(page: Page) {
        super(page);
        this.addressForm = new AddressForm(page);
        this.vehicleSelectionForm = new VehicleSelectionForm(page);
        
        // Override the unserviceableZipAlertMessage for address-specific message
        this.unserviceableZipAlertMessage = this.page.locator('div.alert-danger.widget-name-AlertVinNotFoundWidget', 
            { hasText: "Your address didn't return a VIN match." });
    }

    async lookupVehicleByAddress(customerDetails: ICustomerDetails, vehicleDetails: IVehicleDetails) {
        await this.addressForm.populateAddress(customerDetails);
        //await this.nextPage();
        //await this.vehicleSelectionForm.selectVehicle(vehicleDetails);
    }

    @step("VehicleLookupAddressPage >> Lookup by address: ")
    async handleVehicleLookupAddressPage(testData: Partial<ITestData>) {
        const { customerDetails, vehicleDetails, alertFlags } = testData;

        await this.validateProgressBar(ProgressBarPercentages.VehicleLookupAddressPage);
        await this.lookupVehicleByAddress(customerDetails!, vehicleDetails!);
        await this.handleZipValidation(customerDetails!.address.postalCode!, vehicleDetails!.vehicleLookupType!, alertFlags!);
    }
}