import { defineComponent as q, ref as w, reactive as U, computed as u, watch as z, onMounted as G, nextTick as m, resolveComponent as c, openBlock as f, createBlock as C, withCtx as S, createElementVNode as h, createVNode as v, createElementBlock as H, createCommentVNode as x } from "vue";
import { C as g } from "../Shared/base-PQGakkrl.js";
const J = {
  key: 0,
  className: "selectTree-inText-num"
}, Q = { class: "selectTree-inDropdown-container" }, R = { class: "selectTree-inDropdown-search" }, W = { class: "selectTree-inDropdown-body" }, te = /* @__PURE__ */ q({
  name: "ClSelectTree",
  __name: "Index",
  props: {
    value: [String, Number],
    list: {
      type: Array,
      default: () => []
    },
    className: String,
    placeholder: String,
    classDropDown: String,
    disabled: {
      type: Boolean,
      default: !1
    },
    multiple: {
      type: Boolean,
      default: !1
    },
    isClear: {
      type: Boolean,
      default: !1
    },
    arrowDirection: {
      type: String,
      default: "right"
      // left|right
    },
    searchPlaceholder: String,
    searchKey: {
      type: Array,
      default: () => ["name"]
    },
    searchKeyType: {
      type: String,
      default: "||"
      // || 或者  ， && 并且
    },
    showTextFormat: String,
    // "${id} ${name}"
    showDropDownTextFormat: String,
    onOpenBefore: Function,
    isSingleSelectParent: {
      type: Boolean,
      default: !1
    },
    isOutMerge: {
      type: Boolean,
      default: !0
    },
    parentKey: {
      type: String,
      default: "parentId"
    },
    topParentValue: {
      type: String,
      default: "0"
    }
  },
  emits: ["update:value", "onChange", "onInit", "onOpen"],
  setup(n, { expose: I, emit: b }) {
    const l = n, s = b, o = w(null), p = w(null), t = U({
      isOpen: !1,
      isFirstDataFinish: !1,
      selectIds: "",
      selectLabel: []
    }), d = {
      prevSelectIds: []
    }, O = u(() => l.arrowDirection), T = u(() => {
      let a = ["panel-selectTree", "box-width"].join(" ");
      return g.isEmpty(l.className) || (a += " " + l.className), a;
    }), V = u(() => {
      const e = ["selectTree-inDropdown"];
      return l.classDropDown && !g.isEmpty(l.classDropDown) && e.push(l.classDropDown), e.join(" ");
    }), B = (e) => {
      s("update:value", e);
    }, _ = (e, a) => {
      B(e), s("onChange", e, a);
    }, F = () => {
      m(() => {
        s("onInit");
      });
    }, k = (e) => {
      m(() => {
        s("onOpen", e);
      });
    }, D = () => {
      if (!t.isOpen) {
        const e = t.selectIds, a = e.split(",");
        if (!g.isEqualArr(a, d.prevSelectIds)) {
          d.prevSelectIds = a;
          const i = p.value.getValueData();
          _(e, i);
        }
      }
    }, y = () => {
      t.isFirstDataFinish || (t.isFirstDataFinish = !0, F());
    }, L = () => {
      l.list.length > 0 && y();
    };
    z(
      [() => l.value, () => l.list],
      ([e, a], [r, i]) => {
        e === r && (t.isFirstDataFinish || y());
      }
    ), G(() => {
      m(() => {
        L();
      });
    });
    const P = (e) => {
      l.disabled || (t.isOpen = e, e ? d.prevSelectIds = t.selectIds.split(",") : D(), k(e));
    }, E = () => {
      l.disabled || (t.selectIds = "", D());
    }, N = () => {
      o.value && (o.value.checkCurrentIsOpen() || o.value.initCompleteOpen());
    }, A = () => {
    };
    return I({
      getValue: () => t.selectIds,
      getValueData: () => p.value.getValueData(),
      setValue: (e) => {
        t.selectIds = e;
      }
    }), (e, a) => {
      const r = c("cl-badge"), i = c("cl-input-search"), K = c("cl-tree"), M = c("cl-dropdownlayer-list");
      return f(), C(M, {
        ref_key: "refElDropdownLayer",
        ref: o,
        classParent: T.value,
        classText: "selectTree-inText",
        classDropDown: V.value,
        placeholder: n.placeholder,
        isDisabled: n.disabled,
        isClear: n.isClear,
        textLabel: t.selectLabel.join(","),
        textArrowDirection: O.value,
        onOpenBeforeCallback: n.onOpenBefore,
        onOnChangeOpen: P,
        onOnClear: E
      }, {
        textExtend: S(() => [
          n.multiple ? (f(), H("span", J, [
            n.multiple && t.selectLabel.length > 1 ? (f(), C(r, {
              key: 0,
              num: t.selectLabel.length
            }, null, 8, ["num"])) : x("", !0)
          ])) : x("", !0)
        ]),
        dropdown: S(() => [
          h("div", Q, [
            h("div", R, [
              v(i, {
                ref: "refElSearch",
                onOnChange: A
              }, null, 512)
            ]),
            h("div", W, [
              v(K, {
                ref_key: "refElList",
                ref: p,
                list: n.list,
                value: t.selectIds,
                "onUpdate:value": a[0] || (a[0] = (j) => t.selectIds = j),
                multiple: n.multiple,
                textFormat: n.showDropDownTextFormat,
                isSingleSelectParent: n.isSingleSelectParent,
                parentKey: n.parentKey,
                topParentValue: n.topParentValue,
                shrinkColorBg: "transparent",
                onOnInit: N
              }, null, 8, ["list", "value", "multiple", "textFormat", "isSingleSelectParent", "parentKey", "topParentValue"])
            ])
          ])
        ]),
        _: 1
      }, 8, ["classParent", "classDropDown", "placeholder", "isDisabled", "isClear", "textLabel", "textArrowDirection", "onOpenBeforeCallback"]);
    };
  }
});
export {
  te as default
};
//# sourceMappingURL=ClSelectTree.js.map
