"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.useTransition = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = require("@floating-ui/react");
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 getDuration = function getDuration() {
  var _transition$type;
  var transition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  var type = arguments.length > 1 ? arguments[1] : undefined;
  return typeof transition === 'number' ? transition : (_transition$type = transition == null ? void 0 : transition[type]) !== null && _transition$type !== void 0 ? _transition$type : 0;
};

/**
 * PopoverNext Content transition hook.
 */
var useTransition = _ref => {
  var {
    context,
    openDelay = 0,
    closeDelay = 0,
    duration = 0,
    opacity,
    transformOrigin,
    transform
  } = _ref;
  var openDuration = getDuration(duration, 'open');
  var closeDuration = getDuration(duration, 'close');
  var transitionStyles = {
    duration: {
      open: openDuration + openDelay,
      close: closeDuration + closeDelay
    },
    common: _ref2 => {
      var {
        side
      } = _ref2;
      return {
        transitionProperty: 'opacity',
        transformOrigin: typeof transformOrigin === 'string' ? transformOrigin : transformOrigin == null ? void 0 : transformOrigin(side)
      };
    },
    initial: _ref3 => {
      var {
        side
      } = _ref3;
      return _objectSpread(_objectSpread({
        opacity: 0
      }, opacity ? {
        opacity: opacity.close
      } : {}), {}, {
        transform: typeof transform === 'string' ? transform : transform == null ? void 0 : transform(side)
      });
    },
    open: _objectSpread(_objectSpread({
      opacity: 1
    }, opacity ? {
      opacity: opacity.open
    } : {}), {}, {
      transitionDelay: "".concat(openDelay, "ms"),
      transitionDuration: "".concat(openDuration, "ms")
    }),
    close: _objectSpread(_objectSpread({
      opacity: 0
    }, opacity ? {
      opacity: opacity.close
    } : {}), {}, {
      transitionDelay: "".concat(closeDelay, "ms"),
      transitionDuration: "".concat(closeDuration, "ms")
    })
  };
  return (0, _react.useTransitionStyles)(context, transitionStyles);
};
exports.useTransition = useTransition;
//# sourceMappingURL=useTransition.js.map