import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
var _excluded = ["tag"];
import { createVNode as _createVNode } from "vue";
import { onUpdated, getCurrentInstance, defineComponent, nextTick, Transition as T, TransitionGroup as TG } from 'vue';
export var getTransitionProps = function getTransitionProps(transitionName) {
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

  if (process.env.NODE_ENV === 'test') {
    return opt;
  }

  var transitionProps = transitionName ? _objectSpread({
    appear: true,
    // type: 'animation',
    // appearFromClass: `${transitionName}-appear ${transitionName}-appear-prepare`,
    // appearActiveClass: `antdv-base-transtion`,
    // appearToClass: `${transitionName}-appear ${transitionName}-appear-active`,
    enterFromClass: "".concat(transitionName, "-enter ").concat(transitionName, "-enter-prepare"),
    // enterActiveClass: `${transitionName}-enter ${transitionName}-enter-active`,
    enterToClass: "".concat(transitionName, "-enter ").concat(transitionName, "-enter-active"),
    leaveFromClass: " ".concat(transitionName, "-leave"),
    leaveActiveClass: "".concat(transitionName, "-leave ").concat(transitionName, "-leave-active"),
    leaveToClass: "".concat(transitionName, "-leave ").concat(transitionName, "-leave-active")
  }, opt) : _objectSpread({
    css: false
  }, opt);
  return transitionProps;
};
export var getTransitionGroupProps = function getTransitionGroupProps(transitionName) {
  var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  var transitionProps = transitionName ? _objectSpread({
    appear: true,
    // appearFromClass: `${transitionName}-appear ${transitionName}-appear-prepare`,
    appearActiveClass: "".concat(transitionName),
    appearToClass: "".concat(transitionName, "-appear ").concat(transitionName, "-appear-active"),
    enterFromClass: "".concat(transitionName, "-appear ").concat(transitionName, "-enter ").concat(transitionName, "-appear-prepare ").concat(transitionName, "-enter-prepare"),
    enterActiveClass: "".concat(transitionName),
    enterToClass: "".concat(transitionName, "-enter ").concat(transitionName, "-appear ").concat(transitionName, "-appear-active ").concat(transitionName, "-enter-active"),
    leaveActiveClass: "".concat(transitionName, " ").concat(transitionName, "-leave"),
    leaveToClass: "".concat(transitionName, "-leave-active")
  }, opt) : _objectSpread({
    css: false
  }, opt);
  return transitionProps;
};
var Transition = T;
var TransitionGroup = TG;

if (process.env.NODE_ENV === 'test') {
  Transition = defineComponent({
    name: 'TransitionForTest',
    inheritAttrs: false,
    setup: function setup(_props, _ref) {
      var slots = _ref.slots,
          attrs = _ref.attrs;
      var instance = getCurrentInstance();
      onUpdated(function () {
        var child = instance.subTree.children[0];

        if (child && child.dirs && child.dirs[0]) {
          var value = child.dirs[0].value;
          var oldValue = child.dirs[0].oldValue;

          if (!value && value !== oldValue) {
            nextTick(function () {
              if (attrs.onAfterLeave) {
                attrs.onAfterLeave(instance.vnode.el);
              }
            });
          }
        }
      });
      return function () {
        var _slots$default;

        return (_slots$default = slots.default) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots);
      };
    }
  });
  TransitionGroup = defineComponent({
    name: 'TransitionGroupForTest',
    inheritAttrs: false,
    props: ['tag', 'class'],
    setup: function setup(props, _ref2) {
      var slots = _ref2.slots;
      return function () {
        var _slots$default2;

        var Tag = props.tag,
            rest = _objectWithoutProperties(props, _excluded);

        var children = ((_slots$default2 = slots.default) === null || _slots$default2 === void 0 ? void 0 : _slots$default2.call(slots)) || [];

        if (Tag) {
          return _createVNode(Tag, rest, {
            default: function _default() {
              return [children];
            }
          });
        } else {
          return children;
        }
      };
    }
  });
}

// ================== Collapse Motion ==================
var getCollapsedHeight = function getCollapsedHeight() {
  return {
    height: 0,
    opacity: 0
  };
};

var getRealHeight = function getRealHeight(node) {
  return {
    height: "".concat(node.scrollHeight, "px"),
    opacity: 1
  };
};

var getCurrentHeight = function getCurrentHeight(node) {
  return {
    height: "".concat(node.offsetHeight, "px")
  };
}; // const skipOpacityTransition: MotionEndEventHandler = (_, event) =>
//   (event as TransitionEvent).propertyName === 'height';


var collapseMotion = function collapseMotion(style, className) {
  return {
    name: 'ant-motion-collapse',
    appear: true,
    css: true,
    onBeforeEnter: function onBeforeEnter(node) {
      className.value = 'ant-motion-collapse';
      style.value = getCollapsedHeight(node);
    },
    onEnter: function onEnter(node) {
      nextTick(function () {
        style.value = getRealHeight(node);
      });
    },
    onAfterEnter: function onAfterEnter() {
      className.value = '';
      style.value = {};
    },
    onBeforeLeave: function onBeforeLeave(node) {
      className.value = 'ant-motion-collapse';
      style.value = getCurrentHeight(node);
    },
    onLeave: function onLeave(node) {
      window.setTimeout(function () {
        style.value = getCollapsedHeight(node);
      });
    },
    onAfterLeave: function onAfterLeave() {
      className.value = '';
      style.value = {};
    }
  };
};

var getTransitionName = function getTransitionName(rootPrefixCls, motion, transitionName) {
  if (transitionName !== undefined) {
    return transitionName;
  }

  return "".concat(rootPrefixCls, "-").concat(motion);
};

export { Transition, TransitionGroup, collapseMotion, getTransitionName };
export default Transition;