import { __awaiter } from 'tslib';
import { ExpectedConditions, browser, element, by } from 'protractor';

// WARNING:
class LoginPageObject {
    constructor() {
        this.until = ExpectedConditions;
    }
    login(email, landingPageRegexp) {
        return __awaiter(this, void 0, void 0, function* () {
            // The page where we are going (Auth0 login page) is not Angular
            yield browser.waitForAngularEnabled(false);
            yield browser.get(browser.params.baseUrl);
            // Wait for login form is available
            yield browser.wait(this.until.visibilityOf(element(by.tagName('portero-login')).element(by.name('email'))), 30000, 'Email input field is not present in the page');
            const emailField = element(by.tagName('portero-login')).element(by.name('email'));
            const passwordField = element(by.tagName('portero-login')).element(by.name('password'));
            const loginButton = element(by.tagName('portero-login')).element(by.css('button'));
            console.log(browser.params);
            // type credentials and submit the form
            yield emailField.sendKeys(email);
            yield passwordField.sendKeys(browser.params.logins[email]);
            yield loginButton.click();
            // wait until it is redirected to expecting landing page
            yield browser.wait(() => __awaiter(this, void 0, void 0, function* () { return landingPageRegexp.test((yield browser.getCurrentUrl())); }), 60000, `URL is not the expected for a landing page: ${landingPageRegexp}`);
        });
    }
}

// WARNING:
class TutorialPageObject {
    constructor() {
        this.until = ExpectedConditions;
    }
    closeFirstTimeTutorial() {
        return __awaiter(this, void 0, void 0, function* () {
            // NOTE:
            // Because some redirections occurring at first loading, this tutorial is not
            // being displayed consistently. so this appears randomly.
            // we need to make sure that tutorial is being displayed before trying to close it
            const tutorialDialog = element(by.tagName('mat-dialog-container'));
            const tutorialSkipButton = element(by.tagName('al-alert-box')).element(by.tagName('button'));
            yield browser.wait(this.until.visibilityOf(tutorialSkipButton), 30000, 'Skip button for tutorial is not present');
            const isTutorialPresent = yield tutorialDialog.isPresent();
            if (isTutorialPresent) {
                yield tutorialSkipButton.click();
                yield browser.sleep(1000);
            }
        });
    }
}

class PrimeNgMenuPageObject {
    constructor() {
        this.menuElement = element(by.className('ui-menu-dynamic'));
        this.menuItems = this.menuElement.element(by.tagName('ul')).all(by.className('ui-menuitem'));
    }
    selectItemAtIndex(index) {
        return __awaiter(this, void 0, void 0, function* () {
            yield this.menuItems.get(index).element(by.tagName('a')).click();
        });
    }
}

class PrimeNgMultiSelectPageObject {
    constructor() {
        this.multiSelectElement = element(by.className('ui-multiselect'));
        this.multiSelectItems = element.all(by.className('ui-multiselect-item'));
    }
    selectItemContainingText(name) {
        return __awaiter(this, void 0, void 0, function* () {
            yield element(by.cssContainingText('.ui-multiselect-item > span', name)).click();
        });
    }
}

class PrimeNgTreeTablePageObject {
    constructor() {
        this.treeTableBody = element((by.className('ui-treetable-tbody')));
        this.treeTableRows = this.treeTableBody.all(by.tagName('tr'));
    }
    getTreeTableRowAtIndex(index) {
        return this.treeTableRows.get(index);
    }
}

/**
 * Generated bundle index. Do not edit.
 */

export { LoginPageObject, PrimeNgMenuPageObject, PrimeNgMultiSelectPageObject, PrimeNgTreeTablePageObject, TutorialPageObject };
//# sourceMappingURL=al-ng-generic-components-protractor.js.map
