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

var AlArchipeligo17PageObject = /** @class */ (function () {
    function AlArchipeligo17PageObject() {
        this.archipeligo17UserMenu = element(by.css('al-archipeligo17-user-menu'));
        this.accountSelector = this.archipeligo17UserMenu.element(by.css('div.entity-wrapper.textual-label div.user-menu-block'));
        this.ellipsisUserMenu = this.archipeligo17UserMenu.element(by.css('div.stacked-vertical i'));
    }
    /**
     * It allows changing the account by passing a string with the id or the name of the account,
     * if there is more than one account that matches the string, the first one will be selected.
     */
    AlArchipeligo17PageObject.prototype.changeAccount = function (account) {
        return __awaiter(this, void 0, void 0, function () {
            var accountInput, dropdownPanel, elmAccount;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, browser.wait(ExpectedConditions.visibilityOf(this.accountSelector))];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, this.accountSelector.click()];
                    case 2:
                        _a.sent();
                        accountInput = this.archipeligo17UserMenu.element(by.css('p-dropdown input.ui-dropdown-label'));
                        return [4 /*yield*/, accountInput.sendKeys(account)];
                    case 3:
                        _a.sent();
                        dropdownPanel = this.archipeligo17UserMenu.element(by.css('p-dropdown div.ui-dropdown-panel'));
                        return [4 /*yield*/, browser.wait(ExpectedConditions.visibilityOf(dropdownPanel))];
                    case 4:
                        _a.sent();
                        elmAccount = dropdownPanel.element(by.css('p-dropdownitem:first-child li'));
                        return [4 /*yield*/, browser.wait(ExpectedConditions.presenceOf(elmAccount))];
                    case 5:
                        _a.sent();
                        return [4 /*yield*/, elmAccount.click()];
                    case 6:
                        _a.sent();
                        return [4 /*yield*/, browser.sleep(5000)];
                    case 7:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    AlArchipeligo17PageObject.prototype.goToUserOption = function (option) {
        return __awaiter(this, void 0, void 0, function () {
            var items, elem;
            var _this = this;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, browser.wait(ExpectedConditions.presenceOf(this.ellipsisUserMenu))];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, this.ellipsisUserMenu.click()];
                    case 2:
                        _a.sent();
                        items = this.archipeligo17UserMenu.all(by.xpath("//p-menu[contains(@class, 'elipsis-menu')]//li[not(contains(@class, 'ui-helper-hidden'))]"));
                        return [4 /*yield*/, browser.wait(ExpectedConditions.presenceOf(items.get(0)))];
                    case 3:
                        _a.sent();
                        elem = items.filter(function (item) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
                            switch (_a.label) {
                                case 0: return [4 /*yield*/, item.getText()];
                                case 1: return [2 /*return*/, (_a.sent()) === option];
                            }
                        }); }); });
                        return [4 /*yield*/, elem.get(0).click().then(function () { return browser.sleep(500); })];
                    case 4:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    return AlArchipeligo17PageObject;
}());

var AlArchipeligo19NavHeaderPageObject = /** @class */ (function () {
    function AlArchipeligo19NavHeaderPageObject() {
        this.archipeligo19Header = element(by.css('al-archipeligo19-app-header'));
        this.archipeligoCustomerSelector = this.archipeligo19Header.element(by.css('.al-account-selector'));
        this.menuToggle = element(by.className('menu-toggle'));
    }
    AlArchipeligo19NavHeaderPageObject.prototype.toggleMenu = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.menuToggle.click()];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * It allows changing the account by passing a string with the id or the name of the account,
     * if there is more than one account that matches the string, the first one will be selected.
     */
    AlArchipeligo19NavHeaderPageObject.prototype.changeAccount = function (account) {
        return __awaiter(this, void 0, void 0, function () {
            var customerSearchInput;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.archipeligoCustomerSelector.click()];
                    case 1:
                        _a.sent();
                        customerSearchInput = this.archipeligoCustomerSelector.element(by.css('.ng-dropdown-panel input'));
                        return [4 /*yield*/, browser.wait(ExpectedConditions.presenceOf(customerSearchInput))];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, customerSearchInput.sendKeys(account)];
                    case 3:
                        _a.sent();
                        return [4 /*yield*/, customerSearchInput.sendKeys(protractor.Key.ENTER)];
                    case 4:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    return AlArchipeligo19NavHeaderPageObject;
}());

function waitForPresenceOfNumberOfElements(elementArrayFinder, numberOfElements) {
    return browser.wait(function () {
        return elementArrayFinder.count().then(function (actualCount) {
            return actualCount === numberOfElements;
        });
    }, 60000, "Could not find exactly " + numberOfElements + " elements on the page");
}
function waitForPresenceOfMultiple(elementArrayFinder, minNumber) {
    if (minNumber === void 0) { minNumber = 0; }
    return browser.wait(function () {
        return elementArrayFinder.count().then(function (actualCount) {
            return actualCount > minNumber;
        });
    }, 60000, 'Could not find any elements on the page');
}

var AlArchipeligo19SidenavPageObject = /** @class */ (function () {
    function AlArchipeligo19SidenavPageObject() {
        this.sideNavContainer = element(by.className('sidenav-container'));
        this.EC = protractor.ExpectedConditions;
        this.navHeader = new AlArchipeligo19NavHeaderPageObject();
    }
    AlArchipeligo19SidenavPageObject.prototype.clickNavItem = function (parentItemIconName, menuItemCaption) {
        return __awaiter(this, void 0, void 0, function () {
            var iconEl, parentEl, childItem;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, browser.wait(this.EC.visibilityOf(this.sideNavContainer))];
                    case 1:
                        _a.sent();
                        iconEl = element(by.cssContainingText('i', parentItemIconName));
                        parentEl = iconEl.element(by.xpath('..'));
                        return [4 /*yield*/, parentEl.click()];
                    case 2:
                        _a.sent();
                        if (!menuItemCaption) return [3 /*break*/, 5];
                        childItem = element(by.cssContainingText('a', menuItemCaption));
                        return [4 /*yield*/, browser.wait(this.EC.visibilityOf(childItem))];
                    case 3:
                        _a.sent();
                        return [4 /*yield*/, element(by.cssContainingText('a', menuItemCaption)).click()];
                    case 4:
                        _a.sent();
                        _a.label = 5;
                    case 5: return [2 /*return*/];
                }
            });
        });
    };
    /**
    *  Expands and clicks on a given sidenav menu item
    *  Note - for the Dashboards menu item just provide the first parentItemIconName parameter
    *
    *  @param {string} parentItemIconName The icon name for the parent menu item.
    *  @param {string} menuItemCaption The caption of the menu item to be clicked on (optional).
    *
    */
    AlArchipeligo19SidenavPageObject.prototype.expandMenuAndNavigateToItem = function (parentItemIconName, menuItemCaption) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, browser.wait(this.EC.visibilityOf(this.navHeader.menuToggle))];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, this.navHeader.toggleMenu()];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, browser.wait(waitForPresenceOfMultiple(element.all(by.className('menu-item-parent'))))];
                    case 3:
                        _a.sent();
                        return [4 /*yield*/, this.clickNavItem(parentItemIconName, menuItemCaption)];
                    case 4:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    return AlArchipeligo19SidenavPageObject;
}());

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

export { AlArchipeligo17PageObject, AlArchipeligo19NavHeaderPageObject, AlArchipeligo19SidenavPageObject };
//# sourceMappingURL=al-ng-navigation-components-protractor.js.map
