import S from "../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import * as r from "react";
import B from "../../../@ant-design/icons/es/icons/FileOutlined.mjs";
import G from "../../../@ant-design/icons/es/icons/FolderOpenOutlined.mjs";
import H from "../../../@ant-design/icons/es/icons/FolderOutlined.mjs";
import J from "../../../classnames/index.mjs";
import { conductExpandParent as M } from "../../../rc-tree/es/util.mjs";
import { convertDataToEntities as Q, convertTreeToData as U } from "../../../rc-tree/es/utils/treeUtil.mjs";
import "../config-provider/index.mjs";
import W from "./Tree.mjs";
import { convertDirectoryKeysToNodes as v, calcRangeKeys as X } from "./utils/dictUtil.mjs";
import { ConfigContext as Y } from "../config-provider/context.mjs";
var h = globalThis && globalThis.__rest || function(t, d) {
  var s = {};
  for (var n in t)
    Object.prototype.hasOwnProperty.call(t, n) && d.indexOf(n) < 0 && (s[n] = t[n]);
  if (t != null && typeof Object.getOwnPropertySymbols == "function")
    for (var c = 0, n = Object.getOwnPropertySymbols(t); c < n.length; c++)
      d.indexOf(n[c]) < 0 && Object.prototype.propertyIsEnumerable.call(t, n[c]) && (s[n[c]] = t[n[c]]);
  return s;
};
function Z(t) {
  const {
    isLeaf: d,
    expanded: s
  } = t;
  return d ? /* @__PURE__ */ r.createElement(B, null) : s ? /* @__PURE__ */ r.createElement(G, null) : /* @__PURE__ */ r.createElement(H, null);
}
function P(t) {
  let {
    treeData: d,
    children: s
  } = t;
  return d || U(s);
}
const ee = (t, d) => {
  var {
    defaultExpandAll: s,
    defaultExpandParent: n,
    defaultExpandedKeys: c
  } = t, e = h(t, ["defaultExpandAll", "defaultExpandParent", "defaultExpandedKeys"]);
  const x = r.useRef(), K = r.useRef(), w = () => {
    const {
      keyEntities: i
    } = Q(P(e));
    let l;
    return s ? l = Object.keys(i) : n ? l = M(e.expandedKeys || c || [], i) : l = e.expandedKeys || c, l;
  }, [C, O] = r.useState(e.selectedKeys || e.defaultSelectedKeys || []), [b, g] = r.useState(() => w());
  r.useEffect(() => {
    "selectedKeys" in e && O(e.selectedKeys);
  }, [e.selectedKeys]), r.useEffect(() => {
    "expandedKeys" in e && g(e.expandedKeys);
  }, [e.expandedKeys]);
  const D = (i, l) => {
    var f;
    return "expandedKeys" in e || g(i), (f = e.onExpand) === null || f === void 0 ? void 0 : f.call(e, i, l);
  }, j = (i, l) => {
    var f;
    const {
      multiple: N,
      fieldNames: p
    } = e, {
      node: L,
      nativeEvent: a
    } = l, {
      key: u = ""
    } = L, y = P(e), m = Object.assign(Object.assign({}, l), {
      selected: !0
    }), V = (a == null ? void 0 : a.ctrlKey) || (a == null ? void 0 : a.metaKey), q = a == null ? void 0 : a.shiftKey;
    let o;
    N && V ? (o = i, x.current = u, K.current = o, m.selectedNodes = v(y, o, p)) : N && q ? (o = Array.from(new Set([].concat(S(K.current || []), S(X({
      treeData: y,
      expandedKeys: b,
      startKey: u,
      endKey: x.current,
      fieldNames: p
    }))))), m.selectedNodes = v(y, o, p)) : (o = [u], x.current = u, K.current = o, m.selectedNodes = v(y, o, p)), (f = e.onSelect) === null || f === void 0 || f.call(e, o, m), "selectedKeys" in e || O(o);
  }, {
    getPrefixCls: A,
    direction: _
  } = r.useContext(Y), {
    prefixCls: k,
    className: I,
    showIcon: R = !0,
    expandAction: F = "click"
  } = e, $ = h(e, ["prefixCls", "className", "showIcon", "expandAction"]), E = A("tree", k), z = J(`${E}-directory`, {
    [`${E}-directory-rtl`]: _ === "rtl"
  }, I);
  return /* @__PURE__ */ r.createElement(W, Object.assign({
    icon: Z,
    ref: d,
    blockNode: !0
  }, $, {
    showIcon: R,
    expandAction: F,
    prefixCls: E,
    className: z,
    expandedKeys: b,
    selectedKeys: C,
    onSelect: j,
    onExpand: D
  }));
}, T = /* @__PURE__ */ r.forwardRef(ee);
process.env.NODE_ENV !== "production" && (T.displayName = "DirectoryTree");
const pe = T;
export {
  pe as default
};
