import { defineComponent, useAttrs, ref, watch, resolveComponent, createBlock, openBlock, withCtx, createElementVNode, normalizeClass, unref, createElementBlock, mergeProps, createCommentVNode, createVNode, renderSlot, normalizeProps, guardReactiveProps, toDisplayString, Transition, Fragment, createTextVNode } from 'vue';
import '../../../utils/index.mjs';
import { operateTreeEmits, operateTreeProps } from './operate-tree.mjs';
import { CaretRightOutlined, CaretDownOutlined } from '@ant-design/icons-vue';
import { createNamespace } from '../../../utils/create-namespace.mjs';

"use strict";
var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{ name: "LlOperateTree" },
  __name: "operate-tree",
  props: operateTreeProps,
  emits: operateTreeEmits,
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emits = __emit;
    const attrs = useAttrs();
    const newExpandedKeys = ref([]);
    const hoverTreeNodeItem = ref();
    const bem = createNamespace("operate-tree");
    const handleMouseenter = ({ node }) => {
      hoverTreeNodeItem.value = node;
    };
    const handleMouseleave = () => {
      hoverTreeNodeItem.value = void 0;
    };
    const expand = (expandedKeys, data) => {
      newExpandedKeys.value = expandedKeys;
      emits("expand", expandedKeys, data);
    };
    const select = (selectedKeys, e) => {
      emits("select", selectedKeys, e);
    };
    watch(
      () => props.expandedKeys,
      (keys) => {
        if (keys) {
          newExpandedKeys.value = keys;
        }
      },
      {
        deep: true,
        immediate: true
      }
    );
    return (_ctx, _cache) => {
      const _component_a_directory_tree = resolveComponent("a-directory-tree");
      const _component_ll_empty = resolveComponent("ll-empty");
      const _component_a_spin = resolveComponent("a-spin");
      return openBlock(), createBlock(_component_a_spin, { spinning: _ctx.loading }, {
        default: withCtx(() => [
          createElementVNode(
            "div",
            {
              class: normalizeClass(unref(bem).b()),
              onMouseleave: handleMouseleave
            },
            [
              _ctx.treeData?.length ? (openBlock(), createBlock(_component_a_directory_tree, mergeProps({ key: 0 }, unref(attrs), {
                "block-node": true,
                multiple: "",
                "tree-data": _ctx.treeData,
                "expanded-keys": newExpandedKeys.value,
                "field-names": _ctx.fieldNames,
                onExpand: expand,
                onSelect: select,
                onMouseenter: handleMouseenter
              }), {
                switcherIcon: withCtx((slots) => [
                  renderSlot(_ctx.$slots, "switcherIcon", normalizeProps(guardReactiveProps(slots)), () => [
                    !slots.expanded ? (openBlock(), createBlock(unref(CaretRightOutlined), { key: 0 })) : (openBlock(), createBlock(unref(CaretDownOutlined), { key: 1 }))
                  ])
                ]),
                title: withCtx((slots) => [
                  createElementVNode(
                    "div",
                    {
                      class: normalizeClass(unref(bem).e("title"))
                    },
                    [
                      createElementVNode("div", null, [
                        createCommentVNode(" icon-slots "),
                        _ctx.$slots.icon ? (openBlock(), createElementBlock(
                          "div",
                          {
                            key: 0,
                            class: normalizeClass(unref(bem).e("icon"))
                          },
                          [
                            renderSlot(_ctx.$slots, "icon", normalizeProps(guardReactiveProps(slots)))
                          ],
                          2
                          /* CLASS */
                        )) : createCommentVNode("v-if", true),
                        createCommentVNode(" title-slots "),
                        renderSlot(_ctx.$slots, "treeTitle", normalizeProps(guardReactiveProps(slots)), () => [
                          createElementVNode(
                            "span",
                            null,
                            toDisplayString(slots[_ctx.fieldNames["title"]]),
                            1
                            /* TEXT */
                          )
                        ])
                      ]),
                      createCommentVNode(" operate-slots "),
                      createVNode(
                        Transition,
                        { duration: 100 },
                        {
                          default: withCtx(() => [
                            hoverTreeNodeItem.value && hoverTreeNodeItem.value[_ctx.fieldNames["key"]] === slots[_ctx.fieldNames["key"]] ? (openBlock(), createElementBlock(
                              "div",
                              {
                                key: 0,
                                class: normalizeClass(`${unref(bem).e("operate")} ${hoverTreeNodeItem.value && hoverTreeNodeItem.value[_ctx.fieldNames["key"]] === slots[_ctx.fieldNames["key"]] && ((props.dropdownOpenState?.[slots[_ctx.fieldNames["key"]]] || props.operateDropdownOpen) ?? false) ? unref(bem).is("open") : unref(bem).is("close")}`)
                              },
                              [
                                renderSlot(_ctx.$slots, "treeOperate", { data: slots })
                              ],
                              2
                              /* CLASS */
                            )) : createCommentVNode("v-if", true)
                          ]),
                          _: 2
                          /* DYNAMIC */
                        },
                        1024
                        /* DYNAMIC_SLOTS */
                      )
                    ],
                    2
                    /* CLASS */
                  )
                ]),
                _: 3
                /* FORWARDED */
              }, 16, ["tree-data", "expanded-keys", "field-names"])) : (openBlock(), createElementBlock(
                Fragment,
                { key: 1 },
                [
                  createCommentVNode(" empty-slots "),
                  renderSlot(_ctx.$slots, "empty", {}, () => [
                    createVNode(_component_ll_empty, null, {
                      content: withCtx(() => [..._cache[0] || (_cache[0] = [
                        createTextVNode(
                          "\u6682\u65E0\u6570\u636E",
                          -1
                          /* CACHED */
                        )
                      ])]),
                      _: 1
                      /* STABLE */
                    })
                  ])
                ],
                64
                /* STABLE_FRAGMENT */
              ))
            ],
            34
            /* CLASS, NEED_HYDRATION */
          )
        ]),
        _: 3
        /* FORWARDED */
      }, 8, ["spinning"]);
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=operate-tree.vue2.mjs.map
