import "../../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                             */
/* empty css                                                                     */
/* empty css                                                                    */
/* empty css                                                                */
/* empty css                                                                */
/* empty css                                                                 */
import { ref, computed, onMounted, createElementBlock, openBlock, createElementVNode, createVNode, unref, withCtx, createCommentVNode, toDisplayString } from "vue";
import { Search as search_default } from "../../../../../node_modules/@element-plus/icons-vue/dist/index.mjs";
/* empty css                 */
import _export_sfc from "../../../../../_virtual/_plugin-vue_export-helper.mjs";
import { ElInput } from "../../../../../node_modules/element-plus/es/components/input/index.mjs";
import { ElScrollbar } from "../../../../../node_modules/element-plus/es/components/scrollbar/index.mjs";
import { ElTree } from "../../../../../node_modules/element-plus/es/components/tree/index.mjs";
const _hoisted_1 = { class: "formula-list" };
const _hoisted_2 = { class: "formula-search" };
const _hoisted_3 = ["onMouseenter"];
const _hoisted_4 = {
  key: 0,
  class: "tip"
};
const _sfc_main = {
  __name: "FormulaList",
  props: {
    nodes: {
      type: Array,
      default: () => []
    },
    treeProps: {
      type: Object,
      default: () => ({
        children: "formula",
        label: "name"
      })
    }
  },
  emits: ["formulaClick", "enterInfo"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const searchTreeVariable = ref("");
    const currentKeyNode = ref({});
    const filterData = computed(() => {
      if (!searchTreeVariable.value) {
        return props.nodes;
      }
      return filterTreeData(props.nodes);
    });
    const nodeClick = (o) => {
      if (o.formula) {
        if (currentKeyNode.value && currentKeyNode.value.enCode) {
          currentKeyNode.value = {};
        }
        return;
      }
      currentKeyNode.value = o;
      emit("formulaClick", o);
    };
    const filterTreeData = (nodes) => {
      return nodes.reduce((pre, cur) => {
        if (cur.name.toLowerCase().includes(searchTreeVariable.value)) {
          pre.push({ ...cur });
        }
        if (cur.formula) {
          pre.push(...filterTreeData(cur.formula));
        }
        return pre;
      }, []);
    };
    const enterInfo = (data) => {
      if (data.formula) return;
      emit("enterInfo", data);
    };
    const leaveTree = () => {
      if (currentKeyNode.value && currentKeyNode.value.enCode) {
        emit("enterInfo", currentKeyNode.value);
      }
    };
    onMounted(() => {
    });
    return (_ctx, _cache) => {
      const _component_el_input = ElInput;
      const _component_el_tree = ElTree;
      const _component_el_scrollbar = ElScrollbar;
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createElementVNode("div", _hoisted_2, [
          createVNode(_component_el_input, {
            placeholder: "搜索函数",
            "prefix-icon": unref(search_default),
            modelValue: searchTreeVariable.value,
            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchTreeVariable.value = $event),
            clearable: ""
          }, null, 8, ["prefix-icon", "modelValue"])
        ]),
        createVNode(_component_el_scrollbar, null, {
          default: withCtx(() => [
            createElementVNode("div", {
              class: "treeContainer",
              onMouseleave: leaveTree
            }, [
              createVNode(_component_el_tree, {
                data: filterData.value,
                "default-expanded-keys": ["frequentlyUse"],
                props: __props.treeProps,
                "current-node-key": currentKeyNode.value.enCode,
                "node-key": "enCode",
                onNodeClick: nodeClick
              }, {
                default: withCtx(({ data }) => [
                  createElementVNode("span", {
                    class: "info-container",
                    onMouseenter: ($event) => enterInfo(data)
                  }, [
                    createElementVNode("span", null, toDisplayString(data.name), 1),
                    data.tip ? (openBlock(), createElementBlock("span", _hoisted_4, toDisplayString(data.tip), 1)) : createCommentVNode("", true)
                  ], 40, _hoisted_3)
                ]),
                _: 1
              }, 8, ["data", "props", "current-node-key"])
            ], 32)
          ]),
          _: 1
        })
      ]);
    };
  }
};
const FormulaList = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-d1fdd781"]]);
export {
  FormulaList as default
};
