"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OptimizeReportPage = void 0;
class OptimizeReportPage {
    page;
    processSelectionButton;
    userTaskProcess;
    versionSelection;
    alwaysDisplayLatestSelection;
    createReportLink;
    durationButton;
    countOption;
    processInstanceButton;
    userTaskOption;
    heatMapButton;
    numberButton;
    tableOption;
    reportName;
    saveButton;
    oneUserTaskInstance;
    twoUserTaskInstance;
    cancelButton;
    createNewButton;
    reportOption;
    processInstanceCount;
    blankReportButton;
    selectDropdown;
    constructor(page) {
        this.page = page;
        this.processSelectionButton = page.getByPlaceholder('Select...');
        this.userTaskProcess = page
            .getByText('User_Task_Process', { exact: true })
            .first();
        this.versionSelection = page.getByLabel('Version');
        this.alwaysDisplayLatestSelection = page.getByText('Always display latest');
        this.createReportLink = page.getByRole('link', { name: 'Create Report' });
        this.durationButton = page.getByRole('button', { name: 'Duration' });
        this.countOption = page.getByText('Count').first();
        this.processInstanceButton = page.getByRole('button', {
            name: 'Process Instance',
            exact: true,
        });
        this.userTaskOption = page.getByRole('menuitemcheckbox', {
            name: 'User Task',
        });
        this.heatMapButton = page.getByRole('button', { name: 'Heatmap Open menu' });
        this.numberButton = page.getByRole('menuitemcheckbox', { name: 'Number' });
        this.tableOption = page.getByRole('menuitemcheckbox', { name: 'Table' });
        this.reportName = page.getByPlaceholder('Report name');
        this.saveButton = page.getByRole('button', { name: 'Save' });
        this.oneUserTaskInstance = page.getByRole('cell', { name: '1', exact: true });
        this.twoUserTaskInstance = page.getByRole('cell', { name: '2', exact: true });
        this.cancelButton = page.getByRole('button', { name: 'Cancel' });
        this.createNewButton = page.getByRole('button', {
            name: 'Create New',
            exact: true,
        });
        this.reportOption = page.getByText('Report', { exact: true });
        this.processInstanceCount = page.locator('.progressLabel');
        this.blankReportButton = page.getByRole('button', { name: 'Blank report' });
        this.selectDropdown = page
            .getByRole('button', { name: 'Select... Open menu' })
            .last();
    }
    async clickProcessSelectionButton() {
        await this.processSelectionButton.click();
    }
    async clickUserTaskProcess(processName) {
        await this.page
            .getByText(processName, { exact: true })
            .first()
            .click({ timeout: 90000 });
    }
    async clickVersionSelection() {
        await this.versionSelection.click();
    }
    async clickAlwaysDisplayLatestSelection() {
        await this.alwaysDisplayLatestSelection.click();
    }
    async clickCreateReportLink() {
        await this.createReportLink.click({ timeout: 60000 });
    }
    async clickDurationButton() {
        await this.durationButton.click();
    }
    async clickCountOption() {
        await this.countOption.click();
    }
    async clickProcessInstanceButton() {
        await this.processInstanceButton.click();
    }
    async clickUserTaskOption() {
        await this.userTaskOption.click({ timeout: 60000 });
    }
    async clickHeatMapButton() {
        if (await this.heatMapButton.isVisible()) {
            await this.heatMapButton.click({ timeout: 60000 });
        }
    }
    async clickNumberButton() {
        if (await this.numberButton.isVisible()) {
            await this.numberButton.click();
        }
    }
    async clickTableOption() {
        await this.tableOption.click();
    }
    async clickReportName() {
        await this.reportName.click();
    }
    async clearReportName() {
        await this.reportName.clear({ force: true });
    }
    async fillReportName(name) {
        await this.reportName.fill(name, { force: true });
    }
    async clickSaveButton() {
        await this.saveButton.click();
    }
    async waitUntilLocatorIsVisible(locator, tab) {
        let elapsedTime = 0;
        const maxWaitTimeSeconds = 120000;
        while (elapsedTime < maxWaitTimeSeconds) {
            const element = await locator;
            if (await element.isVisible()) {
                return;
            }
            await tab.reload();
            await tab.waitForTimeout(10 * 1000);
            // Update the elapsed time
            elapsedTime += 10000;
        }
    }
    async waitUntilProcessIsVisible(locator, tab) {
        let elapsedTime = 0;
        const maxWaitTimeSeconds = 240000;
        while (elapsedTime < maxWaitTimeSeconds) {
            const element = await locator;
            if (await element.isVisible()) {
                return;
            }
            await this.cancelButton.click();
            await tab.reload();
            await tab.waitForTimeout(10 * 1000);
            // Update the elapsed time
            elapsedTime += 10000;
            await this.createNewButton.click();
            await this.reportOption.click();
            await this.processSelectionButton.click();
        }
    }
    async clickBlankReportButton() {
        await this.blankReportButton.click();
    }
    async clickSelectDropdown() {
        await this.selectDropdown.click();
    }
}
exports.OptimizeReportPage = OptimizeReportPage;
