"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OCIdentityHomePage = void 0;
const test_1 = require("@playwright/test");
const expectLocatorWithRetry_1 = require("../../utils/assertionHelpers/expectLocatorWithRetry");
const clickLocatorWithRetry_1 = require("../../utils/assertionHelpers/clickLocatorWithRetry");
class OCIdentityHomePage {
    page;
    groupsTab;
    identityBanner;
    mappingRulesTab;
    tenantsTab;
    rolesTab;
    authorizationsTab;
    licenseKeyTagNonProduction;
    licenseKeyTagNonCommercial;
    licenseKeyTagProduction;
    licenseKeyTagCommercial;
    constructor(page) {
        this.page = page;
        this.identityBanner = page.getByRole('link', {
            name: 'Camunda logo Identity',
        });
        this.groupsTab = page
            .getByRole('banner')
            .getByLabel('Identity')
            .locator('a')
            .filter({ hasText: 'Groups' });
        this.mappingRulesTab = page
            .getByRole('banner')
            .locator('a')
            .filter({ hasText: /^Mapping rules$/ })
            .first();
        this.tenantsTab = page
            .getByRole('banner')
            .locator('a')
            .filter({ hasText: /^Tenants$/ });
        this.rolesTab = page
            .getByRole('banner')
            .locator('a')
            .filter({ hasText: 'Roles' });
        this.authorizationsTab = page
            .getByRole('banner')
            .locator('a')
            .filter({ hasText: /^Authorizations$/ });
        this.licenseKeyTagNonProduction = page
            .getByText('Non-production license')
            .first();
        this.licenseKeyTagNonCommercial = page.getByText('Non-commercial license');
        this.licenseKeyTagProduction = page.getByText('Production license').first();
        this.licenseKeyTagCommercial = page.getByText('Commercial license');
    }
    async clickMappingRulesTab() {
        await (0, test_1.expect)(this.mappingRulesTab).toBeVisible({ timeout: 30000 });
        await this.mappingRulesTab.click();
    }
    async clickTenantsTab() {
        await (0, test_1.expect)(this.tenantsTab).toBeVisible({ timeout: 30000 });
        await this.tenantsTab.click();
    }
    async clickAuthorizationsTab() {
        await (0, test_1.expect)(this.authorizationsTab).toBeVisible({ timeout: 30000 });
        await this.authorizationsTab.click();
    }
    async clickRolesTab() {
        // OC Identity occasionally renders the banner without the secondary nav
        // tabs on opensearch upgrade scenarios. Reload between attempts to force
        // the SPA to rehydrate the navigation instead of waiting on a stuck DOM.
        await (0, clickLocatorWithRetry_1.clickLocatorWithRetry)(this.page, this.rolesTab, {
            visibilityTimeout: 15000,
            totalTimeout: 90000,
            maxRetries: 4,
            postAction: async () => {
                await this.page.reload({ waitUntil: 'domcontentloaded' });
            },
        });
    }
    async clickGroupsTab() {
        await (0, expectLocatorWithRetry_1.expectLocatorWithRetry)(this.page, this.groupsTab);
        await this.groupsTab.click({ timeout: 30000 });
    }
}
exports.OCIdentityHomePage = OCIdentityHomePage;
