"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OCIdentityClusterVariablesPage = void 0;
const test_1 = require("@playwright/test");
class OCIdentityClusterVariablesPage {
    page;
    variablesList;
    editVariableButton;
    editVariableModal;
    variableValueField;
    saveVariableButton;
    closeEditVariableModal;
    cancelButton;
    variableRow;
    monacoEditor;
    monacoEditorTextArea;
    successMessage;
    editMenuItem;
    constructor(page) {
        this.page = page;
        this.variablesList = page.locator('table.cds--data-table');
        this.variableRow = (variableName) => this.variablesList
            .locator('tbody')
            .getByRole('row')
            .filter({ hasText: variableName });
        this.editVariableButton = (variableName) => this.variableRow(variableName).getByRole('button', { name: 'Options' });
        this.editVariableModal = page.getByRole('dialog', {
            name: /Edit.*variable/i,
        });
        this.variableValueField = this.editVariableModal.getByRole('textbox', {
            name: 'Editor content',
        });
        this.saveVariableButton = this.editVariableModal.locator('.cds--modal-footer button.cds--btn--primary');
        this.closeEditVariableModal = this.editVariableModal.getByRole('button', {
            name: 'Close',
        });
        this.cancelButton = this.editVariableModal.getByRole('button', {
            name: 'Cancel',
        });
        this.monacoEditor = this.editVariableModal.locator('.monaco-editor');
        this.monacoEditorTextArea = this.monacoEditor.locator('textarea.inputarea');
        this.successMessage = this.page.getByText('Cluster variable updated');
        this.editMenuItem = this.page
            .locator('button[role="menuitem"]')
            .filter({ hasText: /^Edit$/ });
    }
    async editVariable(variableName, newValue) {
        await this.editVariableButton(variableName).click();
        await (0, test_1.expect)(this.editMenuItem).toBeVisible();
        await this.editMenuItem.click();
        await (0, test_1.expect)(this.variableValueField).toBeVisible();
        await (0, test_1.expect)(this.monacoEditor).toBeVisible();
        await this.monacoEditor.click();
        // Monaco editor doesn't respond reliably to clear()/fill() on the
        // hidden textarea. Use keyboard shortcuts to select-all and replace,
        // which mirrors real user interaction.
        await this.monacoEditorTextArea.press('Control+a');
        await this.monacoEditorTextArea.press('Delete');
        await this.monacoEditorTextArea.pressSequentially(newValue, { delay: 10 });
        await (0, test_1.expect)(this.saveVariableButton).toBeEnabled({ timeout: 10000 });
        await this.saveVariableButton.click();
        await (0, test_1.expect)(this.successMessage).toBeVisible();
        await (0, test_1.expect)(this.editVariableModal).toBeHidden();
    }
    async assertVariableExists(variableName) {
        await (0, test_1.expect)(this.variableRow(variableName)).toBeVisible();
    }
    async assertVariableValue(variableName, expectedValue) {
        const row = this.variableRow(variableName);
        await (0, test_1.expect)(row).toContainText(expectedValue);
    }
}
exports.OCIdentityClusterVariablesPage = OCIdentityClusterVariablesPage;
