"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuditLogPage = void 0;
const test_1 = require("@playwright/test");
class AuditLogPage {
    auditLogTab;
    updateButton;
    clientOperationsSection;
    clientCategoryCheckbox;
    clientCategoryLabel;
    constructor(page) {
        this.auditLogTab = page.getByRole('tab', { name: 'Audit log' });
        const auditLogPanel = page.getByRole('tabpanel', { name: 'Audit log' });
        this.updateButton = auditLogPanel.getByRole('button', {
            name: 'Update',
            exact: true,
        });
        // Scope to the Client block: the category labels also exist under the User section.
        this.clientOperationsSection = auditLogPanel
            .getByText('Client operations to log', { exact: true })
            .locator('..');
        this.clientCategoryCheckbox = (category) => this.clientOperationsSection.getByRole('checkbox', { name: category });
        // Carbon hides the real <input>; toggle via the visible label.
        this.clientCategoryLabel = (category) => this.clientOperationsSection.locator('label').filter({ hasText: category });
    }
    async clickAuditLogTab() {
        await (0, test_1.expect)(this.auditLogTab).toBeVisible({ timeout: 60000 });
        await this.auditLogTab.click({ timeout: 60000 });
    }
    async ensureChecked(category) {
        const checkbox = this.clientCategoryCheckbox(category);
        await (0, test_1.expect)(checkbox).toBeAttached({ timeout: 30000 });
        if (!(await checkbox.isChecked())) {
            await this.clientCategoryLabel(category).click({ timeout: 30000 });
            await (0, test_1.expect)(checkbox).toBeChecked();
        }
    }
    async enableClientOperationLogging() {
        const categories = [
            'Administration',
            'Deployed resources',
            'User tasks',
        ];
        for (const category of categories) {
            await this.ensureChecked(category);
        }
        if (await this.updateButton.isEnabled()) {
            await this.updateButton.click({ timeout: 60000 });
            await (0, test_1.expect)(this.updateButton).toBeDisabled({ timeout: 60000 });
        }
    }
}
exports.AuditLogPage = AuditLogPage;
