"use strict";

exports.__esModule = true;
exports.default = void 0;
var _getOr2 = _interopRequireDefault(require("lodash/fp/getOr"));
var _noop2 = _interopRequireDefault(require("lodash/fp/noop"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _provider = _interopRequireWildcard(require("../provider"));
var _getShadowBoxColorFromPrimary = require("../../util/get-shadow-box-color-from-primary");
var _handle = _interopRequireDefault(require("./handle.css"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
class NoopHammer {
  constructor() {}

  // eslint-disable-next-line class-methods-use-this
  on() {
    return;
  }

  // eslint-disable-next-line class-methods-use-this
  stop() {
    return;
  }

  // eslint-disable-next-line class-methods-use-this
  destroy() {
    return;
  }
}
const Hammer =
// eslint-disable-next-line no-undef
typeof window !== 'undefined' ? /* istanbul ignore next */require('hammerjs') : NoopHammer;
const Handle = (props, legacyContext) => {
  const skin = (0, _provider.GetSkinFromContext)(legacyContext);
  const primaryColor = (0, _getOr2.default)('#00B0FF', 'common.primary', skin);
  const backgroundColor = primaryColor;
  const {
    onPanStart = _noop2.default,
    onPanEnd = _noop2.default,
    onPan = _noop2.default,
    HammerForTesting
  } = props;
  const handle = (0, _react.useRef)();
  const hammer = (0, _react.useMemo)(() => {
    return HammerForTesting || handle.current && new Hammer(handle.current);
    // (we need to mount Hammer when handle.current is rendered and ready)
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [handle.current, HammerForTesting]);
  (0, _react.useEffect)(() => {
    if (!hammer) return;
    hammer.on('panstart', onPanStart);
    hammer.on('panend', onPanEnd);
    hammer.on('panleft panright', onPan);
    return () => {
      hammer.stop();
      hammer.destroy();
    };
  }, [hammer, onPanStart, onPanEnd, onPan]);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: _handle.default.wrapper,
    "data-testid": "handle-wrapper"
  }, /*#__PURE__*/_react.default.createElement("div", {
    style: {
      backgroundColor,
      boxShadow: `0px 0px 20px ${(0, _getShadowBoxColorFromPrimary.getShadowBoxColorFromPrimary)(primaryColor)}`
    },
    className: _handle.default.defaultStyle,
    ref: handle,
    "data-name": 'handle'
  }));
};
Handle.propTypes = process.env.NODE_ENV !== "production" ? {
  onPan: _propTypes.default.func,
  onPanStart: _propTypes.default.func,
  onPanEnd: _propTypes.default.func,
  HammerForTesting: _propTypes.default.shape({
    on: _propTypes.default.func,
    destroy: _propTypes.default.func,
    stop: _propTypes.default.func
  })
} : {};
Handle.contextTypes = {
  skin: _provider.default.childContextTypes.skin
};
var _default = exports.default = Handle;
//# sourceMappingURL=handle.js.map