"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _Tooltip = require("../Tooltip/Tooltip.driver");
var _Text = _interopRequireDefault(require("../Text/Text.driver"));
var _constants = require("./constants");
var DATA_ATTR = _interopRequireWildcard(require("./DataAttr"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var checkboxDriverFactory = _ref => {
  var {
    element,
    eventTrigger
  } = _ref;
  var byHook = hook => element.querySelector("[data-hook*=\"".concat(hook, "\"]"));
  var input = () => element.querySelector('input');
  var checkbox = () => element.querySelector(_constants.dataHooks.box);
  var isChecked = () => input().checked;
  var labelText = () => element.querySelector("[data-hook=\"".concat(_constants.dataHooks.children, "\"]"));
  var labelTextDriver = () => (0, _Text.default)({
    element: labelText()
  });
  var getTooltipDriver = () => (0, _Tooltip.tooltipLegacyDriverFactory)({
    element: byHook(_constants.dataHooks.boxTooltip),
    eventTrigger
  });
  return {
    exists: () => !!element,
    click: () => eventTrigger.change(input(), {
      target: {
        checked: !isChecked()
      }
    }),
    /** Trigger focus on the element */
    focus: () => eventTrigger.focus(input()),
    /** Checks whether the checkbox is focused */
    isFocused: () => input() === document.activeElement,
    /** trigger blur on the element */
    blur: () => eventTrigger.blur(input()),
    isChecked,
    isDisabled: () => input().disabled,
    isIndeterminate: () => element.getAttribute(DATA_ATTR.DATA_CHECK_TYPE) === DATA_ATTR.CHECK_TYPES.INDETERMINATE,
    isTooltipEnabled: () => !!getTooltipDriver().getTooltipText(),
    hasError: () => element.getAttribute(DATA_ATTR.DATA_HAS_ERROR) === 'true',
    getTooltipContent: () => getTooltipDriver().getTooltipText(),
    getLabel: () => labelTextDriver().getText(),
    getLabelSize: () => labelTextDriver().getSize()
  };
};
var _default = exports.default = checkboxDriverFactory;
//# sourceMappingURL=Checkbox.driver.js.map