var ht = Object.defineProperty;
var Je = Object.getOwnPropertySymbols;
var pt = Object.prototype.hasOwnProperty, mt = Object.prototype.propertyIsEnumerable;
var Qe = (e, n, a) => n in e ? ht(e, n, { enumerable: !0, configurable: !0, writable: !0, value: a }) : e[n] = a, qe = (e, n) => {
  for (var a in n || (n = {}))
    pt.call(n, a) && Qe(e, a, n[a]);
  if (Je)
    for (var a of Je(n))
      mt.call(n, a) && Qe(e, a, n[a]);
  return e;
};
import { inject as gt, provide as yt, defineComponent as Ge, ref as B, computed as w, watch as Se, nextTick as St, shallowRef as R, toRaw as ae, createVNode as z, watchEffect as we, toRef as re, toRefs as bt, onMounted as Ct, openBlock as de, createElementBlock as fe, unref as Ze, isRef as wt, withCtx as xt, Fragment as et, renderList as kt, normalizeStyle as Tt, toDisplayString as He } from "vue";
import { v as It, c9 as Vt, bL as Nt, K as ve, _ as X, d as S, ac as Et, n as H, aS as Lt, i as ut, y as Dt, z as tt, ca as Pt, cb as lt, o as xe, B as At, A as Kt, P as he, g as Ot, m as it, C as _t, h as $e, E as Ft, F as Ht, G as $t, u as Bt, H as Mt, I as Rt, T as jt, J as Wt, c as at, O as Ut, Q as zt, am as Gt, a2 as Be, a3 as Xt, a1 as Yt, f as Jt, a4 as Me, l as Qt } from "./index2.js";
import { T as qt, g as Zt, r as el } from "./index24.js";
import { c as tl, a as je, u as ll } from "./useMaxLevel.js";
function ct(e) {
  return Array.isArray(e) ? e : e !== void 0 ? [e] : [];
}
function al(e) {
  const {
    label: n,
    value: a,
    children: t
  } = e || {}, l = a || "value";
  return {
    _title: n ? [n] : ["title", "label"],
    value: l,
    key: l,
    children: t || "children"
  };
}
function We(e) {
  return e.disabled || e.disableCheckbox || e.checkable === !1;
}
function nl(e, n) {
  const a = [];
  function t(l) {
    l.forEach((s) => {
      a.push(s[n.value]);
      const r = s[n.children];
      r && t(r);
    });
  }
  return t(e), a;
}
function Ue(e) {
  return e == null;
}
const dt = Symbol("TreeSelectContextPropsKey");
function ol(e) {
  return yt(dt, e);
}
function rl() {
  return gt(dt, {});
}
const sl = {
  width: 0,
  height: 0,
  display: "flex",
  overflow: "hidden",
  opacity: 0,
  border: 0,
  padding: 0,
  margin: 0
}, ul = Ge({
  compatConfig: {
    MODE: 3
  },
  name: "OptionList",
  inheritAttrs: !1,
  setup(e, n) {
    let {
      slots: a,
      expose: t
    } = n;
    const l = It(), s = Vt(), r = rl(), u = B(), c = Nt(() => r.treeData, [() => l.open, () => r.treeData], (f) => f[0]), o = w(() => {
      const {
        checkable: f,
        halfCheckedKeys: C,
        checkedKeys: K
      } = s;
      return f ? {
        checked: K,
        halfChecked: C
      } : null;
    });
    Se(() => l.open, () => {
      St(() => {
        var f;
        l.open && !l.multiple && s.checkedKeys.length && ((f = u.value) === null || f === void 0 || f.scrollTo({
          key: s.checkedKeys[0]
        }));
      });
    }, {
      immediate: !0,
      flush: "post"
    });
    const i = w(() => String(l.searchValue).toLowerCase()), y = (f) => i.value ? String(f[s.treeNodeFilterProp]).toLowerCase().includes(i.value) : !1, E = R(s.treeDefaultExpandedKeys), x = R(null);
    Se(() => l.searchValue, () => {
      l.searchValue && (x.value = nl(ae(r.treeData), ae(r.fieldNames)));
    }, {
      immediate: !0
    });
    const I = w(() => s.treeExpandedKeys ? s.treeExpandedKeys.slice() : l.searchValue ? x.value : E.value), k = (f) => {
      var C;
      E.value = f, x.value = f, (C = s.onTreeExpand) === null || C === void 0 || C.call(s, f);
    }, V = (f) => {
      f.preventDefault();
    }, v = (f, C) => {
      let {
        node: K
      } = C;
      var F, P;
      const {
        checkable: G,
        checkedKeys: Y
      } = s;
      G && We(K) || ((F = r.onSelect) === null || F === void 0 || F.call(r, K.key, {
        selected: !Y.includes(K.key)
      }), l.multiple || (P = l.toggleOpen) === null || P === void 0 || P.call(l, !1));
    }, m = B(null), T = w(() => s.keyEntities[m.value]), p = (f) => {
      m.value = f;
    };
    return t({
      scrollTo: function() {
        for (var f, C, K = arguments.length, F = new Array(K), P = 0; P < K; P++)
          F[P] = arguments[P];
        return (C = (f = u.value) === null || f === void 0 ? void 0 : f.scrollTo) === null || C === void 0 ? void 0 : C.call(f, ...F);
      },
      onKeydown: (f) => {
        var C;
        const {
          which: K
        } = f;
        switch (K) {
          case ve.UP:
          case ve.DOWN:
          case ve.LEFT:
          case ve.RIGHT:
            (C = u.value) === null || C === void 0 || C.onKeydown(f);
            break;
          case ve.ENTER: {
            if (T.value) {
              const {
                selectable: F,
                value: P
              } = T.value.node || {};
              F !== !1 && v(null, {
                node: {
                  key: m.value
                },
                selected: !s.checkedKeys.includes(P)
              });
            }
            break;
          }
          case ve.ESC:
            l.toggleOpen(!1);
        }
      },
      onKeyup: () => {
      }
    }), () => {
      var f;
      const {
        prefixCls: C,
        multiple: K,
        searchValue: F,
        open: P,
        notFoundContent: G = (f = a.notFoundContent) === null || f === void 0 ? void 0 : f.call(a)
      } = l, {
        listHeight: Y,
        listItemHeight: j,
        virtual: ne,
        dropdownMatchSelectWidth: J,
        treeExpandAction: se
      } = r, {
        checkable: ue,
        treeDefaultExpandAll: ie,
        treeIcon: oe,
        showTreeIcon: Q,
        switcherIcon: me,
        treeLine: ge,
        loadData: ye,
        treeLoadedKeys: ce,
        treeMotion: b,
        onTreeLoad: O,
        checkedKeys: $
      } = s;
      if (c.value.length === 0)
        return z("div", {
          role: "listbox",
          class: `${C}-empty`,
          onMousedown: V
        }, [G]);
      const q = {
        fieldNames: r.fieldNames
      };
      return ce && (q.loadedKeys = ce), I.value && (q.expandedKeys = I.value), z("div", {
        onMousedown: V
      }, [T.value && P && z("span", {
        style: sl,
        "aria-live": "assertive"
      }, [T.value.node.value]), z(qt, X(X({
        ref: u,
        focusable: !1,
        prefixCls: `${C}-tree`,
        treeData: c.value,
        height: Y,
        itemHeight: j,
        virtual: ne !== !1 && J !== !1,
        multiple: K,
        icon: oe,
        showIcon: Q,
        switcherIcon: me,
        showLine: ge,
        loadData: F ? null : ye,
        motion: b,
        activeKey: m.value,
        checkable: ue,
        checkStrictly: !0,
        checkedKeys: o.value,
        selectedKeys: ue ? [] : $,
        defaultExpandAll: ie
      }, q), {}, {
        onActiveChange: p,
        onSelect: v,
        onCheck: v,
        onExpand: k,
        onLoad: O,
        filterTreeNode: y,
        expandAction: se
      }), S(S({}, a), {
        checkable: s.customSlots.treeCheckable
      }))]);
    };
  }
}), il = "SHOW_ALL", ft = "SHOW_PARENT", Xe = "SHOW_CHILD";
function nt(e, n, a, t) {
  const l = new Set(e);
  return n === Xe ? e.filter((s) => {
    const r = a[s];
    return !(r && r.children && r.children.some((u) => {
      let {
        node: c
      } = u;
      return l.has(c[t.value]);
    }) && r.children.every((u) => {
      let {
        node: c
      } = u;
      return We(c) || l.has(c[t.value]);
    }));
  }) : n === ft ? e.filter((s) => {
    const r = a[s], u = r ? r.parent : null;
    return !(u && !We(u.node) && l.has(u.key));
  }) : e;
}
const pe = () => null;
pe.inheritAttrs = !1;
pe.displayName = "ATreeSelectNode";
pe.isTreeSelectNode = !0;
var cl = function(e, n) {
  var a = {};
  for (var t in e) Object.prototype.hasOwnProperty.call(e, t) && n.indexOf(t) < 0 && (a[t] = e[t]);
  if (e != null && typeof Object.getOwnPropertySymbols == "function") for (var l = 0, t = Object.getOwnPropertySymbols(e); l < t.length; l++)
    n.indexOf(t[l]) < 0 && Object.prototype.propertyIsEnumerable.call(e, t[l]) && (a[t[l]] = e[t[l]]);
  return a;
};
function dl(e) {
  return e && e.type && e.type.isTreeSelectNode;
}
function fl(e) {
  function n() {
    let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
    return Et(a).map((t) => {
      var l, s, r;
      if (!dl(t))
        return H(!t, "TreeSelect/TreeSelectNode can only accept TreeSelectNode as children."), null;
      const u = t.children || {}, c = t.key, o = {};
      for (const [K, F] of Object.entries(t.props))
        o[Lt(K)] = F;
      const {
        isLeaf: i,
        checkable: y,
        selectable: E,
        disabled: x,
        disableCheckbox: I
      } = o, k = {
        isLeaf: i || i === "" || void 0,
        checkable: y || y === "" || void 0,
        selectable: E || E === "" || void 0,
        disabled: x || x === "" || void 0,
        disableCheckbox: I || I === "" || void 0
      }, V = S(S({}, o), k), {
        title: v = (l = u.title) === null || l === void 0 ? void 0 : l.call(u, V),
        switcherIcon: m = (s = u.switcherIcon) === null || s === void 0 ? void 0 : s.call(u, V)
      } = o, T = cl(o, ["title", "switcherIcon"]), p = (r = u.default) === null || r === void 0 ? void 0 : r.call(u), f = S(S(S({}, T), {
        title: v,
        switcherIcon: m,
        key: c,
        isLeaf: i
      }), k), C = n(p);
      return C.length && (f.children = C), f;
    });
  }
  return n(e);
}
function ze(e) {
  if (!e)
    return e;
  const n = S({}, e);
  return "props" in n || Object.defineProperty(n, "props", {
    get() {
      return H(!1, "New `vc-tree-select` not support return node instance as argument anymore. Please consider to remove `props` access."), n;
    }
  }), n;
}
function vl(e, n, a, t, l, s) {
  let r = null, u = null;
  function c() {
    function o(i) {
      let y = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "0", E = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !1;
      return i.map((x, I) => {
        const k = `${y}-${I}`, V = x[s.value], v = a.includes(V), m = o(x[s.children] || [], k, v), T = z(pe, x, {
          default: () => [m.map((p) => p.node)]
        });
        if (n === V && (r = T), v) {
          const p = {
            pos: k,
            node: T,
            children: m
          };
          return E || u.push(p), p;
        }
        return null;
      }).filter((x) => x);
    }
    u || (u = [], o(t), u.sort((i, y) => {
      let {
        node: {
          props: {
            value: E
          }
        }
      } = i, {
        node: {
          props: {
            value: x
          }
        }
      } = y;
      const I = a.indexOf(E), k = a.indexOf(x);
      return I - k;
    }));
  }
  Object.defineProperty(e, "triggerNode", {
    get() {
      return H(!1, "`triggerNode` is deprecated. Please consider decoupling data with node."), c(), r;
    }
  }), Object.defineProperty(e, "allCheckedNodes", {
    get() {
      return H(!1, "`allCheckedNodes` is deprecated. Please consider decoupling data with node."), c(), l ? u : u.map((o) => {
        let {
          node: i
        } = o;
        return i;
      });
    }
  });
}
function hl(e, n) {
  let {
    id: a,
    pId: t,
    rootPId: l
  } = n;
  const s = {}, r = [];
  return e.map((c) => {
    const o = S({}, c), i = o[a];
    return s[i] = o, o.key = o.key || i, o;
  }).forEach((c) => {
    const o = c[t], i = s[o];
    i && (i.children = i.children || [], i.children.push(c)), (o === l || !i && l === null) && r.push(c);
  }), r;
}
function pl(e, n, a) {
  const t = R();
  return Se([a, e, n], () => {
    const l = a.value;
    e.value ? t.value = a.value ? hl(ae(e.value), S({
      id: "id",
      pId: "pId",
      rootPId: null
    }, l !== !0 ? l : {})) : ae(e.value).slice() : t.value = fl(ae(n.value));
  }, {
    immediate: !0,
    deep: !0
  }), t;
}
const ml = (e) => {
  const n = R({
    valueLabels: /* @__PURE__ */ new Map()
  }), a = R();
  return Se(e, () => {
    a.value = ae(e.value);
  }, {
    immediate: !0
  }), [w(() => {
    const {
      valueLabels: l
    } = n.value, s = /* @__PURE__ */ new Map(), r = a.value.map((u) => {
      var c;
      const {
        value: o
      } = u, i = (c = u.label) !== null && c !== void 0 ? c : l.get(o);
      return s.set(o, i), S(S({}, u), {
        label: i
      });
    });
    return n.value.valueLabels = s, r;
  })];
}, gl = (e, n) => {
  const a = R(/* @__PURE__ */ new Map()), t = R({});
  return we(() => {
    const l = n.value, s = tl(e.value, {
      fieldNames: l,
      initWrapper: (r) => S(S({}, r), {
        valueEntities: /* @__PURE__ */ new Map()
      }),
      processEntity: (r, u) => {
        const c = r.node[l.value];
        if (process.env.NODE_ENV !== "production") {
          const o = r.node.key;
          H(!Ue(c), "TreeNode `value` is invalidate: undefined"), H(!u.valueEntities.has(c), `Same \`value\` exist in the tree: ${c}`), H(!o || String(o) === String(c), `\`key\` or \`value\` with TreeNode must be the same or you can remove one of them. key: ${o}, value: ${c}.`);
        }
        u.valueEntities.set(c, r);
      }
    });
    a.value = s.valueEntities, t.value = s.keyEntities;
  }), {
    valueEntities: a,
    keyEntities: t
  };
}, yl = (e, n, a, t, l, s) => {
  const r = R([]), u = R([]);
  return we(() => {
    let c = e.value.map((y) => {
      let {
        value: E
      } = y;
      return E;
    }), o = n.value.map((y) => {
      let {
        value: E
      } = y;
      return E;
    });
    const i = c.filter((y) => !t.value[y]);
    a.value && ({
      checkedKeys: c,
      halfCheckedKeys: o
    } = je(c, !0, t.value, l.value, s.value)), r.value = Array.from(/* @__PURE__ */ new Set([...i, ...c])), u.value = o;
  }), [r, u];
}, Sl = (e, n, a) => {
  let {
    treeNodeFilterProp: t,
    filterTreeNode: l,
    fieldNames: s
  } = a;
  return w(() => {
    const {
      children: r
    } = s.value, u = n.value, c = t == null ? void 0 : t.value;
    if (!u || l.value === !1)
      return e.value;
    let o;
    if (typeof l.value == "function")
      o = l.value;
    else {
      const y = u.toUpperCase();
      o = (E, x) => {
        const I = x[c];
        return String(I).toUpperCase().includes(y);
      };
    }
    function i(y) {
      let E = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !1;
      const x = [];
      for (let I = 0, k = y.length; I < k; I++) {
        const V = y[I], v = V[r], m = E || o(u, ze(V)), T = i(v || [], m);
        (m || T.length) && x.push(S(S({}, V), {
          [r]: T
        }));
      }
      return x;
    }
    return i(e.value);
  });
};
function bl(e) {
  const {
    searchPlaceholder: n,
    treeCheckStrictly: a,
    treeCheckable: t,
    labelInValue: l,
    value: s,
    multiple: r
  } = e;
  H(!n, "`searchPlaceholder` has been removed, please use `placeholder` instead"), a && l === !1 && H(!1, "`treeCheckStrictly` will force set `labelInValue` to `true`."), (l || a) && H(ct(s).every((u) => u && typeof u == "object" && "value" in u), "Invalid prop `value` supplied to `TreeSelect`. You should use { label: string, value: string | number } or [{ label: string, value: string | number }] instead."), a || r || t ? H(!s || Array.isArray(s), "`value` should be an array when `TreeSelect` is checkable or multiple.") : H(!Array.isArray(s), "`value` should not be array when `TreeSelect` is single mode.");
}
function vt() {
  return S(S({}, xe(Kt(), ["mode"])), {
    prefixCls: String,
    id: String,
    value: {
      type: [String, Number, Object, Array]
    },
    defaultValue: {
      type: [String, Number, Object, Array]
    },
    onChange: {
      type: Function
    },
    searchValue: String,
    /** @deprecated Use `searchValue` instead */
    inputValue: String,
    onSearch: {
      type: Function
    },
    autoClearSearchValue: {
      type: Boolean,
      default: void 0
    },
    filterTreeNode: {
      type: [Boolean, Function],
      default: void 0
    },
    treeNodeFilterProp: String,
    // >>> Select
    onSelect: Function,
    onDeselect: Function,
    showCheckedStrategy: {
      type: String
    },
    treeNodeLabelProp: String,
    fieldNames: {
      type: Object
    },
    // >>> Mode
    multiple: {
      type: Boolean,
      default: void 0
    },
    treeCheckable: {
      type: Boolean,
      default: void 0
    },
    treeCheckStrictly: {
      type: Boolean,
      default: void 0
    },
    labelInValue: {
      type: Boolean,
      default: void 0
    },
    // >>> Data
    treeData: {
      type: Array
    },
    treeDataSimpleMode: {
      type: [Boolean, Object],
      default: void 0
    },
    loadData: {
      type: Function
    },
    treeLoadedKeys: {
      type: Array
    },
    onTreeLoad: {
      type: Function
    },
    // >>> Expanded
    treeDefaultExpandAll: {
      type: Boolean,
      default: void 0
    },
    treeExpandedKeys: {
      type: Array
    },
    treeDefaultExpandedKeys: {
      type: Array
    },
    onTreeExpand: {
      type: Function
    },
    // >>> Options
    virtual: {
      type: Boolean,
      default: void 0
    },
    listHeight: Number,
    listItemHeight: Number,
    onDropdownVisibleChange: {
      type: Function
    },
    // >>> Tree
    treeLine: {
      type: [Boolean, Object],
      default: void 0
    },
    treeIcon: he.any,
    showTreeIcon: {
      type: Boolean,
      default: void 0
    },
    switcherIcon: he.any,
    treeMotion: he.any,
    children: Array,
    treeExpandAction: String,
    showArrow: {
      type: Boolean,
      default: void 0
    },
    showSearch: {
      type: Boolean,
      default: void 0
    },
    open: {
      type: Boolean,
      default: void 0
    },
    defaultOpen: {
      type: Boolean,
      default: void 0
    },
    disabled: {
      type: Boolean,
      default: void 0
    },
    placeholder: he.any,
    maxTagPlaceholder: {
      type: Function
    },
    dropdownPopupAlign: he.any,
    customSlots: Object
  });
}
function Cl(e) {
  return !e || typeof e != "object";
}
const wl = Ge({
  compatConfig: {
    MODE: 3
  },
  name: "TreeSelect",
  inheritAttrs: !1,
  props: ut(vt(), {
    treeNodeFilterProp: "value",
    autoClearSearchValue: !0,
    showCheckedStrategy: Xe,
    listHeight: 200,
    listItemHeight: 20,
    prefixCls: "vc-tree-select"
  }),
  setup(e, n) {
    let {
      attrs: a,
      expose: t,
      slots: l
    } = n;
    const s = Dt(re(e, "id")), r = w(() => e.treeCheckable && !e.treeCheckStrictly), u = w(() => e.treeCheckable || e.treeCheckStrictly), c = w(() => e.treeCheckStrictly || e.labelInValue), o = w(() => u.value || e.multiple);
    process.env.NODE_ENV !== "production" && we(() => {
      bl(e);
    });
    const i = w(() => al(e.fieldNames)), [y, E] = tt("", {
      value: w(() => e.searchValue !== void 0 ? e.searchValue : e.inputValue),
      postState: (d) => d || ""
    }), x = (d) => {
      var h;
      E(d), (h = e.onSearch) === null || h === void 0 || h.call(e, d);
    }, I = pl(re(e, "treeData"), re(e, "children"), re(e, "treeDataSimpleMode")), {
      keyEntities: k,
      valueEntities: V
    } = gl(I, i), v = (d) => {
      const h = [], g = [];
      return d.forEach((L) => {
        V.value.has(L) ? g.push(L) : h.push(L);
      }), {
        missingRawValues: h,
        existRawValues: g
      };
    }, m = Sl(I, y, {
      fieldNames: i,
      treeNodeFilterProp: re(e, "treeNodeFilterProp"),
      filterTreeNode: re(e, "filterTreeNode")
    }), T = (d) => {
      if (d) {
        if (e.treeNodeLabelProp)
          return d[e.treeNodeLabelProp];
        const {
          _title: h
        } = i.value;
        for (let g = 0; g < h.length; g += 1) {
          const L = d[h[g]];
          if (L !== void 0)
            return L;
        }
      }
    }, p = (d) => ct(d).map((g) => Cl(g) ? {
      value: g
    } : g), f = (d) => p(d).map((g) => {
      let {
        label: L
      } = g;
      const {
        value: _,
        halfChecked: A
      } = g;
      let N;
      const D = V.value.get(_);
      return D && (L = L != null ? L : T(D.node), N = D.node.disabled), {
        label: L,
        value: _,
        halfChecked: A,
        disabled: N
      };
    }), [C, K] = tt(e.defaultValue, {
      value: re(e, "value")
    }), F = w(() => p(C.value)), P = R([]), G = R([]);
    we(() => {
      const d = [], h = [];
      F.value.forEach((g) => {
        g.halfChecked ? h.push(g) : d.push(g);
      }), P.value = d, G.value = h;
    });
    const Y = w(() => P.value.map((d) => d.value)), {
      maxLevel: j,
      levelEntities: ne
    } = ll(k), [J, se] = yl(P, G, r, k, j, ne), ue = w(() => {
      const g = nt(J.value, e.showCheckedStrategy, k.value, i.value).map((A) => {
        var N, D, M;
        return (M = (D = (N = k.value[A]) === null || N === void 0 ? void 0 : N.node) === null || D === void 0 ? void 0 : D[i.value.value]) !== null && M !== void 0 ? M : A;
      }).map((A) => {
        const N = P.value.find((D) => D.value === A);
        return {
          value: A,
          label: N == null ? void 0 : N.label
        };
      }), L = f(g), _ = L[0];
      return !o.value && _ && Ue(_.value) && Ue(_.label) ? [] : L.map((A) => {
        var N;
        return S(S({}, A), {
          label: (N = A.label) !== null && N !== void 0 ? N : A.value
        });
      });
    }), [ie] = ml(ue), oe = (d, h, g) => {
      const L = f(d);
      if (K(L), e.autoClearSearchValue && E(""), e.onChange) {
        let _ = d;
        r.value && (_ = nt(d, e.showCheckedStrategy, k.value, i.value).map((le) => {
          const Ce = V.value.get(le);
          return Ce ? Ce.node[i.value.value] : le;
        }));
        const {
          triggerValue: A,
          selected: N
        } = h || {
          triggerValue: void 0,
          selected: void 0
        };
        let D = _;
        if (e.treeCheckStrictly) {
          const U = G.value.filter((le) => !_.includes(le.value));
          D = [...D, ...U];
        }
        const M = f(D), ee = {
          // [Legacy] Always return as array contains label & value
          preValue: P.value,
          triggerValue: A
        };
        let te = !0;
        (e.treeCheckStrictly || g === "selection" && !N) && (te = !1), vl(ee, A, d, I.value, te, i.value), u.value ? ee.checked = N : ee.selected = N;
        const W = c.value ? M : M.map((U) => U.value);
        e.onChange(o.value ? W : W[0], c.value ? null : M.map((U) => U.label), ee);
      }
    }, Q = (d, h) => {
      let {
        selected: g,
        source: L
      } = h;
      var _, A, N;
      const D = ae(k.value), M = ae(V.value), ee = D[d], te = ee == null ? void 0 : ee.node, W = (_ = te == null ? void 0 : te[i.value.value]) !== null && _ !== void 0 ? _ : d;
      if (!o.value)
        oe([W], {
          selected: !0,
          triggerValue: W
        }, "option");
      else {
        let U = g ? [...Y.value, W] : J.value.filter((le) => le !== W);
        if (r.value) {
          const {
            missingRawValues: le,
            existRawValues: Ce
          } = v(U), Ye = Ce.map((Fe) => M.get(Fe).key);
          let _e;
          g ? {
            checkedKeys: _e
          } = je(Ye, !0, D, j.value, ne.value) : {
            checkedKeys: _e
          } = je(Ye, {
            checked: !1,
            halfCheckedKeys: se.value
          }, D, j.value, ne.value), U = [...le, ..._e.map((Fe) => D[Fe].node[i.value.value])];
        }
        oe(U, {
          selected: g,
          triggerValue: W
        }, L || "option");
      }
      g || !o.value ? (A = e.onSelect) === null || A === void 0 || A.call(e, W, ze(te)) : (N = e.onDeselect) === null || N === void 0 || N.call(e, W, ze(te));
    }, me = (d) => {
      if (e.onDropdownVisibleChange) {
        const h = {};
        Object.defineProperty(h, "documentClickClose", {
          get() {
            return H(!1, "Second param of `onDropdownVisibleChange` has been removed."), !1;
          }
        }), e.onDropdownVisibleChange(d, h);
      }
    }, ge = (d, h) => {
      const g = d.map((L) => L.value);
      if (h.type === "clear") {
        oe(g, {}, "selection");
        return;
      }
      h.values.length && Q(h.values[0].value, {
        selected: !1,
        source: "selection"
      });
    }, {
      treeNodeFilterProp: ye,
      // Data
      loadData: ce,
      treeLoadedKeys: b,
      onTreeLoad: O,
      // Expanded
      treeDefaultExpandAll: $,
      treeExpandedKeys: q,
      treeDefaultExpandedKeys: ke,
      onTreeExpand: Te,
      // Options
      virtual: Ie,
      listHeight: Ve,
      listItemHeight: Ne,
      // Tree
      treeLine: Ee,
      treeIcon: be,
      showTreeIcon: Le,
      switcherIcon: De,
      treeMotion: Pe,
      customSlots: Ae,
      dropdownMatchSelectWidth: Ke,
      treeExpandAction: Oe
    } = bt(e);
    Pt(lt({
      checkable: u,
      loadData: ce,
      treeLoadedKeys: b,
      onTreeLoad: O,
      checkedKeys: J,
      halfCheckedKeys: se,
      treeDefaultExpandAll: $,
      treeExpandedKeys: q,
      treeDefaultExpandedKeys: ke,
      onTreeExpand: Te,
      treeIcon: be,
      treeMotion: Pe,
      showTreeIcon: Le,
      switcherIcon: De,
      treeLine: Ee,
      treeNodeFilterProp: ye,
      keyEntities: k,
      customSlots: Ae
    })), ol(lt({
      virtual: Ie,
      listHeight: Ve,
      listItemHeight: Ne,
      treeData: m,
      fieldNames: i,
      onSelect: Q,
      dropdownMatchSelectWidth: Ke,
      treeExpandAction: Oe
    }));
    const Z = B();
    return t({
      focus() {
        var d;
        (d = Z.value) === null || d === void 0 || d.focus();
      },
      blur() {
        var d;
        (d = Z.value) === null || d === void 0 || d.blur();
      },
      scrollTo(d) {
        var h;
        (h = Z.value) === null || h === void 0 || h.scrollTo(d);
      }
    }), () => {
      var d;
      const h = xe(e, [
        "id",
        "prefixCls",
        "customSlots",
        // Value
        "value",
        "defaultValue",
        "onChange",
        "onSelect",
        "onDeselect",
        // Search
        "searchValue",
        "inputValue",
        "onSearch",
        "autoClearSearchValue",
        "filterTreeNode",
        "treeNodeFilterProp",
        // Selector
        "showCheckedStrategy",
        "treeNodeLabelProp",
        //  Mode
        "multiple",
        "treeCheckable",
        "treeCheckStrictly",
        "labelInValue",
        // FieldNames
        "fieldNames",
        // Data
        "treeDataSimpleMode",
        "treeData",
        "children",
        "loadData",
        "treeLoadedKeys",
        "onTreeLoad",
        // Expanded
        "treeDefaultExpandAll",
        "treeExpandedKeys",
        "treeDefaultExpandedKeys",
        "onTreeExpand",
        // Options
        "virtual",
        "listHeight",
        "listItemHeight",
        "onDropdownVisibleChange",
        // Tree
        "treeLine",
        "treeIcon",
        "showTreeIcon",
        "switcherIcon",
        "treeMotion"
      ]);
      return z(At, X(X(X({
        ref: Z
      }, a), h), {}, {
        id: s,
        prefixCls: e.prefixCls,
        mode: o.value ? "multiple" : void 0,
        displayValues: ie.value,
        onDisplayValuesChange: ge,
        searchValue: y.value,
        onSearch: x,
        OptionList: ul,
        emptyOptions: !I.value.length,
        onDropdownVisibleChange: me,
        tagRender: e.tagRender || l.tagRender,
        dropdownMatchSelectWidth: (d = e.dropdownMatchSelectWidth) !== null && d !== void 0 ? d : !0
      }), l);
    };
  }
}), xl = (e) => {
  const {
    componentCls: n,
    treePrefixCls: a,
    colorBgElevated: t
  } = e, l = `.${a}`;
  return [
    // ======================================================
    // ==                     Dropdown                     ==
    // ======================================================
    {
      [`${n}-dropdown`]: [
        {
          padding: `${e.paddingXS}px ${e.paddingXS / 2}px`
        },
        // ====================== Tree ======================
        Zt(a, it(e, {
          colorBgContainer: t
        })),
        {
          [l]: {
            borderRadius: 0,
            "&-list-holder-inner": {
              alignItems: "stretch",
              [`${l}-treenode`]: {
                [`${l}-node-content-wrapper`]: {
                  flex: "auto"
                }
              }
            }
          }
        },
        // ==================== Checkbox ====================
        _t(`${a}-checkbox`, e),
        // ====================== RTL =======================
        {
          "&-rtl": {
            direction: "rtl",
            [`${l}-switcher${l}-switcher_close`]: {
              [`${l}-switcher-icon svg`]: {
                transform: "rotate(90deg)"
              }
            }
          }
        }
      ]
    }
  ];
};
function kl(e, n) {
  return Ot("TreeSelect", (a) => {
    const t = it(a, {
      treePrefixCls: n.value
    });
    return [xl(t)];
  })(e);
}
const ot = (e, n, a) => a !== void 0 ? a : `${e}-${n}`;
function Tl() {
  return S(S({}, xe(vt(), ["showTreeIcon", "treeMotion", "inputIcon", "getInputElement", "treeLine", "customSlots"])), {
    suffixIcon: he.any,
    size: Be(),
    bordered: Xt(),
    treeLine: Yt([Boolean, Object]),
    replaceFields: Jt(),
    placement: Be(),
    status: Be(),
    popupClassName: String,
    /** @deprecated Please use `popupClassName` instead */
    dropdownClassName: String,
    "onUpdate:value": Me(),
    "onUpdate:treeExpandedKeys": Me(),
    "onUpdate:searchValue": Me()
  });
}
const Re = Ge({
  compatConfig: {
    MODE: 3
  },
  name: "ATreeSelect",
  inheritAttrs: !1,
  props: ut(Tl(), {
    choiceTransitionName: "",
    listHeight: 256,
    treeIcon: !1,
    listItemHeight: 26,
    bordered: !0
  }),
  slots: Object,
  setup(e, n) {
    let {
      attrs: a,
      slots: t,
      expose: l,
      emit: s
    } = n;
    H(!(e.treeData === void 0 && t.default), "`children` of TreeSelect is deprecated. Please use `treeData` instead."), $e(e.multiple !== !1 || !e.treeCheckable, "TreeSelect", "`multiple` will always be `true` when `treeCheckable` is true"), $e(e.replaceFields === void 0, "TreeSelect", "`replaceFields` is deprecated, please use fieldNames instead"), $e(!e.dropdownClassName, "TreeSelect", "`dropdownClassName` is deprecated. Please use `popupClassName` instead.");
    const r = Ft(), u = Ht.useInject(), c = w(() => $t(u.status, e.status)), {
      prefixCls: o,
      renderEmpty: i,
      direction: y,
      virtual: E,
      dropdownMatchSelectWidth: x,
      size: I,
      getPopupContainer: k,
      getPrefixCls: V,
      disabled: v
    } = Bt("select", e), {
      compactSize: m,
      compactItemClassnames: T
    } = Mt(o, y), p = w(() => m.value || I.value), f = Rt(), C = w(() => {
      var b;
      return (b = v.value) !== null && b !== void 0 ? b : f.value;
    }), K = w(() => V()), F = w(() => e.placement !== void 0 ? e.placement : y.value === "rtl" ? "bottomRight" : "bottomLeft"), P = w(() => ot(K.value, jt(F.value), e.transitionName)), G = w(() => ot(K.value, "", e.choiceTransitionName)), Y = w(() => V("select-tree", e.prefixCls)), j = w(() => V("tree-select", e.prefixCls)), [ne, J] = Wt(o), [se] = kl(j, Y), ue = w(() => at(e.popupClassName || e.dropdownClassName, `${j.value}-dropdown`, {
      [`${j.value}-dropdown-rtl`]: y.value === "rtl"
    }, J.value)), ie = w(() => !!(e.treeCheckable || e.multiple)), oe = w(() => e.showArrow !== void 0 ? e.showArrow : e.loading || !ie.value), Q = B();
    l({
      focus() {
        var b, O;
        (O = (b = Q.value).focus) === null || O === void 0 || O.call(b);
      },
      blur() {
        var b, O;
        (O = (b = Q.value).blur) === null || O === void 0 || O.call(b);
      }
    });
    const me = function() {
      for (var b = arguments.length, O = new Array(b), $ = 0; $ < b; $++)
        O[$] = arguments[$];
      s("update:value", O[0]), s("change", ...O), r.onFieldChange();
    }, ge = (b) => {
      s("update:treeExpandedKeys", b), s("treeExpand", b);
    }, ye = (b) => {
      s("update:searchValue", b), s("search", b);
    }, ce = (b) => {
      s("blur", b), r.onFieldBlur();
    };
    return () => {
      var b, O, $;
      const {
        notFoundContent: q = (b = t.notFoundContent) === null || b === void 0 ? void 0 : b.call(t),
        prefixCls: ke,
        bordered: Te,
        listHeight: Ie,
        listItemHeight: Ve,
        multiple: Ne,
        treeIcon: Ee,
        treeLine: be,
        showArrow: Le,
        switcherIcon: De = (O = t.switcherIcon) === null || O === void 0 ? void 0 : O.call(t),
        fieldNames: Pe = e.replaceFields,
        id: Ae = r.id.value,
        placeholder: Ke = ($ = t.placeholder) === null || $ === void 0 ? void 0 : $.call(t)
      } = e, {
        isFormItemInput: Oe,
        hasFeedback: Z,
        feedbackIcon: d
      } = u, {
        suffixIcon: h,
        removeIcon: g,
        clearIcon: L
      } = Ut(S(S({}, e), {
        multiple: ie.value,
        showArrow: oe.value,
        hasFeedback: Z,
        feedbackIcon: d,
        prefixCls: o.value
      }), t);
      let _;
      q !== void 0 ? _ = q : _ = i("Select");
      const A = xe(e, ["suffixIcon", "itemIcon", "removeIcon", "clearIcon", "switcherIcon", "bordered", "status", "onUpdate:value", "onUpdate:treeExpandedKeys", "onUpdate:searchValue"]), N = at(!ke && j.value, {
        [`${o.value}-lg`]: p.value === "large",
        [`${o.value}-sm`]: p.value === "small",
        [`${o.value}-rtl`]: y.value === "rtl",
        [`${o.value}-borderless`]: !Te,
        [`${o.value}-in-form-item`]: Oe
      }, zt(o.value, c.value, Z), T.value, a.class, J.value), D = {};
      return e.treeData === void 0 && t.default && (D.children = Gt(t.default())), ne(se(z(wl, X(X(X(X({}, a), A), {}, {
        disabled: C.value,
        virtual: E.value,
        dropdownMatchSelectWidth: x.value,
        id: Ae,
        fieldNames: Pe,
        ref: Q,
        prefixCls: o.value,
        class: N,
        listHeight: Ie,
        listItemHeight: Ve,
        treeLine: !!be,
        inputIcon: h,
        multiple: Ne,
        removeIcon: g,
        clearIcon: L,
        switcherIcon: (M) => el(Y.value, De, M, t.leafIcon, be),
        showTreeIcon: Ee,
        notFoundContent: _,
        getPopupContainer: k == null ? void 0 : k.value,
        treeMotion: null,
        dropdownClassName: ue.value,
        choiceTransitionName: G.value,
        onChange: me,
        onBlur: ce,
        onSearch: ye,
        onTreeExpand: ge
      }, D), {}, {
        transitionName: P.value,
        customSlots: S(S({}, t), {
          treeCheckable: () => z("span", {
            class: `${o.value}-tree-checkbox-inner`
          }, null)
        }),
        maxTagPlaceholder: e.maxTagPlaceholder || t.maxTagPlaceholder,
        placement: F.value,
        showArrow: Z || Le,
        placeholder: Ke
      }), S(S({}, t), {
        treeCheckable: () => z("span", {
          class: `${o.value}-tree-checkbox-inner`
        }, null)
      }))));
    };
  }
}), rt = pe, st = S(Re, {
  TreeNode: pe,
  SHOW_ALL: il,
  SHOW_PARENT: ft,
  SHOW_CHILD: Xe,
  install: (e) => (e.component(Re.name, Re), e.component(rt.displayName, rt), e)
}), Il = { class: "s-tree-select-common" }, Vl = ["title"], Nl = ["title"], El = ["title"], Ll = {
  __name: "STreeSelect",
  props: {
    // 过滤字段 - search为tree 时生效
    filterField: {
      type: String,
      default: "name"
    },
    // 树节点属性
    props: {
      type: Object,
      default: () => ({
        children: "children",
        label: "name",
        value: "value"
      })
    },
    // 是否支持查询
    search: {
      type: Boolean,
      default: !0
    },
    // 是否支持清空
    clear: {
      type: Boolean,
      default: !0
    },
    // 是否展开所有节点
    expandAll: {
      type: Boolean,
      default: !1
    },
    // 占位符 - 文案提示
    placeholder: {
      type: String,
      default() {
        return window.$l("请选择");
      }
    },
    // 默认值 - 默认选中项
    // 默认为空字符串，表示不选中任何项，也可以是字符串数组，表示选中项的 value 值
    // 默认选中项，支持 v-model 双向绑定
    value: {
      type: [String, Array],
      default() {
        return "";
      }
    },
    // 获取数据
    recursionChildren: {
      type: Function,
      default: () => []
    },
    // 是否添加全选节点
    appendRootNodeAll: {
      type: Boolean,
      default: !1
    },
    // 多选
    multiple: {
      type: Boolean,
      default: !1
    },
    // 显示数量
    maxTagCount: {
      type: Number,
      default: 1
    },
    //
    listHeight: {
      type: Number,
      default: 232
    }
  },
  emits: ["change"],
  setup(e, { emit: n }) {
    const a = n, t = e, l = B(null), s = B(""), r = B([]), u = B([]), c = t.multiple ? B([]) : B(null), o = B([]), i = B("");
    Se(
      () => t.value,
      (v) => {
        v && (c.value = v);
      },
      { immediate: !0 }
    );
    const y = (v) => {
      c.value = v, a("change", c.value);
    }, E = (v) => {
      v.value = v;
    }, x = () => {
      u.value = [], t.recursionChildren("", s.value).then((v) => {
        r.value = I(v), r.value && r.value.length > 0 && (t.value ? u.value = [t.value] : u.value = [r.value[0].id]);
      });
    }, I = (v) => {
      if (t.appendRootNodeAll) {
        const m = {
          id: "all",
          key: "all",
          value: "all",
          label: "全选",
          name: "全选",
          title: "全选",
          type: "1",
          typeLabel: "组织",
          parent: { id: "0" },
          children: null,
          isLeaf: !0
        };
        V(v, o.value, "children"), o.value && o.value.length && (o.value = o.value.map((T) => T.id)), v.unshift(m);
      }
      return v;
    }, k = (v, m) => m.name.toLowerCase().indexOf(v.toLowerCase()) >= 0, V = (v, m = [], T = "children") => {
      v && v.length > 0 && v.forEach((p) => {
        const f = qe({}, p);
        m.push(f), p[T] instanceof Array && p[T].length > 0 && V(p[T], m, T);
      });
    };
    return Ct(() => {
      x(), l.value = window.$theme;
    }), (v, m) => {
      const T = st;
      return de(), fe("div", Il, [
        z(T, {
          style: { width: "100%" },
          multiple: e.multiple,
          "allow-clear": e.clear,
          "field-names": t,
          "show-search": e.search,
          "tree-data": r.value,
          listHeight: e.listHeight,
          maxTagCount: e.maxTagCount,
          placeholder: e.placeholder,
          value: Ze(c),
          "onUpdate:value": m[0] || (m[0] = (p) => wt(c) ? c.value = p : null),
          showCheckedStrategy: Ze(st).SHOW_ALL,
          searchValue: i.value,
          "onUpdate:searchValue": m[1] || (m[1] = (p) => i.value = p),
          "tree-node-filter-prop": e.filterField,
          "tree-default-expand-all": e.expandAll,
          treeExpandedKeys: u.value,
          "onUpdate:treeExpandedKeys": m[2] || (m[2] = (p) => u.value = p),
          filterTreeNode: k,
          onTreeExpand: E,
          onSelect: y
        }, {
          title: xt(({ name: p }) => [
            i.value.length ? (de(!0), fe(et, { key: 0 }, kt(p.toString().split(new RegExp(`(?<=${i.value})|(?=${i.value})`, "i")), (f, C) => (de(), fe(et, { key: C }, [
              f.toLowerCase() === i.value.toLowerCase() ? (de(), fe("span", {
                key: 0,
                title: p,
                style: Tt({ color: l.value.color })
              }, He(f), 13, Vl)) : (de(), fe("span", {
                key: 1,
                title: p
              }, He(f), 9, Nl))
            ], 64))), 128)) : (de(), fe("div", {
              key: 1,
              title: p
            }, He(p.length > 15 ? p.slice(0, 15) + "..." : p), 9, El))
          ]),
          _: 1
        }, 8, ["multiple", "allow-clear", "field-names", "show-search", "tree-data", "listHeight", "maxTagCount", "placeholder", "value", "showCheckedStrategy", "searchValue", "tree-node-filter-prop", "tree-default-expand-all", "treeExpandedKeys"])
      ]);
    };
  }
}, _l = /* @__PURE__ */ Qt(Ll, [["__scopeId", "data-v-3fed6e0c"]]);
export {
  _l as default
};
