"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OCIdentityMappingRulesPage = void 0;
const test_1 = require("@playwright/test");
const sleep_1 = require("../../utils/sleep");
const expectLocatorWithRetry_1 = require("../../utils/assertionHelpers/expectLocatorWithRetry");
class OCIdentityMappingRulesPage {
    page;
    mappingRuleCell;
    mappingRuleRow;
    deleteMappingRuleDialog;
    deleteMappingRuleButton;
    createMappingModal;
    closeCreateMappingModal;
    createMappingIdField;
    createMappingNameField;
    createMappingClaimNameField;
    createMappingClaimValueField;
    createMappingModalCancelButton;
    createMappingModalCreateButton;
    createMappingButton;
    filterTableSearchbox;
    constructor(page) {
        this.page = page;
        this.mappingRuleCell = (name) => page.getByRole('cell', {
            name,
            exact: true,
        });
        this.mappingRuleRow = (name) => page.getByRole('row').filter({ hasText: name });
        this.deleteMappingRuleDialog = page.getByRole('dialog', {
            name: 'Delete Mapping rule',
        });
        this.filterTableSearchbox = page.getByRole('searchbox', {
            name: 'Filter table',
        });
        this.deleteMappingRuleButton = this.deleteMappingRuleDialog
            .getByRole('button', {
            name: 'Delete Mapping rule',
        })
            .first();
        // Create mapping modal
        this.createMappingModal = page.getByRole('dialog', {
            name: 'Create new mapping rule',
        });
        this.closeCreateMappingModal = this.createMappingModal.getByRole('button', {
            name: 'Close',
        });
        this.createMappingIdField = this.createMappingModal.getByRole('textbox', {
            name: 'Mapping rule ID',
        });
        this.createMappingNameField = this.createMappingModal.getByRole('textbox', {
            name: 'Mapping rule name',
        });
        this.createMappingClaimNameField = this.createMappingModal.getByRole('textbox', {
            name: 'Claim name',
        });
        this.createMappingClaimValueField = this.createMappingModal.getByRole('textbox', {
            name: 'Claim value',
        });
        this.createMappingModalCancelButton = this.createMappingModal.getByRole('button', {
            name: 'Cancel',
        });
        this.createMappingButton = page.getByRole('button', {
            name: /Create a mapping rule/i,
        });
        this.createMappingModalCreateButton = this.createMappingModal.getByRole('button', {
            name: /create a mapping rule/i,
        });
    }
    async filterTable(name) {
        await this.filterTableSearchbox.click({ timeout: 60000 });
        await this.filterTableSearchbox.fill(name);
        await this.filterTableSearchbox.press('Enter');
    }
    async createMappingRule(mappingId, mappingName, claimName, claimValue) {
        await (0, test_1.expect)(this.createMappingButton).toBeVisible({
            timeout: 30000,
        });
        await this.createMappingButton.click();
        await (0, test_1.expect)(this.createMappingModal).toBeVisible({
            timeout: 30000,
        });
        await this.createMappingIdField.fill(mappingId);
        await this.createMappingNameField.fill(mappingName);
        await this.createMappingClaimNameField.fill(claimName);
        await this.createMappingClaimValueField.fill(claimValue);
        await this.createMappingModalCreateButton.click({
            timeout: 30000,
        });
        await (0, test_1.expect)(this.createMappingModal).not.toBeVisible({
            timeout: 30000,
        });
    }
    //Ignored due to Identity bug https://github.com/camunda/camunda/issues/35673
    async deleteMappingRule(rule) {
        try {
            await (0, test_1.expect)(this.mappingRuleRow(rule).first()).toBeVisible({
                timeout: 10000,
            });
        }
        catch (error) {
            return; //No rules found in the list
        }
        await this.filterTable(rule);
        await (0, sleep_1.sleep)(3000);
        const deleteButtons = this.page.getByRole('button', {
            name: 'danger Delete',
        });
        (0, test_1.expect)(await deleteButtons.count()).toEqual(1);
        await deleteButtons.first().click({ timeout: 60000 });
        await (0, test_1.expect)(this.deleteMappingRuleDialog).toBeVisible({
            timeout: 60000,
        });
        await this.deleteMappingRuleButton.click();
        await (0, test_1.expect)(this.page.getByText('Mapping rule deleted')).toBeVisible({
            timeout: 60000,
        });
        await (0, expectLocatorWithRetry_1.expectLocatorWithRetry)(this.page, this.mappingRuleRow(rule).first(), {
            shouldBeVisible: false,
        });
        await (0, sleep_1.sleep)(60000);
    }
}
exports.OCIdentityMappingRulesPage = OCIdentityMappingRulesPage;
