"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConnectorSettingsPage = void 0;
const test_1 = require("@playwright/test");
const sleep_1 = require("../../utils/sleep");
class ConnectorSettingsPage {
    page;
    urlInput;
    resultExpressionInput;
    authenticationTypeDropdown;
    usernameInput;
    passwordInput;
    methodTypeDropdown;
    resultVariableInput;
    bearerTokenInput;
    authenticationTab;
    outputMappingTab;
    httpEndpointTab;
    correlationTab;
    inputTab;
    constructor(page) {
        this.page = page;
        this.urlInput = page.getByLabel('URL');
        this.resultExpressionInput = page.getByRole('textbox', {
            name: /^Result expression$/,
        });
        this.authenticationTypeDropdown = page.getByLabel('Type');
        this.usernameInput = page.getByLabel('Username');
        this.passwordInput = page.getByLabel('Password');
        this.methodTypeDropdown = page.getByLabel('Method');
        this.resultVariableInput = page.getByLabel('Result variable');
        this.bearerTokenInput = page.getByLabel('Bearer token');
        this.authenticationTab = page
            .locator('div')
            .filter({ hasText: /^Authentication$/ })
            .first();
        this.outputMappingTab = page
            .locator('div')
            .filter({ hasText: /^Output mapping$/ })
            .first();
        this.httpEndpointTab = page
            .locator('div')
            .filter({ hasText: /^HTTP endpoint$/ })
            .first();
        this.correlationTab = page
            .locator('div')
            .filter({ hasText: /^Correlation$/ })
            .first();
        this.inputTab = page
            .locator('div')
            .filter({ hasText: /^Input$/ })
            .first();
    }
    async clickUrlInput() {
        await this.urlInput.click({ timeout: 90000 });
    }
    async fillUrlInput(url) {
        await this.urlInput.fill(url, { timeout: 90000 });
        (0, test_1.expect)(await this.urlInput.inputValue()).toEqual(url);
        await (0, test_1.expect)(this.page.getByText('URL must not be empty.')).not.toBeVisible({
            timeout: 30000,
        });
        await this.page.waitForTimeout(1000);
    }
    async clickResultExpressionInput() {
        await this.resultExpressionInput.click({ timeout: 90000 });
    }
    async fillResultExpressionInput(resultExpression) {
        await this.resultExpressionInput.fill(resultExpression, {
            timeout: 120000,
            force: true,
        });
        (0, test_1.expect)(await this.resultExpressionInput.textContent()).toEqual(resultExpression);
        await this.page.waitForTimeout(1000);
    }
    async selectAuthenticationType(authentication) {
        await this.authenticationTypeDropdown.selectOption(authentication, {
            timeout: 20000,
        });
    }
    async clickUsernameInput() {
        await this.usernameInput.click({ timeout: 90000 });
    }
    async fillUsernameInput(username) {
        await this.usernameInput.fill(username, { timeout: 60000 });
        (0, test_1.expect)(await this.usernameInput.inputValue()).toEqual(username);
        await (0, test_1.expect)(this.page.getByText('Username must not be empty.')).not.toBeVisible({
            timeout: 30000,
        });
        await this.page.waitForTimeout(1000);
    }
    async clickPasswordInput() {
        await this.passwordInput.click({ timeout: 60000 });
    }
    async fillPasswordInput(password) {
        await this.passwordInput.fill(password, { timeout: 60000 });
        (0, test_1.expect)(await this.passwordInput.inputValue()).toEqual(password);
        await (0, test_1.expect)(this.page.getByText('Password must not be empty.')).not.toBeVisible({
            timeout: 30000,
        });
        await this.page.waitForTimeout(1000);
    }
    async selectMethodType(method) {
        await this.methodTypeDropdown.selectOption(method, { timeout: 60000 });
    }
    async clickResultVariableInput() {
        await (0, test_1.expect)(this.resultVariableInput).toBeVisible({
            timeout: 15000,
        });
        await this.resultVariableInput.click();
    }
    async fillResultVariableInput(variable) {
        await this.resultVariableInput.fill(variable, { timeout: 90000 });
        (0, test_1.expect)(await this.resultVariableInput.inputValue()).toEqual(variable);
        await (0, sleep_1.sleep)(1000);
    }
    async clickBearerTokenInput() {
        await this.bearerTokenInput.click({ timeout: 90000 });
    }
    async fillBearerTokenInput(token) {
        await this.bearerTokenInput.fill(token, { timeout: 60000 });
        (0, test_1.expect)(await this.bearerTokenInput.inputValue()).toEqual(token);
        await (0, test_1.expect)(this.page.getByText('Bearer token must not be empty.')).not.toBeVisible({
            timeout: 30000,
        });
    }
    async clickAuthenticationTab() {
        await (0, test_1.expect)(this.authenticationTab).toBeVisible({ timeout: 15000 });
        await this.authenticationTab.click();
    }
    async clickOutputMappingTab() {
        await this.outputMappingTab.click({ timeout: 60000 });
    }
    async clickHTTPEndpointTab() {
        await (0, test_1.expect)(this.httpEndpointTab).toBeVisible({ timeout: 15000 });
        await this.httpEndpointTab.click();
    }
    async clickCorrelationTab() {
        await this.correlationTab.click({ timeout: 60000 });
    }
    async clickInputTab() {
        await this.inputTab.click({ timeout: 60000 });
    }
}
exports.ConnectorSettingsPage = ConnectorSettingsPage;
