"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.autoCompleteWithLabelDriverFactory = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _unidriver = require("../utils/test-utils/unidriver");
var _InputUni = require("../Input/Input.uni.driver");
var _LabelledElementUni = require("../LabelledElement/LabelledElement.uni.driver");
var _AutoCompleteWithLabel = require("./AutoCompleteWithLabel.constants");
var _DropdownLayoutUni = require("../DropdownLayout/DropdownLayout.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 autoCompleteWithLabelDriverFactory = base => {
  var labelledElementSelector = "[data-hook=\"".concat(_AutoCompleteWithLabel.DATA_HOOKS.labelledElement, "\"]");
  var labelledElementDriver = (0, _LabelledElementUni.labelledElementDriverFactory)(base.$(labelledElementSelector));
  var inputWrapperSelector = "[data-hook=\"".concat(_AutoCompleteWithLabel.DATA_HOOKS.inputWithLabel, "\"]");
  // @ts-expect-error body is a required argument but this driver does not use methods that require it
  var inputDriver = (0, _InputUni.testkit)(base.$(inputWrapperSelector));

  // @ts-expect-error body is a required argument but this driver does not use methods that require it
  var dropdownLayoutDriver = (0, _DropdownLayoutUni.dropdownLayoutDriverFactory)(base.$("[data-hook=\"".concat(_AutoCompleteWithLabel.DATA_HOOKS.inputDropdownLayout, "\"]")));
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    /**
     * Gets label text
     * @return {Promise<string>}
     */
    getLabelText: () => labelledElementDriver.getLabelText(),
    /**
     * Gets input value
     * @return {Promise<string>}
     */
    getValue: () => inputDriver.getValue(),
    /**
     * Enters given text to input
     * @param {string} text Text to input
     * @returns {Promise<void>}
     */
    enterText: function () {
      var _enterText = (0, _asyncToGenerator2.default)(function* (text) {
        return inputDriver.enterText(text);
      });
      function enterText(_x) {
        return _enterText.apply(this, arguments);
      }
      return enterText;
    }(),
    /**
     * Clicks an option at given index
     * @param {number} index Position of the option
     * @returns {Promise<void>}
     */
    clickAtOption: function () {
      var _clickAtOption = (0, _asyncToGenerator2.default)(function* (index) {
        yield inputDriver.click();
        return dropdownLayoutDriver.clickAtOption(index);
      });
      function clickAtOption(_x2) {
        return _clickAtOption.apply(this, arguments);
      }
      return clickAtOption;
    }(),
    /**
     * Clicks an option with a given value
     * @param {string} value The option value
     * @returns {Promise<void>}
     */
    clickAtOptionWithValue: function () {
      var _clickAtOptionWithValue = (0, _asyncToGenerator2.default)(function* (value) {
        yield inputDriver.click();
        return dropdownLayoutDriver.clickAtOptionWithValue(value);
      });
      function clickAtOptionWithValue(_x3) {
        return _clickAtOptionWithValue.apply(this, arguments);
      }
      return clickAtOptionWithValue;
    }(),
    /**
     * Clicks the menu arrow
     * @returns {Promise<void>}
     */
    clickMenuArrow: () => inputDriver.clickMenuArrow(),
    /**
     * Checks if input is disabled
     * @returns {Promise<boolean>}
     */
    isDisabled: function () {
      var _isDisabled = (0, _asyncToGenerator2.default)(function* () {
        return inputDriver.isDisabled();
      });
      function isDisabled() {
        return _isDisabled.apply(this, arguments);
      }
      return isDisabled;
    }(),
    /**
     * Triggers blur event on the input element
     * @returns {Promise<void>}
     */
    blur: () => inputDriver.blur(),
    /**
     * Checks whether there's a visible error icon
     * @return {Promise<boolean>}
     */
    hasError: () => inputDriver.hasStatus('error')
  });
};
exports.autoCompleteWithLabelDriverFactory = autoCompleteWithLabelDriverFactory;
//# sourceMappingURL=AutoCompleteWithLabel.uni.driver.js.map