"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _Text = _interopRequireDefault(require("../Text/Text.driver"));
var _Tooltip = require("../Tooltip/Tooltip.driver");
var _constants = require("./constants");
var _deprecationTestkitLog = _interopRequireDefault(require("../utils/deprecationTestkitLog"));
var addItemDriverFactory = _ref => {
  var {
    element,
    eventTrigger
  } = _ref;
  (0, _deprecationTestkitLog.default)('addItemTestkitFactory legacy testkit is deprecated and will be removed in next major release. Please use the AddItemTestkit unidriver testkit instead.');
  var byHook = hook => element == null ? void 0 : element.querySelector("[data-hook=\"".concat(hook, "\"]"));
  var tooltipTestkit = (0, _Tooltip.tooltipLegacyDriverFactory)({
    // @ts-expect-error
    element: byHook(_constants.dataHooks.itemTooltip),
    eventTrigger
  });
  var textDriver = () =>
  // @ts-ignore
  (0, _Text.default)({
    element: byHook(_constants.dataHooks.itemText)
  });
  var subtitleTextDriver = () =>
  // @ts-ignore
  (0, _Text.default)({
    element: byHook(_constants.dataHooks.itemSubtitle)
  });
  var baseElement = byHook(_constants.dataHooks.addItem);
  return {
    /** returns true if element in the DOM */
    exists: () => !!baseElement,
    /** returns the driver element */
    element: () => baseElement,
    /** returns value of action text */
    getText: () => textDriver().getText(),
    /** true if passed children in string exists */
    textExists: () => textDriver().exists(),
    /** returns value of tooltip content */
    getTooltipContent: () => tooltipTestkit.getTooltipText(),
    /** clicks on element */
    click: () => baseElement && eventTrigger.click(baseElement),
    /** returns value of subtitle */
    getSubtitle: () => subtitleTextDriver().getText(),
    /** returns true if element is focused */
    isFocused: () => document.activeElement === baseElement,
    /** sets focus on the element */
    focus: () => {
      if (baseElement) {
        // @ts-expect-error
        baseElement.focus();
        eventTrigger.focus(baseElement);
      }
    },
    /** removes focus on the element */
    blur: () => {
      if (baseElement) {
        // @ts-expect-error
        baseElement.blur();
        eventTrigger.blur(baseElement);
      }
    }
  };
};
var _default = exports.default = addItemDriverFactory;
//# sourceMappingURL=AddItem.driver.js.map