"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.timeTableDriverFactory = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _unidriver = require("../utils/test-utils/unidriver");
var _AddItemUni = require("../AddItem/AddItem.uni.driver");
var _constants = require("./constants");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var timeTableDriverFactory = base => {
  var byHook = dataHook => "[data-hook=\"".concat(dataHook, "\"]");
  var getElementAt = /*#__PURE__*/function () {
    var _ref = (0, _asyncToGenerator2.default)(function* (dataHook, index) {
      return (yield base.$$(byHook(dataHook))).get(index);
    });
    return function getElementAt(_x, _x2) {
      return _ref.apply(this, arguments);
    };
  }();
  function getColumnByIndex(_x3) {
    return _getColumnByIndex.apply(this, arguments);
  }
  function _getColumnByIndex() {
    _getColumnByIndex = (0, _asyncToGenerator2.default)(function* (columnIndex) {
      var column = yield getElementAt(_constants.DataHook.Column, columnIndex);
      if (!(yield column.exists())) {
        throw new Error("Column with index ".concat(columnIndex, " doesn't exist"));
      }
      return column;
    });
    return _getColumnByIndex.apply(this, arguments);
  }
  var getColumnActions = /*#__PURE__*/function () {
    var _ref2 = (0, _asyncToGenerator2.default)(function* (columnIndex) {
      var column = yield getColumnByIndex(columnIndex);
      yield column.hover();
      return column.$$(byHook(_constants.DataHook.ColumnAction));
    });
    return function getColumnActions(_x4) {
      return _ref2.apply(this, arguments);
    };
  }();
  var getAction = /*#__PURE__*/function () {
    var _ref3 = (0, _asyncToGenerator2.default)(function* (columnIndex, actionIndex) {
      var actions = yield getColumnActions(columnIndex);
      return actions == null ? void 0 : actions.get(actionIndex);
    });
    return function getAction(_x5, _x6) {
      return _ref3.apply(this, arguments);
    };
  }();
  var getBooleanDataAttribute = /*#__PURE__*/function () {
    var _ref4 = (0, _asyncToGenerator2.default)(function* (element, dataAttribute) {
      return (yield element.attr(dataAttribute)) === 'true';
    });
    return function getBooleanDataAttribute(_x7, _x8) {
      return _ref4.apply(this, arguments);
    };
  }();
  var getAllColumnItemElementsAt = /*#__PURE__*/function () {
    var _ref5 = (0, _asyncToGenerator2.default)(function* (columnIndex) {
      var column = yield getColumnByIndex(columnIndex);
      return column.$$(byHook(_constants.DataHook.Item));
    });
    return function getAllColumnItemElementsAt(_x9) {
      return _ref5.apply(this, arguments);
    };
  }();
  var getColumnItemElementAt = /*#__PURE__*/function () {
    var _ref6 = (0, _asyncToGenerator2.default)(function* (columnIndex, itemIndex) {
      var items = yield getAllColumnItemElementsAt(columnIndex);
      return items.get(itemIndex);
    });
    return function getColumnItemElementAt(_x0, _x1) {
      return _ref6.apply(this, arguments);
    };
  }();
  var getAddItemButtonElementAt = /*#__PURE__*/function () {
    var _ref7 = (0, _asyncToGenerator2.default)(function* (columnIndex) {
      var column = yield getColumnByIndex(columnIndex);
      yield column.hover();
      return (0, _AddItemUni.addItemUniDriverFactory)(column.$(byHook(_constants.DataHook.AddItemButton)));
    });
    return function getAddItemButtonElementAt(_x10) {
      return _ref7.apply(this, arguments);
    };
  }();
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    /** Get column count. */
    getColumnCount: function () {
      var _getColumnCount = (0, _asyncToGenerator2.default)(function* () {
        return (yield base.$$(byHook(_constants.DataHook.Column))).count();
      });
      function getColumnCount() {
        return _getColumnCount.apply(this, arguments);
      }
      return getColumnCount;
    }(),
    /** Get title at column index. */
    getTitleAt: function () {
      var _getTitleAt = (0, _asyncToGenerator2.default)(function* (columnIndex) {
        return (yield getElementAt(_constants.DataHook.Title, columnIndex)).text();
      });
      function getTitleAt(_x11) {
        return _getTitleAt.apply(this, arguments);
      }
      return getTitleAt;
    }(),
    /** Get actions count in column with give columnIndex. */
    getActionsCount: function () {
      var _getActionsCount = (0, _asyncToGenerator2.default)(function* (columnIndex) {
        var actions = yield getColumnActions(columnIndex);
        return actions.count();
      });
      function getActionsCount(_x12) {
        return _getActionsCount.apply(this, arguments);
      }
      return getActionsCount;
    }(),
    /**  Clicks at action with given column and action id  */
    clickActionAt: function () {
      var _clickActionAt = (0, _asyncToGenerator2.default)(function* (columnIndex, actionIndex) {
        var action = yield getAction(columnIndex, actionIndex);
        if ((yield action.exists()) === false) {
          throw new Error("Action at columnIndex: ".concat(columnIndex, ", actionIndex: ").concat(actionIndex, " doesn't exist"));
        }
        return (0, _AddItemUni.addItemUniDriverFactory)(action).click();
      });
      function clickActionAt(_x13, _x14) {
        return _clickActionAt.apply(this, arguments);
      }
      return clickActionAt;
    }(),
    /** Hover column by column index. Used to display action buttons */
    hoverColumn: function () {
      var _hoverColumn = (0, _asyncToGenerator2.default)(function* (columnIndex) {
        var column = yield getColumnByIndex(columnIndex);
        yield column.hover();
      });
      function hoverColumn(_x15) {
        return _hoverColumn.apply(this, arguments);
      }
      return hoverColumn;
    }(),
    /** Return label of action by column and action id */
    getActionLabelAt: function () {
      var _getActionLabelAt = (0, _asyncToGenerator2.default)(function* (columnIndex, actionIndex) {
        var action = yield getAction(columnIndex, actionIndex);
        return action.text();
      });
      function getActionLabelAt(_x16, _x17) {
        return _getActionLabelAt.apply(this, arguments);
      }
      return getActionLabelAt;
    }(),
    /** Get subtitle at column index. */
    getSubtitleAt: function () {
      var _getSubtitleAt = (0, _asyncToGenerator2.default)(function* (columnIndex) {
        return (yield getElementAt(_constants.DataHook.Subtitle, columnIndex)).text();
      });
      function getSubtitleAt(_x18) {
        return _getSubtitleAt.apply(this, arguments);
      }
      return getSubtitleAt;
    }(),
    /** Get active state at column index. */
    isColumnActiveAt: function () {
      var _isColumnActiveAt = (0, _asyncToGenerator2.default)(function* (columnIndex) {
        var column = yield getColumnByIndex(columnIndex);
        return getBooleanDataAttribute(column, _constants.DataAttribute.ColumnActive);
      });
      function isColumnActiveAt(_x19) {
        return _isColumnActiveAt.apply(this, arguments);
      }
      return isColumnActiveAt;
    }(),
    /** Get disabled state at column index. */
    isColumnDisabledAt: function () {
      var _isColumnDisabledAt = (0, _asyncToGenerator2.default)(function* (columnIndex) {
        var column = yield getColumnByIndex(columnIndex);
        return getBooleanDataAttribute(column, _constants.DataAttribute.ColumnDisabled);
      });
      function isColumnDisabledAt(_x20) {
        return _isColumnDisabledAt.apply(this, arguments);
      }
      return isColumnDisabledAt;
    }(),
    /** Get droppable state at column index. */
    isColumnDroppableAt: function () {
      var _isColumnDroppableAt = (0, _asyncToGenerator2.default)(function* (columnIndex) {
        var column = yield getColumnByIndex(columnIndex);
        return getBooleanDataAttribute(column, _constants.DataAttribute.ColumnDroppable);
      });
      function isColumnDroppableAt(_x21) {
        return _isColumnDroppableAt.apply(this, arguments);
      }
      return isColumnDroppableAt;
    }(),
    /** Get item count at column index. */
    getItemCountAt: function () {
      var _getItemCountAt = (0, _asyncToGenerator2.default)(function* (columnIndex) {
        return (yield getAllColumnItemElementsAt(columnIndex)).count();
      });
      function getItemCountAt(_x22) {
        return _getItemCountAt.apply(this, arguments);
      }
      return getItemCountAt;
    }(),
    /** Get item disabled state at column and item index. */
    isItemDisabledAt: function () {
      var _isItemDisabledAt = (0, _asyncToGenerator2.default)(function* (columnIndex, itemIndex) {
        var item = yield getColumnItemElementAt(columnIndex, itemIndex);
        return getBooleanDataAttribute(item, _constants.DataAttribute.ItemDisabled);
      });
      function isItemDisabledAt(_x23, _x24) {
        return _isItemDisabledAt.apply(this, arguments);
      }
      return isItemDisabledAt;
    }(),
    /** Get item draggable state at column and item index. */
    isItemDraggableAt: function () {
      var _isItemDraggableAt = (0, _asyncToGenerator2.default)(function* (columnIndex, itemIndex) {
        var item = yield getColumnItemElementAt(columnIndex, itemIndex);
        return getBooleanDataAttribute(item, _constants.DataAttribute.ItemDraggable);
      });
      function isItemDraggableAt(_x25, _x26) {
        return _isItemDraggableAt.apply(this, arguments);
      }
      return isItemDraggableAt;
    }(),
    /** Click on add item button at column index. */
    clickOnAddItemButtonAt: function () {
      var _clickOnAddItemButtonAt = (0, _asyncToGenerator2.default)(function* (columnIndex) {
        var addItemButton = yield getAddItemButtonElementAt(columnIndex);
        return addItemButton.click();
      });
      function clickOnAddItemButtonAt(_x27) {
        return _clickOnAddItemButtonAt.apply(this, arguments);
      }
      return clickOnAddItemButtonAt;
    }(),
    /** Check if add button is shown on hover at column index. */
    addItemButtonExistsAt: function () {
      var _addItemButtonExistsAt = (0, _asyncToGenerator2.default)(function* (columnIndex) {
        var addItemButton = yield getAddItemButtonElementAt(columnIndex);
        return addItemButton.exists();
      });
      function addItemButtonExistsAt(_x28) {
        return _addItemButtonExistsAt.apply(this, arguments);
      }
      return addItemButtonExistsAt;
    }()
  });
};
exports.timeTableDriverFactory = timeTableDriverFactory;
//# sourceMappingURL=TimeTable.uni.driver.js.map