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

// WARNING:
var LoginPageObject = /** @class */ (function () {
    function LoginPageObject() {
        this.until = ExpectedConditions;
    }
    LoginPageObject.prototype.login = function (email, landingPageRegexp) {
        return __awaiter(this, void 0, void 0, function () {
            var emailField, passwordField, loginButton;
            var _this = this;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: 
                    // The page where we are going (Auth0 login page) is not Angular
                    return [4 /*yield*/, browser.waitForAngularEnabled(false)];
                    case 1:
                        // The page where we are going (Auth0 login page) is not Angular
                        _a.sent();
                        return [4 /*yield*/, browser.get(browser.params.baseUrl)];
                    case 2:
                        _a.sent();
                        // Wait for login form is available
                        return [4 /*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')];
                    case 3:
                        // Wait for login form is available
                        _a.sent();
                        emailField = element(by.tagName('portero-login')).element(by.name('email'));
                        passwordField = element(by.tagName('portero-login')).element(by.name('password'));
                        loginButton = element(by.tagName('portero-login')).element(by.css('button'));
                        console.log(browser.params);
                        // type credentials and submit the form
                        return [4 /*yield*/, emailField.sendKeys(email)];
                    case 4:
                        // type credentials and submit the form
                        _a.sent();
                        return [4 /*yield*/, passwordField.sendKeys(browser.params.logins[email])];
                    case 5:
                        _a.sent();
                        return [4 /*yield*/, loginButton.click()];
                    case 6:
                        _a.sent();
                        // wait until it is redirected to expecting landing page
                        return [4 /*yield*/, browser.wait(function () { return __awaiter(_this, void 0, void 0, function () { var _a, _b; return __generator(this, function (_c) {
                                switch (_c.label) {
                                    case 0:
                                        _b = (_a = landingPageRegexp).test;
                                        return [4 /*yield*/, browser.getCurrentUrl()];
                                    case 1: return [2 /*return*/, _b.apply(_a, [(_c.sent())])];
                                }
                            }); }); }, 60000, "URL is not the expected for a landing page: " + landingPageRegexp)];
                    case 7:
                        // wait until it is redirected to expecting landing page
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    return LoginPageObject;
}());

// WARNING:
var TutorialPageObject = /** @class */ (function () {
    function TutorialPageObject() {
        this.until = ExpectedConditions;
    }
    TutorialPageObject.prototype.closeFirstTimeTutorial = function () {
        return __awaiter(this, void 0, void 0, function () {
            var tutorialDialog, tutorialSkipButton, isTutorialPresent;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        tutorialDialog = element(by.tagName('mat-dialog-container'));
                        tutorialSkipButton = element(by.tagName('al-alert-box')).element(by.tagName('button'));
                        return [4 /*yield*/, browser.wait(this.until.visibilityOf(tutorialSkipButton), 30000, 'Skip button for tutorial is not present')];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, tutorialDialog.isPresent()];
                    case 2:
                        isTutorialPresent = _a.sent();
                        if (!isTutorialPresent) return [3 /*break*/, 5];
                        return [4 /*yield*/, tutorialSkipButton.click()];
                    case 3:
                        _a.sent();
                        return [4 /*yield*/, browser.sleep(1000)];
                    case 4:
                        _a.sent();
                        _a.label = 5;
                    case 5: return [2 /*return*/];
                }
            });
        });
    };
    return TutorialPageObject;
}());

var PrimeNgMenuPageObject = /** @class */ (function () {
    function PrimeNgMenuPageObject() {
        this.menuElement = element(by.className('ui-menu-dynamic'));
        this.menuItems = this.menuElement.element(by.tagName('ul')).all(by.className('ui-menuitem'));
    }
    PrimeNgMenuPageObject.prototype.selectItemAtIndex = function (index) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.menuItems.get(index).element(by.tagName('a')).click()];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    return PrimeNgMenuPageObject;
}());

var PrimeNgMultiSelectPageObject = /** @class */ (function () {
    function PrimeNgMultiSelectPageObject() {
        this.multiSelectElement = element(by.className('ui-multiselect'));
        this.multiSelectItems = element.all(by.className('ui-multiselect-item'));
    }
    PrimeNgMultiSelectPageObject.prototype.selectItemContainingText = function (name) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, element(by.cssContainingText('.ui-multiselect-item > span', name)).click()];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    return PrimeNgMultiSelectPageObject;
}());

var PrimeNgTreeTablePageObject = /** @class */ (function () {
    function PrimeNgTreeTablePageObject() {
        this.treeTableBody = element((by.className('ui-treetable-tbody')));
        this.treeTableRows = this.treeTableBody.all(by.tagName('tr'));
    }
    PrimeNgTreeTablePageObject.prototype.getTreeTableRowAtIndex = function (index) {
        return this.treeTableRows.get(index);
    };
    return PrimeNgTreeTablePageObject;
}());

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

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