"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var BasePage_1 = require("../../common/BasePage");
var consts_1 = require("../consts");
var FocusZonePageObject = /** @class */ (function (_super) {
    tslib_1.__extends(FocusZonePageObject, _super);
    function FocusZonePageObject() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    FocusZonePageObject.prototype.resetTest = function () {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.configureGridFocusZone('SetDirection', 'bidirectional')];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, this.configureGridFocusZone('Set2DNavigation', false)];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, this.configureGridFocusZone('SetCircularNavigation', false)];
                    case 3:
                        _a.sent();
                        return [4 /*yield*/, this.configureGridFocusZone('Disable', false)];
                    case 4:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    FocusZonePageObject.prototype.configureGridFocusZone = function (option, arg) {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var switchElement, _a, DirectionDropdown_1, switchValue, _b, _c, _d, _e, _f;
            var _g;
            var _this = this;
            return tslib_1.__generator(this, function (_h) {
                switch (_h.label) {
                    case 0:
                        _a = option;
                        switch (_a) {
                            case 'SetDirection': return [3 /*break*/, 1];
                            case 'Set2DNavigation': return [3 /*break*/, 9];
                            case 'SetCircularNavigation': return [3 /*break*/, 11];
                            case 'UseDefaultTabbableElement': return [3 /*break*/, 13];
                            case 'Disable': return [3 /*break*/, 15];
                        }
                        return [3 /*break*/, 17];
                    case 1: return [4 /*yield*/, this._directionPicker];
                    case 2:
                        DirectionDropdown_1 = _h.sent();
                        return [4 /*yield*/, DirectionDropdown_1.getAttribute('Name')];
                    case 3:
                        // If the dropdown is already at the default value, break
                        if ((_h.sent()).indexOf(arg) !== -1) {
                            return [2 /*return*/];
                        }
                        return [4 /*yield*/, DirectionDropdown_1.click()];
                    case 4:
                        _h.sent();
                        return [4 /*yield*/, browser.waitUntil(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, this._getGridFocusZoneMenuOption(arg)];
                                    case 1: return [4 /*yield*/, (_a.sent()).isDisplayed()];
                                    case 2: return [2 /*return*/, _a.sent()];
                                }
                            }); }); })];
                    case 5:
                        _h.sent();
                        return [4 /*yield*/, this._getGridFocusZoneMenuOption(arg)];
                    case 6: return [4 /*yield*/, (_h.sent()).click()];
                    case 7:
                        _h.sent();
                        return [4 /*yield*/, browser.waitUntil(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, DirectionDropdown_1.getAttribute('Name')];
                                    case 1: return [2 /*return*/, (_a.sent()).indexOf(arg) !== -1];
                                }
                            }); }); }, {
                                timeout: 15000,
                                timeoutMsg: 'Could not reset the directional dropdown back to it\'s original value'
                            })];
                    case 8:
                        _h.sent();
                        return [2 /*return*/];
                    case 9: return [4 /*yield*/, this._twoDimSwitch];
                    case 10:
                        switchElement = _h.sent();
                        return [3 /*break*/, 17];
                    case 11: return [4 /*yield*/, this._circleNavSwitch];
                    case 12:
                        switchElement = _h.sent();
                        return [3 /*break*/, 17];
                    case 13: return [4 /*yield*/, this._defaultTabbableElementSwitch];
                    case 14:
                        switchElement = _h.sent();
                        return [3 /*break*/, 17];
                    case 15: return [4 /*yield*/, this._disabledSwitch];
                    case 16:
                        switchElement = _h.sent();
                        return [3 /*break*/, 17];
                    case 17: return [4 /*yield*/, switchElement.isSelected()];
                    case 18:
                        switchValue = _h.sent();
                        if (!(switchValue !== arg)) return [3 /*break*/, 20];
                        return [4 /*yield*/, switchElement.click()];
                    case 19:
                        _h.sent();
                        _h.label = 20;
                    case 20:
                        _c = (_b = browser).waitUntil;
                        _d = [function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: return [4 /*yield*/, switchElement.isSelected()];
                                    case 1: return [2 /*return*/, (_a.sent()) == arg];
                                }
                            }); }); }];
                        _g = {
                            timeout: 15000
                        };
                        _f = (_e = "Attempted to switch the ".concat(option, " to ").concat(arg, ", but it remained at ")).concat;
                        return [4 /*yield*/, switchElement.isSelected()];
                    case 21: 
                    // Wait until the switch correctly changes states
                    return [4 /*yield*/, _c.apply(_b, _d.concat([(_g.timeoutMsg = _f.apply(_e, [_h.sent()]),
                                _g)]))];
                    case 22:
                        // Wait until the switch correctly changes states
                        _h.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    FocusZonePageObject.prototype.gridButton = function (button) {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, (0, BasePage_1.By)((0, consts_1.FOCUSZONE_GRID_BUTTON)(button))];
                    case 1: return [2 /*return*/, _a.sent()];
                }
            });
        });
    };
    FocusZonePageObject.prototype._getGridFocusZoneMenuOption = function (direction) {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, (0, BasePage_1.By)((0, consts_1.FOCUSZONE_DIRECTION_ID)(direction))];
                    case 1: return [2 /*return*/, _a.sent()];
                }
            });
        });
    };
    Object.defineProperty(FocusZonePageObject.prototype, "_pageName", {
        /*****************************************/
        /**************** Getters ****************/
        /*****************************************/
        get: function () {
            return consts_1.FOCUSZONE_TESTPAGE;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(FocusZonePageObject.prototype, "_primaryComponentName", {
        get: function () {
            return consts_1.FOCUSZONE_TEST_COMPONENT;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(FocusZonePageObject.prototype, "_pageButtonName", {
        get: function () {
            return consts_1.HOMEPAGE_FOCUSZONE_BUTTON;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(FocusZonePageObject.prototype, "_directionPicker", {
        get: function () {
            return (0, BasePage_1.By)(consts_1.FOCUSZONE_DIRECTION_PICKER);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(FocusZonePageObject.prototype, "_twoDimSwitch", {
        get: function () {
            return (0, BasePage_1.By)(consts_1.FOCUSZONE_TWO_DIM_SWITCH);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(FocusZonePageObject.prototype, "_disabledSwitch", {
        get: function () {
            return (0, BasePage_1.By)(consts_1.FOCUSZONE_DISABLED_SWITCH);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(FocusZonePageObject.prototype, "_circleNavSwitch", {
        get: function () {
            return (0, BasePage_1.By)(consts_1.FOCUSZONE_CIRCLE_NAV_SWITCH);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(FocusZonePageObject.prototype, "_defaultTabbableElementSwitch", {
        get: function () {
            return (0, BasePage_1.By)(consts_1.FOCUSZONE_DEFAULT_TABBABLE_SWITCH);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(FocusZonePageObject.prototype, "_beforeButton", {
        get: function () {
            return (0, BasePage_1.By)(consts_1.FOCUSZONE_GRID_BEFORE);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(FocusZonePageObject.prototype, "_afterButton", {
        get: function () {
            return (0, BasePage_1.By)(consts_1.FOCUSZONE_GRID_AFTER);
        },
        enumerable: false,
        configurable: true
    });
    return FocusZonePageObject;
}(BasePage_1.BasePage));
exports.default = new FocusZonePageObject();
//# sourceMappingURL=FocusZonePageObject.js.map