'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
require('../../transition/index.cjs');
var TreeNode = require('./TreeNode.cjs');
var contextTypes = require('./contextTypes.cjs');
var props = require('./props.cjs');
var collapseMotion = require('../../transition/src/collapseMotion.cjs');

var MotionTreeNode = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "MotionTreeNode",
  inheritAttrs: false,
  props: {
    ...props.treeNodeProps,
    active: Boolean,
    motion: Object,
    motionNodes: {
      type: Array
    },
    onMotionStart: Function,
    onMotionEnd: Function,
    motionType: String
    // treeNodeRequiredProps: { type: Object as PropType<TreeNodeRequiredProps> },
  },
  setup(props, {
    attrs,
    slots
  }) {
    const visible = vue.shallowRef(true);
    const context = contextTypes.useInjectTreeContext();
    const motionedRef = vue.shallowRef(false);
    const transitionProps = vue.computed(() => {
      if (props.motion)
        return props.motion;
      else
        return collapseMotion.collapseMotion();
    });
    const onMotionEnd = (node, type) => {
      var _a, _b, _c, _d;
      if (type === "appear")
        (_b = (_a = transitionProps.value) == null ? void 0 : _a.onAfterEnter) == null ? void 0 : _b.call(_a, node);
      else if (type === "leave")
        (_d = (_c = transitionProps.value) == null ? void 0 : _c.onAfterLeave) == null ? void 0 : _d.call(_c, node);
      if (!motionedRef.value)
        props.onMotionEnd();
      motionedRef.value = true;
    };
    vue.watch(() => props.motionNodes, () => {
      if (props.motionNodes && props.motionType === "hide" && visible.value) {
        vue.nextTick(() => {
          visible.value = false;
        });
      }
    }, {
      immediate: true,
      flush: "post"
    });
    vue.onMounted(() => {
      props.motionNodes && props.onMotionStart();
    });
    vue.onBeforeUnmount(() => {
      props.motionNodes && onMotionEnd();
    });
    return () => {
      const {
        motion,
        motionNodes,
        motionType,
        active,
        eventKey,
        ...otherProps
      } = props;
      if (motionNodes) {
        return vue.createVNode(vue.Transition, {
          ...transitionProps.value,
          "appear": motionType === "show",
          "onAfterAppear": (node) => onMotionEnd(node, "appear"),
          "onAfterLeave": (node) => onMotionEnd(node, "leave")
        }, {
          default: () => [vue.withDirectives(vue.createVNode("div", {
            "class": `${context.value.prefixCls}-treenode-motion`
          }, [motionNodes.map((treeNode) => {
            const {
              data: {
                ...restProps
              },
              title,
              key,
              isStart,
              isEnd
            } = treeNode;
            delete restProps.children;
            return vue.createVNode(TreeNode.default, {
              ...restProps,
              "title": title,
              "active": active,
              "data": treeNode.data,
              "key": key,
              "eventKey": key,
              "isStart": isStart,
              "isEnd": isEnd
            }, slots);
          })]), [[vue.vShow, visible.value]])]
        });
      }
      return vue.createVNode(TreeNode.default, {
        "class": attrs.class,
        "style": attrs.style,
        ...otherProps,
        "active": active,
        "eventKey": eventKey
      }, slots);
    };
  }
});

exports.default = MotionTreeNode;
//# sourceMappingURL=MotionTreeNode.cjs.map
