"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KeycloakAdminPage = void 0;
const test_1 = require("@playwright/test");
const sleep_1 = require("../../utils/sleep");
class KeycloakAdminPage {
    page;
    keycloakBanner;
    constructor(page) {
        this.page = page;
        this.keycloakBanner = page.locator('#kc-main-content-page-container');
    }
    async toBeVisible() {
        await (0, test_1.expect)(this.keycloakBanner).toBeVisible({ timeout: 60000 });
    }
    async switchToCamundaPlatform() {
        const realmSelector = this.page.getByTestId('realmSelector');
        await realmSelector.click();
        await this.page.getByText('camunda-platform').click();
        const mainLocator = this.page.locator('#kc-main-content-page-container');
        await (0, test_1.expect)(mainLocator).toBeVisible();
    }
    async clickUsersTab() {
        await this.page.click('[id="nav-item-users"]');
    }
    async clickAddUser() {
        await this.page.getByTestId('add-user').click();
    }
    async fillUser(username) {
        await this.page.getByTestId('username').fill(username);
        await this.page.getByTestId('firstName').fill(username);
        await this.page.getByTestId('lastName').fill(username);
        await this.page.getByTestId('email').fill(username + '@camunda.com');
    }
    async saveUser() {
        await this.page.getByTestId('create-user').click();
    }
    async fillPassword(password) {
        await this.page.getByTestId('credentials').click();
        await this.page.getByTestId('no-credentials-empty-action').click();
        await this.page.getByTestId('passwordField').fill(password);
        await this.page.getByTestId('passwordConfirmationField').fill(password);
    }
    async savePassword() {
        await this.page
            .locator('label.pf-v5-c-switch[for="temporaryPassword"]')
            .click();
        await this.page.getByTestId('confirm').click();
        await this.page.getByTestId('confirm').click();
        // if the browser is firefox, delay for 500 ms
        if (await this.page.evaluate(() => navigator.userAgent.includes('Firefox'))) {
            await (0, sleep_1.sleep)(500);
        }
    }
}
exports.KeycloakAdminPage = KeycloakAdminPage;
