"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModelerHomePage = void 0;
const test_1 = require("@playwright/test");
const expectLocatorWithRetry_1 = require("../../utils/assertionHelpers/expectLocatorWithRetry");
class ModelerHomePage {
    page;
    defaultFolderName;
    modelerPageBanner;
    createNewProjectButton;
    projectNameInput;
    chooseBpmnTemplateButton;
    diagramTypeDropdown;
    bpmnTemplateOption;
    formTemplateOption;
    projectBreadcrumb;
    openOrganizationsButton;
    manageButton;
    crossComponentProjectFolder;
    homeBreadcrumb;
    formNameInput;
    rows;
    licenseKeyTagNonProduction;
    licenseKeyTagNonCommercial;
    licenseKeyTagProduction;
    licenseKeyTagCommercial;
    uploadFilesButton;
    constructor(page, folderName) {
        this.page = page;
        this.defaultFolderName = folderName;
        this.modelerPageBanner = page
            .locator('a')
            .filter({ hasText: 'Camunda logoModeler' });
        this.createNewProjectButton = page.getByRole('button', {
            name: 'New project',
        });
        this.projectNameInput = page.locator('[data-test="editable-input"]');
        this.chooseBpmnTemplateButton = page.getByRole('button', {
            name: 'Choose BPMN template',
        });
        this.diagramTypeDropdown = page.locator('[data-test="diagram-dropdown"]');
        this.bpmnTemplateOption = page
            .locator('[data-test="create-bpmn-diagram"]')
            .getByText('BPMN Diagram');
        this.formTemplateOption = page
            .locator('[data-test="create-form"]')
            .getByText('Form');
        this.projectBreadcrumb = page.locator('[data-test="breadcrumb-project"]');
        this.openOrganizationsButton = page.getByLabel('Open Organizations');
        this.manageButton = page.getByRole('button', { name: 'Manage' });
        this.crossComponentProjectFolder = page
            .getByTitle(this.defaultFolderName, {
            exact: true,
        })
            .first();
        this.homeBreadcrumb = page.locator('[data-test="breadcrumb-home"]');
        this.formNameInput = page.locator('[data-test="editable-input"]');
        this.rows = page.getByRole('row');
        this.licenseKeyTagNonProduction = page
            .getByText('Non-production license')
            .first();
        this.licenseKeyTagNonCommercial = page.getByText('Non-commercial license');
        this.licenseKeyTagProduction = page.getByText('Production license').first();
        this.licenseKeyTagCommercial = page.getByText('Commercial license');
        this.uploadFilesButton = page.getByRole('menuitem', { name: 'Upload files' });
    }
    async clickCreateNewProjectButton() {
        await (0, expectLocatorWithRetry_1.expectLocatorWithRetry)(this.page, this.createNewProjectButton);
        await this.createNewProjectButton.click({ timeout: 10000 });
    }
    async enterNewProjectName(name) {
        await this.projectNameInput.click({ timeout: 5000 });
        await this.projectNameInput.fill(name);
        await this.projectNameInput.press('Enter');
    }
    async createCrossComponentProjectFolder() {
        await this.enterNewProjectName(this.defaultFolderName);
    }
    async clickCrossComponentProjectFolder() {
        await this.page
            .getByTitle(this.defaultFolderName, {
            exact: true,
        })
            .first()
            .click({ timeout: 4000 });
    }
    async clickProcessDiagram(name) {
        const process = this.rows.filter({ hasText: name }).getByTitle(name).first();
        await (0, test_1.expect)(process).toBeVisible({ timeout: 5000 });
        await process.click();
    }
    async clickHomeBreadcrumb() {
        try {
            await this.homeBreadcrumb.click();
        }
        catch (error) {
            await this.page.getByText('Home', { exact: true }).first().click();
        }
    }
    async clickChooseBpmnTemplateButton() {
        await this.chooseBpmnTemplateButton.click();
    }
    async clickDiagramTypeDropdown() {
        await (0, test_1.expect)(this.diagramTypeDropdown).toBeVisible({
            timeout: 5000,
        });
        await this.diagramTypeDropdown.click();
    }
    async clickBpmnTemplateOption() {
        await this.bpmnTemplateOption.click();
    }
    async clickFormOption() {
        await this.formTemplateOption.click();
    }
    async enterFormName(name) {
        await this.formNameInput.click();
        await this.formNameInput.fill(name);
        await this.formNameInput.press('Enter');
    }
    async clickProjectBreadcrumb() {
        await this.projectBreadcrumb.click();
    }
    async clickOpenOrganizationsButton() {
        await this.openOrganizationsButton.click();
    }
    async clickManageButton() {
        await this.manageButton.click({ timeout: 5000 });
    }
    async clickUploadFilesButton() {
        await this.uploadFilesButton.click();
    }
    getDefaultFolderName() {
        return this.defaultFolderName;
    }
}
exports.ModelerHomePage = ModelerHomePage;
