"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.listItemEditableDriverFactory = void 0;
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _IconButtonUni = require("../IconButton/IconButton.uni.driver");
var _InputUni = require("../Input/Input.uni.driver");
var _TooltipUni = require("../Tooltip/Tooltip.uni.driver");
var _unidriver = require("../utils/test-utils/unidriver");
var _ListItemEditable = require("./ListItemEditable.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 listItemEditableDriverFactory = (base, body) => {
  var inputSelector = "[data-hook=\"".concat(_ListItemEditable.dataHooks.input, "\"]");
  var approveButtonSelector = "[data-hook=\"".concat(_ListItemEditable.dataHooks.approveButton, "\"]");
  var cancelButtonSelector = "[data-hook=\"".concat(_ListItemEditable.dataHooks.cancelButton, "\"]");
  var cancelButtonTooltipSelector = "[data-hook=\"".concat(_ListItemEditable.dataHooks.cancelButtonTooltip, "\"]");
  var approveButtonTooltipSelector = "[data-hook=\"".concat(_ListItemEditable.dataHooks.approveButtonTooltip, "\"]");
  var inputDriver = (0, _InputUni.testkit)(base.$(inputSelector), body);
  var approveButtonDriver = (0, _IconButtonUni.iconButtonDriverFactory)(base.$(approveButtonSelector));
  var cancelButtonDriver = (0, _IconButtonUni.iconButtonDriverFactory)(base.$(cancelButtonSelector));
  var cancelButtonTooltipDriver = (0, _TooltipUni.tooltipDriverFactory)(base.$(cancelButtonTooltipSelector), body);
  var approveButtonTooltipDriver = (0, _TooltipUni.tooltipDriverFactory)(base.$(approveButtonTooltipSelector), body);
  return _objectSpread(_objectSpread({}, (0, _unidriver.baseUniDriverFactory)(base)), {}, {
    /** A getter for the value */
    getValue: () => inputDriver.getValue(),
    /** A getter for the placeholder */
    getPlaceholder: () => inputDriver.getPlaceholder(),
    /** Returns true it the approve button is disabled */
    isApproveButtonDisabled: () => approveButtonDriver.isButtonDisabled(),
    /** Simulated writing text in the input */
    enterText: text => inputDriver.enterText(text),
    /** Simulates clicking the approve button */
    clickApprove: () => approveButtonDriver.click(),
    /** Simulates clicking the cancel button */
    clickCancel: () => cancelButtonDriver.click(),
    /** Simulates clicking the enter key */
    pressEnter: () => inputDriver.trigger('keyDown', {
      key: 'Enter'
    }),
    /** Returns true if input element is focused */
    isFocus: () => inputDriver.isFocus(),
    /** Returns true if input element has suffix */
    hasSuffix: () => inputDriver.hasSuffix(),
    /** Returns cancel button tooltip text */
    getCancelButtonTooltipText: function () {
      var _getCancelButtonTooltipText = (0, _asyncToGenerator2.default)(function* () {
        yield cancelButtonTooltipDriver.mouseEnter();
        if (yield cancelButtonTooltipDriver.tooltipExists()) {
          // @ts-ignore users expect string, but implementation can give null
          return cancelButtonTooltipDriver.getTooltipText();
        }

        // @ts-expect-error users expect string, but implementation can give null
        return null;
      });
      function getCancelButtonTooltipText() {
        return _getCancelButtonTooltipText.apply(this, arguments);
      }
      return getCancelButtonTooltipText;
    }(),
    /** Returns approve button tooltip text */
    getApproveButtonTooltipText: function () {
      var _getApproveButtonTooltipText = (0, _asyncToGenerator2.default)(function* () {
        yield approveButtonTooltipDriver.mouseEnter();
        if (yield approveButtonTooltipDriver.tooltipExists()) {
          // @ts-ignore users expect string, but implementation can give null
          return approveButtonTooltipDriver.getTooltipText();
        }

        // @ts-expect-error users expect string, but implementation can give null
        return null;
      });
      function getApproveButtonTooltipText() {
        return _getApproveButtonTooltipText.apply(this, arguments);
      }
      return getApproveButtonTooltipText;
    }(),
    // Status
    /** Return true if the given status is displayed */
    hasStatus: status => inputDriver.hasStatus(status),
    /** If there's a status message, returns its text value */
    getStatusMessage: () => inputDriver.getStatusMessage(),
    /** Returns the maxLength attribute value */
    getMaxLength: () => inputDriver.getMaxLength()
  });
};
exports.listItemEditableDriverFactory = listItemEditableDriverFactory;
//# sourceMappingURL=ListItemEditable.uni.driver.js.map