"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.createDriver = exports.WithFocusablePureComponent = exports.PureChildComponent = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _react = _interopRequireDefault(require("react"));
var _react2 = require("../../utils/test-utils/react");
var _Focusable = require("./Focusable");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/common/Focusable/Focusable.driver.jsx";
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; }
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var _hasFocusState = function hasFocusState(element) {
  return element.className.includes('focus') === true;
};
var _hasFocusVisibleState = function hasFocusVisibleState(element) {
  return element.className.includes('focus-visible') === true;
};
var PureChildComponent = exports.PureChildComponent = /*#__PURE__*/function (_React$PureComponent) {
  function PureChildComponent(props) {
    var _this;
    (0, _classCallCheck2["default"])(this, PureChildComponent);
    _this = _callSuper(this, PureChildComponent, [props]);
    _this.id = void 0;
    _this.unboundMethod = function () {
      return 'unboundMethod';
    };
    _this.boundMethod = function () {
      return _this.id;
    };
    _this.id = props.id;
    _this.boundMethod = _this.boundMethod.bind(_this);
    return _this;
  }
  (0, _inherits2["default"])(PureChildComponent, _React$PureComponent);
  return (0, _createClass2["default"])(PureChildComponent, [{
    key: "render",
    value: function render() {
      return /*#__PURE__*/_react["default"].createElement("div", {
        onFocus: this.props.focusableOnFocus,
        onBlur: this.props.focusableOnBlur,
        "data-hook": this.props['data-hook'],
        className: this.props.className,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 27,
          columnNumber: 7
        }
      }, "Hello");
    }
  }]);
}(_react["default"].PureComponent);
PureChildComponent.staticVariable = 'staticVariable';
PureChildComponent.staticMethod = function () {
  return 'staticMethod';
};
var focusableDriverFactory = function focusableDriverFactory(_ref) {
  var element = _ref.element,
    eventTrigger = _ref.eventTrigger;
  return {
    exists: function exists() {
      return !!element;
    },
    focus: function focus() {
      return !!element && eventTrigger.focus(element);
    },
    blur: function blur() {
      return !!element && eventTrigger.blur(element);
    },
    hasFocusState: function hasFocusState() {
      return !!element && _hasFocusState(element);
    },
    hasFocusVisibleState: function hasFocusVisibleState() {
      return !!element && _hasFocusVisibleState(element);
    }
  };
};
var render = (0, _react2.createRendererWithDriver)(focusableDriverFactory);
var createDriver = exports.createDriver = function createDriver(Component) {
  var _render = render(Component),
    driver = _render.driver;
  var fireMouseDown = function fireMouseDown() {
    return window.dispatchEvent(new window.Event('mousedown'));
  };
  var fireMouseUp = function fireMouseUp() {
    return window.dispatchEvent(new window.Event('mouseup'));
  };
  var fireKeyDown = function fireKeyDown() {
    return window.dispatchEvent(new window.Event('keydown'));
  };
  var fireKeyUp = function fireKeyUp() {
    return window.dispatchEvent(new window.Event('keyup'));
  };
  var tabOut = function tabOut() {
    fireKeyDown();
    driver.blur();
    fireKeyUp();
  };
  var tabIn = function tabIn() {
    fireKeyDown();
    driver.focus();
    fireKeyUp();
  };
  var click = function click() {
    fireMouseDown();
    driver.focus();
    fireMouseUp();
  };
  return _objectSpread(_objectSpread({}, driver), {}, {
    fireMouseDown: fireMouseDown,
    fireKeyDown: fireKeyDown,
    fireKeyUp: fireKeyUp,
    tabOut: tabOut,
    tabIn: tabIn,
    click: click
  });
};
var WithFocusablePureComponent = exports.WithFocusablePureComponent = (0, _Focusable.withFocusable)(PureChildComponent);