import { Page } from "@playwright/test";
import { BasePage } from "../base.page";

export class ForgotPage extends BasePage {

    constructor(page: Page) {
        super(page)
    }

    get forgotLoc() {
        return {
            mainContainer: this.genLoc("//div[./form]"),
            errorMissingEmail: this.genLoc("//span[contains(normalize-space(), 'Enter an email.')]"),
            errorInvalidEmail: this.genLoc("//span[contains(normalize-space(), 'Please enter a valid email address.')]"),
            errorEmailNotFound: this.genLoc(`//span[contains(normalize-space(), "We're searching our records to find the account for")]`),
            inputEmail: this.genLoc("//input[@name='email']"),
            btnSubmit: this.genLoc("//button[@type='submit']"),
            inputVerificationCode: this.genLoc("//input[@name='token']"),

            // Verification msg
            verificationMsg: this.genLoc("//span[contains(text(), 'Passcode is invalid or has expired.')]"),
            headingCreateNewPassword: this.genLoc("//h3[contains(text(), 'Create a new password')]"),
            inputNewPassword: this.genLoc("//input[@name='password']"),
            createPasswordSuccessMsg: this.genLoc("//span[contains(text(), 'Your password has been successfully updated')]"),
        }
    }

    async open() {
        await this.page.goto('forgot-password')
    }

    async fillEmail(email: string) {
        await this.forgotLoc.inputEmail.fill(email)
    }

    async submit() {
        await this.forgotLoc.btnSubmit.click()
    }

    async fillAndSubmit(email: string) {
        await this.fillEmail(email)
        await this.submit()
    }

    async fillVerificationCode(code: string) {
        await this.forgotLoc.inputVerificationCode.fill(code)
    }

    async fillNewPassword(password: string) {
        await this.forgotLoc.inputNewPassword.fill(password)
    }
}