import xe, { forwardRef as Ke, createElement as $e, createContext as Lt, useContext as Gt, useState as C, useRef as ue, useCallback as A, useEffect as B, useMemo as H } from "react";
import Ot, { Handle as Ve, Position as Ye, useReactFlow as Ut, getBezierPath as Vt, BaseEdge as Yt, EdgeLabelRenderer as Bt, MarkerType as Z, ReactFlowProvider as Ht, applyNodeChanges as Ft, applyEdgeChanges as Wt, addEdge as qt, updateEdge as Xt, ConnectionMode as Kt, Background as Jt, MiniMap as Zt, Panel as Qt } from "reactflow";
var Ne = { exports: {} }, ce = {};
/**
 * @license React
 * react-jsx-runtime.production.js
 *
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var Be;
function es() {
  if (Be) return ce;
  Be = 1;
  var t = Symbol.for("react.transitional.element"), s = Symbol.for("react.fragment");
  function a(n, l, i) {
    var x = null;
    if (i !== void 0 && (x = "" + i), l.key !== void 0 && (x = "" + l.key), "key" in l) {
      i = {};
      for (var m in l)
        m !== "key" && (i[m] = l[m]);
    } else i = l;
    return l = i.ref, {
      $$typeof: t,
      type: n,
      key: x,
      ref: l !== void 0 ? l : null,
      props: i
    };
  }
  return ce.Fragment = s, ce.jsx = a, ce.jsxs = a, ce;
}
var de = {};
/**
 * @license React
 * react-jsx-runtime.development.js
 *
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var He;
function ts() {
  return He || (He = 1, process.env.NODE_ENV !== "production" && (function() {
    function t(o) {
      if (o == null) return null;
      if (typeof o == "function")
        return o.$$typeof === ee ? null : o.displayName || o.name || null;
      if (typeof o == "string") return o;
      switch (o) {
        case y:
          return "Fragment";
        case M:
          return "Profiler";
        case w:
          return "StrictMode";
        case we:
          return "Suspense";
        case Q:
          return "SuspenseList";
        case ke:
          return "Activity";
      }
      if (typeof o == "object")
        switch (typeof o.tag == "number" && console.error(
          "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
        ), o.$$typeof) {
          case f:
            return "Portal";
          case R:
            return o.displayName || "Context";
          case I:
            return (o._context.displayName || "Context") + ".Consumer";
          case V:
            var N = o.render;
            return o = o.displayName, o || (o = N.displayName || N.name || "", o = o !== "" ? "ForwardRef(" + o + ")" : "ForwardRef"), o;
          case me:
            return N = o.displayName || null, N !== null ? N : t(o.type) || "Memo";
          case W:
            N = o._payload, o = o._init;
            try {
              return t(o(N));
            } catch {
            }
        }
      return null;
    }
    function s(o) {
      return "" + o;
    }
    function a(o) {
      try {
        s(o);
        var N = !1;
      } catch {
        N = !0;
      }
      if (N) {
        N = console;
        var P = N.error, D = typeof Symbol == "function" && Symbol.toStringTag && o[Symbol.toStringTag] || o.constructor.name || "Object";
        return P.call(
          N,
          "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
          D
        ), s(o);
      }
    }
    function n(o) {
      if (o === y) return "<>";
      if (typeof o == "object" && o !== null && o.$$typeof === W)
        return "<...>";
      try {
        var N = t(o);
        return N ? "<" + N + ">" : "<...>";
      } catch {
        return "<...>";
      }
    }
    function l() {
      var o = te.A;
      return o === null ? null : o.getOwner();
    }
    function i() {
      return Error("react-stack-top-frame");
    }
    function x(o) {
      if (q.call(o, "key")) {
        var N = Object.getOwnPropertyDescriptor(o, "key").get;
        if (N && N.isReactWarning) return !1;
      }
      return o.key !== void 0;
    }
    function m(o, N) {
      function P() {
        fe || (fe = !0, console.error(
          "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
          N
        ));
      }
      P.isReactWarning = !0, Object.defineProperty(o, "key", {
        get: P,
        configurable: !0
      });
    }
    function u() {
      var o = t(this.type);
      return ge[o] || (ge[o] = !0, console.error(
        "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
      )), o = this.props.ref, o !== void 0 ? o : null;
    }
    function g(o, N, P, D, O, X) {
      var T = P.ref;
      return o = {
        $$typeof: h,
        type: o,
        key: N,
        props: P,
        _owner: D
      }, (T !== void 0 ? T : null) !== null ? Object.defineProperty(o, "ref", {
        enumerable: !1,
        get: u
      }) : Object.defineProperty(o, "ref", { enumerable: !1, value: null }), o._store = {}, Object.defineProperty(o._store, "validated", {
        configurable: !1,
        enumerable: !1,
        writable: !0,
        value: 0
      }), Object.defineProperty(o, "_debugInfo", {
        configurable: !1,
        enumerable: !1,
        writable: !0,
        value: null
      }), Object.defineProperty(o, "_debugStack", {
        configurable: !1,
        enumerable: !1,
        writable: !0,
        value: O
      }), Object.defineProperty(o, "_debugTask", {
        configurable: !1,
        enumerable: !1,
        writable: !0,
        value: X
      }), Object.freeze && (Object.freeze(o.props), Object.freeze(o)), o;
    }
    function c(o, N, P, D, O, X) {
      var T = N.children;
      if (T !== void 0)
        if (D)
          if (E(T)) {
            for (D = 0; D < T.length; D++)
              v(T[D]);
            Object.freeze && Object.freeze(T);
          } else
            console.error(
              "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
            );
        else v(T);
      if (q.call(N, "key")) {
        T = t(o);
        var U = Object.keys(N).filter(function(ae) {
          return ae !== "key";
        });
        D = 0 < U.length ? "{key: someKey, " + U.join(": ..., ") + ": ...}" : "{key: someKey}", re[T + D] || (U = 0 < U.length ? "{" + U.join(": ..., ") + ": ...}" : "{}", console.error(
          `A props object containing a "key" prop is being spread into JSX:
  let props = %s;
  <%s {...props} />
React keys must be passed directly to JSX without using spread:
  let props = %s;
  <%s key={someKey} {...props} />`,
          D,
          T,
          U,
          T
        ), re[T + D] = !0);
      }
      if (T = null, P !== void 0 && (a(P), T = "" + P), x(N) && (a(N.key), T = "" + N.key), "key" in N) {
        P = {};
        for (var K in N)
          K !== "key" && (P[K] = N[K]);
      } else P = N;
      return T && m(
        P,
        typeof o == "function" ? o.displayName || o.name || "Unknown" : o
      ), g(
        o,
        T,
        P,
        l(),
        O,
        X
      );
    }
    function v(o) {
      r(o) ? o._store && (o._store.validated = 1) : typeof o == "object" && o !== null && o.$$typeof === W && (o._payload.status === "fulfilled" ? r(o._payload.value) && o._payload.value._store && (o._payload.value._store.validated = 1) : o._store && (o._store.validated = 1));
    }
    function r(o) {
      return typeof o == "object" && o !== null && o.$$typeof === h;
    }
    var b = xe, h = Symbol.for("react.transitional.element"), f = Symbol.for("react.portal"), y = Symbol.for("react.fragment"), w = Symbol.for("react.strict_mode"), M = Symbol.for("react.profiler"), I = Symbol.for("react.consumer"), R = Symbol.for("react.context"), V = Symbol.for("react.forward_ref"), we = Symbol.for("react.suspense"), Q = Symbol.for("react.suspense_list"), me = Symbol.for("react.memo"), W = Symbol.for("react.lazy"), ke = Symbol.for("react.activity"), ee = Symbol.for("react.client.reference"), te = b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, q = Object.prototype.hasOwnProperty, E = Array.isArray, se = console.createTask ? console.createTask : function() {
      return null;
    };
    b = {
      react_stack_bottom_frame: function(o) {
        return o();
      }
    };
    var fe, ge = {}, S = b.react_stack_bottom_frame.bind(
      b,
      i
    )(), ne = se(n(i)), re = {};
    de.Fragment = y, de.jsx = function(o, N, P) {
      var D = 1e4 > te.recentlyCreatedOwnerStacks++;
      return c(
        o,
        N,
        P,
        !1,
        D ? Error("react-stack-top-frame") : S,
        D ? se(n(o)) : ne
      );
    }, de.jsxs = function(o, N, P) {
      var D = 1e4 > te.recentlyCreatedOwnerStacks++;
      return c(
        o,
        N,
        P,
        !0,
        D ? Error("react-stack-top-frame") : S,
        D ? se(n(o)) : ne
      );
    };
  })()), de;
}
var Fe;
function ss() {
  return Fe || (Fe = 1, process.env.NODE_ENV === "production" ? Ne.exports = es() : Ne.exports = ts()), Ne.exports;
}
var e = ss();
const L = [];
for (let t = 0; t < 256; ++t)
  L.push((t + 256).toString(16).slice(1));
function ns(t, s = 0) {
  return (L[t[s + 0]] + L[t[s + 1]] + L[t[s + 2]] + L[t[s + 3]] + "-" + L[t[s + 4]] + L[t[s + 5]] + "-" + L[t[s + 6]] + L[t[s + 7]] + "-" + L[t[s + 8]] + L[t[s + 9]] + "-" + L[t[s + 10]] + L[t[s + 11]] + L[t[s + 12]] + L[t[s + 13]] + L[t[s + 14]] + L[t[s + 15]]).toLowerCase();
}
let Me;
const rs = new Uint8Array(16);
function as() {
  if (!Me) {
    if (typeof crypto > "u" || !crypto.getRandomValues)
      throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
    Me = crypto.getRandomValues.bind(crypto);
  }
  return Me(rs);
}
const os = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), We = { randomUUID: os };
function ls(t, s, a) {
  var l;
  t = t || {};
  const n = t.random ?? ((l = t.rng) == null ? void 0 : l.call(t)) ?? as();
  if (n.length < 16)
    throw new Error("Random bytes length must be >= 16");
  return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, ns(n);
}
function ze(t, s, a) {
  return We.randomUUID && !t ? We.randomUUID() : ls(t);
}
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const is = (t) => t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), cs = (t) => t.replace(
  /^([A-Z])|[\s-_]+(\w)/g,
  (s, a, n) => n ? n.toUpperCase() : a.toLowerCase()
), qe = (t) => {
  const s = cs(t);
  return s.charAt(0).toUpperCase() + s.slice(1);
}, Je = (...t) => t.filter((s, a, n) => !!s && s.trim() !== "" && n.indexOf(s) === a).join(" ").trim(), ds = (t) => {
  for (const s in t)
    if (s.startsWith("aria-") || s === "role" || s === "title")
      return !0;
};
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
var us = {
  xmlns: "http://www.w3.org/2000/svg",
  width: 24,
  height: 24,
  viewBox: "0 0 24 24",
  fill: "none",
  stroke: "currentColor",
  strokeWidth: 2,
  strokeLinecap: "round",
  strokeLinejoin: "round"
};
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const hs = Ke(
  ({
    color: t = "currentColor",
    size: s = 24,
    strokeWidth: a = 2,
    absoluteStrokeWidth: n,
    className: l = "",
    children: i,
    iconNode: x,
    ...m
  }, u) => $e(
    "svg",
    {
      ref: u,
      ...us,
      width: s,
      height: s,
      stroke: t,
      strokeWidth: n ? Number(a) * 24 / Number(s) : a,
      className: Je("lucide", l),
      ...!i && !ds(m) && { "aria-hidden": "true" },
      ...m
    },
    [
      ...x.map(([g, c]) => $e(g, c)),
      ...Array.isArray(i) ? i : [i]
    ]
  )
);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const k = (t, s) => {
  const a = Ke(
    ({ className: n, ...l }, i) => $e(hs, {
      ref: i,
      iconNode: s,
      className: Je(
        `lucide-${is(qe(t))}`,
        `lucide-${t}`,
        n
      ),
      ...l
    })
  );
  return a.displayName = qe(t), a;
};
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const xs = [
  [
    "path",
    {
      d: "M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2",
      key: "169zse"
    }
  ]
], ps = k("activity", xs);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const ms = [
  ["path", { d: "m12 19-7-7 7-7", key: "1l729n" }],
  ["path", { d: "M19 12H5", key: "x3x0zl" }]
], fs = k("arrow-left", ms);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const gs = [
  ["path", { d: "M12 10h.01", key: "1nrarc" }],
  ["path", { d: "M12 14h.01", key: "1etili" }],
  ["path", { d: "M12 6h.01", key: "1vi96p" }],
  ["path", { d: "M16 10h.01", key: "1m94wz" }],
  ["path", { d: "M16 14h.01", key: "1gbofw" }],
  ["path", { d: "M16 6h.01", key: "1x0f13" }],
  ["path", { d: "M8 10h.01", key: "19clt8" }],
  ["path", { d: "M8 14h.01", key: "6423bh" }],
  ["path", { d: "M8 6h.01", key: "1dz90k" }],
  ["path", { d: "M9 22v-3a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v3", key: "cabbwy" }],
  ["rect", { x: "4", y: "2", width: "16", height: "20", rx: "2", key: "1uxh74" }]
], bs = k("building", gs);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const vs = [["path", { d: "m15 18-6-6 6-6", key: "1wnfg3" }]], ys = k("chevron-left", vs);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const js = [["path", { d: "m9 18 6-6-6-6", key: "mthhwq" }]], Ns = k("chevron-right", js);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const ws = [
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
  ["line", { x1: "12", x2: "12", y1: "8", y2: "12", key: "1pkeuh" }],
  ["line", { x1: "12", x2: "12.01", y1: "16", y2: "16", key: "4dfq90" }]
], Ze = k("circle-alert", ws);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const ks = [
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
  ["path", { d: "m9 12 2 2 4-4", key: "dzmm74" }]
], Cs = k("circle-check", ks);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const Es = [
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
  ["line", { x1: "10", x2: "10", y1: "15", y2: "9", key: "c1nkhi" }],
  ["line", { x1: "14", x2: "14", y1: "15", y2: "9", key: "h65svq" }]
], Qe = k("circle-pause", Es);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const _s = [["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }]], Rs = k("circle", _s);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const Ms = [
  ["path", { d: "M12 15V3", key: "m9g1x1" }],
  ["path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4", key: "ih7n3h" }],
  ["path", { d: "m7 10 5 5 5-5", key: "brsn70" }]
], Ss = k("download", Ms);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const As = [
  [
    "path",
    {
      d: "M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",
      key: "1oefj6"
    }
  ],
  ["path", { d: "M14 2v5a1 1 0 0 0 1 1h5", key: "wfsgrz" }],
  ["path", { d: "M10 9H8", key: "b1mrlr" }],
  ["path", { d: "M16 13H8", key: "t4e002" }],
  ["path", { d: "M16 17H8", key: "z1uh3a" }]
], Ps = k("file-text", As);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const $s = [
  ["line", { x1: "6", x2: "6", y1: "3", y2: "15", key: "17qcm7" }],
  ["circle", { cx: "18", cy: "6", r: "3", key: "1h7g24" }],
  ["circle", { cx: "6", cy: "18", r: "3", key: "fqmcym" }],
  ["path", { d: "M18 9a9 9 0 0 1-9 9", key: "n2h4wq" }]
], et = k("git-branch", $s);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const zs = [
  [
    "path",
    {
      d: "M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z",
      key: "zw3jo"
    }
  ],
  [
    "path",
    {
      d: "M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12",
      key: "1wduqc"
    }
  ],
  [
    "path",
    {
      d: "M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17",
      key: "kqbvx6"
    }
  ]
], tt = k("layers", zs);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const Ts = [
  ["rect", { width: "7", height: "7", x: "3", y: "3", rx: "1", key: "1g98yp" }],
  ["rect", { width: "7", height: "7", x: "14", y: "3", rx: "1", key: "6d4xhi" }],
  ["rect", { width: "7", height: "7", x: "14", y: "14", rx: "1", key: "nxv5o0" }],
  ["rect", { width: "7", height: "7", x: "3", y: "14", rx: "1", key: "1bb6yr" }]
], Ds = k("layout-grid", Ts);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const Is = [
  ["path", { d: "M9 17H7A5 5 0 0 1 7 7h2", key: "8i5ue5" }],
  ["path", { d: "M15 7h2a5 5 0 1 1 0 10h-2", key: "1b9ql8" }],
  ["line", { x1: "8", x2: "16", y1: "12", y2: "12", key: "1jonct" }]
], st = k("link-2", Is);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const Ls = [["path", { d: "M21 12a9 9 0 1 1-6.219-8.56", key: "13zald" }]], Gs = k("loader-circle", Ls);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const Os = [
  ["path", { d: "M8 3H5a2 2 0 0 0-2 2v3", key: "1dcmit" }],
  ["path", { d: "M21 8V5a2 2 0 0 0-2-2h-3", key: "1e4gt3" }],
  ["path", { d: "M3 16v3a2 2 0 0 0 2 2h3", key: "wsl5sc" }],
  ["path", { d: "M16 21h3a2 2 0 0 0 2-2v-3", key: "18trek" }]
], Us = k("maximize", Os);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const Vs = [["path", { d: "M5 12h14", key: "1ays0h" }]], Ys = k("minus", Vs);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const Bs = [
  ["rect", { width: "18", height: "18", x: "3", y: "3", rx: "2", key: "afitv7" }],
  ["path", { d: "M3 9h18", key: "1pudct" }],
  ["path", { d: "M9 21V9", key: "1oto5p" }]
], nt = k("panels-top-left", Bs);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const Hs = [
  ["path", { d: "M5 12h14", key: "1ays0h" }],
  ["path", { d: "M12 5v14", key: "s699le" }]
], rt = k("plus", Hs);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const Fs = [
  ["path", { d: "m15 14 5-5-5-5", key: "12vg1m" }],
  ["path", { d: "M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13", key: "6uklza" }]
], Ws = k("redo-2", Fs);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const qs = [
  [
    "path",
    {
      d: "M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",
      key: "1c8476"
    }
  ],
  ["path", { d: "M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7", key: "1ydtos" }],
  ["path", { d: "M7 3v4a1 1 0 0 0 1 1h7", key: "t51u73" }]
], Xs = k("save", qs);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const Ks = [
  ["path", { d: "m21 21-4.34-4.34", key: "14j7rj" }],
  ["circle", { cx: "11", cy: "11", r: "8", key: "4ej97u" }]
], Te = k("search", Ks);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const Js = [
  [
    "path",
    {
      d: "M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",
      key: "1i5ecw"
    }
  ],
  ["circle", { cx: "12", cy: "12", r: "3", key: "1v7zrd" }]
], Zs = k("settings", Js);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const Qs = [
  [
    "path",
    {
      d: "M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",
      key: "oel41y"
    }
  ]
], en = k("shield", Qs);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const tn = [
  ["circle", { cx: "9", cy: "12", r: "3", key: "u3jwor" }],
  ["rect", { width: "20", height: "14", x: "2", y: "5", rx: "7", key: "g7kal2" }]
], Se = k("toggle-left", tn);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const sn = [
  ["circle", { cx: "15", cy: "12", r: "3", key: "1afu0r" }],
  ["rect", { width: "20", height: "14", x: "2", y: "5", rx: "7", key: "g7kal2" }]
], Ae = k("toggle-right", sn);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const nn = [
  ["path", { d: "M10 11v6", key: "nco0om" }],
  ["path", { d: "M14 11v6", key: "outv1u" }],
  ["path", { d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6", key: "miytrc" }],
  ["path", { d: "M3 6h18", key: "d0wm0j" }],
  ["path", { d: "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2", key: "e791ji" }]
], at = k("trash-2", nn);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const rn = [
  [
    "path",
    {
      d: "m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",
      key: "wmoenq"
    }
  ],
  ["path", { d: "M12 9v4", key: "juzpu7" }],
  ["path", { d: "M12 17h.01", key: "p32p05" }]
], ot = k("triangle-alert", rn);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const an = [
  ["path", { d: "M9 14 4 9l5-5", key: "102s5s" }],
  ["path", { d: "M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11", key: "f3b9sd" }]
], on = k("undo-2", an);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const ln = [
  ["path", { d: "M12 3v12", key: "1x0j5s" }],
  ["path", { d: "m17 8-5-5-5 5", key: "7q97r8" }],
  ["path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4", key: "ih7n3h" }]
], cn = k("upload", ln);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const dn = [
  ["path", { d: "M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2", key: "975kel" }],
  ["circle", { cx: "12", cy: "7", r: "4", key: "17ys0d" }]
], lt = k("user", dn);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const un = [
  ["path", { d: "M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2", key: "1yyitq" }],
  ["path", { d: "M16 3.128a4 4 0 0 1 0 7.744", key: "16gr8j" }],
  ["path", { d: "M22 21v-2a4 4 0 0 0-3-3.87", key: "kshegd" }],
  ["circle", { cx: "9", cy: "7", r: "4", key: "nufk8" }]
], he = k("users", un);
/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */
const hn = [
  ["path", { d: "M18 6 6 18", key: "1bl5f8" }],
  ["path", { d: "m6 6 12 12", key: "d8bk6v" }]
], F = k("x", hn), it = {
  Building: bs,
  Users: he,
  Layout: nt,
  Shield: en,
  User: lt,
  Group: he
}, ct = Lt({
  iconMap: it
}), pe = () => Gt(ct), xn = ({ children: t, onFetchMembers: s, iconMap: a, onRemoveEdge: n, onUpdateNode: l }) => {
  const i = { ...it, ...a };
  return /* @__PURE__ */ e.jsx(ct.Provider, { value: { onFetchMembers: s, iconMap: i, onRemoveEdge: n, onUpdateNode: l }, children: t });
}, pn = ({ id: t, data: s, selected: a }) => {
  const { iconMap: n, onUpdateNode: l } = pe(), i = n[s.iconPath] || n.Layout, [x, m] = C(!1), [u, g] = C(s.name), c = ue(null), r = s.inCycle ? {
    border: "border-red-400",
    bg: "bg-red-50",
    iconBg: "bg-red-100 text-red-600",
    badge: "bg-red-600 text-white",
    badgeText: "CYCLE ERROR",
    opacity: "opacity-100"
  } : s.isDeleted ? {
    border: "border-slate-200",
    bg: "bg-slate-100",
    iconBg: "bg-slate-200 text-slate-400",
    badge: "bg-slate-500 text-white",
    badgeText: "DELETED",
    opacity: "opacity-75 grayscale"
  } : s.isSuspended ? {
    border: "border-amber-300",
    bg: "bg-amber-50",
    iconBg: "bg-amber-100 text-amber-600",
    badge: "bg-amber-500 text-white",
    badgeText: "SUSPENDED",
    opacity: "opacity-100"
  } : s.isActive ? {
    border: a ? "border-teal-500" : "border-transparent",
    bg: s.isRootNode ? "bg-slate-50" : "bg-white",
    iconBg: s.isRootNode ? "bg-teal-100 text-teal-600" : "bg-slate-100 text-slate-500",
    badge: s.isRootNode ? "bg-teal-600 text-white" : null,
    badgeText: "ROOT GROUP",
    opacity: "opacity-100"
  } : {
    border: "border-slate-200",
    bg: "bg-slate-50",
    iconBg: "bg-slate-200 text-slate-500",
    badge: "bg-slate-200 text-slate-600",
    badgeText: "INACTIVE",
    opacity: "opacity-90"
  }, b = A((y) => {
    y == null || y.stopPropagation(), m(!0), g(s.name);
  }, [s.name]), h = A(() => {
    m(!1), u !== s.name && l && l(t, { name: u });
  }, [u, s.name, t, l]), f = (y) => {
    y.stopPropagation(), y.key === "Enter" && h();
  };
  return B(() => {
    if (!a || x) return;
    const y = (w) => {
      (w.ctrlKey || w.metaKey) && w.key.toLowerCase() === "r" && (w.preventDefault(), b());
    };
    return window.addEventListener("keydown", y), () => window.removeEventListener("keydown", y);
  }, [a, x, b]), B(() => {
    x && c.current && (c.current.focus(), c.current.select());
  }, [x]), B(() => {
    x || g(s.name);
  }, [s.name, x]), /* @__PURE__ */ e.jsxs(
    "div",
    {
      className: `
        relative px-4 py-3 rounded-xl shadow-lg border-2 transition-all duration-300
        ${r.border}
        ${r.bg}
        ${r.opacity}
        ${a ? "ring-4 ring-teal-500/20 scale-105 z-50" : "hover:border-slate-300"}
        min-w-[220px] group font-sans
      `,
      onDoubleClick: b,
      children: [
        r.badgeText && (r.badge || s.inCycle || s.isDeleted || s.isSuspended || !s.isActive) && /* @__PURE__ */ e.jsxs("div", { className: `
          absolute -top-3 left-4 px-2 py-0.5 rounded-full text-[9px] font-bold uppercase tracking-widest shadow-sm flex items-center gap-1 z-10
          ${r.badge || "bg-slate-200 text-slate-600"}
          ${s.inCycle ? "animate-pulse" : ""}
        `, children: [
          s.isDeleted && /* @__PURE__ */ e.jsx(at, { size: 8 }),
          s.isSuspended && /* @__PURE__ */ e.jsx(Qe, { size: 8 }),
          r.badgeText
        ] }),
        /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-3", children: [
          /* @__PURE__ */ e.jsx("div", { className: `
          w-10 h-10 rounded-xl flex items-center justify-center transition-colors shrink-0
          ${r.iconBg}
        `, children: i && /* @__PURE__ */ e.jsx(i, { size: 20, strokeWidth: 2.5 }) }),
          /* @__PURE__ */ e.jsxs("div", { className: "flex-1 overflow-hidden min-h-[36px] flex flex-col justify-center", children: [
            x ? /* @__PURE__ */ e.jsx(
              "input",
              {
                ref: c,
                type: "text",
                value: u,
                onChange: (y) => g(y.target.value),
                onBlur: h,
                onKeyDown: f,
                className: "w-full text-sm font-bold text-slate-800 border border-teal-500 rounded px-1 py-0.5 outline-none bg-white shadow-sm nodrag",
                onClick: (y) => y.stopPropagation(),
                onMouseDown: (y) => y.stopPropagation()
              }
            ) : /* @__PURE__ */ e.jsx("h3", { className: `text-sm font-bold text-slate-800 truncate leading-tight ${s.isDeleted ? "line-through decoration-slate-400" : ""}`, children: s.name || "Unnamed Group" }),
            /* @__PURE__ */ e.jsx("p", { className: "text-[10px] text-slate-500 truncate mt-0.5 opacity-80 italic", children: s.description || "No description provided..." })
          ] })
        ] }),
        /* @__PURE__ */ e.jsxs("div", { className: "mt-3 pt-2 border-t border-slate-200/50 flex items-center justify-between gap-2", children: [
          /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-1.5 bg-white/50 px-2 py-1 rounded-md border border-slate-100 text-[10px] font-mono", children: [
            /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-1 text-slate-400", title: "Direct Members", children: [
              /* @__PURE__ */ e.jsx(he, { size: 12, strokeWidth: 2 }),
              /* @__PURE__ */ e.jsx("span", { children: s.memberCount || 0 })
            ] }),
            /* @__PURE__ */ e.jsx("div", { className: "w-px h-3 bg-slate-300 mx-0.5" }),
            /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-1 text-teal-600", title: "Inclusive Members", children: [
              /* @__PURE__ */ e.jsx(tt, { size: 12, strokeWidth: 2 }),
              /* @__PURE__ */ e.jsx("span", { children: s.inclusiveMemberCount || s.memberCount || 0 })
            ] })
          ] }),
          /* @__PURE__ */ e.jsx("div", { className: "flex items-center gap-1 text-[9px] font-bold uppercase", children: s.inCycle ? /* @__PURE__ */ e.jsxs("div", { className: "text-red-600 flex items-center gap-1", children: [
            /* @__PURE__ */ e.jsx(ot, { size: 10 }),
            "ERROR"
          ] }) : s.isActive && !s.isDeleted && !s.isSuspended ? /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-1 text-emerald-600", children: [
            /* @__PURE__ */ e.jsx(Rs, { size: 8, className: "fill-emerald-500" }),
            "Active"
          ] }) : /* @__PURE__ */ e.jsx("span", { className: "text-slate-400", children: "Inactive" }) })
        ] }),
        !s.isRootNode && /* @__PURE__ */ e.jsx(
          Ve,
          {
            type: "target",
            position: Ye.Left,
            className: "!w-3 !h-3 !bg-slate-400 !border-2 !border-white hover:!bg-teal-500 transition-colors"
          }
        ),
        /* @__PURE__ */ e.jsx(
          Ve,
          {
            type: "source",
            position: Ye.Right,
            className: "!w-3 !h-3 !bg-slate-400 !border-2 !border-white hover:!bg-teal-500 transition-colors"
          }
        )
      ]
    }
  );
}, mn = xe.memo(pn), fn = ({
  id: t,
  sourceX: s,
  sourceY: a,
  targetX: n,
  targetY: l,
  sourcePosition: i,
  targetPosition: x,
  style: m = {},
  markerEnd: u,
  data: g
}) => {
  const { setEdges: c } = Ut(), { onRemoveEdge: v } = pe(), [r, b, h] = Vt({
    sourceX: s,
    sourceY: a,
    sourcePosition: i,
    targetX: n,
    targetY: l,
    targetPosition: x
  }), f = (w) => {
    w.stopPropagation(), v ? v(t) : c((M) => M.filter((I) => I.id !== t));
  }, y = g == null ? void 0 : g.inCycle;
  return /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
    /* @__PURE__ */ e.jsx(
      Yt,
      {
        path: r,
        markerEnd: u,
        style: {
          ...m,
          stroke: y ? "#ef4444" : "#94a3b8",
          strokeWidth: y ? 3 : 2,
          transition: "stroke 0.3s"
        }
      }
    ),
    /* @__PURE__ */ e.jsx(Bt, { children: /* @__PURE__ */ e.jsx(
      "div",
      {
        style: {
          position: "absolute",
          transform: `translate(-50%, -50%) translate(${b}px,${h}px)`,
          pointerEvents: "all",
          zIndex: 10
        },
        className: "nodrag nopan",
        children: /* @__PURE__ */ e.jsx(
          "button",
          {
            className: "w-5 h-5 bg-white border border-slate-300 rounded-full flex items-center justify-center cursor-pointer hover:bg-red-50 hover:border-red-400 hover:text-red-500 text-slate-400 shadow-sm transition-all focus:outline-none",
            onClick: f,
            "aria-label": "Delete connection",
            title: "Delete connection",
            children: /* @__PURE__ */ e.jsx(F, { size: 12, strokeWidth: 2.5 })
          }
        )
      }
    ) })
  ] });
}, gn = xe.memo(fn), bn = ({ node: t, readOnly: s, onUpdateNode: a, onClose: n }) => {
  const { onFetchMembers: l } = pe(), [i, x] = C("General"), m = ["General", "Status"];
  return l && m.push("Members"), t ? /* @__PURE__ */ e.jsxs("div", { className: "w-[450px] bg-white border-l border-slate-200 flex flex-col h-full shadow-xl z-20", children: [
    /* @__PURE__ */ e.jsxs("div", { className: "p-5 pb-0 shrink-0", children: [
      /* @__PURE__ */ e.jsxs("div", { className: "flex justify-between items-start mb-1", children: [
        /* @__PURE__ */ e.jsx("h2", { className: "text-xl font-bold text-slate-900", children: "Edit Group" }),
        /* @__PURE__ */ e.jsx("button", { onClick: n, className: "text-slate-400 hover:text-slate-600 transition-colors", children: /* @__PURE__ */ e.jsx(F, { size: 20 }) })
      ] }),
      /* @__PURE__ */ e.jsxs("div", { className: "text-[10px] text-slate-400 font-mono mb-4 truncate", children: [
        "ID: ",
        t.id
      ] }),
      /* @__PURE__ */ e.jsx("div", { className: "flex border-b border-slate-200 gap-6", children: m.map((u) => /* @__PURE__ */ e.jsxs(
        "button",
        {
          onClick: () => x(u),
          className: `pb-3 text-sm font-medium transition-all relative ${i === u ? "text-teal-600" : "text-slate-500 hover:text-slate-700"}`,
          children: [
            /* @__PURE__ */ e.jsxs("span", { className: "flex items-center gap-2", children: [
              u === "General" && /* @__PURE__ */ e.jsx(Ps, { size: 14 }),
              u === "Status" && /* @__PURE__ */ e.jsx(ps, { size: 14 }),
              u === "Members" && /* @__PURE__ */ e.jsx(he, { size: 14 }),
              u
            ] }),
            i === u && /* @__PURE__ */ e.jsx("div", { className: "absolute bottom-0 left-0 right-0 h-0.5 bg-teal-600 rounded-t-full" })
          ]
        },
        u
      )) })
    ] }),
    /* @__PURE__ */ e.jsxs("div", { className: "flex-1 overflow-hidden bg-white", children: [
      i === "General" && /* @__PURE__ */ e.jsx(vn, { node: t, readOnly: s, onUpdateNode: a }),
      i === "Status" && /* @__PURE__ */ e.jsx(yn, { node: t, readOnly: s, onUpdateNode: a }),
      i === "Members" && l && /* @__PURE__ */ e.jsx(jn, { node: t, readOnly: s })
    ] })
  ] }) : null;
}, vn = ({ node: t, readOnly: s, onUpdateNode: a }) => {
  const { iconMap: n } = pe(), l = Object.keys(n);
  if (!t) return null;
  const i = t.data, x = (g, c, v) => {
    const r = [...i.attributes];
    r[g][c] = v, a(t.id, { attributes: r });
  }, m = () => {
    a(t.id, { attributes: [...i.attributes, { role: "", value: "" }] });
  }, u = (g) => {
    const c = i.attributes.filter((v, r) => r !== g);
    a(t.id, { attributes: c });
  };
  return /* @__PURE__ */ e.jsx("div", { className: "p-5 h-full overflow-y-auto", children: /* @__PURE__ */ e.jsxs("div", { className: "space-y-6", children: [
    /* @__PURE__ */ e.jsxs("div", { className: "space-y-1", children: [
      /* @__PURE__ */ e.jsx("label", { className: "text-xs font-bold text-slate-500 uppercase tracking-wider", children: "Group Name" }),
      /* @__PURE__ */ e.jsx(
        "input",
        {
          className: "w-full p-2.5 text-sm border border-slate-200 rounded-lg focus:ring-1 focus:ring-teal-500 focus:border-teal-500 outline-none text-slate-700 transition-all font-medium",
          value: i.name,
          onChange: (g) => a(t.id, { name: g.target.value }),
          placeholder: "Enter group name",
          readOnly: s
        }
      )
    ] }),
    /* @__PURE__ */ e.jsxs("div", { className: "space-y-1", children: [
      /* @__PURE__ */ e.jsx("label", { className: "text-xs font-bold text-slate-500 uppercase tracking-wider", children: "Icon" }),
      /* @__PURE__ */ e.jsx("div", { className: "flex gap-2 flex-wrap", children: l.map((g) => {
        const c = n[g] || nt, v = i.iconPath === g;
        return /* @__PURE__ */ e.jsx(
          "button",
          {
            onClick: () => !s && a(t.id, { iconPath: g }),
            className: `p-3 rounded-lg border transition-all flex items-center justify-center ${v ? "bg-teal-50 border-teal-500 text-teal-600 shadow-sm ring-2 ring-teal-500/20" : "border-slate-200 text-slate-400 hover:border-slate-300 hover:bg-slate-50"}`,
            title: g,
            type: "button",
            children: /* @__PURE__ */ e.jsx(c, { size: 20, strokeWidth: v ? 2.5 : 2 })
          },
          g
        );
      }) })
    ] }),
    /* @__PURE__ */ e.jsxs("div", { className: "space-y-1", children: [
      /* @__PURE__ */ e.jsx("label", { className: "text-xs font-bold text-slate-500 uppercase tracking-wider", children: "Description" }),
      /* @__PURE__ */ e.jsx(
        "textarea",
        {
          className: "w-full p-2.5 text-sm border border-slate-200 rounded-lg focus:ring-1 focus:ring-teal-500 focus:border-teal-500 outline-none text-slate-700 min-h-[100px] resize-none",
          value: i.description,
          onChange: (g) => a(t.id, { description: g.target.value }),
          placeholder: "Enter description...",
          readOnly: s
        }
      )
    ] }),
    /* @__PURE__ */ e.jsxs("div", { className: "space-y-2 pt-2 border-t border-slate-100", children: [
      /* @__PURE__ */ e.jsxs("div", { className: "flex items-center justify-between", children: [
        /* @__PURE__ */ e.jsx("label", { className: "text-xs font-bold text-slate-500 uppercase tracking-wider", children: "Attributes" }),
        /* @__PURE__ */ e.jsx("span", { className: "text-[10px] bg-slate-100 text-slate-500 px-1.5 py-0.5 rounded-full", children: i.attributes.length })
      ] }),
      /* @__PURE__ */ e.jsxs("div", { className: "space-y-2", children: [
        i.attributes.map((g, c) => /* @__PURE__ */ e.jsxs("div", { className: "flex gap-2 group", children: [
          /* @__PURE__ */ e.jsx(
            "input",
            {
              className: "flex-1 p-2 text-xs border border-slate-200 rounded-md focus:border-teal-500 outline-none",
              value: g.role,
              placeholder: "Key",
              onChange: (v) => x(c, "role", v.target.value),
              readOnly: s
            }
          ),
          /* @__PURE__ */ e.jsx(
            "input",
            {
              className: "flex-1 p-2 text-xs border border-slate-200 rounded-md focus:border-teal-500 outline-none",
              value: g.value,
              placeholder: "Value",
              onChange: (v) => x(c, "value", v.target.value),
              readOnly: s
            }
          ),
          !s && /* @__PURE__ */ e.jsx("button", { onClick: () => u(c), className: "p-2 text-slate-300 hover:text-red-500 transition-colors", children: /* @__PURE__ */ e.jsx(F, { size: 14 }) })
        ] }, c)),
        !s && /* @__PURE__ */ e.jsxs(
          "button",
          {
            onClick: m,
            className: "w-full p-2 border border-slate-200 border-dashed rounded-md bg-slate-50 flex items-center justify-center gap-2 text-slate-500 hover:bg-slate-100 hover:text-teal-600 transition-colors text-xs font-medium",
            children: [
              /* @__PURE__ */ e.jsx(rt, { size: 14 }),
              "Add Attribute"
            ]
          }
        )
      ] })
    ] })
  ] }) });
}, yn = ({ node: t, readOnly: s, onUpdateNode: a }) => {
  if (!t) return null;
  const n = t.data;
  return /* @__PURE__ */ e.jsx("div", { className: "p-5 h-full overflow-y-auto", children: /* @__PURE__ */ e.jsxs("div", { className: "space-y-6", children: [
    /* @__PURE__ */ e.jsxs("div", { className: "bg-slate-50 rounded-lg p-4 border border-slate-100", children: [
      /* @__PURE__ */ e.jsxs("div", { className: "flex items-center justify-between mb-2", children: [
        /* @__PURE__ */ e.jsx("span", { className: "text-sm text-slate-900 font-bold", children: "Active Status" }),
        /* @__PURE__ */ e.jsx(
          "button",
          {
            disabled: s,
            onClick: () => a(t.id, { isActive: !n.isActive }),
            className: `transition-colors ${n.isActive ? "text-emerald-600" : "text-slate-300"}`,
            children: n.isActive ? /* @__PURE__ */ e.jsx(Ae, { size: 32 }) : /* @__PURE__ */ e.jsx(Se, { size: 32 })
          }
        )
      ] }),
      /* @__PURE__ */ e.jsx("p", { className: "text-xs text-slate-500 leading-relaxed", children: "Controls whether this group is currently active in the system. Inactive groups are hidden from most standard views." })
    ] }),
    /* @__PURE__ */ e.jsxs("div", { className: `rounded-lg p-4 border transition-colors ${n.isSuspended ? "bg-amber-50 border-amber-200" : "bg-slate-50 border-slate-100"}`, children: [
      /* @__PURE__ */ e.jsxs("div", { className: "flex items-center justify-between mb-3", children: [
        /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-2", children: [
          /* @__PURE__ */ e.jsx(Qe, { size: 18, className: n.isSuspended ? "text-amber-600" : "text-slate-400" }),
          /* @__PURE__ */ e.jsx("span", { className: `text-sm font-bold ${n.isSuspended ? "text-amber-800" : "text-slate-700"}`, children: "Suspended" })
        ] }),
        /* @__PURE__ */ e.jsx(
          "button",
          {
            disabled: s,
            onClick: () => a(t.id, { isSuspended: !n.isSuspended }),
            className: `transition-colors ${n.isSuspended ? "text-amber-600" : "text-slate-300"}`,
            children: n.isSuspended ? /* @__PURE__ */ e.jsx(Ae, { size: 32 }) : /* @__PURE__ */ e.jsx(Se, { size: 32 })
          }
        )
      ] }),
      n.isSuspended && /* @__PURE__ */ e.jsxs("div", { className: "space-y-3 animate-in fade-in slide-in-from-top-2", children: [
        /* @__PURE__ */ e.jsxs("div", { children: [
          /* @__PURE__ */ e.jsx("label", { className: "text-[10px] font-bold text-amber-700/70 uppercase tracking-wider", children: "Suspension Reason" }),
          /* @__PURE__ */ e.jsx(
            "input",
            {
              className: "w-full mt-1 p-2 text-xs border border-amber-200 rounded bg-white text-slate-700 focus:outline-none focus:ring-1 focus:ring-amber-500",
              placeholder: "e.g. Under Investigation",
              value: n.suspensionReason || "",
              onChange: (l) => a(t.id, { suspensionReason: l.target.value }),
              readOnly: s
            }
          )
        ] }),
        /* @__PURE__ */ e.jsxs("div", { children: [
          /* @__PURE__ */ e.jsx("label", { className: "text-[10px] font-bold text-amber-700/70 uppercase tracking-wider", children: "Additional Message" }),
          /* @__PURE__ */ e.jsx(
            "textarea",
            {
              className: "w-full mt-1 p-2 text-xs border border-amber-200 rounded bg-white text-slate-700 focus:outline-none focus:ring-1 focus:ring-amber-500 resize-none h-16",
              placeholder: "Details about suspension...",
              value: n.suspensionMessage || "",
              onChange: (l) => a(t.id, { suspensionMessage: l.target.value }),
              readOnly: s
            }
          )
        ] })
      ] })
    ] }),
    /* @__PURE__ */ e.jsxs("div", { className: `rounded-lg p-4 border transition-colors ${n.isDeleted ? "bg-red-50 border-red-200" : "bg-slate-50 border-slate-100"}`, children: [
      /* @__PURE__ */ e.jsxs("div", { className: "flex items-center justify-between mb-3", children: [
        /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-2", children: [
          /* @__PURE__ */ e.jsx(at, { size: 18, className: n.isDeleted ? "text-red-600" : "text-slate-400" }),
          /* @__PURE__ */ e.jsx("span", { className: `text-sm font-bold ${n.isDeleted ? "text-red-800" : "text-slate-700"}`, children: "Deleted (Soft)" })
        ] }),
        /* @__PURE__ */ e.jsx(
          "button",
          {
            disabled: s,
            onClick: () => a(t.id, { isDeleted: !n.isDeleted }),
            className: `transition-colors ${n.isDeleted ? "text-red-600" : "text-slate-300"}`,
            children: n.isDeleted ? /* @__PURE__ */ e.jsx(Ae, { size: 32 }) : /* @__PURE__ */ e.jsx(Se, { size: 32 })
          }
        )
      ] }),
      n.isDeleted && /* @__PURE__ */ e.jsxs("div", { className: "space-y-3 animate-in fade-in slide-in-from-top-2", children: [
        /* @__PURE__ */ e.jsxs("div", { children: [
          /* @__PURE__ */ e.jsx("label", { className: "text-[10px] font-bold text-red-700/70 uppercase tracking-wider", children: "Deletion Reason" }),
          /* @__PURE__ */ e.jsx(
            "input",
            {
              className: "w-full mt-1 p-2 text-xs border border-red-200 rounded bg-white text-slate-700 focus:outline-none focus:ring-1 focus:ring-red-500",
              placeholder: "e.g. Department Closure",
              value: n.deletionReason || "",
              onChange: (l) => a(t.id, { deletionReason: l.target.value }),
              readOnly: s
            }
          )
        ] }),
        /* @__PURE__ */ e.jsxs("div", { children: [
          /* @__PURE__ */ e.jsx("label", { className: "text-[10px] font-bold text-red-700/70 uppercase tracking-wider", children: "Additional Message" }),
          /* @__PURE__ */ e.jsx(
            "textarea",
            {
              className: "w-full mt-1 p-2 text-xs border border-red-200 rounded bg-white text-slate-700 focus:outline-none focus:ring-1 focus:ring-red-500 resize-none h-16",
              placeholder: "Details about deletion...",
              value: n.deletionMessage || "",
              onChange: (l) => a(t.id, { deletionMessage: l.target.value }),
              readOnly: s
            }
          )
        ] })
      ] })
    ] })
  ] }) });
}, jn = ({ node: t }) => {
  const { onFetchMembers: s } = pe(), [a, n] = C(!0), [l, i] = C([]), [x, m] = C(1), [u, g] = C(0), [c, v] = C(""), [r, b] = C(!1);
  return B(() => {
    if (!t) return;
    let h = !0;
    n(!0);
    const f = setTimeout(() => {
      s ? s(t.id, t.data.name, x, c, r).then((y) => {
        h && (i(y.data), g(y.total), n(!1));
      }) : h && (n(!1), i([]), g(0));
    }, 300);
    return () => {
      h = !1, clearTimeout(f);
    };
  }, [t, x, c, r, s]), t ? /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col h-full", children: [
    /* @__PURE__ */ e.jsxs("div", { className: "p-4 border-b border-slate-100 space-y-3", children: [
      /* @__PURE__ */ e.jsxs("div", { className: "flex p-1 bg-slate-100 rounded-lg", children: [
        /* @__PURE__ */ e.jsxs(
          "button",
          {
            onClick: () => {
              b(!1), m(1);
            },
            className: `flex-1 flex items-center justify-center gap-2 py-1.5 text-xs font-bold rounded-md transition-all ${r ? "text-slate-500 hover:text-slate-700" : "bg-white text-teal-600 shadow-sm"}`,
            children: [
              /* @__PURE__ */ e.jsx(lt, { size: 14 }),
              "Direct Members"
            ]
          }
        ),
        /* @__PURE__ */ e.jsxs(
          "button",
          {
            onClick: () => {
              b(!0), m(1);
            },
            className: `flex-1 flex items-center justify-center gap-2 py-1.5 text-xs font-bold rounded-md transition-all ${r ? "bg-white text-teal-600 shadow-sm" : "text-slate-500 hover:text-slate-700"}`,
            children: [
              /* @__PURE__ */ e.jsx(tt, { size: 14 }),
              "Inclusive"
            ]
          }
        )
      ] }),
      /* @__PURE__ */ e.jsxs("div", { className: "relative", children: [
        /* @__PURE__ */ e.jsx(Te, { size: 16, className: "absolute left-3 top-1/2 -translate-y-1/2 text-slate-400" }),
        /* @__PURE__ */ e.jsx(
          "input",
          {
            className: "w-full pl-9 pr-4 py-2 bg-slate-50 border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-1 focus:ring-teal-500 transition-all",
            placeholder: "Search members...",
            value: c,
            onChange: (h) => {
              v(h.target.value), m(1);
            }
          }
        )
      ] })
    ] }),
    /* @__PURE__ */ e.jsx("div", { className: "flex-1 overflow-y-auto", children: a ? /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col items-center justify-center h-40 gap-3 text-slate-400", children: [
      /* @__PURE__ */ e.jsx(Gs, { size: 24, className: "animate-spin text-teal-500" }),
      /* @__PURE__ */ e.jsx("span", { className: "text-xs font-medium", children: "Loading members..." })
    ] }) : l.length === 0 ? /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col items-center justify-center h-40 gap-2 text-slate-400", children: [
      /* @__PURE__ */ e.jsx(he, { size: 24 }),
      /* @__PURE__ */ e.jsx("span", { className: "text-xs", children: "No members found" })
    ] }) : /* @__PURE__ */ e.jsx("div", { className: "divide-y divide-slate-100", children: l.map((h) => /* @__PURE__ */ e.jsxs("div", { className: "p-4 hover:bg-slate-50 transition-colors flex items-center justify-between group", children: [
      /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-3", children: [
        /* @__PURE__ */ e.jsx("div", { className: "w-8 h-8 rounded-full bg-teal-100 text-teal-700 flex items-center justify-center font-bold text-xs shrink-0", children: h.name.substring(0, 2).toUpperCase() }),
        /* @__PURE__ */ e.jsxs("div", { className: "min-w-0", children: [
          /* @__PURE__ */ e.jsx("div", { className: "text-sm font-medium text-slate-800 truncate", children: h.name }),
          /* @__PURE__ */ e.jsx("div", { className: "text-[10px] text-slate-500 truncate", children: h.email }),
          r && h.sourceGroup && /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-1 mt-1", children: [
            /* @__PURE__ */ e.jsx("span", { className: "text-[9px] text-slate-400", children: "from" }),
            /* @__PURE__ */ e.jsx("span", { className: "text-[9px] font-medium text-slate-600 bg-slate-100 px-1.5 py-0.5 rounded border border-slate-200 truncate max-w-[200px]", title: h.sourceGroup, children: h.sourceGroup })
          ] })
        ] })
      ] }),
      /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col items-end gap-1 shrink-0 ml-2", children: [
        /* @__PURE__ */ e.jsx("span", { className: `text-[10px] px-1.5 py-0.5 rounded font-bold uppercase tracking-wider ${h.status === "Active" ? "bg-emerald-50 text-emerald-600" : "bg-slate-100 text-slate-500"}`, children: h.status }),
        /* @__PURE__ */ e.jsx("span", { className: "text-[10px] text-slate-400 font-mono", children: h.role })
      ] })
    ] }, h.id)) }) }),
    /* @__PURE__ */ e.jsxs("div", { className: "p-3 border-t border-slate-200 bg-slate-50 flex items-center justify-between shrink-0", children: [
      /* @__PURE__ */ e.jsxs("span", { className: "text-xs text-slate-500", children: [
        (x - 1) * 10 + 1,
        "-",
        Math.min(x * 10, u),
        " of ",
        u
      ] }),
      /* @__PURE__ */ e.jsxs("div", { className: "flex gap-1", children: [
        /* @__PURE__ */ e.jsx(
          "button",
          {
            onClick: () => m((h) => Math.max(1, h - 1)),
            disabled: x === 1 || a,
            className: "p-1.5 hover:bg-white rounded border border-transparent hover:border-slate-200 disabled:opacity-30 disabled:hover:bg-transparent",
            children: /* @__PURE__ */ e.jsx(ys, { size: 16, className: "text-slate-600" })
          }
        ),
        /* @__PURE__ */ e.jsx(
          "button",
          {
            onClick: () => m((h) => h + 1),
            disabled: x * 10 >= u || a,
            className: "p-1.5 hover:bg-white rounded border border-transparent hover:border-slate-200 disabled:opacity-30 disabled:hover:bg-transparent",
            children: /* @__PURE__ */ e.jsx(Ns, { size: 16, className: "text-slate-600" })
          }
        )
      ] })
    ] })
  ] }) : null;
}, Nn = ({ open: t, onClose: s, onSubmit: a, saving: n }) => {
  const [l, i] = C("Configuration Update"), [x, m] = C("");
  return t ? /* @__PURE__ */ e.jsxs("div", { className: "fixed inset-0 z-[200] flex items-center justify-center p-4", children: [
    /* @__PURE__ */ e.jsx("div", { className: "absolute inset-0 bg-slate-900/40 backdrop-blur-sm", onClick: s }),
    /* @__PURE__ */ e.jsx("div", { className: "relative bg-white rounded-2xl shadow-2xl w-full max-w-md overflow-hidden animate-in fade-in zoom-in duration-200 border border-slate-200", children: /* @__PURE__ */ e.jsxs("div", { className: "p-6", children: [
      /* @__PURE__ */ e.jsxs("div", { className: "flex items-center justify-between mb-6", children: [
        /* @__PURE__ */ e.jsxs("h3", { className: "text-lg font-bold text-slate-900 flex items-center gap-2", children: [
          /* @__PURE__ */ e.jsx(Cs, { className: "text-teal-500" }),
          "Save Group Hierarchy"
        ] }),
        /* @__PURE__ */ e.jsx("button", { onClick: s, className: "p-1 text-slate-400 hover:bg-slate-100 rounded-full transition-colors", children: /* @__PURE__ */ e.jsx(F, { size: 20 }) })
      ] }),
      /* @__PURE__ */ e.jsxs("div", { className: "space-y-4", children: [
        /* @__PURE__ */ e.jsxs("div", { children: [
          /* @__PURE__ */ e.jsx("label", { className: "block text-[10px] font-bold text-slate-500 uppercase tracking-wider mb-1", children: "Reason for Change" }),
          /* @__PURE__ */ e.jsxs(
            "select",
            {
              className: "w-full p-2.5 text-sm border border-slate-300 rounded-lg focus:ring-1 focus:ring-teal-500/20 focus:border-teal-500 focus:outline-none bg-white text-slate-700",
              value: l,
              onChange: (u) => i(u.target.value),
              children: [
                /* @__PURE__ */ e.jsx("option", { children: "Configuration Update" }),
                /* @__PURE__ */ e.jsx("option", { children: "New Group Structure" }),
                /* @__PURE__ */ e.jsx("option", { children: "Refactor / Hierarchy Change" }),
                /* @__PURE__ */ e.jsx("option", { children: "Emergency Fix" }),
                /* @__PURE__ */ e.jsx("option", { children: "Other" })
              ]
            }
          )
        ] }),
        /* @__PURE__ */ e.jsxs("div", { children: [
          /* @__PURE__ */ e.jsx("label", { className: "block text-[10px] font-bold text-slate-500 uppercase tracking-wider mb-1", children: "Detailed Message" }),
          /* @__PURE__ */ e.jsx(
            "textarea",
            {
              className: "w-full p-2.5 text-sm border border-slate-300 rounded-lg h-32 focus:ring-1 focus:ring-teal-500/20 focus:border-teal-500 focus:outline-none resize-none text-slate-700 placeholder-slate-400",
              placeholder: "Describe the changes made to the group hierarchy...",
              value: x,
              onChange: (u) => m(u.target.value)
            }
          )
        ] })
      ] }),
      /* @__PURE__ */ e.jsxs("div", { className: "mt-8 flex gap-3", children: [
        /* @__PURE__ */ e.jsx(
          "button",
          {
            onClick: s,
            className: "flex-1 py-2.5 px-4 border border-slate-300 text-slate-600 font-bold text-sm rounded-xl hover:bg-slate-50 transition-colors",
            children: "Cancel"
          }
        ),
        /* @__PURE__ */ e.jsx(
          "button",
          {
            onClick: () => a(l, x),
            disabled: n || !l,
            className: `flex-1 py-2.5 px-4 bg-teal-600 text-white font-bold text-sm rounded-xl transition-all shadow-lg shadow-teal-600/20 ${n ? "opacity-50 cursor-not-allowed" : "hover:bg-teal-700 active:scale-95"}`,
            children: n ? "Saving..." : "Confirm Save"
          }
        )
      ] })
    ] }) })
  ] }) : null;
}, wn = ({ open: t, parentNode: s, candidates: a, onClose: n, onConfirm: l }) => {
  const [i, x] = C(""), [m, u] = C(/* @__PURE__ */ new Set());
  xe.useEffect(() => {
    t && (x(""), u(/* @__PURE__ */ new Set()));
  }, [t]);
  const { matches: g, error: c } = H(() => {
    if (!i.trim()) return { matches: [], error: null };
    let b;
    try {
      b = new RegExp(i, "i");
    } catch (h) {
      return { matches: [], error: h.message };
    }
    return {
      matches: a.filter((h) => b.test(h.data.name || "")),
      error: null
    };
  }, [i, a]);
  if (!t) return null;
  const v = g.filter((b) => !m.has(b.id)).map((b) => b.id), r = (b) => {
    u((h) => {
      const f = new Set(h);
      return f.has(b) ? f.delete(b) : f.add(b), f;
    });
  };
  return /* @__PURE__ */ e.jsxs("div", { className: "fixed inset-0 z-[200] flex items-center justify-center p-4", children: [
    /* @__PURE__ */ e.jsx("div", { className: "absolute inset-0 bg-slate-900/40 backdrop-blur-sm", onClick: n }),
    /* @__PURE__ */ e.jsxs("div", { className: "relative bg-white rounded-2xl shadow-2xl w-full max-w-lg overflow-hidden animate-in fade-in zoom-in duration-200 border border-slate-200 flex flex-col max-h-[80vh]", children: [
      /* @__PURE__ */ e.jsxs("div", { className: "p-6 pb-4 shrink-0", children: [
        /* @__PURE__ */ e.jsxs("div", { className: "flex items-center justify-between mb-1", children: [
          /* @__PURE__ */ e.jsxs("h3", { className: "text-lg font-bold text-slate-900 flex items-center gap-2", children: [
            /* @__PURE__ */ e.jsx(st, { className: "text-teal-500" }),
            "Connect by Regex"
          ] }),
          /* @__PURE__ */ e.jsx("button", { onClick: n, className: "p-1 text-slate-400 hover:bg-slate-100 rounded-full transition-colors", children: /* @__PURE__ */ e.jsx(F, { size: 20 }) })
        ] }),
        /* @__PURE__ */ e.jsxs("p", { className: "text-xs text-slate-500 mb-4", children: [
          "Matching groups will be re-parented under",
          " ",
          /* @__PURE__ */ e.jsx("span", { className: "font-semibold text-slate-700", children: (s == null ? void 0 : s.data.name) || "the selected group" }),
          "."
        ] }),
        /* @__PURE__ */ e.jsxs("div", { className: "relative", children: [
          /* @__PURE__ */ e.jsx("div", { className: "absolute left-3 top-1/2 -translate-y-1/2 text-slate-400", children: /* @__PURE__ */ e.jsx(Te, { size: 16 }) }),
          /* @__PURE__ */ e.jsx(
            "input",
            {
              autoFocus: !0,
              className: `w-full pl-9 pr-3 py-2.5 text-sm border rounded-lg focus:outline-none focus:ring-1 transition-all font-mono ${c ? "border-red-300 focus:ring-red-500/20 focus:border-red-500" : "border-slate-300 focus:ring-teal-500/20 focus:border-teal-500"}`,
              placeholder: "e.g. ^Sales|North$",
              value: i,
              onChange: (b) => x(b.target.value)
            }
          )
        ] }),
        c && /* @__PURE__ */ e.jsxs("div", { className: "mt-2 flex items-center gap-1.5 text-xs text-red-600", children: [
          /* @__PURE__ */ e.jsx(Ze, { size: 13 }),
          /* @__PURE__ */ e.jsxs("span", { children: [
            "Invalid regex: ",
            c
          ] })
        ] }),
        !c && i.trim() && /* @__PURE__ */ e.jsxs("div", { className: "mt-2 text-xs text-slate-500", children: [
          /* @__PURE__ */ e.jsx("span", { className: "font-bold text-slate-700", children: v.length }),
          " of ",
          g.length,
          " matched group",
          g.length === 1 ? "" : "s",
          " selected"
        ] })
      ] }),
      /* @__PURE__ */ e.jsxs("div", { className: "flex-1 overflow-y-auto px-6 min-h-[80px]", children: [
        i.trim() && !c && g.length === 0 && /* @__PURE__ */ e.jsx("div", { className: "text-center text-sm text-slate-400 py-8", children: "No groups match this pattern." }),
        /* @__PURE__ */ e.jsx("ul", { className: "space-y-1 pb-2", children: g.map((b) => {
          const h = !m.has(b.id);
          return /* @__PURE__ */ e.jsx("li", { children: /* @__PURE__ */ e.jsxs("label", { className: "flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-slate-50 cursor-pointer", children: [
            /* @__PURE__ */ e.jsx(
              "input",
              {
                type: "checkbox",
                checked: h,
                onChange: () => r(b.id),
                className: "w-4 h-4 rounded border-slate-300 text-teal-600 focus:ring-teal-500/30"
              }
            ),
            /* @__PURE__ */ e.jsx("span", { className: `text-sm truncate ${h ? "text-slate-700" : "text-slate-400 line-through"}`, children: b.data.name || "(unnamed)" })
          ] }) }, b.id);
        }) })
      ] }),
      /* @__PURE__ */ e.jsxs("div", { className: "p-6 pt-4 flex gap-3 shrink-0 border-t border-slate-100", children: [
        /* @__PURE__ */ e.jsx(
          "button",
          {
            onClick: n,
            className: "flex-1 py-2.5 px-4 border border-slate-300 text-slate-600 font-bold text-sm rounded-xl hover:bg-slate-50 transition-colors",
            children: "Cancel"
          }
        ),
        /* @__PURE__ */ e.jsxs(
          "button",
          {
            onClick: () => l(v),
            disabled: v.length === 0,
            className: `flex-1 py-2.5 px-4 bg-teal-600 text-white font-bold text-sm rounded-xl transition-all shadow-lg shadow-teal-600/20 ${v.length === 0 ? "opacity-50 cursor-not-allowed" : "hover:bg-teal-700 active:scale-95"}`,
            children: [
              "Connect ",
              v.length > 0 ? `(${v.length})` : ""
            ]
          }
        )
      ] })
    ] })
  ] });
};
class kn {
  constructor() {
    this.adj = /* @__PURE__ */ new Map();
  }
  addVertex(s) {
    this.adj.has(s) || this.adj.set(s, []);
  }
  addEdge(s, a) {
    this.addVertex(s), this.addVertex(a);
    const n = this.adj.get(s) || [];
    n.includes(a) || (n.push(a), this.adj.set(s, n));
  }
  findCycles() {
    const s = [], a = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), l = [], i = (x) => {
      a.add(x), n.add(x), l.push(x);
      const m = this.adj.get(x) || [];
      for (const u of m)
        if (!a.has(u))
          i(u);
        else if (n.has(u)) {
          const g = l.indexOf(u);
          g !== -1 && s.push(l.slice(g));
        }
      n.delete(x), l.pop();
    };
    for (const x of this.adj.keys())
      a.has(x) || i(x);
    return s;
  }
  getDeepChildren(s) {
    const a = /* @__PURE__ */ new Set(), n = [s], l = /* @__PURE__ */ new Set();
    for (; n.length > 0; ) {
      const i = n.pop();
      if (l.has(i)) continue;
      l.add(i);
      const x = this.adj.get(i) || [];
      for (const m of x)
        a.add(m), n.push(m);
    }
    return a.delete(s), Array.from(a);
  }
}
const dt = (t, s, a) => ({
  id: t || ze(),
  type: "group",
  position: s || { x: 0, y: 0 },
  data: {
    name: "New Group",
    description: "",
    iconPath: "Layout",
    color: "#0d9488",
    // Teal-600
    isRootNode: a,
    inCycle: !1,
    isActive: !0,
    isDeleted: !1,
    isSuspended: !1,
    deletionReason: null,
    deletionMessage: null,
    suspensionReason: null,
    suspensionMessage: null,
    attributes: [],
    properties: [],
    memberCount: 0,
    inclusiveMemberCount: 0,
    descendants: []
  }
}), Cn = (t, s) => {
  const a = s.filter((n) => n.source === t.id).map((n) => n.target);
  return {
    id: t.id,
    name: t.data.name,
    isActive: t.data.isActive,
    isDeleted: t.data.isDeleted,
    isSuspended: t.data.isSuspended,
    deletionReason: t.data.deletionReason,
    deletionMessage: t.data.deletionMessage,
    suspensionReason: t.data.suspensionReason,
    suspensionMessage: t.data.suspensionMessage,
    children: a,
    attributes: t.data.attributes,
    properties: t.data.properties,
    memberCount: t.data.memberCount,
    // Store diagrammatic data if the backend supports it, otherwise this might be lost on roundtrip
    // depending on the backend schema. For now, we map it back.
    description: t.data.description,
    iconPath: t.data.iconPath
  };
}, Xe = (t, s, a) => {
  var b, h;
  const i = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Set();
  s.forEach((f) => {
    const y = i.get(f.source) || [];
    y.push(f.target), i.set(f.source, y), x.add(f.target);
  });
  const m = a && t.some((f) => f.id === a) ? a : ((b = t.find((f) => !x.has(f.id))) == null ? void 0 : b.id) ?? ((h = t[0]) == null ? void 0 : h.id), u = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Set(), c = { val: 0 }, v = (f, y) => {
    if (g.has(f)) return;
    g.add(f);
    const w = i.get(f) || [];
    if (w.length === 0) {
      u.set(f, { x: y * 300, y: c.val }), c.val += 180;
      return;
    }
    w.forEach((R) => v(R, y + 1));
    const M = w.map((R) => {
      var V;
      return (V = u.get(R)) == null ? void 0 : V.y;
    }).filter((R) => R !== void 0), I = M.length ? (Math.min(...M) + Math.max(...M)) / 2 : c.val;
    u.set(f, { x: y * 300, y: I });
  };
  m && v(m, 0);
  let r = c.val + 180;
  return t.forEach((f) => {
    u.has(f.id) || (u.set(f.id, { x: 0, y: r }), r += 180);
  }), t.map((f) => ({ ...f, position: u.get(f.id) || f.position }));
}, In = (t) => {
  const s = [], a = [], n = {};
  t.nodes.forEach((r) => {
    n[r.id] = { ...r, _children: [] };
  });
  let l = null;
  t.nodes.forEach((r) => {
    r.parent && n[r.parent] ? n[r.parent]._children.push(r.id) : l = r.id;
  }), !l && t.rootGroupId && (l = t.rootGroupId);
  const i = /* @__PURE__ */ new Map(), x = (r) => {
    if (i.has(r))
      return i.get(r);
    const b = n[r];
    if (!b) return 0;
    let h = b.memberCount || 0;
    const f = b._children || [];
    for (const y of f)
      h += x(y);
    return i.set(r, h), h;
  };
  t.nodes.forEach((r) => {
    x(r.id);
  });
  const m = 300, u = 180, g = (r, b, h) => {
    const f = n[r];
    if (!f) return;
    const y = h.val, w = r === l, M = f.attributes || [];
    s.push({
      id: r,
      type: "group",
      position: { x: b * m, y },
      data: {
        name: f.name,
        // Removed type injection. Description can come from JSON or be empty.
        description: f.description || "",
        iconPath: w ? "Building" : f.iconPath || "Users",
        color: "#0d9488",
        isRootNode: w,
        inCycle: !1,
        // Map Status Flags
        isActive: f.isActive !== void 0 ? f.isActive : !0,
        isDeleted: f.isDeleted || !1,
        isSuspended: f.isSuspended || !1,
        deletionReason: f.deletionReason || null,
        deletionMessage: f.deletionMessage || null,
        suspensionReason: f.suspensionReason || null,
        suspensionMessage: f.suspensionMessage || null,
        attributes: M,
        properties: [],
        memberCount: f.memberCount,
        inclusiveMemberCount: i.get(r),
        descendants: []
      }
    }), f.parent && n[f.parent] && a.push({
      id: `e-${f.parent}-${r}`,
      source: f.parent,
      target: r,
      type: "base",
      markerEnd: { type: Z.ArrowClosed }
    });
    const I = f._children || [];
    I.length > 0 ? I.forEach((R) => {
      g(R, b + 1, h);
    }) : h.val += u;
  };
  l && g(l, 0, { val: 0 });
  const c = new Set(s.map((r) => r.id));
  let v = 0;
  return t.nodes.forEach((r) => {
    c.has(r.id) || (s.push({
      id: r.id,
      type: "group",
      position: { x: 0, y: v + 500 },
      // Place them below
      data: {
        name: r.name,
        description: "Detached Node",
        iconPath: "AlertTriangle",
        color: "#ef4444",
        isRootNode: !1,
        inCycle: !1,
        isActive: r.isActive !== void 0 ? r.isActive : !0,
        isDeleted: r.isDeleted || !1,
        isSuspended: r.isSuspended || !1,
        deletionReason: r.deletionReason || null,
        deletionMessage: r.deletionMessage || null,
        suspensionReason: r.suspensionReason || null,
        suspensionMessage: r.suspensionMessage || null,
        attributes: [],
        properties: [],
        memberCount: r.memberCount,
        inclusiveMemberCount: r.memberCount,
        descendants: []
      }
    }), v += u);
  }), { nodes: s, edges: a };
}, Pe = "", En = (t) => {
  const s = t.split(/[\s,;]+/).filter(Boolean);
  if (s.length === 0)
    return { lengths: [], error: null };
  const a = [];
  for (const n of s) {
    if (!/^\d+\*?$/.test(n))
      return { lengths: [], error: "Use positive whole numbers, optionally followed by *, separated by commas or spaces." };
    const l = n.endsWith("*"), i = Number(l ? n.slice(0, -1) : n);
    if (!Number.isSafeInteger(i) || i <= 0)
      return { lengths: [], error: "Lengths must be positive whole numbers." };
    a.push({ length: i, repeat: l });
  }
  return { lengths: a, error: null };
}, _n = (t, s) => {
  const a = t.trim();
  if (!a || s.length === 0)
    return null;
  const n = [];
  let l = 0;
  for (const i of s) {
    if (l >= a.length) break;
    do {
      const x = a.length - l, m = Math.min(i.length, x);
      n.push(a.slice(l, l + m)), l += m;
    } while (i.repeat && l < a.length);
  }
  return n.length > 0 ? n : null;
}, Rn = (t, s) => {
  const a = (t.data.name || "").trim();
  let n = "";
  const l = s.map((x) => (n += x, n)), i = l[l.length - 1] === a ? l.slice(0, -1) : l;
  return {
    node: t,
    chunks: s,
    prefixes: l,
    generatedPath: i,
    pathKey: i[i.length - 1] || null
  };
}, ut = (t) => {
  const s = /* @__PURE__ */ new Set();
  return t.forEach((a) => {
    a.generatedPath.forEach((n) => s.add(n));
  }), Array.from(s).sort((a, n) => a.length - n.length || a.localeCompare(n));
}, Mn = (t) => {
  const s = /* @__PURE__ */ new Map();
  return t.forEach((a) => {
    a.generatedPath.forEach((n, l) => {
      s.has(n) || s.set(n, l === 0 ? null : a.generatedPath[l - 1]);
    });
  }), s;
}, ht = (t, s = []) => {
  const a = /* @__PURE__ */ new Map();
  [...t.map((l) => l.node), ...s].forEach((l) => {
    const i = (l.data.name || "").trim();
    if (!i) return;
    const x = a.get(i) || [];
    x.push(l), a.set(i, x);
  });
  const n = /* @__PURE__ */ new Map();
  return a.forEach((l, i) => {
    l.length === 1 && n.set(i, l[0]);
  }), n;
}, xt = (t, s, a = []) => {
  const n = [], l = [];
  t.forEach((u) => {
    const g = _n(u.data.name || "", s);
    if (!g) {
      l.push({ node: u, reason: "Name is blank." });
      return;
    }
    n.push(Rn(u, g));
  });
  const i = ut(n), x = ht(n, a), m = i.filter((u) => !x.has(u)).length;
  return {
    matches: n,
    skipped: l,
    generatedPathCount: m,
    totalPathCount: i.length
  };
}, Sn = (t, s, a, n, l) => {
  const i = t.find((w) => w.id === a) || null, x = xt(n, l, i ? [i] : []);
  if (x.matches.length === 0) return null;
  const m = ut(x.matches), u = Mn(x.matches), g = ht(x.matches, i ? [i] : []), c = /* @__PURE__ */ new Map(), v = [];
  m.forEach((w) => {
    const M = g.get(w);
    if (M) {
      c.set(w, M.id);
      return;
    }
    const I = ze(), R = dt(I, null, !1);
    v.push({
      ...R,
      data: {
        ...R.data,
        name: w,
        iconPath: "Layout",
        color: "#0d9488"
      }
    }), c.set(w, I);
  });
  const r = t.concat(v), b = new Set(c.values());
  x.matches.forEach((w) => b.add(w.node.id)), b.delete(a);
  const h = s.filter((w) => !b.has(w.target)), f = new Set(h.map((w) => `${w.source}${Pe}${w.target}`)), y = [];
  return m.forEach((w) => {
    const M = c.get(w);
    if (!M) return;
    const I = u.get(w) || null, R = I ? c.get(I) : a;
    if (!R || R === M) return;
    const V = `${R}${Pe}${M}`;
    f.has(V) || (f.add(V), y.push({
      id: `e-${R}-${M}`,
      source: R,
      target: M,
      type: "base",
      markerEnd: { type: Z.ArrowClosed }
    }));
  }), x.matches.forEach((w) => {
    const M = w.pathKey ? c.get(w.pathKey) : a;
    if (!M || M === w.node.id) return;
    const I = `${M}${Pe}${w.node.id}`;
    f.has(I) || (f.add(I), y.push({
      id: `e-${M}-${w.node.id}`,
      source: M,
      target: w.node.id,
      type: "base",
      markerEnd: { type: Z.ArrowClosed }
    }));
  }), {
    nodes: r,
    edges: [...h, ...y],
    affectedCount: x.matches.length,
    generatedCount: v.length
  };
}, An = ({
  open: t,
  parentNode: s,
  candidates: a,
  onClose: n,
  onConfirm: l
}) => {
  const [i, x] = C("");
  xe.useEffect(() => {
    t && x("");
  }, [t]);
  const m = H(() => En(i), [i]), u = H(() => m.error || m.lengths.length === 0 ? null : xt(a, m.lengths, s ? [s] : []), [a, s, m.error, m.lengths]);
  if (!t) return null;
  const g = (u == null ? void 0 : u.matches.slice(0, 20)) || [], c = (u == null ? void 0 : u.skipped.slice(0, 5)) || [], v = !m.error && m.lengths.length > 0 && !!u && u.matches.length > 0;
  return /* @__PURE__ */ e.jsxs("div", { className: "fixed inset-0 z-[200] flex items-center justify-center p-4", children: [
    /* @__PURE__ */ e.jsx("div", { className: "absolute inset-0 bg-slate-900/40 backdrop-blur-sm", onClick: n }),
    /* @__PURE__ */ e.jsxs("div", { className: "relative bg-white rounded-2xl shadow-2xl w-full max-w-xl overflow-hidden animate-in fade-in zoom-in duration-200 border border-slate-200 flex flex-col max-h-[82vh]", children: [
      /* @__PURE__ */ e.jsxs("div", { className: "p-6 pb-4 shrink-0", children: [
        /* @__PURE__ */ e.jsxs("div", { className: "flex items-center justify-between mb-1", children: [
          /* @__PURE__ */ e.jsxs("h3", { className: "text-lg font-bold text-slate-900 flex items-center gap-2", children: [
            /* @__PURE__ */ e.jsx(et, { className: "text-teal-500" }),
            "Restructure by Prefix"
          ] }),
          /* @__PURE__ */ e.jsx("button", { onClick: n, className: "p-1 text-slate-400 hover:bg-slate-100 rounded-full transition-colors", children: /* @__PURE__ */ e.jsx(F, { size: 20 }) })
        ] }),
        /* @__PURE__ */ e.jsxs("p", { className: "text-xs text-slate-500 mb-4", children: [
          "Existing children of",
          " ",
          /* @__PURE__ */ e.jsx("span", { className: "font-semibold text-slate-700", children: (s == null ? void 0 : s.data.name) || "the selected group" }),
          " ",
          "will be rearranged into prefix paths."
        ] }),
        /* @__PURE__ */ e.jsx("label", { className: "block text-xs font-bold uppercase tracking-wide text-slate-500 mb-1.5", children: "Chunk lengths" }),
        /* @__PURE__ */ e.jsx(
          "input",
          {
            autoFocus: !0,
            className: `w-full px-3 py-2.5 text-sm border rounded-lg focus:outline-none focus:ring-1 transition-all font-mono ${m.error ? "border-red-300 focus:ring-red-500/20 focus:border-red-500" : "border-slate-300 focus:ring-teal-500/20 focus:border-teal-500"}`,
            placeholder: "2, 3 or 5*",
            value: i,
            onChange: (r) => x(r.target.value)
          }
        ),
        m.error && /* @__PURE__ */ e.jsxs("div", { className: "mt-2 flex items-center gap-1.5 text-xs text-red-600", children: [
          /* @__PURE__ */ e.jsx(Ze, { size: 13 }),
          /* @__PURE__ */ e.jsx("span", { children: m.error })
        ] }),
        !m.error && m.lengths.length > 0 && u && /* @__PURE__ */ e.jsxs("div", { className: "mt-2 text-xs text-slate-500", children: [
          /* @__PURE__ */ e.jsx("span", { className: "font-bold text-slate-700", children: u.matches.length }),
          " group",
          u.matches.length === 1 ? "" : "s",
          " arranged,",
          " ",
          /* @__PURE__ */ e.jsx("span", { className: "font-bold text-slate-700", children: u.generatedPathCount }),
          " prefix node",
          u.generatedPathCount === 1 ? "" : "s",
          " created"
        ] })
      ] }),
      /* @__PURE__ */ e.jsxs("div", { className: "flex-1 overflow-y-auto px-6 min-h-[120px]", children: [
        !i.trim() && /* @__PURE__ */ e.jsx("div", { className: "text-center text-sm text-slate-400 py-8", children: "Enter lengths to preview the new prefix paths." }),
        u && u.matches.length === 0 && /* @__PURE__ */ e.jsx("div", { className: "text-center text-sm text-slate-400 py-8", children: "No eligible groups can be split with these lengths." }),
        g.length > 0 && /* @__PURE__ */ e.jsxs("ul", { className: "space-y-1 pb-3", children: [
          g.map((r) => /* @__PURE__ */ e.jsxs("li", { className: "px-3 py-2 rounded-lg bg-slate-50 border border-slate-100", children: [
            /* @__PURE__ */ e.jsx("div", { className: "text-xs text-slate-400 truncate", children: r.node.data.name || "(unnamed)" }),
            /* @__PURE__ */ e.jsx("div", { className: "text-sm font-medium text-slate-700 truncate", children: [...r.generatedPath, r.node.data.name || "(unnamed)"].join(" / ") })
          ] }, r.node.id)),
          u && u.matches.length > g.length && /* @__PURE__ */ e.jsxs("li", { className: "text-xs text-slate-400 px-3 py-2", children: [
            "+",
            u.matches.length - g.length,
            " more"
          ] })
        ] }),
        c.length > 0 && /* @__PURE__ */ e.jsxs("div", { className: "border-t border-slate-100 pt-3 pb-2", children: [
          /* @__PURE__ */ e.jsx("div", { className: "text-xs font-bold uppercase tracking-wide text-slate-400 mb-1.5", children: "Skipped" }),
          /* @__PURE__ */ e.jsx("ul", { className: "space-y-1", children: c.map(({ node: r, reason: b }) => /* @__PURE__ */ e.jsxs("li", { className: "text-xs text-slate-500 px-3 py-1.5 rounded bg-slate-50 truncate", children: [
            /* @__PURE__ */ e.jsx("span", { className: "font-medium text-slate-600", children: r.data.name || "(unnamed)" }),
            " - ",
            b
          ] }, r.id)) })
        ] })
      ] }),
      /* @__PURE__ */ e.jsxs("div", { className: "p-6 pt-4 flex gap-3 shrink-0 border-t border-slate-100", children: [
        /* @__PURE__ */ e.jsx(
          "button",
          {
            onClick: n,
            className: "flex-1 py-2.5 px-4 border border-slate-300 text-slate-600 font-bold text-sm rounded-xl hover:bg-slate-50 transition-colors",
            children: "Cancel"
          }
        ),
        /* @__PURE__ */ e.jsxs(
          "button",
          {
            onClick: () => l(m.lengths),
            disabled: !v,
            className: `flex-1 py-2.5 px-4 bg-teal-600 text-white font-bold text-sm rounded-xl transition-all shadow-lg shadow-teal-600/20 ${v ? "hover:bg-teal-700 active:scale-95" : "opacity-50 cursor-not-allowed"}`,
            children: [
              "Restructure ",
              u && u.matches.length > 0 ? `(${u.matches.length})` : ""
            ]
          }
        )
      ] })
    ] })
  ] });
}, Pn = () => {
  const [t, s] = C([]), [a, n] = C([]), l = A((m, u) => {
    s((g) => [...g.length > 50 ? g.slice(1) : g, { nodes: m, edges: u }]), n([]);
  }, []), i = A((m, u) => {
    if (t.length === 0) return null;
    const g = t[t.length - 1], c = t.slice(0, t.length - 1);
    return s(c), n((v) => [{ nodes: m, edges: u }, ...v]), g;
  }, [t]), x = A((m, u) => {
    if (a.length === 0) return null;
    const g = a[0], c = a.slice(1);
    return n(c), s((v) => [...v, { nodes: m, edges: u }]), g;
  }, [a]);
  return { takeSnapshot: l, undo: i, redo: x, canUndo: t.length > 0, canRedo: a.length > 0 };
}, $n = ({
  groupData: t,
  nodes: s,
  edges: a = [],
  onSave: n,
  onExport: l,
  onBack: i,
  isValidated: x,
  enableForce: m = !0,
  onFetchMembers: u,
  icons: g
}) => {
  const [c, v] = C(s), [r, b] = C(a), [h, f] = C(null), [y, w] = C(!1), [M, I] = C(!1), [R, V] = C(null), [we, Q] = C(!1), [me, W] = C(!1), [ke, ee] = C(!1), [te, q] = C(!1), [E, se] = C(null), fe = H(() => ({ group: mn }), []), ge = H(() => ({ base: gn }), []), { takeSnapshot: S, undo: ne, redo: re, canUndo: o, canRedo: N } = Pn(), [P, D] = C(""), [O, X] = C([]), [T, U] = C(0), K = ue(null), ae = ue(null), oe = ue(null), be = ue(!0), Ce = A(() => {
    const d = ne(c, r);
    d && (v(d.nodes), b(d.edges));
  }, [ne, c, r]), ve = A(() => {
    const d = re(c, r);
    d && (v(d.nodes), b(d.edges));
  }, [re, c, r]);
  B(() => {
    const d = (p) => {
      p.target instanceof HTMLInputElement || p.target instanceof HTMLTextAreaElement || ((p.ctrlKey || p.metaKey) && p.key.toLowerCase() === "z" ? (p.shiftKey ? ve() : Ce(), p.preventDefault()) : (p.ctrlKey || p.metaKey) && p.key.toLowerCase() === "y" && (ve(), p.preventDefault()));
    };
    return window.addEventListener("keydown", d), () => window.removeEventListener("keydown", d);
  }, [Ce, ve]);
  const pt = A((d, p) => {
    const j = new kn();
    d.forEach(($) => j.addVertex($.id)), p.forEach(($) => j.addEdge($.source, $.target));
    const _ = j.findCycles(), z = new Set(_.flat()), G = _.length === 0, _e = new Set(p.map(($) => $.target)), je = d.filter(($) => !_e.has($.id)), le = je.length === 1;
    let Re = null;
    G ? d.length > 0 && !le && (Re = `Graph disconnected: Found ${je.length} root-like nodes. Ensure all groups are connected.`) : Re = "Cycles detected in hierarchy.", V(Re);
    let Oe = !1;
    const Dt = d.map(($) => {
      const Y = $.id === t.id, ie = z.has($.id);
      return $.deletable === !Y && $.data.inCycle === ie && $.data.isRootNode === Y ? $ : (Oe = !0, {
        ...$,
        deletable: !Y,
        data: {
          ...$.data,
          inCycle: ie,
          isRootNode: Y
        }
      });
    });
    let Ue = !1;
    const It = p.map(($) => {
      var ie;
      const Y = z.has($.source) && z.has($.target);
      return $.animated === Y && ((ie = $.data) == null ? void 0 : ie.inCycle) === Y ? $ : (Ue = !0, {
        ...$,
        animated: Y,
        data: {
          ...$.data,
          inCycle: Y
        }
      });
    });
    Oe && v(Dt), Ue && b(It);
  }, [t.id]), mt = A(
    (d) => {
      v((p) => Ft(d, p));
    },
    []
  ), ft = A(
    (d) => {
      b((p) => Wt(d, p));
    },
    []
  );
  B(() => {
    pt(c, r);
  }, [
    c.length,
    r.length,
    r.map((d) => d.source + d.target).join(",")
  ]), B(() => {
    const d = (p) => {
      var j;
      (p.ctrlKey || p.metaKey) && p.key === "f" && (p.preventDefault(), (j = K.current) == null || j.focus());
    };
    return window.addEventListener("keydown", d), () => window.removeEventListener("keydown", d);
  }, []);
  const De = (d) => {
    if (D(d), !d.trim()) {
      X([]), U(0);
      return;
    }
    const p = c.filter(
      (j) => j.data.name.toLowerCase().includes(d.toLowerCase()) || j.data.description.toLowerCase().includes(d.toLowerCase())
    ).map((j) => j.id);
    X(p), U(0), p.length > 0 && ye(p[0]);
  }, ye = (d) => {
    if (!E) return;
    const p = E.getNode(d);
    p && (f(d), E.setCenter(
      p.position.x + (p.width || 200) / 2,
      p.position.y + (p.height || 100) / 2,
      { zoom: 1.2, duration: 800 }
    ));
  }, gt = () => {
    if (O.length === 0) return;
    const d = (T + 1) % O.length;
    U(d), ye(O[d]);
  }, bt = () => {
    if (R) {
      if (R.includes("Disconnected") || R.includes("disconnected")) {
        const d = new Set(r.map((j) => j.target)), p = c.filter((j) => !d.has(j.id) && j.id !== t.id);
        p.length > 0 && ye(p[0].id);
      } else if (R.includes("Cycles") || R.includes("Cycle")) {
        const d = c.find((p) => p.data.inCycle);
        d && ye(d.id);
      }
    }
  };
  B(() => {
    if (h && E) {
      const d = E.getNode(h);
      d && E.setCenter(
        d.position.x + (d.width || 200) / 2,
        d.position.y + (d.height || 100) / 2,
        { zoom: 1.2, duration: 600 }
      );
    }
  }, [h, E]);
  const vt = A((d) => {
    if (y) return;
    if (r.some((j) => j.target === d.target)) {
      alert("A group can only have one parent.");
      return;
    }
    S(c, r), b((j) => qt({
      ...d,
      type: "base",
      markerEnd: { type: Z.ArrowClosed }
    }, j));
  }, [r, y, c, S]), yt = A((d, { nodeId: p }) => {
    oe.current = p;
  }, []), jt = A((d) => {
    if (!oe.current || y) return;
    if (d.target.classList.contains("react-flow__pane") && E && ae.current) {
      const { top: j, left: _ } = ae.current.getBoundingClientRect(), z = ze(), G = E.project({
        x: d.clientX - _,
        y: d.clientY - j
      });
      S(c, r);
      const _e = dt(z, G, !1), je = {
        id: `e-${oe.current}-${z}`,
        source: oe.current,
        target: z,
        type: "base",
        markerEnd: { type: Z.ArrowClosed }
      };
      v((le) => le.concat(_e)), b((le) => le.concat(je)), f(z);
    }
    oe.current = null;
  }, [E, y, c, r, S]), Nt = A((d, p) => {
    be.current = !1;
  }, []), wt = A((d, p) => {
    be.current = !0, S(c, r), b((j) => Xt(d, p, j));
  }, [c, r, S]), kt = A((d, p) => {
    be.current || (S(c, r), b((j) => j.filter((_) => _.id !== p.id))), be.current = !0;
  }, [c, r, S]), Ct = A((d, p) => {
    f(p.id);
  }, []), Et = A(() => {
    f(null);
  }, []), Ie = (d, p) => {
    S(c, r), v((j) => j.map((_) => _.id === d ? { ..._, data: { ..._.data, ...p } } : _));
  }, _t = A((d) => {
    S(c, r), b((p) => p.filter((j) => j.id !== d));
  }, [c, r, S]), Rt = A((d) => {
    d.length > 0 && S(c, r);
  }, [c, r, S]), Mt = A((d) => {
    d.length > 0 && S(c, r);
  }, [c, r, S]), St = A(() => {
    S(c, r);
  }, [c, r, S]), At = A(() => {
    c.length !== 0 && (S(c, r), v(Xe(c, r, t.id)), setTimeout(() => E == null ? void 0 : E.fitView({ duration: 800 }), 50));
  }, [c, r, t.id, S, E]), Le = A((d) => {
    const p = /* @__PURE__ */ new Map();
    r.forEach((z) => {
      const G = p.get(z.target) || [];
      G.push(z.source), p.set(z.target, G);
    });
    const j = /* @__PURE__ */ new Set(), _ = [d];
    for (; _.length; ) {
      const z = _.pop();
      for (const G of p.get(z) || [])
        j.has(G) || (j.add(G), _.push(G));
    }
    return j;
  }, [r]), Pt = H(() => {
    if (!h) return [];
    const d = Le(h);
    return c.filter(
      (p) => p.id !== h && p.id !== t.id && !d.has(p.id)
    );
  }, [h, c, t.id, Le]), J = H(() => {
    if (!h) return [];
    const d = /* @__PURE__ */ new Map();
    r.forEach((_) => {
      const z = d.get(_.source) || [];
      z.push(_.target), d.set(_.source, z);
    });
    const p = /* @__PURE__ */ new Set(), j = [...d.get(h) || []];
    for (; j.length; ) {
      const _ = j.pop();
      p.has(_) || (p.add(_), j.push(...d.get(_) || []));
    }
    return c.filter((_) => p.has(_.id));
  }, [h, c, r]), $t = A((d) => {
    if (!h || d.length === 0) return;
    const p = new Set(d);
    S(c, r), b((j) => {
      const _ = j.filter((G) => !p.has(G.target)), z = d.map((G) => ({
        id: `e-${h}-${G}`,
        source: h,
        target: G,
        type: "base",
        markerEnd: { type: Z.ArrowClosed }
      }));
      return [..._, ...z];
    }), ee(!1);
  }, [h, c, r, S]), zt = A((d) => {
    if (!h || d.length === 0) return;
    const p = Sn(
      c,
      r,
      h,
      J,
      d
    );
    p && (S(c, r), v(Xe(p.nodes, p.edges, t.id)), b(p.edges), q(!1), setTimeout(() => E == null ? void 0 : E.fitView({ duration: 800 }), 50));
  }, [h, c, r, J, S, t.id, E]), Tt = (d, p) => {
    W(!0);
    const j = c.find((z) => z.id === t.id) || c[0], _ = {
      ...t,
      id: j.id,
      reason: d,
      message: p,
      nodes: c.map((z) => Cn(z, r))
    };
    setTimeout(() => {
      n(_), W(!1), Q(!1);
    }, 800);
  }, Ee = c.find((d) => d.id === h) || null, Ge = !!R || !x || me;
  return /* @__PURE__ */ e.jsx("div", { className: "flex flex-col h-full bg-white text-slate-900 font-sans", children: /* @__PURE__ */ e.jsxs(
    xn,
    {
      onFetchMembers: u,
      iconMap: g,
      onRemoveEdge: _t,
      onUpdateNode: Ie,
      children: [
        /* @__PURE__ */ e.jsxs("header", { className: "h-16 border-b border-slate-200 flex items-center justify-between px-4 bg-white z-20 shadow-sm shrink-0 relative", children: [
          /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-4 flex-1", children: [
            /* @__PURE__ */ e.jsx(
              "button",
              {
                onClick: i,
                className: "p-2 hover:bg-slate-100 rounded-full text-slate-500 transition-colors",
                children: /* @__PURE__ */ e.jsx(fs, { size: 20 })
              }
            ),
            /* @__PURE__ */ e.jsxs("div", { className: "flex flex-col min-w-[120px]", children: [
              /* @__PURE__ */ e.jsx("h1", { className: "text-lg font-bold leading-tight truncate", children: t.name || "Hierachy Editor" }),
              /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-2 text-xs text-slate-500", children: [
                /* @__PURE__ */ e.jsxs("span", { className: "bg-slate-100 px-1.5 py-0.5 rounded text-slate-600 font-medium", children: [
                  c.length,
                  " Groups"
                ] }),
                /* @__PURE__ */ e.jsx("span", { children: "•" }),
                /* @__PURE__ */ e.jsx("span", { children: t.type })
              ] })
            ] })
          ] }),
          /* @__PURE__ */ e.jsxs("div", { className: "flex items-center gap-1 pl-4", children: [
            /* @__PURE__ */ e.jsx(
              "button",
              {
                onClick: Ce,
                disabled: !o,
                className: `p-2 rounded-lg transition-colors ${o ? "text-slate-600 hover:bg-slate-100" : "text-slate-300 cursor-not-allowed"}`,
                title: "Undo (Ctrl+Z)",
                children: /* @__PURE__ */ e.jsx(on, { size: 18 })
              }
            ),
            /* @__PURE__ */ e.jsx(
              "button",
              {
                onClick: ve,
                disabled: !N,
                className: `p-2 mr-2 rounded-lg transition-colors ${N ? "text-slate-600 hover:bg-slate-100" : "text-slate-300 cursor-not-allowed"}`,
                title: "Redo (Ctrl+Y)",
                children: /* @__PURE__ */ e.jsx(Ws, { size: 18 })
              }
            ),
            /* @__PURE__ */ e.jsx("div", { className: "h-6 w-px bg-slate-200 mx-1 hidden sm:block" }),
            /* @__PURE__ */ e.jsx(
              "button",
              {
                onClick: At,
                className: "p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-50 rounded-lg",
                title: "Auto-arrange layout",
                children: /* @__PURE__ */ e.jsx(Ds, { size: 18 })
              }
            ),
            /* @__PURE__ */ e.jsx(
              "button",
              {
                onClick: () => ee(!0),
                disabled: !h || h === t.id,
                className: `p-2 rounded-lg transition-colors ${h && h !== t.id ? "text-slate-400 hover:text-slate-600 hover:bg-slate-50" : "text-slate-300 cursor-not-allowed"}`,
                title: h && h !== t.id ? "Connect matching groups by regex" : "Select a group first to connect matches under it",
                children: /* @__PURE__ */ e.jsx(st, { size: 18 })
              }
            ),
            /* @__PURE__ */ e.jsx(
              "button",
              {
                onClick: () => q(!0),
                disabled: !h || J.length === 0,
                className: `p-2 rounded-lg transition-colors ${h && J.length > 0 ? "text-slate-400 hover:text-slate-600 hover:bg-slate-50" : "text-slate-300 cursor-not-allowed"}`,
                title: h && J.length > 0 ? "Restructure this group's children by prefix chunks" : "Select a group with child groups first",
                children: /* @__PURE__ */ e.jsx(et, { size: 18 })
              }
            ),
            /* @__PURE__ */ e.jsx("button", { className: "p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-50 rounded-lg mr-2", title: "Settings", children: /* @__PURE__ */ e.jsx(Zs, { size: 18 }) }),
            /* @__PURE__ */ e.jsx("div", { className: "h-6 w-px bg-slate-200 mx-1 hidden sm:block" }),
            /* @__PURE__ */ e.jsx(
              "button",
              {
                onClick: () => alert("Upload clicked"),
                className: "p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-50 rounded-lg",
                children: /* @__PURE__ */ e.jsx(cn, { size: 18 })
              }
            ),
            /* @__PURE__ */ e.jsx(
              "button",
              {
                onClick: () => l({ id: t.id, nodes: c, edges: r }),
                className: "p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-50 rounded-lg mr-4",
                children: /* @__PURE__ */ e.jsx(Ss, { size: 18 })
              }
            ),
            /* @__PURE__ */ e.jsxs(
              "button",
              {
                onClick: () => Q(!0),
                disabled: Ge,
                className: `
              flex items-center gap-2 px-4 py-2 rounded-lg font-medium text-sm transition-all shadow-sm
              ${Ge ? "bg-slate-100 text-slate-400 cursor-not-allowed border border-slate-200" : "bg-teal-700 text-white hover:bg-teal-800"}
            `,
                children: [
                  /* @__PURE__ */ e.jsx(Xs, { size: 16 }),
                  /* @__PURE__ */ e.jsx("span", { children: "Save" })
                ]
              }
            )
          ] })
        ] }),
        /* @__PURE__ */ e.jsxs("div", { className: "flex-1 flex overflow-hidden", children: [
          /* @__PURE__ */ e.jsxs("div", { className: "flex-1 relative bg-slate-50 transition-all duration-300", ref: ae, children: [
            /* @__PURE__ */ e.jsxs("div", { className: "absolute top-4 left-4 right-4 sm:right-auto sm:w-80 z-10 flex flex-col gap-2 pointer-events-none", children: [
              /* @__PURE__ */ e.jsxs("div", { className: "relative w-full group pointer-events-auto shadow-md rounded-lg", children: [
                /* @__PURE__ */ e.jsx("div", { className: "absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 group-focus-within:text-teal-500 transition-colors", children: /* @__PURE__ */ e.jsx(Te, { size: 16 }) }),
                /* @__PURE__ */ e.jsx(
                  "input",
                  {
                    ref: K,
                    className: "w-full pl-9 pr-12 py-2.5 bg-white/95 backdrop-blur border border-slate-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-teal-500/50 focus:border-teal-500 transition-all",
                    placeholder: "Search groups (Ctrl+F)",
                    value: P,
                    onChange: (d) => De(d.target.value),
                    onKeyDown: (d) => {
                      d.key === "Enter" && (d.preventDefault(), gt());
                    }
                  }
                ),
                O.length > 0 && /* @__PURE__ */ e.jsxs("div", { className: "absolute right-2 top-1/2 -translate-y-1/2 text-xs font-bold text-slate-400 bg-slate-100 px-1.5 py-0.5 rounded", children: [
                  T + 1,
                  "/",
                  O.length
                ] }),
                P && O.length === 0 && /* @__PURE__ */ e.jsx("div", { className: "absolute right-2 top-1/2 -translate-y-1/2 text-slate-300", children: /* @__PURE__ */ e.jsx(F, { size: 14, className: "cursor-pointer hover:text-red-500", onClick: () => De("") }) })
              ] }),
              R && /* @__PURE__ */ e.jsxs(
                "div",
                {
                  onClick: bt,
                  className: "pointer-events-auto cursor-pointer flex items-center gap-3 px-4 py-3 bg-red-50/95 backdrop-blur text-red-700 rounded-lg border border-red-200 shadow-md animate-in fade-in slide-in-from-top-4 hover:bg-red-100 transition-colors group",
                  role: "alert",
                  title: "Click to zoom to issue",
                  children: [
                    /* @__PURE__ */ e.jsx("div", { className: "p-2 bg-red-100 rounded-full text-red-600 group-hover:bg-white transition-colors shrink-0", children: /* @__PURE__ */ e.jsx(ot, { size: 16, className: "stroke-[2.5]" }) }),
                    /* @__PURE__ */ e.jsxs("div", { className: "flex-1 min-w-0", children: [
                      /* @__PURE__ */ e.jsx("h4", { className: "text-xs font-bold uppercase tracking-wider text-red-800 mb-0.5", children: "Validation Error" }),
                      /* @__PURE__ */ e.jsx("p", { className: "text-xs font-medium leading-tight", children: R })
                    ] })
                  ]
                }
              )
            ] }),
            /* @__PURE__ */ e.jsxs(
              Ot,
              {
                nodes: c,
                edges: r,
                onNodesChange: mt,
                onEdgesChange: ft,
                onNodesDelete: Rt,
                onEdgesDelete: Mt,
                onNodeDragStart: St,
                onConnect: vt,
                onConnectStart: yt,
                onConnectEnd: jt,
                onEdgeUpdate: wt,
                onEdgeUpdateStart: Nt,
                onEdgeUpdateEnd: kt,
                onNodeClick: Ct,
                onPaneClick: Et,
                nodeTypes: fe,
                edgeTypes: ge,
                onInit: se,
                connectionMode: Kt.Loose,
                onlyRenderVisibleElements: !0,
                fitView: !0,
                snapToGrid: !0,
                snapGrid: [15, 15],
                nodesDraggable: !M,
                nodesConnectable: !y,
                elementsSelectable: !0,
                deleteKeyCode: ["Delete", "Backspace"],
                className: "bg-slate-50",
                proOptions: { hideAttribution: !0 },
                zoomOnScroll: !0,
                panOnScroll: !1,
                children: [
                  /* @__PURE__ */ e.jsx(Jt, { color: "#cbd5e1", gap: 20 }),
                  /* @__PURE__ */ e.jsx(
                    Zt,
                    {
                      nodeColor: (d) => d.data.isRootNode ? "#0f766e" : "#e2e8f0",
                      maskColor: "rgba(248, 250, 252, 0.6)",
                      className: "!bottom-6 !left-auto !right-6 bg-white border border-slate-200 shadow-lg rounded-lg",
                      style: { width: 120, height: 90 }
                    }
                  ),
                  /* @__PURE__ */ e.jsxs(Qt, { position: "bottom-left", className: "m-4 ml-6 mb-6 flex flex-col gap-1 bg-white p-1 rounded-lg shadow-md border border-slate-200", children: [
                    /* @__PURE__ */ e.jsx("button", { onClick: () => E == null ? void 0 : E.zoomIn(), className: "p-2 hover:bg-slate-100 rounded text-slate-600", children: /* @__PURE__ */ e.jsx(rt, { size: 18 }) }),
                    /* @__PURE__ */ e.jsx("button", { onClick: () => E == null ? void 0 : E.zoomOut(), className: "p-2 hover:bg-slate-100 rounded text-slate-600", children: /* @__PURE__ */ e.jsx(Ys, { size: 18 }) }),
                    /* @__PURE__ */ e.jsx("div", { className: "h-px bg-slate-200 my-0.5 mx-2" }),
                    /* @__PURE__ */ e.jsx("button", { onClick: () => E == null ? void 0 : E.fitView({ duration: 800 }), className: "p-2 hover:bg-slate-100 rounded text-slate-600", children: /* @__PURE__ */ e.jsx(Us, { size: 18 }) })
                  ] })
                ]
              }
            )
          ] }),
          h && /* @__PURE__ */ e.jsx("div", { className: "h-full border-l border-slate-200 bg-white shadow-xl z-20 animate-in slide-in-from-right-10 duration-200", children: /* @__PURE__ */ e.jsx(
            bn,
            {
              node: Ee,
              readOnly: y,
              onUpdateNode: Ie,
              onClose: () => f(null)
            }
          ) })
        ] }),
        /* @__PURE__ */ e.jsx(
          Nn,
          {
            open: we,
            onClose: () => Q(!1),
            onSubmit: Tt,
            saving: me
          }
        ),
        /* @__PURE__ */ e.jsx(
          wn,
          {
            open: ke,
            parentNode: Ee,
            candidates: Pt,
            onClose: () => ee(!1),
            onConfirm: $t
          }
        ),
        /* @__PURE__ */ e.jsx(
          An,
          {
            open: te,
            parentNode: Ee,
            candidates: J,
            onClose: () => q(!1),
            onConfirm: zt
          }
        )
      ]
    }
  ) });
}, Ln = ({ localKey: t, onFetchMembers: s, icons: a, ...n }) => /* @__PURE__ */ e.jsx(Ht, { children: /* @__PURE__ */ e.jsx(
  $n,
  {
    ...n,
    groupData: n.groupData,
    onFetchMembers: s,
    icons: a
  }
) });
var zn = /* @__PURE__ */ ((t) => (t.EditingLocked = "Editing Locked", t.CanvasLocked = "Canvas Locked", t.TargetHasParent = "A group can only have one parent.", t.AcyclicGraph = "Graph is acyclic", t.CyclicGraph = "Warning: Cycles detected in hierarchy!", t.RootNode = "Root Group", t.SaveSuccess = "Saved Successfully", t.MemberCount = "Members", t.Attributes = "Attributes", t.Description = "Description", t.GroupIcon = "Group Icon", t.GroupName = "Group Name", t))(zn || {});
export {
  kn as DiGraph,
  zn as LocalKeys,
  dt as createEmptyNode,
  Ln as default,
  Cn as groupFromNode,
  Xe as layoutNodes,
  In as transformJsonToGraph
};
//# sourceMappingURL=index.js.map
