"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.tableUniDriverFactory = 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 _DataTablePrivateUni = require("./DataTable/DataTable.private.uni.driver");
var _CheckboxUni = require("../Checkbox/Checkbox.uni.driver");
var _FloatingScrollBarUni = require("./FloatingScrollBar/FloatingScrollBar.uni.driver");
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 tableUniDriverFactory = (base, body) => {
  var dataTableDriver = (0, _DataTablePrivateUni.dataTablePrivateUniDriverFactory)(base);
  var _getRowNumberCell = /*#__PURE__*/function () {
    var _ref = (0, _asyncToGenerator2.default)(function* (index) {
      var row = yield dataTableDriver.getRow(index);
      var cell = yield row.$('[data-hook="bulk-selection-cell"]');
      return cell.$('[data-hook="row-number-cell"]');
    });
    return function getRowNumberCell(_x) {
      return _ref.apply(this, arguments);
    };
  }();
  var _getRowNumberText = /*#__PURE__*/function () {
    var _ref2 = (0, _asyncToGenerator2.default)(function* (index) {
      var cell = yield _getRowNumberCell(index);
      return cell.$('[data-hook="row-number-text"]');
    });
    return function getRowNumberText(_x2) {
      return _ref2.apply(this, arguments);
    };
  }();
  var getRowCheckbox = /*#__PURE__*/function () {
    var _ref3 = (0, _asyncToGenerator2.default)(function* (index) {
      var row = yield dataTableDriver.getRow(index);
      var cell = yield row.$('[data-hook="bulk-selection-cell"]');
      return cell.$('[data-hook="row-select"]');
    });
    return function getRowCheckbox(_x3) {
      return _ref3.apply(this, arguments);
    };
  }();
  var getRowCheckboxDriver = /*#__PURE__*/function () {
    var _ref4 = (0, _asyncToGenerator2.default)(function* (index) {
      return (0, _CheckboxUni.checkboxUniDriverFactory)(yield getRowCheckbox(index), body);
    });
    return function getRowCheckboxDriver(_x4) {
      return _ref4.apply(this, arguments);
    };
  }();
  var getBulkSelectionCheckboxDriver = /*#__PURE__*/function () {
    var _ref5 = (0, _asyncToGenerator2.default)(function* () {
      var cell = yield dataTableDriver.getHeaderCellByDataHook('bulk-selection-cell');
      return (0, _CheckboxUni.checkboxUniDriverFactory)(yield cell.$('[data-hook="table-select"]'));
    });
    return function getBulkSelectionCheckboxDriver() {
      return _ref5.apply(this, arguments);
    };
  }();
  var isBulkSelectionChecked = /*#__PURE__*/function () {
    var _ref6 = (0, _asyncToGenerator2.default)(function* () {
      var checkboxDriver = yield getBulkSelectionCheckboxDriver();
      return (yield checkboxDriver.isChecked()) && !(yield checkboxDriver.isIndeterminate());
    });
    return function isBulkSelectionChecked() {
      return _ref6.apply(this, arguments);
    };
  }();
  var isBulkSelectionIndeterminate = /*#__PURE__*/function () {
    var _ref7 = (0, _asyncToGenerator2.default)(function* () {
      var checkboxDriver = yield getBulkSelectionCheckboxDriver();
      return !(yield checkboxDriver.isChecked()) && (yield checkboxDriver.isIndeterminate());
    });
    return function isBulkSelectionIndeterminate() {
      return _ref7.apply(this, arguments);
    };
  }();
  var isBulkSelectionUnchecked = /*#__PURE__*/function () {
    var _ref8 = (0, _asyncToGenerator2.default)(function* () {
      var checkboxDriver = yield getBulkSelectionCheckboxDriver();
      return !(yield checkboxDriver.isChecked()) && !(yield checkboxDriver.isIndeterminate());
    });
    return function isBulkSelectionUnchecked() {
      return _ref8.apply(this, arguments);
    };
  }();
  return _objectSpread(_objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), dataTableDriver), {}, {
    /** Get driver of row selection checkbox by row index */
    getRowCheckboxDriver,
    /** Get driver of row bulk-selection checkbox */
    getBulkSelectionCheckboxDriver,
    /** Whether bulk selection checkbox is disabled */
    isBulkSelectionDisabled: function () {
      var _isBulkSelectionDisabled = (0, _asyncToGenerator2.default)(function* () {
        return (yield getBulkSelectionCheckboxDriver()).isDisabled();
      });
      function isBulkSelectionDisabled() {
        return _isBulkSelectionDisabled.apply(this, arguments);
      }
      return isBulkSelectionDisabled;
    }(),
    /** Whether specific row selection checkbox is disabled */
    isRowSelectionDisabled: function () {
      var _isRowSelectionDisabled = (0, _asyncToGenerator2.default)(function* (index) {
        return (yield getRowCheckboxDriver(index)).isDisabled();
      });
      function isRowSelectionDisabled(_x5) {
        return _isRowSelectionDisabled.apply(this, arguments);
      }
      return isRowSelectionDisabled;
    }(),
    /** Click the row selection checkbox */
    clickRowCheckbox: function () {
      var _clickRowCheckbox = (0, _asyncToGenerator2.default)(function* (index) {
        return (yield getRowCheckbox(index)).click();
      });
      function clickRowCheckbox(_x6) {
        return _clickRowCheckbox.apply(this, arguments);
      }
      return clickRowCheckbox;
    }(),
    /** Click the bulk-selection checkbox */
    clickBulkSelectionCheckbox: function () {
      var _clickBulkSelectionCheckbox = (0, _asyncToGenerator2.default)(function* () {
        return (yield getBulkSelectionCheckboxDriver()).click();
      });
      function clickBulkSelectionCheckbox() {
        return _clickBulkSelectionCheckbox.apply(this, arguments);
      }
      return clickBulkSelectionCheckbox;
    }(),
    /** Is row selected by index */
    isRowSelected: function () {
      var _isRowSelected = (0, _asyncToGenerator2.default)(function* (index) {
        return (yield getRowCheckboxDriver(index)).isChecked();
      });
      function isRowSelected(_x7) {
        return _isRowSelected.apply(this, arguments);
      }
      return isRowSelected;
    }(),
    getBulkSelectionState: function () {
      var _getBulkSelectionState = (0, _asyncToGenerator2.default)(function* () {
        if (yield isBulkSelectionChecked()) {
          return 'ALL';
        }
        if (yield isBulkSelectionIndeterminate()) {
          return 'SOME';
        }
        if (yield isBulkSelectionUnchecked()) {
          return 'NONE';
        }
      });
      function getBulkSelectionState() {
        return _getBulkSelectionState.apply(this, arguments);
      }
      return getBulkSelectionState;
    }(),
    /** Get title-bar (column titles) */
    getTitlebar: () => (0, _unidriver.getElement)(base.$('[data-hook="table-title-bar"]')),
    getCellTextValue: function () {
      var _getCellTextValue = (0, _asyncToGenerator2.default)(function* () {
        var row = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
        var column = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
        return (yield dataTableDriver.getCell(row, column))._prop('textContent');
      });
      function getCellTextValue() {
        return _getCellTextValue.apply(this, arguments);
      }
      return getCellTextValue;
    }(),
    isSelectionTooltipEnabled: function () {
      var _isSelectionTooltipEnabled = (0, _asyncToGenerator2.default)(function* (index) {
        return (yield getRowCheckboxDriver(index)).isTooltipEnabled();
      });
      function isSelectionTooltipEnabled(_x8) {
        return _isSelectionTooltipEnabled.apply(this, arguments);
      }
      return isSelectionTooltipEnabled;
    }(),
    getSelectionTooltipContent: function () {
      var _getSelectionTooltipContent = (0, _asyncToGenerator2.default)(function* (index) {
        return (yield getRowCheckboxDriver(index)).getTooltipContent();
      });
      function getSelectionTooltipContent(_x9) {
        return _getSelectionTooltipContent.apply(this, arguments);
      }
      return getSelectionTooltipContent;
    }(),
    /** Get the row number cell wrapper element by row index */
    getRowNumberCell: function () {
      var _getRowNumberCell2 = (0, _asyncToGenerator2.default)(function* (index) {
        return _getRowNumberCell(index);
      });
      function getRowNumberCell(_x0) {
        return _getRowNumberCell2.apply(this, arguments);
      }
      return getRowNumberCell;
    }(),
    /** Get the row number text value by row index */
    getRowNumberText: function () {
      var _getRowNumberText2 = (0, _asyncToGenerator2.default)(function* (index) {
        return (yield _getRowNumberText(index))._prop('textContent');
      });
      function getRowNumberText(_x1) {
        return _getRowNumberText2.apply(this, arguments);
      }
      return getRowNumberText;
    }(),
    /** Whether row number text is visible for a row */
    hasRowNumberText: function () {
      var _hasRowNumberText = (0, _asyncToGenerator2.default)(function* (index) {
        return (yield _getRowNumberText(index)).exists();
      });
      function hasRowNumberText(_x10) {
        return _hasRowNumberText.apply(this, arguments);
      }
      return hasRowNumberText;
    }(),
    /** Whether row number cell exists for a row */
    hasRowNumberCell: function () {
      var _hasRowNumberCell = (0, _asyncToGenerator2.default)(function* (index) {
        return (yield _getRowNumberCell(index)).exists();
      });
      function hasRowNumberCell(_x11) {
        return _hasRowNumberCell.apply(this, arguments);
      }
      return hasRowNumberCell;
    }(),
    getFloatingScrollBarDriver: function getFloatingScrollBarDriver() {
      var viewportElement = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : body;
      return (0, _FloatingScrollBarUni.FloatingScrollBarUniDriver)(viewportElement.$('[data-hook="table-floating-scroll-bar"]'), body);
    }
  });
};
exports.tableUniDriverFactory = tableUniDriverFactory;
//# sourceMappingURL=Table.uni.driver.js.map