"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('nav-item-realms');
        await realmSelector.click();
        const searchField = this.page.getByTestId('selectRealminput');
        await searchField.click({ timeout: 30000 });
        await this.page
            .getByPlaceholder('Search')
            .fill(process.env.KEYCLOAK_REALM || 'camunda-platform');
        await this.page
            .locator('[data-ouia-component-id="OUIA-Generated-Button-control-1"]')
            .click();
        await this.page
            .getByText(process.env.KEYCLOAK_REALM || '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('a[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(`test${username}`);
        await this.page.getByTestId('lastName').fill('user');
        await this.page
            .getByTestId('email')
            .fill(`qacamunda+${username}@gmail.com`);
    }
    async saveUser() {
        await this.page.getByTestId('user-creation-save').click();
    }
    async fillPassword(password) {
        await (0, test_1.expect)(this.page.getByTestId('credentials')).toBeVisible({
            timeout: 30000,
        });
        await this.page.getByTestId('credentials').click();
        await (0, test_1.expect)(this.page.getByTestId('no-credentials-empty-action')).toBeVisible({ timeout: 30000 });
        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;
