import { isVNode as E, defineComponent as K, computed as g, useSlots as M, shallowRef as U, unref as e, createVNode as r, Fragment as v, openBlock as S, createBlock as w, resolveDynamicComponent as _, mergeProps as z, createSlots as j, renderList as q, withCtx as x, renderSlot as O, normalizeProps as $, guardReactiveProps as H } from "vue";
import { Space as W, Tag as G, TreeSelect as J, Spin as Q } from "@aplus-frontend/antdv";
import { omit as X, isArray as Y } from "lodash-unified";
import "../../hooks/index.mjs";
import { useDefaultPlaceholder as Z } from "../hooks/use-default-placeholder.mjs";
import { useRequest as ee } from "./use-request.mjs";
import { useControllableValue as te } from "../../hooks/useControllableValue.mjs";
function B(n) {
  return typeof n == "function" || Object.prototype.toString.call(n) === "[object Object]" && !E(n);
}
const se = /* @__PURE__ */ K({
  name: "ApFieldTreeSelect",
  __name: "index",
  props: {
    mode: {
      default: "edit"
    },
    class: {},
    style: {},
    emptyText: {
      default: "--"
    },
    customReadMode: {},
    suffixIcon: {},
    size: {},
    bordered: {
      type: Boolean,
      default: void 0
    },
    treeLine: {},
    replaceFields: {},
    placement: {},
    status: {},
    popupClassName: {},
    dropdownClassName: {},
    "onUpdate:value": {},
    "onUpdate:treeExpandedKeys": {},
    "onUpdate:searchValue": {},
    variant: {},
    switcherLoadingIcon: {},
    value: {},
    children: {},
    listHeight: {},
    onMouseenter: {},
    onMouseleave: {},
    tabindex: {},
    onClick: {},
    onFocus: {},
    onBlur: {},
    onChange: {},
    onKeydown: {},
    onKeyup: {},
    onMousedown: {},
    onSelect: {},
    open: {
      type: Boolean,
      default: void 0
    },
    animation: {},
    direction: {},
    multiple: {
      type: Boolean,
      default: void 0
    },
    disabled: {
      type: Boolean,
      default: void 0
    },
    prefixCls: {},
    id: {},
    autofocus: {
      type: Boolean,
      default: void 0
    },
    getPopupContainer: {},
    virtual: {
      type: Boolean,
      default: !0
    },
    dropdownMatchSelectWidth: {
      default: !0
    },
    placeholder: {},
    loading: {
      type: Boolean,
      default: void 0
    },
    defaultValue: {},
    prefix: {},
    clearIcon: {},
    allowClear: {
      type: Boolean,
      default: void 0
    },
    getRawInputElement: {},
    fieldNames: {},
    inputValue: {},
    searchValue: {},
    onSearch: {},
    autoClearSearchValue: {
      type: Boolean,
      default: void 0
    },
    onDeselect: {},
    listItemHeight: {},
    labelInValue: {
      type: Boolean,
      default: void 0
    },
    maxCount: {},
    showSearch: {
      type: Boolean,
      default: void 0
    },
    tagRender: {},
    optionLabelRender: {},
    notFoundContent: {},
    onClear: {},
    choiceTransitionName: {},
    defaultOpen: {
      type: Boolean,
      default: void 0
    },
    onDropdownVisibleChange: {},
    maxTagTextLength: {},
    maxTagCount: {},
    maxTagPlaceholder: {},
    tokenSeparators: {},
    removeIcon: {},
    transitionName: {},
    dropdownStyle: {},
    dropdownRender: {},
    dropdownAlign: {},
    showAction: {},
    onPopupScroll: {},
    onInputKeyDown: {},
    showArrow: {
      type: Boolean,
      default: void 0
    },
    showCheckedStrategy: {},
    filterTreeNode: {},
    treeNodeFilterProp: {},
    treeNodeLabelProp: {},
    treeCheckable: {
      type: Boolean,
      default: void 0
    },
    treeCheckStrictly: {
      type: Boolean,
      default: void 0
    },
    treeData: {},
    treeDataSimpleMode: {},
    treeLoadedKeys: {},
    onTreeLoad: {},
    treeDefaultExpandAll: {
      type: Boolean,
      default: void 0
    },
    treeExpandedKeys: {},
    treeDefaultExpandedKeys: {},
    onTreeExpand: {},
    treeIcon: {},
    switcherIcon: {},
    treeExpandAction: {},
    dropdownPopupAlign: {},
    request: {},
    lazy: {
      type: Boolean
    },
    params: {},
    loadData: {
      type: Boolean
    }
  },
  emits: ["update:value"],
  setup(n, {
    expose: C,
    emit: N
  }) {
    const o = n, T = g(() => X(o, ["onUpdate:value", "value", "treeData", "loadData"])), b = M(), D = N, s = U(), {
      value: c,
      updateValue: V
    } = te(o, D), k = Z("TreeSelect", o), {
      treeData: f,
      loading: m,
      request: y
    } = ee(o), P = g(() => {
      let a;
      const u = e(c), i = Y(u) ? u : [u].filter(Boolean);
      if (!i.length)
        return r(v, null, [o.emptyText]);
      const t = [], p = o.fieldNames?.label || "label", A = o.fieldNames?.value || "value";
      function h(l) {
        for (const d of l) {
          if (i.find((F) => F === d[A]) && t.push(d[p]), t.length === i.length)
            return;
          d.children?.length && h(d.children);
        }
      }
      return h(e(f)), t.length ? t.length === 1 ? r("span", null, [t[0]]) : r(W, {
        size: 4
      }, B(a = t.map((l, d) => r(G, {
        style: {
          marginRight: 0
        },
        key: `${l}-${d}`
      }, B(l) ? l : {
        default: () => [l]
      }))) ? a : {
        default: () => [a]
      }) : r(v, null, [o.emptyText]);
    });
    function R() {
      s.value?.focus?.();
    }
    function I() {
      s.value?.blur?.();
    }
    function L(a) {
      return y(a);
    }
    return C({
      request: y,
      focus: R,
      blur: I
    }), (a, u) => n.mode === "read" ? (S(), w(_(P.value), {
      key: 0
    })) : (S(), w(e(J), z({
      key: 1
    }, T.value, {
      ref_key: "treeSelectRef",
      ref: s,
      value: e(c),
      "tree-data": e(f),
      loading: e(m),
      placeholder: e(k),
      "load-data": n.loadData ? L : void 0,
      "onUpdate:value": e(V)
    }), j({
      _: 2
    }, [q(b, (i, t) => ({
      name: t,
      fn: x((p) => [O(a.$slots, t, $(H(p || {})))])
    })), e(m) ? {
      name: "notFoundContent",
      fn: x(() => [r(e(Q), {
        size: "small"
      })]),
      key: "0"
    } : void 0]), 1040, ["value", "tree-data", "loading", "placeholder", "load-data", "onUpdate:value"]));
  }
});
export {
  se as default
};
