import { defineComponent, ref, useAttrs, watch, resolveComponent, createElementBlock, openBlock, normalizeClass, unref, createCommentVNode, createVNode, createBlock, withCtx, renderSlot, mergeProps, normalizeProps, guardReactiveProps, Fragment } from 'vue';
import '../../../utils/index.mjs';
import './config/index.mjs';
import './components/header-search.vue.mjs';
import './components/directory-title.vue.mjs';
import '../../index.mjs';
import { createNamespace } from '../../../utils/create-namespace.mjs';
import _sfc_main$1 from './components/header-search.vue2.mjs';
import _sfc_main$2 from './components/directory-title.vue2.mjs';
import { LlOperateTree } from '../../operate-tree/index.mjs';
import { treeSearchEmits, treeSearchProps } from './config/tree-search.mjs';

"use strict";
var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{ name: "LlTreeSearch" },
  __name: "tree-search",
  props: treeSearchProps,
  emits: treeSearchEmits,
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emits = __emit;
    const isCollapseMenu = ref(false);
    const newExpandedKeys = ref([]);
    const bem = createNamespace("tree-search");
    const attrs = useAttrs();
    const getTreeDataKeys = (children) => {
      const keys = [];
      const getKeys = (children2) => {
        if (children2) {
          children2.forEach((item) => {
            keys.push(item[props.fieldNames["key"]]);
            if (item[props.fieldNames["children"]]) {
              getKeys(item[props.fieldNames["children"]]);
            }
          });
        }
      };
      getKeys(children);
      return keys;
    };
    const handleCollapseMenu = () => {
      isCollapseMenu.value = !isCollapseMenu.value;
      if (isCollapseMenu.value) {
        newExpandedKeys.value = getTreeDataKeys(props.treeData);
      } else {
        newExpandedKeys.value = [];
      }
    };
    const handleSearchInputChange = (v) => {
      props.onSearchInputChange && props.onSearchInputChange(v);
    };
    const handleClickAddBtn = () => emits("clickAdd");
    const handleTreeExpand = (expandedKeys, data) => {
      emits("expand", expandedKeys, data);
    };
    const handleTreeSelect = (keys, e) => {
      emits("select", keys, e);
    };
    const handleClickOkBtn = () => emits("ok");
    const handleClickCancelBtn = () => emits("cancel");
    const handleClickCloseBtn = () => emits("close");
    watch(
      () => props.expandedKeys,
      (keys) => {
        if (keys) {
          newExpandedKeys.value = keys;
        }
      },
      {
        deep: true
      }
    );
    return (_ctx, _cache) => {
      const _component_ll_modal = resolveComponent("ll-modal");
      const _component_ll_drawer = resolveComponent("ll-drawer");
      return openBlock(), createElementBlock(
        "div",
        {
          class: normalizeClass(unref(bem).b())
        },
        [
          createCommentVNode(" \u5934\u90E8\u641C\u7D22 "),
          createVNode(_sfc_main$1, {
            "throttle-time": _ctx.throttleTime,
            "search-value": _ctx.searchValue,
            "is-show-add-btn": _ctx.isShowAddBtn,
            "on-search-input-change": handleSearchInputChange,
            onClick: handleClickAddBtn
          }, null, 8, ["throttle-time", "search-value", "is-show-add-btn"]),
          createCommentVNode(" \u76EE\u5F55\u6807\u9898 "),
          createVNode(_sfc_main$2, {
            "is-collapse-menu": isCollapseMenu.value,
            onCollapseMenu: handleCollapseMenu
          }, {
            title: withCtx(() => [
              renderSlot(_ctx.$slots, "directoryTitle")
            ]),
            _: 3
            /* FORWARDED */
          }, 8, ["is-collapse-menu"]),
          createCommentVNode(" operate-tree "),
          createVNode(unref(LlOperateTree), mergeProps(unref(attrs), {
            "operate-dropdown-open": _ctx.operateDropdownOpen,
            loading: _ctx.loading,
            "field-names": _ctx.fieldNames,
            "tree-data": _ctx.treeData,
            "expanded-keys": newExpandedKeys.value,
            onExpand: handleTreeExpand,
            onSelect: handleTreeSelect
          }), {
            switcherIcon: withCtx((slots) => [
              renderSlot(_ctx.$slots, "switcherIcon", normalizeProps(guardReactiveProps(slots)))
            ]),
            icon: withCtx((slots) => [
              renderSlot(_ctx.$slots, "icon", normalizeProps(guardReactiveProps(slots)))
            ]),
            treeTitle: withCtx((slots) => [
              renderSlot(_ctx.$slots, "treeTitle", normalizeProps(guardReactiveProps(slots)))
            ]),
            treeOperate: withCtx((slots) => [
              renderSlot(_ctx.$slots, "treeOperate", normalizeProps(guardReactiveProps(slots.data)))
            ]),
            empty: withCtx(() => [
              renderSlot(_ctx.$slots, "empty")
            ]),
            _: 3
            /* FORWARDED */
          }, 16, ["operate-dropdown-open", "loading", "field-names", "tree-data", "expanded-keys"]),
          createCommentVNode(" \u64CD\u4F5C\u51FA\u73B0\u7684\u65B9\u5F0F "),
          createCommentVNode(" \u6A21\u6001\u6846 "),
          _ctx.operateWay === "modal" ? (openBlock(), createBlock(_component_ll_modal, mergeProps({ key: 0 }, _ctx.modalConfigProps, {
            open: _ctx.open,
            onOk: handleClickOkBtn,
            onCancel: handleClickCancelBtn
          }), {
            default: withCtx(() => [
              renderSlot(_ctx.$slots, "operateBoxContent")
            ]),
            _: 3
            /* FORWARDED */
          }, 16, ["open"])) : _ctx.operateWay === "drawer" ? (openBlock(), createElementBlock(
            Fragment,
            { key: 1 },
            [
              createCommentVNode(" \u62BD\u5C49 "),
              createVNode(_component_ll_drawer, mergeProps(_ctx.drawerConfigProps, {
                open: _ctx.open,
                onConfirm: handleClickOkBtn,
                onCancel: handleClickCancelBtn,
                onClose: handleClickCloseBtn
              }), {
                "footer-left": withCtx(() => [
                  renderSlot(_ctx.$slots, "drawerFooterLeft")
                ]),
                default: withCtx(() => [
                  renderSlot(_ctx.$slots, "operateBoxContent")
                ]),
                _: 3
                /* FORWARDED */
              }, 16, ["open"])
            ],
            64
            /* STABLE_FRAGMENT */
          )) : createCommentVNode("v-if", true)
        ],
        2
        /* CLASS */
      );
    };
  }
});

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