"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OptimizeHomePage = void 0;
const test_1 = require("@playwright/test");
const sleep_1 = require("../../utils/sleep");
class OptimizeHomePage {
    page;
    collectionsLink;
    dashboardLink;
    modalCloseButton;
    optimizeBanner;
    noPermissionsMessage;
    constructor(page) {
        this.page = page;
        this.collectionsLink = page
            .getByRole('banner')
            .getByRole('link', { name: 'Collections' });
        this.dashboardLink = page.getByRole('link', { name: 'Dashboards' });
        this.modalCloseButton = page.locator('button').filter({ hasText: /^Close$/ });
        this.optimizeBanner = page.getByRole('link', {
            name: 'Camunda logo Optimize',
        });
        this.noPermissionsMessage = page.getByText('default backend - 404');
    }
    async clickCollectionsLink() {
        if (await this.modalCloseButton.isVisible({ timeout: 60000 })) {
            await this.modalCloseButton.click();
        }
        await this.collectionsLink.click({ timeout: 60000 });
    }
    async clickDashboardLink() {
        const maxRetries = 5;
        for (let attempt = 0; attempt < maxRetries; attempt++) {
            try {
                if (await this.modalCloseButton.isVisible({ timeout: 15000 })) {
                    await this.modalCloseButton.click({ timeout: 60000 });
                }
                await (0, test_1.expect)(this.dashboardLink).toBeVisible({ timeout: 60000 });
                await this.dashboardLink.click({ timeout: 60000 });
                return;
            }
            catch (error) {
                if (attempt < maxRetries - 1) {
                    console.warn(`Attempt ${attempt + 1} failed. Retrying...`);
                    await this.page.reload();
                    await (0, sleep_1.sleep)(60000);
                }
                else {
                    throw new Error(`Assertion failed after ${maxRetries} attempts: ` + error);
                }
            }
        }
    }
}
exports.OptimizeHomePage = OptimizeHomePage;
