"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LoginPage = void 0;
const test_1 = require("@playwright/test");
const BasePage_1 = require("../BasePage/BasePage");
const LoginPage_locators_1 = require("./LoginPage.locators");
const timeouts_1 = require("../../timeouts");
class LoginPage extends BasePage_1.BasePage {
    constructor(page) {
        super(page);
        const locators = (0, LoginPage_locators_1.createLoginPageLocators)(page);
        this.emailInput = locators.emailInput;
        this.passwordInput = locators.passwordInput;
        this.submitButton = locators.submitButton;
        this.loginWithCertificateCSP = locators.loginWithCertificateCSP;
        this.loginWithEmail = locators.loginWithEmail;
    }
    async gotoLogin() {
        await this.goto('main/auth/signin');
    }
    async login(email, password) {
        await this.loginWithEmail.click();
        await this.emailInput.fill(email);
        await this.passwordInput.fill(password);
        await (0, test_1.expect)(async () => {
            await Promise.all([
                this.page.waitForResponse((response) => response.url().includes('token') && response.status() === 200, { timeout: (0, timeouts_1.getTimeouts)().WAIT_FOR_RESPONSE / 10 }),
                this.submitButton.click()
            ]);
        }).toPass({
            timeout: 10000,
            intervals: [2500, 2500, 2500, 2500]
        });
    }
    /** Вход через сертификат; владелец определяется по роли (`setRole`). */
    async loginWithCertificate() {
        await this.loginWithCertificateCSP.click();
        await this.certificateHelper.chooseCertificateAndSign();
    }
}
exports.LoginPage = LoginPage;
