"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;
    webhookConfigurationTab;
    constructor(page) {
        this.page = page;
        this.urlInput = page.getByLabel('URL');
        this.resultExpressionInput = page.getByLabel('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();
        this.webhookConfigurationTab = page
            .locator('div')
            .filter({ hasText: /^Webhook configuration$/ })
            .first();
    }
    async clickUrlInput() {
        try {
            await this.urlInput.click({ timeout: 60000 });
        }
        catch {
            await this.httpEndpointTab.click();
            await this.urlInput.click({ timeout: 60000 });
        }
    }
    async fillUrlInput(url) {
        await this.urlInput.fill(url);
        await (0, test_1.expect)(this.page.getByText('URL must not be empty.')).not.toBeVisible({ timeout: 30000 });
    }
    async clickResultExpressionInput() {
        try {
            await this.resultExpressionInput.click();
        }
        catch {
            await this.clickOutputMappingTab();
            await this.resultExpressionInput.click();
        }
    }
    async fillResultExpressionInput(resultExpression) {
        await this.resultExpressionInput.fill(resultExpression);
    }
    async selectAuthenticationType(authentication) {
        await this.authenticationTypeDropdown.selectOption(authentication);
    }
    async clickUsernameInput() {
        await this.usernameInput.click({ timeout: 30000 });
    }
    async fillUsernameInput(username) {
        await this.usernameInput.fill(username, { timeout: 30000 });
        await (0, sleep_1.sleep)(1000);
    }
    async clickPasswordInput() {
        await this.passwordInput.click();
    }
    async fillPasswordInput(password) {
        await this.passwordInput.fill(password);
    }
    async selectMethodType(method) {
        await this.methodTypeDropdown.selectOption(method, { timeout: 60000 });
    }
    async clickResultVariableInput() {
        try {
            await this.resultVariableInput.click();
        }
        catch {
            await this.clickOutputMappingTab();
            await this.resultVariableInput.click();
        }
    }
    async fillResultVariableInput(variable) {
        await this.resultVariableInput.fill(variable);
    }
    async clickBearerTokenInput() {
        await this.bearerTokenInput.click({ timeout: 30000 });
    }
    async fillBearerTokenInput(token) {
        await this.bearerTokenInput.fill(token);
        await (0, sleep_1.sleep)(1000);
    }
    async clickAuthenticationTab() {
        await this.authenticationTab.click({ timeout: 60000 });
    }
    async clickOutputMappingTab() {
        await this.outputMappingTab.click({ timeout: 60000 });
    }
    async clickHTTPEndpointTab() {
        await this.httpEndpointTab.click({ timeout: 60000 });
    }
    async clickCorrelationTab() {
        await this.correlationTab.click({ timeout: 60000 });
    }
    async clickInputTab() {
        await this.inputTab.click({ timeout: 60000 });
    }
    async clickWebhookConfigurationTab() {
        await this.webhookConfigurationTab.click({ timeout: 60000 });
    }
}
exports.ConnectorSettingsPage = ConnectorSettingsPage;
