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

export class PaypalPage extends BasePage {
    readonly page: Page;
    readonly loginWithPasswordButton: Locator;
    readonly passwordTextBox: Locator;
    readonly paypalLoginButton: Locator;
    readonly completePurchaseButton: Locator;

    constructor(page: Page) {
        super(page);
        this.page = page;
        this.loginWithPasswordButton = page.getByRole('link', { name: 'Log in with a password instead' });
        this.passwordTextBox = page.getByPlaceholder('Password');
        this.paypalLoginButton = page.getByRole('button', { name: 'Log In', exact: true });
        this.completePurchaseButton = page.getByTestId('submit-button-initial');
    }

    async completePaypalPurchase(paymentDetails: IPaymentDetails){
        await this.loginWithPasswordButton.click();
        await this.passwordTextBox.fill(paymentDetails.password!);
        await this.paypalLoginButton.click();
        await this.completePurchaseButton.click();
    }
}
