"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IdentityLoginPage = void 0;
const test_1 = require("@playwright/test");
class IdentityLoginPage {
    page;
    usernameInput;
    passwordInput;
    loginButton;
    backupLogin;
    constructor(page) {
        this.page = page;
        this.usernameInput = page.getByLabel('Username');
        this.passwordInput = page.getByRole('textbox', { name: 'password' });
        this.loginButton = page.getByRole('button', { name: 'Login' });
        this.backupLogin = page.getByRole('button', { name: 'Log in' });
    }
    async fillUsername(username) {
        await this.usernameInput.fill(username);
    }
    async clickUsername() {
        await this.usernameInput.click({ timeout: 60000 });
    }
    async fillPassword(password) {
        await this.passwordInput.fill(password);
    }
    async clickLoginButton() {
        const login = this.loginButton.or(this.backupLogin).first();
        await (0, test_1.expect)(login).toBeVisible({ timeout: 60000 });
        await login.click({ timeout: 60000 });
    }
    async login(username, password) {
        try {
            await (0, test_1.expect)(this.usernameInput).toBeVisible();
            await (0, test_1.expect)(this.passwordInput).toBeVisible();
            await this.clickUsername();
            await this.fillUsername(username);
            await this.fillPassword(password);
            await this.clickLoginButton();
        }
        catch (error) {
            await (0, test_1.expect)(this.page.getByRole('link', { name: 'Camunda logo Identity' })).toBeVisible();
        }
    }
}
exports.IdentityLoginPage = IdentityLoginPage;
