"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.multiselectUniDriverFactory = 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 _InputWithOptionsUni = require("../InputWithOptions/InputWithOptions.uni.driver");
var _TagUni = require("../Tag/Tag.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 multiselectUniDriverFactory = (base, body) => {
  var {
    driver,
    inputDriver,
    dropdownLayoutDriver
  } = (0, _InputWithOptionsUni.inputWithOptionsUniDriverFactory)(base, body);
  var getInputWrapper = /*#__PURE__*/function () {
    var _ref = (0, _asyncToGenerator2.default)(function* () {
      return (yield driver.inputWrapper()).childNodes[0];
    });
    return function getInputWrapper() {
      return _ref.apply(this, arguments);
    };
  }();
  var tags = base.$$('[data-hook="tag"]');
  var multiSelectDriver = _objectSpread(_objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), driver), {}, {
    /** returns the max height of the component */
    getMaxHeight: function () {
      var _getMaxHeight = (0, _asyncToGenerator2.default)(function* () {
        return (yield getInputWrapper()).style.maxHeight;
      });
      function getMaxHeight() {
        return _getMaxHeight.apply(this, arguments);
      }
      return getMaxHeight;
    }(),
    /** click on the input element wrapper */
    clickOnInputWrapper: function () {
      var _clickOnInputWrapper = (0, _asyncToGenerator2.default)(function* () {
        return inputDriver.click();
      });
      function clickOnInputWrapper() {
        return _clickOnInputWrapper.apply(this, arguments);
      }
      return clickOnInputWrapper;
    }(),
    /** returns true if the input is focused */
    inputWrapperHasFocus: () => inputDriver.isFocusedStyle(),
    /** returns true if the input is disabled */
    inputWrapperIsDisabled: function () {
      var _inputWrapperIsDisabled = (0, _asyncToGenerator2.default)(function* () {
        return !!(yield base.$('[data-hook="wsr-custom-input"]')).attr('disabled');
      });
      function inputWrapperIsDisabled() {
        return _inputWrapperIsDisabled.apply(this, arguments);
      }
      return inputWrapperIsDisabled;
    }(),
    /** returns the number of tags selected in the input */
    numberOfTags: () => tags.count(),
    /** returns the label of the tag given it's index */
    getTagLabelAt: index => tags.get(index).text(),
    /** press the comma key in the input field */
    pressCommaKey: () => inputDriver.pressKey(','),
    /** returns the `tagDriver` for the specified tag id */
    getTagDriverByTagId: function () {
      var _getTagDriverByTagId = (0, _asyncToGenerator2.default)(function* (tagId) {
        return (0, _TagUni.tagUniDriverFactory)(tags.filter(/*#__PURE__*/function () {
          var _ref2 = (0, _asyncToGenerator2.default)(function* (tag) {
            return (yield tag._prop('id')) === tagId;
          });
          return function (_x2) {
            return _ref2.apply(this, arguments);
          };
        }()).get(0));
      });
      function getTagDriverByTagId(_x) {
        return _getTagDriverByTagId.apply(this, arguments);
      }
      return getTagDriverByTagId;
    }(),
    /** returns true if a custom suffix exists */
    customSuffixExists: function () {
      var _customSuffixExists = (0, _asyncToGenerator2.default)(function* () {
        return !!(yield getInputWrapper()).querySelector('[data-hook="custom-suffix"]');
      });
      function customSuffixExists() {
        return _customSuffixExists.apply(this, arguments);
      }
      return customSuffixExists;
    }(),
    /** returns true if a custom prefix exists */
    customPrefixExists: function () {
      var _customPrefixExists = (0, _asyncToGenerator2.default)(function* () {
        return !!(yield getInputWrapper()).querySelector('[data-hook="custom-prefix"]');
      });
      function customPrefixExists() {
        return _customPrefixExists.apply(this, arguments);
      }
      return customPrefixExists;
    }(),
    /** returns true if a status indicator exists */
    statusIndicatorExists: function () {
      var _statusIndicatorExists = (0, _asyncToGenerator2.default)(function* () {
        return !!(yield getInputWrapper()).querySelector('[data-hook="input-status"]');
      });
      function statusIndicatorExists() {
        return _statusIndicatorExists.apply(this, arguments);
      }
      return statusIndicatorExists;
    }()
  });
  return {
    exists: function () {
      var _exists = (0, _asyncToGenerator2.default)(function* () {
        return base.exists();
      });
      function exists() {
        return _exists.apply(this, arguments);
      }
      return exists;
    }(),
    driver: multiSelectDriver,
    inputDriver,
    dropdownLayoutDriver
  };
};
exports.multiselectUniDriverFactory = multiselectUniDriverFactory;
//# sourceMappingURL=MultiSelect.uni.driver.js.map