"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("../../../../../node_modules/element-plus/es/index.js");
;/* empty css                                                             */
;/* empty css                                                                     */
;/* empty css                                                                    */
;/* empty css                                                                */
;/* empty css                                                                */
;/* empty css                                                                 */
const Vue = require("vue");
const index$1 = require("../../../../../node_modules/@element-plus/icons-vue/dist/index.js");
;/* empty css                 */
const _pluginVue_exportHelper = require("../../../../../_virtual/_plugin-vue_export-helper.js");
const index = require("../../../../../node_modules/element-plus/es/components/input/index.js");
const index$2 = require("../../../../../node_modules/element-plus/es/components/scrollbar/index.js");
const index$3 = require("../../../../../node_modules/element-plus/es/components/tree/index.js");
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 = Vue.ref("");
    const currentKeyNode = Vue.ref({});
    const filterData = Vue.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);
      }
    };
    Vue.onMounted(() => {
    });
    return (_ctx, _cache) => {
      const _component_el_input = index.ElInput;
      const _component_el_tree = index$3.ElTree;
      const _component_el_scrollbar = index$2.ElScrollbar;
      return Vue.openBlock(), Vue.createElementBlock("div", _hoisted_1, [
        Vue.createElementVNode("div", _hoisted_2, [
          Vue.createVNode(_component_el_input, {
            placeholder: "搜索函数",
            "prefix-icon": Vue.unref(index$1.Search),
            modelValue: searchTreeVariable.value,
            "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => searchTreeVariable.value = $event),
            clearable: ""
          }, null, 8, ["prefix-icon", "modelValue"])
        ]),
        Vue.createVNode(_component_el_scrollbar, null, {
          default: Vue.withCtx(() => [
            Vue.createElementVNode("div", {
              class: "treeContainer",
              onMouseleave: leaveTree
            }, [
              Vue.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: Vue.withCtx(({ data }) => [
                  Vue.createElementVNode("span", {
                    class: "info-container",
                    onMouseenter: ($event) => enterInfo(data)
                  }, [
                    Vue.createElementVNode("span", null, Vue.toDisplayString(data.name), 1),
                    data.tip ? (Vue.openBlock(), Vue.createElementBlock("span", _hoisted_4, Vue.toDisplayString(data.tip), 1)) : Vue.createCommentVNode("", true)
                  ], 40, _hoisted_3)
                ]),
                _: 1
              }, 8, ["data", "props", "current-node-key"])
            ], 32)
          ]),
          _: 1
        })
      ]);
    };
  }
};
const FormulaList = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-d1fdd781"]]);
exports.default = FormulaList;
