"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConnectorMarketplacePage = void 0;
const test_1 = require("@playwright/test");
class ConnectorMarketplacePage {
    page;
    searchForConnectorTextbox;
    downloadToProjectButton;
    snackbar;
    closeButton;
    replaceResourceButton;
    cancelButton;
    constructor(page) {
        this.page = page;
        this.searchForConnectorTextbox = page.getByPlaceholder('Search for a connector');
        this.downloadToProjectButton = page
            .getByRole('button', { name: 'Download to project' })
            .first();
        this.snackbar = page.locator('[data-test="snackbar"]');
        this.closeButton = page.getByRole('button', { name: 'Close' });
        this.replaceResourceButton = page.getByRole('button', {
            name: 'Replace resource',
        });
        this.cancelButton = page.getByRole('button', { name: 'Cancel' });
    }
    async clickSearchForConnectorTextbox() {
        await this.searchForConnectorTextbox.click({ timeout: 60000 });
    }
    async fillSearchForConnectorTextbox(connectorName) {
        await this.searchForConnectorTextbox.fill(connectorName, { timeout: 60000 });
    }
    async clickDownloadToProjectButton() {
        await this.downloadToProjectButton.click({ timeout: 60000 });
    }
    async clickSnackbar() {
        await this.snackbar.click({ timeout: 120000 });
    }
    async clickCloseButton() {
        await this.closeButton.click({ timeout: 60000 });
    }
    async clickReplaceResourceButton() {
        await this.replaceResourceButton.click({ timeout: 60000 });
    }
    async downloadConnectorToProject() {
        await this.clickDownloadToProjectButton();
        await (0, test_1.expect)(this.page.getByText('Downloading')).not.toBeVisible({
            timeout: 30000,
        });
        try {
            await Promise.race([
                this.replaceResourceButton.click({ timeout: 20000 }),
                this.cancelButton.click({ timeout: 20000 }),
            ]);
        }
        catch (e) {
            return;
        }
    }
}
exports.ConnectorMarketplacePage = ConnectorMarketplacePage;
