"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModelerCreatePage = void 0;
const test_1 = require("@playwright/test");
const ConnectorMarketplacePage_1 = require("./ConnectorMarketplacePage");
const sleep_1 = require("../../utils/sleep");
class ModelerCreatePage {
    page;
    generalPanel;
    idInput;
    taskDefinitionPanel;
    processIdInput;
    elemendIdInput;
    startEventElement;
    appendTaskButton;
    changeTypeButton;
    userTaskOption;
    serviceTaskOption;
    appendEndEventButton;
    appendGatewayButton;
    parallelGatewayOption;
    startInstanceMainButton;
    startInstanceSubButton;
    viewProcessInstanceLink;
    nameInput;
    jobTypeInput;
    diagramBreadcrumb;
    editDiagramNameButton;
    diagramNameInput;
    variableInput;
    embedFormButton;
    embedButton;
    newForm;
    deployMainButton;
    deploySubButton;
    cancelButton;
    restConnectorOption;
    marketPlaceButton;
    clusterEndpointTextbox;
    operateBaseUrlTextbox;
    tasklistBaseUrlTextbox;
    zeebeRestUrlTextbox;
    clientIdTextbox;
    clientSecretTextbox;
    oauthUrlTextbox;
    audienceTextbox;
    operateAudienceTextbox;
    tasklistAudienceTextbox;
    rememberCredentialsCheckbox;
    oAuthCheckbox;
    webhookMessageStartEventConnectorOption;
    webhookIdInput;
    implementationSection;
    assignmentSection;
    priorityInput;
    implementationOptions;
    secondElement;
    firstElement;
    appendElementButton;
    firstPlacedGateway;
    secondPlacedGateway;
    connectToOtherElementButton;
    canvas;
    playTab;
    continueToPlayButton;
    intermediateBoundaryEvent;
    intermediateWebhookConnectorOption;
    correlationKeyProcessInput;
    correlationKeyPayloadInput;
    candidateUsersInput;
    assigneeInput;
    candidateGroupsInput;
    thirdElement;
    tenantIdInput;
    dialog;
    timerEventOption;
    timerEventSettings;
    timerType;
    timerValue;
    eighthPlacedElement;
    processIdSecondLocator;
    constructor(page) {
        this.page = page;
        this.generalPanel = page.locator('[data-group-id="group-general"]');
        this.idInput = page.getByLabel('ID', { exact: true });
        this.taskDefinitionPanel = page.getByTitle('Task definition').first();
        this.processIdInput = page.getByLabel('ID', { exact: true });
        this.elemendIdInput = page.getByLabel('ID', { exact: true });
        this.startEventElement = page.locator('.djs-hit').first();
        this.appendTaskButton = page.getByTitle('Append task');
        this.changeTypeButton = page.getByRole('button', {
            name: 'Change element',
            exact: true,
        });
        this.userTaskOption = page
            .getByRole('listitem', { name: 'User task' })
            .locator('span')
            .first();
        this.serviceTaskOption = page.getByRole('listitem', { name: 'Service Task' });
        this.appendEndEventButton = page.getByTitle('Append end event');
        this.appendGatewayButton = page.getByTitle('append gateway');
        this.parallelGatewayOption = page.getByText('parallel gateway');
        this.startInstanceMainButton = page.locator('[data-test="start-instance-button"]');
        this.startInstanceSubButton = page
            .getByLabel('Start instance')
            .getByRole('button', { name: 'Run' });
        this.viewProcessInstanceLink = page.getByRole('link', {
            name: 'View process instance',
        });
        this.nameInput = page.getByLabel('Name', { exact: true });
        this.jobTypeInput = page.getByRole('textbox', { name: /job type/i });
        this.diagramBreadcrumb = page.locator('[data-test="breadcrumb-diagram"]');
        this.editDiagramNameButton = page.getByText('Edit name');
        this.diagramNameInput = page.locator('[data-test="editable-input"]');
        this.variableInput = page.getByLabel('Variables');
        this.embedFormButton = page.getByRole('button', { name: 'Link form' });
        this.embedButton = page.locator('[data-test="confirm-move"]');
        this.newForm = page.locator('[data-test="item-New Form"]');
        this.deployMainButton = page.locator('[data-test="deploy-button"]');
        this.continueToPlayButton = page.getByRole('button', { name: 'Continue' });
        this.deploySubButton = page
            .getByLabel('Deploy diagram')
            .getByRole('button', { name: 'Deploy' });
        this.cancelButton = page.getByRole('button', { name: 'Cancel' });
        this.restConnectorOption = page.getByRole('listitem', {
            name: 'REST Outbound Connector',
        });
        this.marketPlaceButton = page.getByTitle('Browse Marketplace for more Connectors');
        this.clusterEndpointTextbox = page.getByLabel('Cluster endpoint');
        this.operateBaseUrlTextbox = page.getByLabel('Operate base url');
        this.tasklistBaseUrlTextbox = page.getByLabel('Tasklist base url');
        this.zeebeRestUrlTextbox = page.getByLabel('Zeebe rest url');
        this.clientIdTextbox = page.getByLabel('Client ID');
        this.clientSecretTextbox = page.getByLabel('Client secret');
        this.oauthUrlTextbox = page.getByLabel('OAuth Token URL');
        this.audienceTextbox = page.getByLabel('OAuth Audience');
        this.operateAudienceTextbox = page.getByLabel('Operate Audience');
        this.tasklistAudienceTextbox = page.getByLabel('Tasklist Audience');
        this.rememberCredentialsCheckbox = page.getByText('Remember credentials');
        this.oAuthCheckbox = page.getByLabel('OAuth', { exact: true });
        this.webhookMessageStartEventConnectorOption = page.getByRole('listitem', {
            name: 'Webhook Message Start Event Connector',
            exact: true,
        });
        this.webhookIdInput = page.getByLabel('Webhook ID');
        this.firstElement = page.locator('[class="djs-element djs-shape"]').nth(0);
        this.secondElement = page.locator('[class="djs-element djs-shape"]').nth(1);
        this.thirdElement = page.locator('[class="djs-element djs-shape"]').nth(2);
        this.implementationSection = page.locator('[data-group-id="group-userTaskImplementation"]');
        this.implementationOptions = page.locator('#bio-properties-panel-userTaskImplementation');
        this.assignmentSection = page.locator('[data-group-id="group-assignmentDefinition"]');
        this.priorityInput = page.getByRole('textbox', { name: 'priority' });
        this.appendElementButton = page
            .locator('[class="djs-create-pad open djs-append-create-pad"]')
            .first();
        this.firstPlacedGateway = page
            .locator('[data-element-id*="Gateway"]')
            .first();
        this.secondPlacedGateway = page
            .locator('[data-element-id*="Gateway"]')
            .last();
        this.connectToOtherElementButton = page
            .getByLabel('Connect to other element')
            .locator('path');
        this.canvas = page.locator('rect').nth(1);
        this.playTab = page.getByRole('tab', {
            name: 'Play',
        });
        this.intermediateBoundaryEvent = page.getByTitle('Append intermediate/boundary');
        this.intermediateWebhookConnectorOption = page.getByRole('listitem', {
            name: 'Webhook Intermediate Event',
        });
        this.correlationKeyPayloadInput = page.getByLabel('Correlation key (payload)');
        this.correlationKeyProcessInput = page.getByLabel('Correlation key (process)');
        this.candidateUsersInput = page.getByRole('textbox', {
            name: 'candidate users',
        });
        this.assigneeInput = page.getByRole('textbox', { name: 'assignee' });
        this.candidateGroupsInput = page.getByRole('textbox', {
            name: 'candidate groups',
        });
        this.dialog = page.getByRole('dialog');
        this.tenantIdInput = page.getByLabel('Tenant ID');
        this.timerEventOption = page.getByRole('listitem', {
            name: 'Timer intermediate catch event',
            exact: true,
        });
        this.timerEventSettings = page.getByText(/^Timer$/).first();
        this.timerType = page.getByLabel('Type');
        this.timerValue = page.getByLabel('Value');
        this.eighthPlacedElement = page
            .locator('g:nth-child(8) > .djs-element > .djs-hit')
            .first();
        this.processIdSecondLocator = page.getByLabel('Process ID');
    }
    async switchToPlay() {
        await this.playTab.click();
    }
    async clickGeneralPropertiesPanel() {
        const isExpanded = (await this.generalPanel
            .locator('.bio-properties-panel-group-header.open')
            .count()) > 0;
        if (!isExpanded) {
            await this.generalPanel.click({ timeout: 60000 });
        }
    }
    async expandAssignmentSection() {
        const isExpanded = (await this.assignmentSection
            .locator('[data-group-id="group-assignmentDefinition"] .bio-properties-panel-group-header.open')
            .count()) > 0;
        if (!isExpanded) {
            await this.assignmentSection.click({ timeout: 60000 });
        }
    }
    async clickTaskDefinitionPropertiesPanel() {
        await this.taskDefinitionPanel.click();
    }
    async clickProcessIdInput() {
        await this.processIdInput.click();
    }
    async clickIdInput() {
        try {
            await this.processIdInput.click();
        }
        catch {
            await this.processIdSecondLocator.click();
        }
    }
    async fillIdInput(id) {
        try {
            await this.processIdInput.fill(id);
        }
        catch {
            await this.processIdSecondLocator.fill(id);
        }
    }
    async clickElemendIdInput() {
        await this.elemendIdInput.click();
    }
    async fillElementIdInput(id) {
        await (0, test_1.expect)(this.elemendIdInput).toBeVisible();
        await this.elemendIdInput.fill(id);
        await (0, test_1.expect)(this.elemendIdInput).toHaveValue(id);
        await (0, sleep_1.sleep)(1000);
    }
    async clickStartEventElement() {
        await this.startEventElement.click({ force: true });
    }
    async selectStartEventElement() {
        await this.startEventElement.click({ force: true });
    }
    async clickAppendTaskButton() {
        await this.appendTaskButton.click({ timeout: 90000 });
    }
    async clickAppendGatewayButton() {
        await this.appendGatewayButton.click({ timeout: 90000 });
    }
    async clickChangeTypeButton() {
        try {
            await this.changeTypeButton.click({ timeout: 180000, force: true });
        }
        catch {
            await this.page.reload();
            if (await this.secondElement.isVisible({ timeout: 6000 })) {
                await this.secondElement.click({ timeout: 90000, force: true });
                await this.changeTypeButton.click({ timeout: 90000, force: true });
            }
            else {
                await this.firstElement.click({ timeout: 90000, force: true });
                await this.changeTypeButton.click({ timeout: 90000, force: true });
            }
        }
    }
    async clickUserTaskOption() {
        const maxRetries = 3;
        for (let retries = 0; retries < maxRetries; retries++) {
            try {
                if (retries === 0) {
                    await this.userTaskOption.click({ timeout: 30000, force: true });
                }
                else {
                    await this.changeTypeButton.click({ force: true, timeout: 30000 });
                    await this.userTaskOption.click({ timeout: 30000, force: true });
                }
                return;
            }
            catch (error) {
                console.error(`Click attempt ${retries + 1} failed: ${error}`);
                await new Promise((resolve) => setTimeout(resolve, 10000));
            }
        }
        throw new Error(`Failed to click the button after ${maxRetries} attempts.`);
    }
    async clickServiceTaskOption() {
        const maxRetries = 3;
        for (let retries = 0; retries < maxRetries; retries++) {
            try {
                if (retries === 0) {
                    await this.serviceTaskOption.click({ timeout: 30000, force: true });
                }
                else {
                    await this.changeTypeButton.click({ force: true, timeout: 30000 });
                    await this.serviceTaskOption.click({ timeout: 30000, force: true });
                }
                return;
            }
            catch (error) {
                console.error(`Click attempt ${retries + 1} failed: ${error}`);
                await new Promise((resolve) => setTimeout(resolve, 10000));
            }
        }
        throw new Error(`Failed to click the button after ${maxRetries} attempts.`);
    }
    async clickAppendEndEventButton(parentElement) {
        try {
            await this.appendEndEventButton.click({ timeout: 120000 });
        }
        catch (error) {
            await this.page.reload();
            await (0, sleep_1.sleep)(10000);
            if (parentElement == undefined) {
                await this.clickSecondPlacedElement();
            }
            else if (parentElement == 'parallelGateway') {
                await this.clickSecondPlacedGateway();
            }
            await this.appendElementButton.hover();
            await this.appendEndEventButton.click({ timeout: 120000 });
        }
    }
    async clickFirstPlacedElement() {
        await this.firstElement.click({ timeout: 90000 });
    }
    async clickSecondPlacedElement() {
        await this.secondElement.click({ timeout: 60000 });
    }
    async clickFirstPlacedGateway() {
        try {
            await this.firstPlacedGateway.click({ timeout: 60000 });
            await this.appendElementButton.isVisible({ timeout: 60000 });
        }
        catch (error) {
            await this.page.reload();
            await (0, sleep_1.sleep)(10000);
            await this.firstPlacedGateway.click({ timeout: 60000 });
        }
    }
    async clickSecondPlacedGateway() {
        try {
            await this.secondPlacedGateway.click({ timeout: 60000 });
            await this.appendElementButton.isVisible({ timeout: 60000 });
        }
        catch (error) {
            await this.page.reload();
            await (0, sleep_1.sleep)(10000);
            await this.secondPlacedGateway.click({ timeout: 60000 });
        }
    }
    async clickStartInstanceMainButton() {
        await this.startInstanceMainButton.click({ timeout: 120000 });
    }
    async clickStartInstanceSubButton() {
        await this.startInstanceSubButton.click({ timeout: 120000 });
    }
    async clickViewProcessInstanceLink() {
        await this.viewProcessInstanceLink.click({ timeout: 90000 });
    }
    async clickNameInput() {
        await this.nameInput.click();
    }
    async fillNameInput(name) {
        await this.nameInput.fill(name);
    }
    async clickJobTypeInput() {
        await this.jobTypeInput.click();
    }
    async fillJobTypeInput(name) {
        await this.jobTypeInput.fill(name);
    }
    async clickDiagramBreadcrumb() {
        await this.diagramBreadcrumb.click({ timeout: 60000 });
    }
    async clickEditDiagramNameButton() {
        await this.editDiagramNameButton.click();
    }
    async enterDiagramName(name) {
        await this.diagramNameInput.fill(name, { timeout: 60000 });
        await this.diagramNameInput.press('Enter', { timeout: 60000 });
    }
    async clickVariableInput() {
        await this.variableInput.click();
    }
    async fillVariableInput(variable) {
        await this.variableInput.fill(variable);
    }
    async clickEmbedFormButton() {
        await this.embedFormButton.click({ timeout: 90000 });
    }
    async clickEmbedButton() {
        await this.embedButton.click();
    }
    async clickDeployMainButton() {
        await this.deployMainButton.click({ timeout: 90000 });
    }
    async clickDeploySubButton() {
        await this.deploySubButton.click({ timeout: 90000 });
    }
    async clickCancelButton() {
        await this.cancelButton.click();
    }
    async clickRestConnectorOption() {
        const maxRetries = 4;
        for (let retries = 0; retries < maxRetries; retries++) {
            try {
                if (retries === 0) {
                    // First attempt
                    await this.restConnectorOption.click({ timeout: 60000 });
                }
                else if (retries === 1 || retries === 2) {
                    // Second or third attempt
                    await this.page.reload();
                    await this.secondElement.click({ timeout: 60000 });
                    await this.changeTypeButton.click({ force: true, timeout: 60000 });
                    await this.restConnectorOption.click({ timeout: 90000 });
                }
                else {
                    // Forth and subsequent attempts
                    await this.clickMarketPlaceButton();
                    const connectorMarketplacePage = new ConnectorMarketplacePage_1.ConnectorMarketplacePage(this.page);
                    await connectorMarketplacePage.clickSearchForConnectorTextbox();
                    await connectorMarketplacePage.fillSearchForConnectorTextbox('REST Connector');
                    await (0, sleep_1.sleep)(10000);
                    await connectorMarketplacePage.downloadConnectorToProject();
                    await this.clickChangeTypeButton();
                    await this.restConnectorOption.click({ timeout: 120000 });
                }
                return;
            }
            catch (error) {
                console.error(`Click attempt ${retries + 1} failed: ${error}`);
                await new Promise((resolve) => setTimeout(resolve, 10000));
            }
        }
        throw new Error(`Failed to click the button after ${maxRetries} attempts.`);
    }
    async clickMarketPlaceButton() {
        const maxRetries = 3;
        for (let retries = 0; retries < maxRetries; retries++) {
            try {
                if (retries === 0) {
                    await this.marketPlaceButton.click({ timeout: 30000 });
                }
                else {
                    await this.changeTypeButton.click({ force: true, timeout: 30000 });
                    await this.marketPlaceButton.click({ timeout: 30000 });
                }
                return;
            }
            catch (error) {
                console.error(`Click attempt ${retries + 1} failed: ${error}`);
                await new Promise((resolve) => setTimeout(resolve, 10000));
            }
        }
        throw new Error(`Failed to click the button after ${maxRetries} attempts.`);
    }
    async clickClusterEndpointTextbox() {
        await this.clusterEndpointTextbox.click();
    }
    async fillClusterEndpointTextbox(clusterEndpoint) {
        await this.clusterEndpointTextbox.fill(clusterEndpoint);
    }
    async completeDeploymentEndpointConfiguration() {
        await this.oAuthCheckbox.click({ timeout: 30000 });
        await this.clusterEndpointTextbox.click({ timeout: 30000 });
        await this.clusterEndpointTextbox.fill(process.env.CLUSTER_ENDPOINT, {
            timeout: 30000,
        });
        await (0, test_1.expect)(this.clientIdTextbox).toBeVisible({ timeout: 30000 });
        await this.clientIdTextbox.click({ timeout: 30000 });
        await this.clientIdTextbox.fill('test', { timeout: 30000 });
        await this.clientSecretTextbox.click({ timeout: 30000 });
        await this.clientSecretTextbox.fill(process.env.DISTRO_QA_E2E_TESTS_KEYCLOAK_CLIENTS_SECRET);
        await this.oauthUrlTextbox.click({ timeout: 30000 });
        await this.oauthUrlTextbox.fill(process.env.OAUTH_URL);
        await this.audienceTextbox.click({ timeout: 30000 });
        await this.audienceTextbox.fill('zeebe-api');
        await this.rememberCredentialsCheckbox.click({ timeout: 30000 });
    }
    async completePlayConfiguration() {
        const timeout = 30000;
        let attempts = 0;
        const maxRetries = 2;
        while (attempts < maxRetries) {
            try {
                if (attempts > 0)
                    await this.switchToPlay(); // Call switchToPlay on subsequent attempts
                await this.clusterEndpointTextbox.click({ timeout });
                await this.clusterEndpointTextbox.fill(process.env.CLUSTER_ENDPOINT, {
                    timeout,
                });
                await this.operateBaseUrlTextbox.click({ timeout });
                await this.operateBaseUrlTextbox.fill(process.env.OPERATE_BASE_URL, {
                    timeout,
                });
                await this.tasklistBaseUrlTextbox.click({ timeout });
                await this.tasklistBaseUrlTextbox.fill(process.env.TASKLIST_BASE_URL, {
                    timeout,
                });
                await this.zeebeRestUrlTextbox.click({ timeout });
                await this.zeebeRestUrlTextbox.fill(process.env.ZEEBE_REST_URL, {
                    timeout,
                });
                await this.clientIdTextbox.click({ timeout });
                await this.clientIdTextbox.fill('test', { timeout });
                await this.clientSecretTextbox.click({ timeout });
                await this.clientSecretTextbox.fill(process.env.DISTRO_QA_E2E_TESTS_KEYCLOAK_CLIENTS_SECRET);
                await this.oauthUrlTextbox.click({ timeout });
                await this.oauthUrlTextbox.fill(process.env.OAUTH_URL);
                await this.audienceTextbox.click({ timeout });
                await this.audienceTextbox.fill('zeebe-api');
                await this.operateAudienceTextbox.click({ timeout });
                await this.operateAudienceTextbox.fill('operate-api');
                await this.tasklistAudienceTextbox.click({ timeout });
                await this.tasklistAudienceTextbox.fill('tasklist-api');
                await this.continueToPlayButton.click({ timeout });
                await (0, test_1.expect)(this.page.getByText('Play environment is ready')).toBeVisible({ timeout: 90000 });
                await (0, test_1.expect)(this.dialog).not.toBeVisible();
                return; // Exit if successful
            }
            catch (error) {
                if (attempts >= maxRetries - 1)
                    throw error;
                await this.page.reload();
                attempts++;
            }
        }
    }
    async clickWebhookStartEventConnectorOption() {
        const maxRetries = 3;
        for (let retries = 0; retries < maxRetries; retries++) {
            try {
                if (retries === 0) {
                    await this.webhookMessageStartEventConnectorOption.click({
                        timeout: 30000,
                    });
                }
                else {
                    await this.changeTypeButton.click({ force: true, timeout: 30000 });
                    await this.webhookMessageStartEventConnectorOption.click({
                        timeout: 90000,
                    });
                }
                return;
            }
            catch (error) {
                console.error(`Click attempt ${retries + 1} failed: ${error}`);
                await new Promise((resolve) => setTimeout(resolve, 10000));
            }
        }
        throw new Error(`Failed to click the button after ${maxRetries} attempts.`);
    }
    async clickWebhookIdInput() {
        await this.webhookIdInput.click();
    }
    async clearWebhookIdInput() {
        await this.webhookIdInput.clear();
    }
    async fillWebhookIdInput(webhookId) {
        await this.webhookIdInput.fill(webhookId);
    }
    async hoverOnStartEvent() {
        await this.startEventElement.hover();
    }
    async instanceStartedAssertion() {
        try {
            await (0, test_1.expect)(this.page.getByText('Instance started!')).toBeVisible({
                timeout: 180000,
            });
        }
        catch {
            await this.clickStartInstanceMainButton();
            await this.completeDeploymentEndpointConfiguration();
            await this.clickStartInstanceSubButton();
            await (0, test_1.expect)(this.page.getByText('Instance started!')).toBeVisible({
                timeout: 180000,
            });
        }
    }
    async chooseImplementationOption(implementationType) {
        const isExpanded = (await this.implementationSection
            .locator('.bio-properties-panel-group-header open')
            .count()) > 0;
        if (!isExpanded) {
            await this.implementationSection.click();
        }
        await this.implementationOptions.selectOption(implementationType);
    }
    async clickAppendElementButton() {
        try {
            await (0, sleep_1.sleep)(10000);
            await this.appendElementButton.hover({ timeout: 60000, force: true });
        }
        catch (error) {
            await (0, sleep_1.sleep)(10000);
            await this.appendElementButton.hover({ timeout: 90000, force: true });
        }
    }
    async clickParallelGatewayOption() {
        await this.parallelGatewayOption.click({ timeout: 90000 });
    }
    async clickConnectToOtherElementButton() {
        await this.connectToOtherElementButton.click({ timeout: 60000 });
    }
    async clickPriorityInput() {
        try {
            await this.priorityInput.click();
        }
        catch (error) {
            await this.assignmentSection.click({ timeout: 60000 });
            await this.priorityInput.click({ timeout: 60000 });
        }
    }
    async fillPriorityInput(priority) {
        await this.priorityInput.fill(priority, { timeout: 60000 });
    }
    async clickCanvas() {
        await this.canvas.click({ timeout: 60000 });
    }
    async addParallelUserTasks(numberOfTasks, taskName) {
        try {
            await this.clickAppendElementButton();
        }
        catch (error) {
            await this.page.reload();
            await (0, sleep_1.sleep)(10000);
            await this.clickFirstPlacedElement();
            await this.appendElementButton.hover();
        }
        await this.clickAppendGatewayButton();
        await this.clickChangeTypeButton();
        await this.clickParallelGatewayOption();
        await this.clickAppendElementButton();
        await this.clickAppendTaskButton();
        await this.clickChangeTypeButton();
        await this.clickUserTaskOption();
        await this.clickGeneralPropertiesPanel();
        await this.clickNameInput();
        await this.fillNameInput(taskName + '1');
        await this.clickIdInput();
        await this.fillIdInput(taskName + '1');
        await this.chooseImplementationOption('zeebeUserTask');
        await this.clickAppendElementButton();
        await this.clickAppendGatewayButton();
        await this.clickChangeTypeButton();
        await this.clickParallelGatewayOption();
        for (let i = 2; i <= numberOfTasks; i++) {
            await this.clickFirstPlacedGateway();
            await this.clickAppendElementButton();
            await this.clickAppendTaskButton();
            await this.clickChangeTypeButton();
            await this.clickUserTaskOption();
            await this.clickNameInput();
            await this.fillNameInput(taskName + i);
            await this.clickIdInput();
            await this.fillIdInput(taskName + i);
            await this.chooseImplementationOption('zeebeUserTask');
            await this.clickConnectToOtherElementButton();
            await this.clickSecondPlacedGateway();
            await this.clickCanvas();
        }
        await this.clickSecondPlacedGateway();
    }
    async setPriority(taskName, priority, numberOfTasks) {
        for (let i = 1; i <= numberOfTasks; i++) {
            const userTaskId = taskName + i;
            const priorityUserTask = this.page.locator(`g[data-element-id="${userTaskId}"]`);
            await priorityUserTask.click();
            await this.clickPriorityInput();
            await this.fillPriorityInput(priority.toString());
            await this.clickCanvas();
            priority += 25;
        }
    }
    async clickIntermediateBoundaryEvent() {
        await this.intermediateBoundaryEvent.click({ timeout: 60000 });
    }
    async clickIntermediateWebhookConnectorOption() {
        await this.intermediateWebhookConnectorOption.click({ timeout: 60000 });
    }
    async clickCorrelationKeyProcessInput() {
        await this.correlationKeyProcessInput.click({ timeout: 60000 });
    }
    async fillCorrelationKeyProcessInput(correlationKeyProcess) {
        await this.correlationKeyProcessInput.fill(correlationKeyProcess);
    }
    async clickCorrelationKeyPayloadInput() {
        await this.correlationKeyPayloadInput.click({ timeout: 60000 });
    }
    async fillCorrelationKeyPayloadInput(correlationKeyPayload) {
        await this.correlationKeyPayloadInput.fill(correlationKeyPayload);
    }
    async selectUserTask(userTask) {
        await this.page.locator(`[data-element-id="${userTask}"]`).click();
    }
    async clickCandidateUsersInput() {
        await this.candidateUsersInput.click({ timeout: 60000 });
    }
    async fillCandidateUsersInput(candidateUser) {
        await this.candidateUsersInput.fill(candidateUser, { timeout: 60000 });
    }
    async clickAssigneeInput() {
        await this.assigneeInput.click({ timeout: 60000 });
    }
    async fillAssigneeInput(name) {
        await this.assigneeInput.fill(name, { timeout: 60000 });
    }
    async clickCandidateGroupsInput() {
        await this.candidateGroupsInput.click({ timeout: 60000 });
    }
    async fillCandidateGroupsInput(candidateGroup) {
        await this.candidateGroupsInput.fill(candidateGroup, { timeout: 60000 });
    }
    async deployProcessInstance() {
        await this.clickDeployMainButton();
        await this.completeDeploymentEndpointConfiguration();
        await this.clickDeploySubButton();
        await (0, test_1.expect)(this.page.getByText('Diagram Deployed!')).toBeVisible({
            timeout: 180000,
        });
    }
    // Function to model a simple Camunda User Task Diagram with or without a form
    async modelCamundaUserTaskDiagram(processName, processId = '', formName = '') {
        await (0, test_1.expect)(this.generalPanel).toBeVisible({
            timeout: 180000,
        });
        await this.enterDiagramName(processName);
        await (0, sleep_1.sleep)(15000);
        if (typeof processId === 'string' && processId.trim().length > 0) {
            await this.selectStartEventElement();
            await this.clickGeneralPropertiesPanel();
            try {
                await (0, test_1.expect)(this.elemendIdInput).toBeVisible();
            }
            catch (error) {
                console.log('ID input not visible, retrying...');
                await this.clickGeneralPropertiesPanel();
                await (0, test_1.expect)(this.elemendIdInput).toBeVisible();
            }
            await this.clickIdInput();
            await this.fillIdInput(processId);
            await this.selectStartEventElement();
        }
        await this.clickAppendElementButton();
        await this.clickAppendTaskButton();
        await this.clickChangeTypeButton();
        await this.clickUserTaskOption();
        await this.chooseImplementationOption('zeebeUserTask');
        if (formName.length > 0) {
            await this.clickEmbedFormButton();
            await this.clickForm(formName);
            await this.clickEmbedButton();
        }
        await this.clickAppendElementButton();
        await this.clickAppendEndEventButton();
        await this.clickCanvas();
        await this.assertThreeElementsVisible();
        await (0, sleep_1.sleep)(20000);
    }
    async assertImplementationOption(implementationType) {
        await this.expandImplementationOptionIfNecessary();
        (0, test_1.expect)(await this.implementationOptions.inputValue()).toEqual(implementationType);
    }
    async expandImplementationOptionIfNecessary() {
        const isExpanded = (await this.implementationSection
            .locator('.bio-properties-panel-group-header empty open')
            .count()) > 0;
        if (!isExpanded) {
            await this.implementationSection.click();
        }
    }
    async modelJobWorkerDiagram(processName) {
        await (0, test_1.expect)(this.generalPanel).toBeVisible({
            timeout: 120000,
        });
        await this.enterDiagramName(processName);
        await (0, sleep_1.sleep)(15000);
        await this.clickGeneralPropertiesPanel();
        await this.clickIdInput();
        await this.fillIdInput(processName);
        await this.clickAppendElementButton();
        await this.clickAppendTaskButton();
        await this.clickChangeTypeButton();
        await this.clickUserTaskOption();
        await this.chooseImplementationOption('jobWorker');
        await this.clickAppendElementButton();
        await this.clickAppendEndEventButton();
        await (0, sleep_1.sleep)(20000);
    }
    async runProcessInstance(variables = '') {
        await this.clickStartInstanceMainButton();
        await this.completeDeploymentEndpointConfiguration();
        await (0, test_1.expect)(this.dialog).toBeVisible({
            timeout: 30000,
        });
        if (variables.length > 0) {
            await (0, test_1.expect)(this.variableInput).toBeVisible({
                timeout: 60000,
            });
            await this.clickVariableInput();
            await this.fillVariableInput(variables);
        }
        await this.clickStartInstanceSubButton();
        await this.instanceStartedAssertion();
    }
    async clickForm(name) {
        await this.page
            .locator(`[data-test="item-${name}"]`)
            .getByText(name)
            .click({ timeout: 90000 });
    }
    async assertThreeElementsVisible() {
        await (0, test_1.expect)(this.firstElement).toBeVisible({ timeout: 30000 });
        await (0, test_1.expect)(this.secondElement).toBeVisible({ timeout: 30000 });
        await (0, test_1.expect)(this.thirdElement).toBeVisible({ timeout: 30000 });
    }
    async clickTenantIdInput() {
        await this.tenantIdInput.click({ timeout: 60000 });
    }
    async fillTenantIdInput(tenant) {
        await this.tenantIdInput.fill(tenant, { timeout: 60000 });
        await (0, sleep_1.sleep)(1000);
    }
    async clickTimerEventOption() {
        await this.timerEventOption.click();
    }
    async clickTimerEventSettings() {
        await this.timerEventSettings.click();
    }
    async selectTimerType(type) {
        await this.timerType.selectOption(type);
    }
    async clickTimerValue() {
        await this.timerValue.click();
    }
    async fillTimerValue(value) {
        await this.timerValue.fill(value);
    }
    async clickEighthPlacedElement() {
        await this.eighthPlacedElement.click();
    }
}
exports.ModelerCreatePage = ModelerCreatePage;
