"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ManagementIdentityPage = void 0;
const test_1 = require("@playwright/test");
class ManagementIdentityPage {
    page;
    identityBanner;
    usersLink;
    assignedRolesTab;
    demoUser;
    confirmDeleteButton;
    assignRolesButton;
    addButton;
    optimizeCheckbox;
    modelerCheckbox;
    deleteButton;
    deleteSubButton;
    tenantTab;
    licenseKeyTagNonProduction;
    licenseKeyTagNonCommercial;
    licenseKeyTagProduction;
    licenseKeyTagCommercial;
    modelerAdminCheckbox;
    identityCheckbox;
    openSidebarButton;
    logoutButton;
    orchestrationCheckbox;
    constructor(page) {
        this.page = page;
        this.identityBanner = page
            .locator('a')
            .filter({ hasText: /^Camunda logo\s*Management Identity$/ })
            .first();
        this.usersLink = page.locator('a').filter({ hasText: 'Users' });
        this.tenantTab = page
            .getByRole('link', { name: 'Tenants' })
            .or(page.locator('a').filter({ hasText: 'Tenants' }))
            .first();
        this.assignedRolesTab = page.getByRole('tab', { name: 'Assigned roles' });
        this.demoUser = page.getByRole('cell', { name: 'demo' }).first();
        this.confirmDeleteButton = page.getByRole('button', {
            name: 'danger Delete',
        });
        this.assignRolesButton = page.getByRole('button', { name: 'Assign roles' });
        this.addButton = page.getByRole('button', { name: 'Add' });
        this.optimizeCheckbox = page
            .locator('label')
            .filter({ hasText: 'Optimize (Grants full access to Optimize)' });
        this.modelerCheckbox = page
            .locator('label')
            .filter({ hasText: 'Web Modeler (Grants full access to Web Modeler)' });
        this.identityCheckbox = page.locator('label').filter({
            hasText: 'ManagementIdentity (Provides full access to Management Identity)',
        });
        this.deleteSubButton = page.getByRole('button', { name: 'danger delete' });
        this.deleteButton = page.locator('button', { hasText: 'danger' });
        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');
        this.modelerAdminCheckbox = page.locator('label').filter({
            hasText: 'Web Modeler Admin (Grants elevated access to Web Modeler)',
        });
        this.openSidebarButton = page.getByLabel('Open User Sidebar');
        this.logoutButton = page.getByRole('button', { name: 'Log out' });
        this.orchestrationCheckbox = page.locator('label').filter({
            hasText: 'Orchestration (Grants full access to Orchestration)',
        });
    }
    async clickUsersLink() {
        try {
            await this.usersLink.click({ timeout: 180000, force: true });
        }
        catch {
            await this.page.reload();
            await this.usersLink.click({ timeout: 180000, force: true });
        }
    }
    async clickUser(username) {
        const searchbox = this.page.getByRole('searchbox');
        await searchbox.click({ timeout: 30000 });
        await searchbox.fill(username);
        const user = this.page.getByRole('cell', { name: username, exact: true });
        await (0, test_1.expect)(user).toBeVisible({ timeout: 60000 });
        await user.click();
    }
    async clickAssignedRolesTab() {
        await (0, test_1.expect)(this.assignedRolesTab).toBeVisible({ timeout: 60000 });
        await this.assignedRolesTab.click();
    }
    async clickDemoUser() {
        await (0, test_1.expect)(this.demoUser).toBeVisible({ timeout: 60000 });
        await this.demoUser.click({ timeout: 180000 });
    }
    async clickDeleteAccessButton(accessToDelete) {
        try {
            await this.page
                .locator('td:right-of(:text("' + accessToDelete + '"))')
                .first()
                .click({ timeout: 60000 });
        }
        catch {
            console.log('Access already deleted');
        }
    }
    async clickConfirmDeleteButton() {
        try {
            await this.confirmDeleteButton.click();
        }
        catch {
            console.log('Access already deleted');
        }
    }
    async clickAssignRolesButton() {
        await this.assignRolesButton.click();
    }
    async clickAddButton() {
        await this.addButton.click();
    }
    async clickOptimizeCheckbox() {
        await this.optimizeCheckbox.click();
    }
    async clickModelerCheckbox() {
        await this.modelerCheckbox.click();
    }
    async clickIdentityCheckbox() {
        await this.identityCheckbox.click();
    }
    async clickModelerAdminCheckbox() {
        await this.modelerAdminCheckbox.click();
    }
    async clickUserGroup(name) {
        await this.page.getByRole('cell', { name: name }).click();
    }
    async clickTenantTab() {
        await this.tenantTab.click();
    }
    async clickOpenSidebarButton() {
        await this.openSidebarButton.click({ timeout: 60000 });
    }
    async clickLogoutButton() {
        await this.logoutButton.click({ timeout: 60000 });
    }
    async clickOrchestrationCheckbox() {
        await this.orchestrationCheckbox.click();
    }
}
exports.ManagementIdentityPage = ManagementIdentityPage;
