import { defineComponent as L, computed as w, useSlots as O, ref as U, unref as e, openBlock as l, createElementBlock as i, Fragment as x, toDisplayString as B, createBlock as S, withCtx as f, renderList as N, mergeProps as _, createSlots as E, renderSlot as K, normalizeProps as j, guardReactiveProps as q, createVNode as G } from "vue";
import { Space as W, Cascader as $, Spin as H } from "@aplus-frontend/antdv";
import { omit as J, isArray as Q } from "lodash-unified";
import "../../hooks/index.mjs";
import { useDefaultPlaceholder as X } from "../hooks/use-default-placeholder.mjs";
import { useOptions as Y } from "./use-options.mjs";
import { useControllableValue as Z } from "../../hooks/useControllableValue.mjs";
const ee = { key: 0 }, ue = /* @__PURE__ */ L({
  name: "ApFieldCascader",
  __name: "index",
  props: {
    mode: { default: "edit" },
    class: {},
    style: {},
    emptyText: { default: "--" },
    customReadMode: {},
    multiple: { type: Boolean, default: void 0 },
    size: {},
    bordered: { type: Boolean, default: !0 },
    placement: {},
    suffixIcon: {},
    status: {},
    options: {},
    popupClassName: {},
    dropdownClassName: {},
    "onUpdate:value": {},
    variant: {},
    value: {},
    children: {},
    onMouseenter: {},
    onMouseleave: {},
    tabindex: {},
    onClick: {},
    onFocus: {},
    onBlur: {},
    onChange: {},
    onKeydown: {},
    onKeyup: {},
    onMousedown: {},
    open: { type: Boolean, default: void 0 },
    animation: {},
    direction: {},
    disabled: { type: Boolean },
    prefixCls: {},
    id: {},
    autofocus: { type: Boolean },
    getPopupContainer: {},
    dropdownMatchSelectWidth: { type: [Number, Boolean] },
    placeholder: {},
    loading: { type: Boolean },
    defaultValue: {},
    prefix: {},
    clearIcon: {},
    allowClear: { type: Boolean, default: !0 },
    getInputElement: {},
    getRawInputElement: {},
    fieldNames: {},
    searchValue: {},
    onSearch: {},
    maxCount: {},
    showSearch: { type: [Boolean, Object], default: !1 },
    tagRender: {},
    optionLabelRender: {},
    notFoundContent: {},
    onClear: {},
    choiceTransitionName: {},
    defaultOpen: { type: Boolean, default: void 0 },
    onDropdownVisibleChange: {},
    maxTagTextLength: {},
    maxTagCount: {},
    maxTagPlaceholder: {},
    removeIcon: {},
    transitionName: {},
    dropdownStyle: {},
    dropdownRender: {},
    dropdownAlign: {},
    showAction: {},
    onPopupScroll: {},
    onInputKeyDown: {},
    onPopupVisibleChange: {},
    popupStyle: {},
    popupPlacement: {},
    popupVisible: { type: Boolean, default: void 0 },
    expandIcon: {},
    changeOnSelect: { type: Boolean },
    displayRender: {},
    showCheckedStrategy: {},
    expandTrigger: {},
    dropdownPrefixCls: {},
    dropdownMenuColumnStyle: {},
    loadingIcon: {},
    request: {},
    lazy: { type: Boolean },
    params: {},
    loadData: { type: Boolean }
  },
  emits: ["update:value"],
  setup(s, { expose: k, emit: P }) {
    const a = s, T = w(
      () => J(a, ["onUpdate:value", "value", "options", "loadData"])
    ), I = O(), R = P, c = U(), { value: h, updateValue: V } = Z(a, R), D = X("Cascader", a), { options: g, request: y, loading: v } = Y(a), C = w(() => {
      const t = e(h);
      if (!t?.length) return [];
      const b = a.fieldNames?.label || "label", d = a.fieldNames?.value || "value";
      function o(m, n) {
        const r = [];
        for (const p of m || []) {
          if (n.find(
            (A) => A === p[d]
          ) && r.push(p[b]), r.length === n.length)
            return r;
          p.children?.length && r.push(...o(p.children, n));
        }
        return r;
      }
      const u = [], F = Q(t[0]) ? t : [t];
      for (const m of F) {
        const n = o(g.value, m);
        n.length && u.push(n);
      }
      return u;
    });
    function M() {
      c.value?.focus?.();
    }
    function z() {
      c.value?.blur?.();
    }
    return k({
      focus: M,
      blur: z,
      request: y
    }), (t, b) => s.mode === "read" ? (l(), i(x, { key: 0 }, [
      C.value.length ? (l(), S(e(W), {
        key: 1,
        size: 4
      }, {
        default: f(() => [
          (l(!0), i(x, null, N(C.value, (d, o) => (l(), i("span", { key: o }, B(d.join(", ")), 1))), 128))
        ]),
        _: 1
      })) : (l(), i("span", ee, B(s.emptyText), 1))
    ], 64)) : (l(), S(e($), _({ key: 1 }, T.value, {
      ref: c.value,
      value: e(h),
      loading: e(v),
      options: e(g),
      placeholder: e(D),
      "load-data": s.loadData ? e(y) : void 0,
      "onUpdate:value": e(V)
    }), E({ _: 2 }, [
      N(I, (d, o) => ({
        name: o,
        fn: f((u) => [
          K(t.$slots, o, j(q(u || {})))
        ])
      })),
      e(v) ? {
        name: "notFoundContent",
        fn: f(() => [
          G(e(H), { size: "small" })
        ]),
        key: "0"
      } : void 0
    ]), 1040, ["value", "loading", "options", "placeholder", "load-data", "onUpdate:value"]));
  }
});
export {
  ue as default
};
