"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FormJsPage = void 0;
const test_1 = require("@playwright/test");
const sleep_1 = require("../../utils/sleep");
class FormJsPage {
    page;
    aiFormGeneratorButton;
    formRequestInput;
    generateFormButton;
    textField;
    formEditor;
    keyInput;
    generalPanel;
    textFieldInForm;
    deployButton;
    deploySubButton;
    dialog;
    deploySuccessNotification;
    constructor(page) {
        this.page = page;
        this.aiFormGeneratorButton = page.getByRole('button', {
            name: 'AI Form Generator',
        });
        this.formRequestInput = page.getByPlaceholder('A form for an american standard loan request');
        this.generateFormButton = page.getByRole('button', { name: 'Generate form' });
        this.textField = page.locator('button[data-field-type="textfield"]');
        this.formEditor = page.getByLabel('Form Definition');
        this.generalPanel = page.locator('[data-group-id="group-general"]').first();
        this.keyInput = page.getByRole('textbox', { name: 'key' });
        this.textFieldInForm = page.getByLabel('Form Definition');
        this.deployButton = page
            .locator('[data-test="action-bar"]')
            .getByRole('button', { name: 'Deploy', exact: true });
        this.dialog = page
            .locator('.cds--modal-container[role="dialog"]')
            .filter({ hasText: 'Deploy form' });
        this.deploySubButton = this.dialog.getByRole('button', {
            name: 'Deploy',
            exact: true,
        });
        this.deploySuccessNotification = page
            .locator('.cds--toast-notification--success')
            .filter({ hasText: 'Form deployed!' });
    }
    async clickAIFormGeneratorButton() {
        await this.aiFormGeneratorButton.click();
    }
    async generateAIForm(request = 'Create a form with the following fields: 1. A text field with the label "Full Name" 2. A number with the label "Count" 3. A date input with the label "Date of birth"4. A Checkbox with the label "Agree"') {
        await (0, test_1.expect)(this.aiFormGeneratorButton).toBeVisible({
            timeout: 90000,
        });
        await this.clickAIFormGeneratorButton();
        await this.clickFormRequestInput();
        await this.fillFormRequestInput(request);
        await this.clickGenerateFormButton();
        await (0, test_1.expect)(this.page.getByText('Generating...')).toBeVisible();
        await (0, test_1.expect)(this.page.getByText('Successfully generated smart form.')).toBeVisible({ timeout: 300000 });
        await (0, sleep_1.sleep)(60000);
    }
    async clickFormRequestInput() {
        await this.formRequestInput.click();
    }
    async fillFormRequestInput(formRequest) {
        await this.formRequestInput.fill(formRequest);
    }
    async clickGenerateFormButton() {
        await this.generateFormButton.click();
    }
    async dragAndDrop(source, target) {
        await source.waitFor();
        await target.waitFor();
        await source.dragTo(target);
    }
    async fillKeyInput(key) {
        await this.keyInput.fill(key, { timeout: 60000 });
    }
    async clickGeneralPropertiesPanel() {
        await this.generalPanel.click({ timeout: 60000 });
    }
    async selectCluster(clusterName) {
        await (0, test_1.expect)(this.dialog).toBeVisible({ timeout: 30000 });
        const healthCheckTimeout = 30000;
        const healthyRegex = new RegExp(`${clusterName}[\\s\\S]*?HealthydevManage`);
        const cluster = this.dialog.locator(`[title="${clusterName}"]`);
        await (0, test_1.expect)(cluster).toBeVisible({ timeout: 30000 });
        await cluster.click();
        await (0, test_1.expect)(this.dialog
            .locator('label')
            .filter({ hasText: clusterName })
            .getByRole('switch')).toBeChecked({ timeout: 30000 });
        await (0, test_1.expect)(this.dialog).toHaveText(healthyRegex, {
            timeout: healthCheckTimeout,
        });
    }
    async clickDeployButton() {
        await this.deployButton.click({ timeout: 60000 });
    }
    async clickDeploySubButton() {
        await this.deploySubButton.click({ timeout: 60000 });
    }
    async deployForm(clusterName) {
        await this.clickDeployButton();
        await (0, test_1.expect)(this.dialog).toBeVisible({
            timeout: 30000,
        });
        await this.selectCluster(clusterName);
        await this.clickDeploySubButton();
        await (0, test_1.expect)(this.deploySuccessNotification).toBeVisible({ timeout: 30000 });
    }
}
exports.FormJsPage = FormJsPage;
