"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SignUpPage = void 0;
const test_1 = require("@playwright/test");
class SignUpPage {
    page;
    firstNameInput;
    lastNameInput;
    passwordInput;
    passwordInputInvitedUser;
    signupButton;
    emailInput;
    companyInput;
    createAccountButton;
    backgroundDrodownList;
    whatDoYouDoDropdownList;
    APIClientDropdownList;
    levelOfExperienceDropdownList;
    nextButton;
    runProcessRadioButton;
    whyAreYouEvaluatingCamunda;
    confirmSaaSTrial;
    loginToCamundaButton;
    backgroundPageHeading;
    useCasePageHeading;
    goalPageHeading;
    camundaPlansPageHeading;
    setPasswordPageHeading;
    signUpCompletedPageHeading;
    verifyEmailText;
    constructor(page) {
        this.page = page;
        this.firstNameInput = page.getByLabel('First Name');
        this.lastNameInput = page.getByLabel('Last Name');
        this.passwordInput = page.locator('[id="password"]');
        this.passwordInputInvitedUser = page.getByLabel('Password (min 12 characters)');
        this.signupButton = page.getByRole('button', { name: 'Sign up' });
        this.emailInput = page.getByLabel('Email');
        this.companyInput = page.getByLabel('Company*');
        this.createAccountButton = page.getByRole('button', {
            name: 'Create account',
        });
        this.backgroundDrodownList = page.getByLabel('Background*');
        this.whatDoYouDoDropdownList = page.getByLabel('What do you do?*');
        this.APIClientDropdownList = page.getByRole('combobox', {
            name: 'what is your preferred api client?',
        });
        this.levelOfExperienceDropdownList = page.getByLabel('what is your level of experience with process design?*');
        this.nextButton = page.getByRole('button', { name: 'Next' });
        this.runProcessRadioButton = page.getByRole('radio');
        this.whyAreYouEvaluatingCamunda = page.getByLabel('Why are you evaluating');
        this.confirmSaaSTrial = page.getByRole('button', {
            name: 'Confirm SaaS Trial',
        });
        this.loginToCamundaButton = page.getByRole('button', {
            name: 'log in to camunda',
        });
        this.backgroundPageHeading = page.getByRole('heading', {
            name: 'great! to customize your account, tell us a little about yourself',
        });
        this.useCasePageHeading = page.getByRole('heading', {
            name: 'thank you! how will you use camunda',
        });
        this.goalPageHeading = page.getByRole('heading', {
            name: 'finally, what is your goal with camunda?',
        });
        this.camundaPlansPageHeading = page.getByRole('heading', {
            name: 'Here is your custom recommendation, please confirm your Camunda account below:',
        });
        this.setPasswordPageHeading = page.getByRole('heading', {
            name: 'Finish',
        });
        this.signUpCompletedPageHeading = page.getByRole('heading', {
            name: 'thank you for signing up for camunda',
        });
        this.runProcessRadioButton = page.getByRole('radio', { name: 'yes' });
        this.verifyEmailText = page.getByText(/Verify your email|Check your email|Confirm your email/i);
    }
    async signupToC8(emailAddress, password) {
        await this.page.goto('https://accounts.ultrawombat.com/signup');
        await this.clickFirstNameInput();
        await this.fillFirstNameInput('QA');
        await this.clickLastNameInput();
        await this.fillLastNameInput('Camunda');
        await this.clickEmailInput();
        await this.fillEmailInput(emailAddress);
        // Fill Company field if the form now requires it
        if (await this.companyInput.isVisible({ timeout: 3000 }).catch(() => false)) {
            await this.companyInput.fill('QA Camunda');
        }
        await this.clickPasswordInput();
        await this.fillPasswordInput(password);
        await this.clickSignupButton();
        // Sign-up can complete through multiple UI states across Auth0 variants.
        await test_1.expect
            .poll(async () => {
            const pathname = new URL(this.page.url()).pathname;
            if (pathname !== '/signup') {
                return true;
            }
            const canSeeVerificationText = await this.verifyEmailText
                .isVisible({ timeout: 1000 })
                .catch(() => false);
            if (canSeeVerificationText) {
                return true;
            }
            const canSeeLoginButton = await this.loginToCamundaButton
                .isVisible({ timeout: 1000 })
                .catch(() => false);
            if (canSeeLoginButton) {
                return true;
            }
            const signUpButtonHidden = await this.signupButton
                .isHidden({ timeout: 1000 })
                .catch(() => false);
            return signUpButtonHidden;
        }, {
            timeout: 240000,
        })
            .toBe(true);
    }
    async clickFirstNameInput() {
        await this.firstNameInput.click({ timeout: 30000 });
    }
    async fillFirstNameInput(firstName) {
        await this.firstNameInput.fill(firstName);
    }
    async clickLastNameInput() {
        await this.lastNameInput.click();
    }
    async fillLastNameInput(lastName) {
        await this.lastNameInput.fill(lastName);
    }
    async clickPasswordInput() {
        await this.passwordInput.click({ timeout: 30000 });
    }
    async fillPasswordInput(password) {
        await this.passwordInput.fill(password);
    }
    async clickPasswordInputInvitedUser() {
        await this.passwordInputInvitedUser.click({ timeout: 30000 });
    }
    async fillPasswordInputInvitedUser(password) {
        await this.passwordInputInvitedUser.fill(password);
    }
    async clickCompanyInput() {
        await this.companyInput.click();
    }
    async fillCompanyInput(company) {
        await this.companyInput.fill(company);
    }
    async clickSignupButton() {
        await this.signupButton.click();
    }
    async clickEmailInput() {
        await this.emailInput.click();
    }
    async fillEmailInput(email) {
        await this.emailInput.fill(email);
    }
    async selectEndpointsToAutomate(endpoint) {
        // Select the container to expand the dropdown
        await this.page.getByText('choose all that apply').hover();
        const dropdownContainerSelector = '.ginput_container_multiselect';
        await this.page.click(dropdownContainerSelector);
        // Wait for the dropdown options to appear
        await this.page.waitForSelector('.multiselect-dropdown-list > div > input[type="checkbox"]');
        // Select the checkbox
        const checkboxSelector = `.multiselect-dropdown-list  > div > input[type="checkbox"] + label:has-text("${endpoint}")`;
        await this.page.click(checkboxSelector, { timeout: 60000 });
    }
    async clickCreateAccount() {
        await this.createAccountButton.click();
    }
    async clickNext() {
        await this.nextButton.click();
    }
    async selectBackground(background) {
        await this.backgroundDrodownList.selectOption(background);
    }
    async selectWhatDoYouDo(profession) {
        await this.whatDoYouDoDropdownList.selectOption(profession);
    }
    async selectAPIClient(apiClient) {
        await this.APIClientDropdownList.selectOption(apiClient, { timeout: 40000 });
    }
    async selectLevelOfExperience(experience) {
        await this.levelOfExperienceDropdownList.selectOption(experience);
    }
    async selectRunProcessRadioButton() {
        await this.runProcessRadioButton.check({ timeout: 30000 });
    }
    async selectWhyEvaluatingCamunda(reason) {
        await this.whyAreYouEvaluatingCamunda.selectOption(reason);
    }
    async clickConfirmSaaSTrial() {
        await this.confirmSaaSTrial.click();
    }
    async clickLoginToCamunda() {
        await this.loginToCamundaButton.click();
    }
}
exports.SignUpPage = SignUpPage;
