import { u as e, a as t, b as i, c as n, P as o, D as s, d as r } from "./dnd-kit-e67c9595.js";
import { _ as d } from "./lodash-226cb5b1.js";
import a, { useContext as l, Fragment as p, useState as c, useMemo as g } from "react";
import { d as h } from "./styled-components-c6abe9a3.js";
import { lA as m, lR as u, lS as $ } from "./ant-design-icons-14ab96af.js";
import { F as b } from "./antd-97b654da.js";
const f = a.createContext({ toggleFold: () => {
}, foldedStatus: {} }), D = h.div`
  position: relative;
  width: auto;
  height: ${(e2) => e2.$itemHeight ?? 30}px;
  /* border: 1px solid #d7d9e0; */
  border-radius: 4px;
  margin-bottom: ${(e2) => e2.$positionLineHeight ?? 4}px;
  display: flex;
  /* padding: 0 8px; */
  align-items: center;
  opacity: ${(e2) => e2.$dragging ? "0.5" : 1};

  &::before {
    content: "";
    display: ${(e2) => e2.$showPositionLineDot && e2.$isOver && e2.$showPositionLine ? "block" : "none"};
    position: absolute;
    background-color: #315efb;
    height: ${(e2) => e2.$positionLineDotDiameter}px;
    width: ${(e2) => e2.$positionLineDotDiameter}px;
    left: 0;
    border-radius: 100%;
    bottom: ${(e2) => -(e2.$positionLineHeight ?? 4) - ((e2.$positionLineDotDiameter ?? 8) - (e2.$positionLineHeight ?? 4)) / 2}px;
    left: ${(e2) => e2.$positionLineIndent ?? (e2.$dropInAsSub ? 15 : -1)}px;
    z-index: 1;
  }

  &::after {
    content: "";
    display: ${(e2) => e2.$isOver && e2.$showPositionLine ? "block" : "none"};
    height: ${(e2) => e2.$positionLineHeight ?? 4}px;
    border-radius: 4px;
    position: absolute;
    left: ${(e2) => e2.$positionLineIndent ?? (e2.$dropInAsSub ? 15 : -1)}px;
    right: 0;
    background-color: #315efb;
    bottom: ${(e2) => -(e2.$positionLineHeight ?? 4)}px;
  }
`;
const L = a.forwardRef(function(e2, t2) {
  var _a;
  const { extra: i2, dragging: n2 = false, dropInAsSub: o2 = true, isOver: s2 = false, dragListeners: r2, children: d2, path: a2, ...p2 } = e2, c2 = l(f), g2 = (_a = c2.positionLineIndent) == null ? void 0 : _a.call(c2, a2, o2), h2 = (c2.showDropInPositionLine ?? true) || !o2;
  return m(D, { $showPositionLine: h2, $positionLineIndent: g2, $positionLineDotDiameter: c2.positionLineDotDiameter, $showPositionLineDot: c2.showPositionLineDot, $positionLineHeight: c2.positionLineHeight, $itemHeight: c2.itemHeight, $isOver: s2, $dragging: n2, $dropInAsSub: o2, ref: t2, ...p2, ...r2, children: d2 });
}), v = h.div`
  pointer-events: none;
  position: absolute;
  width: 100%;
  top: -${(e2) => e2.$positionLineHeight ?? 4}px;
  height: ${(e2) => 0.6 * (e2.$itemHeight ?? 30)}px;
  z-index: 10;
  /* background-color: rgba(0, 0, 0, 0.2); */
  .position-line {
    height: ${(e2) => e2.$positionLineHeight ?? 4}px;
    border-radius: 4px;
    background-color: ${(e2) => e2.$active ? "#315efb" : "transparent"};
    width: 100%;
    margin-left: ${(e2) => e2.$positionLineIndent ?? 0}px;
    position: relative;
    &::after {
      content: "";
      position: absolute;
      background-color: #315efb;
      display: ${(e2) => e2.$showPositionLineDot && e2.$active ? "block" : "none"};
      left: 0;
      height: ${(e2) => e2.$positionLineDotDiameter ?? 8}px;
      width: ${(e2) => e2.$positionLineDotDiameter ?? 8}px;
      top: ${(e2) => -((e2.$positionLineDotDiameter ?? 8) - (e2.$positionLineHeight ?? 4)) / 2}px;
      border-radius: 100%;
    }
  }
`;
function I(t2) {
  var _a;
  const { path: i2, disabled: n2, targetListSize: o2 } = t2, s2 = { targetPath: i2, targetListSize: o2, dropInAsSub: false }, { setNodeRef: r2, isOver: d2 } = e({ id: `p_${i2.join("_")}`, disabled: n2, data: s2 }), a2 = l(f);
  return m(v, { $itemHeight: a2.itemHeight, $showPositionLineDot: a2.showPositionLineDot, $positionLineDotDiameter: a2.positionLineDotDiameter, $positionLineHeight: a2.positionLineHeight, $positionLineIndent: (_a = a2.positionLineIndent) == null ? void 0 : _a.call(a2, i2, false), $active: d2, ref: r2, children: m("div", { className: "position-line" }) });
}
function x(e2, t2) {
  return !e2 || ("function" == typeof e2 ? e2(t2) : e2);
}
const S = h.div`
  position: relative;
`;
function A(i2) {
  const { item: n2, path: o2, activeNode: s2, disabled: r2, parentDragging: d2, disableDropIn: a2, forceFold: c2 = false, dropInAsSub: g2 = true, isOverlay: h2 = false, onDelete: D2, renderContent: v2 } = i2, w2 = n2.id ?? o2.join("_"), H2 = n2.items, y2 = l(f), P = (c2 || y2.foldedStatus[w2]) && !y2.unfoldAll, O = { path: o2, node: n2 }, { listeners: C, setNodeRef: k, isDragging: F } = t({ id: w2, data: O, disabled: y2.disable ?? false }), j = x(n2.canDropIn, s2 == null ? void 0 : s2.data), z = x(n2.canDropBefore, s2 == null ? void 0 : s2.data), N = x(n2.canDropAfter, s2 == null ? void 0 : s2.data), R = { targetListSize: H2.length, targetPath: g2 ? [...o2, 0] : [...o2.slice(0, -1), o2[o2.length - 1] + 1], dropInAsSub: g2 }, { setNodeRef: M, isOver: _ } = e({ id: w2, disabled: F || r2 || a2 || !g2 && false === N, data: R });
  return u($, { children: [u(S, { children: [s2 && z && m(I, { path: o2, targetListSize: H2.length, disabled: F || r2 }), u(b, { style: { paddingLeft: "15px" }, align: "center", children: [m(L, { path: o2, id: w2, dropInAsSub: g2 && false !== j, isOver: _, ref: (e2) => {
    k(e2), M(e2);
  }, ...C, children: m("span", { style: { cursor: "default" }, children: "⣿" }) }), m("div", { style: { flex: 1, maxWidth: "calc(100% - 12px)" }, children: (v2 == null ? void 0 : v2({ node: n2, isOver: _, path: o2, isOverlay: h2, hasChildren: H2.length > 0, dragging: !(!F && !d2), isFolded: P, onDelete: () => D2 == null ? void 0 : D2(o2), onToggleFold: () => y2.toggleFold(w2) })) || null })] })] }), H2.length > 0 && !P && m("div", { className: "sub-menu-list", children: H2.map((e2, t2) => m(p, { children: m(A, { path: [...o2, t2], activeNode: s2, dropInAsSub: false, item: e2, renderContent: v2, disabled: r2 || F || a2, onDelete: D2, parentDragging: F }) }, t2)) })] });
}
const w = h.div`
  .menu-title {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .menu-list {
    margin-top: 8px;
    position: relative;
  }
`;
function H(e2) {
  const { node: t2, onAddItem: a2, onDeleteItem: p2, onMoveItem: g2, onAddSubItem: h2, renderItemContent: $2 } = e2, b2 = l(f), [D2, L2] = c(null), v2 = D2 && D2.node.items.length > 0;
  const S2 = i(n(o, { activationConstraint: { distance: 8 } })), H2 = t2.items[t2.items.length - 1], y2 = x(H2 == null ? void 0 : H2.canDropAfter, D2 == null ? void 0 : D2.node.data);
  return m(w, { children: u(s, { sensors: S2, onDragStart: function(e3) {
    L2(e3.active.data.current);
  }, onDragEnd: function(e3) {
    var _a;
    const t3 = e3.active.data.current, i2 = (_a = e3.over) == null ? void 0 : _a.data.current;
    if (i2) {
      const e4 = t3.path, n2 = i2.targetPath;
      if (e4.length === n2.length && d.isEqual(e4.slice(0, -1), n2.slice(0, -1))) {
        const t4 = e4[e4.length - 1];
        let i3 = n2[n2.length - 1];
        t4 < i3 && (i3 -= 1), g2(n2, t4, i3);
      } else {
        let o2 = n2[n2.length - 1], s2 = n2, r2 = 0;
        p2(e4), i2.dropInAsSub ? (s2 = s2.slice(0, -1), r2 = h2(s2, t3.node.data)) : r2 = a2(s2, t3.node.data), -1 !== i2.targetListSize && g2(n2, r2, o2);
      }
    }
    L2(null);
  }, children: [t2.items.map((e3, t3) => {
    const i2 = x(e3.canDropIn, D2 == null ? void 0 : D2.node.data);
    return m(A, { activeNode: D2 == null ? void 0 : D2.node, dropInAsSub: !v2 && false !== i2, disableDropIn: !!v2 || false === i2, renderContent: $2, onAddSubMenu: h2, onDelete: p2, path: [t3], item: e3 }, t3);
  }), y2 && m("div", { style: { position: "relative" }, children: D2 && m(I, { targetListSize: -1, path: [t2.items.length] }) }), m(r, { dropAnimation: null, children: D2 && m(A, { isOverlay: true, forceFold: false === b2.showSubInDragOverlay, path: [], item: D2.node, renderContent: $2 }) })] }) });
}
function y(e2) {
  const { node: t2, renderItemContent: i2, ...n2 } = e2, [o2, s2] = c({}), r2 = (e3, i3) => (i3 || (i3 = t2.items), 1 === e3.length ? i3[e3[0]] : r2(e3.slice(1), i3[e3[0]].items)), d2 = (t3, i3) => (i3 || (i3 = e2.node), 1 === t3.length ? i3 : d2(t3.slice(1), i3.items[t3[0]])), a2 = (e3) => {
    s2((t3) => {
      const i3 = { ...t3 };
      return i3[e3] = !i3[e3], i3;
    });
  }, l2 = g(() => ({ ...n2, toggleFold: a2, foldedStatus: o2 }), [o2, n2]);
  return m(f.Provider, { value: l2, children: m(H, { node: t2, renderItemContent: i2, onAddItem: (e3, t3) => {
    const i3 = d2(e3);
    return i3.addItem(t3), i3.items.length;
  }, onDeleteItem: (e3) => {
    d2(e3).deleteItem(e3[e3.length - 1]);
  }, onAddSubItem: (e3, t3) => {
    const i3 = r2(e3);
    return i3.addSubItem(t3), i3.items.length;
  }, onMoveItem: (e3, t3, i3) => {
    d2(e3).moveItem(t3, i3);
  } }) });
}
export {
  y as D
};
