import pe, { forwardRef as lt, createElement as Ue, createContext as Kt, useContext as Zt, useState as S, useRef as W, useCallback as M, useEffect as B, useMemo as X } from "react";
import Qt, { Handle as Ze, Position as Qe, useReactFlow as es, getBezierPath as ts, BaseEdge as ss, EdgeLabelRenderer as ns, MarkerType as H, ReactFlowProvider as rs, applyNodeChanges as os, applyEdgeChanges as as, addEdge as is, updateEdge as ls, ConnectionMode as cs, Background as ds, MiniMap as us, Panel as hs } from "reactflow";
var Ee = { exports: {} }, le = {};
/**
 * @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 et;
function ps() {
  if (et) return le;
  et = 1;
  var t = Symbol.for("react.transitional.element"), s = Symbol.for("react.fragment");
  function a(n, r, i) {
    var x = null;
    if (i !== void 0 && (x = "" + i), r.key !== void 0 && (x = "" + r.key), "key" in r) {
      i = {};
      for (var g in r)
        g !== "key" && (i[g] = r[g]);
    } else i = r;
    return r = i.ref, {
      $$typeof: t,
      type: n,
      key: x,
      ref: r !== void 0 ? r : null,
      props: i
    };
  }
  return le.Fragment = s, le.jsx = a, le.jsxs = a, le;
}
var ce = {};
/**
 * @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 tt;
function ms() {
  return tt || (tt = 1, process.env.NODE_ENV !== "production" && (function() {
    function t(m) {
      if (m == null) return null;
      if (typeof m == "function")
        return m.$$typeof === Me ? null : m.displayName || m.name || null;
      if (typeof m == "string") return m;
      switch (m) {
        case v:
          return "Fragment";
        case P:
          return "Profiler";
        case j:
          return "StrictMode";
        case Se:
          return "Suspense";
        case Re:
          return "SuspenseList";
        case xe:
          return "Activity";
      }
      if (typeof m == "object")
        switch (typeof m.tag == "number" && console.error(
          "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
        ), m.$$typeof) {
          case u:
            return "Portal";
          case O:
            return m.displayName || "Context";
          case D:
            return (m._context.displayName || "Context") + ".Consumer";
          case G:
            var w = m.render;
            return m = m.displayName, m || (m = w.displayName || w.name || "", m = m !== "" ? "ForwardRef(" + m + ")" : "ForwardRef"), m;
          case se:
            return w = m.displayName || null, w !== null ? w : t(m.type) || "Memo";
          case Q:
            w = m._payload, m = m._init;
            try {
              return t(m(w));
            } catch {
            }
        }
      return null;
    }
    function s(m) {
      return "" + m;
    }
    function a(m) {
      try {
        s(m);
        var w = !1;
      } catch {
        w = !0;
      }
      if (w) {
        w = console;
        var A = w.error, T = typeof Symbol == "function" && Symbol.toStringTag && m[Symbol.toStringTag] || m.constructor.name || "Object";
        return A.call(
          w,
          "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
          T
        ), s(m);
      }
    }
    function n(m) {
      if (m === v) return "<>";
      if (typeof m == "object" && m !== null && m.$$typeof === Q)
        return "<...>";
      try {
        var w = t(m);
        return w ? "<" + w + ">" : "<...>";
      } catch {
        return "<...>";
      }
    }
    function r() {
      var m = J.A;
      return m === null ? null : m.getOwner();
    }
    function i() {
      return Error("react-stack-top-frame");
    }
    function x(m) {
      if (fe.call(m, "key")) {
        var w = Object.getOwnPropertyDescriptor(m, "key").get;
        if (w && w.isReactWarning) return !1;
      }
      return m.key !== void 0;
    }
    function g(m, w) {
      function A() {
        ge || (ge = !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)",
          w
        ));
      }
      A.isReactWarning = !0, Object.defineProperty(m, "key", {
        get: A,
        configurable: !0
      });
    }
    function o() {
      var m = t(this.type);
      return be[m] || (be[m] = !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."
      )), m = this.props.ref, m !== void 0 ? m : null;
    }
    function c(m, w, A, T, ee, Y) {
      var I = A.ref;
      return m = {
        $$typeof: b,
        type: m,
        key: w,
        props: A,
        _owner: T
      }, (I !== void 0 ? I : null) !== null ? Object.defineProperty(m, "ref", {
        enumerable: !1,
        get: o
      }) : Object.defineProperty(m, "ref", { enumerable: !1, value: null }), m._store = {}, Object.defineProperty(m._store, "validated", {
        configurable: !1,
        enumerable: !1,
        writable: !0,
        value: 0
      }), Object.defineProperty(m, "_debugInfo", {
        configurable: !1,
        enumerable: !1,
        writable: !0,
        value: null
      }), Object.defineProperty(m, "_debugStack", {
        configurable: !1,
        enumerable: !1,
        writable: !0,
        value: ee
      }), Object.defineProperty(m, "_debugTask", {
        configurable: !1,
        enumerable: !1,
        writable: !0,
        value: Y
      }), Object.freeze && (Object.freeze(m.props), Object.freeze(m)), m;
    }
    function f(m, w, A, T, ee, Y) {
      var I = w.children;
      if (I !== void 0)
        if (T)
          if (ne(I)) {
            for (T = 0; T < I.length; T++)
              d(I[T]);
            Object.freeze && Object.freeze(I);
          } 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 d(I);
      if (fe.call(w, "key")) {
        I = t(m);
        var q = Object.keys(w).filter(function(ve) {
          return ve !== "key";
        });
        T = 0 < q.length ? "{key: someKey, " + q.join(": ..., ") + ": ...}" : "{key: someKey}", re[I + T] || (q = 0 < q.length ? "{" + q.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} />`,
          T,
          I,
          q,
          I
        ), re[I + T] = !0);
      }
      if (I = null, A !== void 0 && (a(A), I = "" + A), x(w) && (a(w.key), I = "" + w.key), "key" in w) {
        A = {};
        for (var K in w)
          K !== "key" && (A[K] = w[K]);
      } else A = w;
      return I && g(
        A,
        typeof m == "function" ? m.displayName || m.name || "Unknown" : m
      ), c(
        m,
        I,
        A,
        r(),
        ee,
        Y
      );
    }
    function d(m) {
      l(m) ? m._store && (m._store.validated = 1) : typeof m == "object" && m !== null && m.$$typeof === Q && (m._payload.status === "fulfilled" ? l(m._payload.value) && m._payload.value._store && (m._payload.value._store.validated = 1) : m._store && (m._store.validated = 1));
    }
    function l(m) {
      return typeof m == "object" && m !== null && m.$$typeof === b;
    }
    var p = pe, b = Symbol.for("react.transitional.element"), u = Symbol.for("react.portal"), v = Symbol.for("react.fragment"), j = Symbol.for("react.strict_mode"), P = Symbol.for("react.profiler"), D = Symbol.for("react.consumer"), O = Symbol.for("react.context"), G = Symbol.for("react.forward_ref"), Se = Symbol.for("react.suspense"), Re = Symbol.for("react.suspense_list"), se = Symbol.for("react.memo"), Q = Symbol.for("react.lazy"), xe = Symbol.for("react.activity"), Me = Symbol.for("react.client.reference"), J = p.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, fe = Object.prototype.hasOwnProperty, ne = Array.isArray, _ = console.createTask ? console.createTask : function() {
      return null;
    };
    p = {
      react_stack_bottom_frame: function(m) {
        return m();
      }
    };
    var ge, be = {}, ye = p.react_stack_bottom_frame.bind(
      p,
      i
    )(), R = _(n(i)), re = {};
    ce.Fragment = v, ce.jsx = function(m, w, A) {
      var T = 1e4 > J.recentlyCreatedOwnerStacks++;
      return f(
        m,
        w,
        A,
        !1,
        T ? Error("react-stack-top-frame") : ye,
        T ? _(n(m)) : R
      );
    }, ce.jsxs = function(m, w, A) {
      var T = 1e4 > J.recentlyCreatedOwnerStacks++;
      return f(
        m,
        w,
        A,
        !0,
        T ? Error("react-stack-top-frame") : ye,
        T ? _(n(m)) : R
      );
    };
  })()), ce;
}
var st;
function xs() {
  return st || (st = 1, process.env.NODE_ENV === "production" ? Ee.exports = ps() : Ee.exports = ms()), Ee.exports;
}
var e = xs();
const L = [];
for (let t = 0; t < 256; ++t)
  L.push((t + 256).toString(16).slice(1));
function fs(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 Oe;
const gs = new Uint8Array(16);
function bs() {
  if (!Oe) {
    if (typeof crypto > "u" || !crypto.getRandomValues)
      throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
    Oe = crypto.getRandomValues.bind(crypto);
  }
  return Oe(gs);
}
const ys = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), nt = { randomUUID: ys };
function vs(t, s, a) {
  var r;
  t = t || {};
  const n = t.random ?? ((r = t.rng) == null ? void 0 : r.call(t)) ?? bs();
  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, fs(n);
}
function ue(t, s, a) {
  return nt.randomUUID && !t ? nt.randomUUID() : vs(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 js = (t) => t.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(), Ns = (t) => t.replace(
  /^([A-Z])|[\s-_]+(\w)/g,
  (s, a, n) => n ? n.toUpperCase() : a.toLowerCase()
), rt = (t) => {
  const s = Ns(t);
  return s.charAt(0).toUpperCase() + s.slice(1);
}, ct = (...t) => t.filter((s, a, n) => !!s && s.trim() !== "" && n.indexOf(s) === a).join(" ").trim(), ws = (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 ks = {
  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 Cs = lt(
  ({
    color: t = "currentColor",
    size: s = 24,
    strokeWidth: a = 2,
    absoluteStrokeWidth: n,
    className: r = "",
    children: i,
    iconNode: x,
    ...g
  }, o) => Ue(
    "svg",
    {
      ref: o,
      ...ks,
      width: s,
      height: s,
      stroke: t,
      strokeWidth: n ? Number(a) * 24 / Number(s) : a,
      className: ct("lucide", r),
      ...!i && !ws(g) && { "aria-hidden": "true" },
      ...g
    },
    [
      ...x.map(([c, f]) => Ue(c, f)),
      ...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 E = (t, s) => {
  const a = lt(
    ({ className: n, ...r }, i) => Ue(Cs, {
      ref: i,
      iconNode: s,
      className: ct(
        `lucide-${js(rt(t))}`,
        `lucide-${t}`,
        n
      ),
      ...r
    })
  );
  return a.displayName = rt(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 Es = [
  [
    "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"
    }
  ]
], _s = E("activity", 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 Ss = [
  ["path", { d: "m12 19-7-7 7-7", key: "1l729n" }],
  ["path", { d: "M19 12H5", key: "x3x0zl" }]
], Rs = E("arrow-left", Ss);
/**
 * @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 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" }]
], Ps = E("building", 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: "m15 18-6-6 6-6", key: "1wnfg3" }]], $s = E("chevron-left", 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 zs = [["path", { d: "m9 18 6-6-6-6", key: "mthhwq" }]], Ts = E("chevron-right", 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 Is = [
  ["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" }]
], dt = E("circle-alert", 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 Ds = [
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
  ["path", { d: "m9 12 2 2 4-4", key: "dzmm74" }]
], Os = E("circle-check", Ds);
/**
 * @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 = [
  ["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" }]
], ut = E("circle-pause", 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 Gs = [["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }]], Vs = E("circle", 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 Us = [
  ["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" }]
], Ys = E("download", Us);
/**
 * @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: "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" }]
], Fs = E("file-text", 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 Bs = [
  ["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" }]
], ht = E("git-branch", 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: "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"
    }
  ]
], pt = E("layers", 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 Ws = [
  ["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" }]
], Xs = E("layout-grid", 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 Js = [
  ["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" }]
], mt = E("link-2", 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 Ks = [["path", { d: "M21 12a9 9 0 1 1-6.219-8.56", key: "13zald" }]], Zs = E("loader-circle", 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 Qs = [
  ["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" }]
], en = E("maximize", 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 = [["path", { d: "M5 12h14", key: "1ays0h" }]], sn = E("minus", 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 nn = [
  ["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" }]
], xt = E("panels-top-left", 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: "M5 12h14", key: "1ays0h" }],
  ["path", { d: "M12 5v14", key: "s699le" }]
], ft = E("plus", 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 on = [
  ["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" }]
], an = E("redo-2", on);
/**
 * @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: "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" }]
], cn = E("save", 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: "m21 21-4.34-4.34", key: "14j7rj" }],
  ["circle", { cx: "11", cy: "11", r: "8", key: "4ej97u" }]
], qe = E("search", 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: "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" }]
], hn = E("settings", 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 pn = [
  [
    "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"
    }
  ]
], mn = E("shield", pn);
/**
 * @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 xn = [
  ["circle", { cx: "9", cy: "12", r: "3", key: "u3jwor" }],
  ["rect", { width: "20", height: "14", x: "2", y: "5", rx: "7", key: "g7kal2" }]
], Le = E("toggle-left", xn);
/**
 * @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 fn = [
  ["circle", { cx: "15", cy: "12", r: "3", key: "1afu0r" }],
  ["rect", { width: "20", height: "14", x: "2", y: "5", rx: "7", key: "g7kal2" }]
], Ge = E("toggle-right", fn);
/**
 * @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 gn = [
  ["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" }]
], gt = E("trash-2", gn);
/**
 * @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 bn = [
  [
    "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" }]
], bt = E("triangle-alert", bn);
/**
 * @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 yn = [
  ["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" }]
], vn = E("undo-2", yn);
/**
 * @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 jn = [
  ["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" }]
], Nn = E("upload", jn);
/**
 * @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 wn = [
  ["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" }]
], yt = E("user", wn);
/**
 * @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 kn = [
  ["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 = E("users", kn);
/**
 * @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 Cn = [
  ["path", { d: "M18 6 6 18", key: "1bl5f8" }],
  ["path", { d: "m6 6 12 12", key: "d8bk6v" }]
], Z = E("x", Cn), vt = {
  Building: Ps,
  Users: he,
  Layout: xt,
  Shield: mn,
  User: yt,
  Group: he
}, jt = Kt({
  iconMap: vt
}), me = () => Zt(jt), En = ({ children: t, onFetchMembers: s, iconMap: a, onRemoveEdge: n, onUpdateNode: r }) => {
  const i = { ...vt, ...a };
  return /* @__PURE__ */ e.jsx(jt.Provider, { value: { onFetchMembers: s, iconMap: i, onRemoveEdge: n, onUpdateNode: r }, children: t });
}, _n = ({ id: t, data: s, selected: a }) => {
  const { iconMap: n, onUpdateNode: r } = me(), i = n[s.iconPath] || n.Layout, [x, g] = S(!1), [o, c] = S(s.name), f = W(null), l = 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"
  }, p = M((v) => {
    v == null || v.stopPropagation(), g(!0), c(s.name);
  }, [s.name]), b = M(() => {
    g(!1), o !== s.name && r && r(t, { name: o });
  }, [o, s.name, t, r]), u = (v) => {
    v.stopPropagation(), v.key === "Enter" && b();
  };
  return B(() => {
    if (!a || x) return;
    const v = (j) => {
      (j.ctrlKey || j.metaKey) && j.key.toLowerCase() === "r" && (j.preventDefault(), p());
    };
    return window.addEventListener("keydown", v), () => window.removeEventListener("keydown", v);
  }, [a, x, p]), B(() => {
    x && f.current && (f.current.focus(), f.current.select());
  }, [x]), B(() => {
    x || c(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
        ${l.border}
        ${l.bg}
        ${l.opacity}
        ${a ? "ring-4 ring-teal-500/20 scale-105 z-50" : "hover:border-slate-300"}
        min-w-[220px] group font-sans
      `,
      onDoubleClick: p,
      children: [
        l.badgeText && (l.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
          ${l.badge || "bg-slate-200 text-slate-600"}
          ${s.inCycle ? "animate-pulse" : ""}
        `, children: [
          s.isDeleted && /* @__PURE__ */ e.jsx(gt, { size: 8 }),
          s.isSuspended && /* @__PURE__ */ e.jsx(ut, { size: 8 }),
          l.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
          ${l.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: f,
                type: "text",
                value: o,
                onChange: (v) => c(v.target.value),
                onBlur: b,
                onKeyDown: u,
                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: (v) => v.stopPropagation(),
                onMouseDown: (v) => v.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(pt, { 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(bt, { 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(Vs, { size: 8, className: "fill-emerald-500" }),
            "Active"
          ] }) : /* @__PURE__ */ e.jsx("span", { className: "text-slate-400", children: "Inactive" }) })
        ] }),
        !s.isRootNode && /* @__PURE__ */ e.jsx(
          Ze,
          {
            type: "target",
            position: Qe.Left,
            className: "!w-3 !h-3 !bg-slate-400 !border-2 !border-white hover:!bg-teal-500 transition-colors"
          }
        ),
        /* @__PURE__ */ e.jsx(
          Ze,
          {
            type: "source",
            position: Qe.Right,
            className: "!w-3 !h-3 !bg-slate-400 !border-2 !border-white hover:!bg-teal-500 transition-colors"
          }
        )
      ]
    }
  );
}, Sn = pe.memo(_n), Rn = ({
  id: t,
  sourceX: s,
  sourceY: a,
  targetX: n,
  targetY: r,
  sourcePosition: i,
  targetPosition: x,
  style: g = {},
  markerEnd: o,
  data: c
}) => {
  const { setEdges: f } = es(), { onRemoveEdge: d } = me(), [l, p, b] = ts({
    sourceX: s,
    sourceY: a,
    sourcePosition: i,
    targetX: n,
    targetY: r,
    targetPosition: x
  }), u = (j) => {
    j.stopPropagation(), d ? d(t) : f((P) => P.filter((D) => D.id !== t));
  }, v = c == null ? void 0 : c.inCycle;
  return /* @__PURE__ */ e.jsxs(e.Fragment, { children: [
    /* @__PURE__ */ e.jsx(
      ss,
      {
        path: l,
        markerEnd: o,
        style: {
          ...g,
          stroke: v ? "#ef4444" : "#94a3b8",
          strokeWidth: v ? 3 : 2,
          transition: "stroke 0.3s"
        }
      }
    ),
    /* @__PURE__ */ e.jsx(ns, { children: /* @__PURE__ */ e.jsx(
      "div",
      {
        style: {
          position: "absolute",
          transform: `translate(-50%, -50%) translate(${p}px,${b}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: u,
            "aria-label": "Delete connection",
            title: "Delete connection",
            children: /* @__PURE__ */ e.jsx(Z, { size: 12, strokeWidth: 2.5 })
          }
        )
      }
    ) })
  ] });
}, Mn = pe.memo(Rn), Pn = ({ node: t, readOnly: s, onUpdateNode: a, onClose: n }) => {
  const { onFetchMembers: r } = me(), [i, x] = S("General"), g = ["General", "Status"];
  return r && g.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(Z, { 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: g.map((o) => /* @__PURE__ */ e.jsxs(
        "button",
        {
          onClick: () => x(o),
          className: `pb-3 text-sm font-medium transition-all relative ${i === o ? "text-teal-600" : "text-slate-500 hover:text-slate-700"}`,
          children: [
            /* @__PURE__ */ e.jsxs("span", { className: "flex items-center gap-2", children: [
              o === "General" && /* @__PURE__ */ e.jsx(Fs, { size: 14 }),
              o === "Status" && /* @__PURE__ */ e.jsx(_s, { size: 14 }),
              o === "Members" && /* @__PURE__ */ e.jsx(he, { size: 14 }),
              o
            ] }),
            i === o && /* @__PURE__ */ e.jsx("div", { className: "absolute bottom-0 left-0 right-0 h-0.5 bg-teal-600 rounded-t-full" })
          ]
        },
        o
      )) })
    ] }),
    /* @__PURE__ */ e.jsxs("div", { className: "flex-1 overflow-hidden bg-white", children: [
      i === "General" && /* @__PURE__ */ e.jsx(An, { node: t, readOnly: s, onUpdateNode: a }),
      i === "Status" && /* @__PURE__ */ e.jsx($n, { node: t, readOnly: s, onUpdateNode: a }),
      i === "Members" && r && /* @__PURE__ */ e.jsx(zn, { node: t, readOnly: s })
    ] })
  ] }) : null;
}, An = ({ node: t, readOnly: s, onUpdateNode: a }) => {
  const { iconMap: n } = me(), r = Object.keys(n);
  if (!t) return null;
  const i = t.data, x = (c, f, d) => {
    const l = [...i.attributes];
    l[c][f] = d, a(t.id, { attributes: l });
  }, g = () => {
    a(t.id, { attributes: [...i.attributes, { role: "", value: "" }] });
  }, o = (c) => {
    const f = i.attributes.filter((d, l) => l !== c);
    a(t.id, { attributes: f });
  };
  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: (c) => a(t.id, { name: c.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: r.map((c) => {
        const f = n[c] || xt, d = i.iconPath === c;
        return /* @__PURE__ */ e.jsx(
          "button",
          {
            onClick: () => !s && a(t.id, { iconPath: c }),
            className: `p-3 rounded-lg border transition-all flex items-center justify-center ${d ? "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: c,
            type: "button",
            children: /* @__PURE__ */ e.jsx(f, { size: 20, strokeWidth: d ? 2.5 : 2 })
          },
          c
        );
      }) })
    ] }),
    /* @__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: (c) => a(t.id, { description: c.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((c, f) => /* @__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: c.role,
              placeholder: "Key",
              onChange: (d) => x(f, "role", d.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: c.value,
              placeholder: "Value",
              onChange: (d) => x(f, "value", d.target.value),
              readOnly: s
            }
          ),
          !s && /* @__PURE__ */ e.jsx("button", { onClick: () => o(f), className: "p-2 text-slate-300 hover:text-red-500 transition-colors", children: /* @__PURE__ */ e.jsx(Z, { size: 14 }) })
        ] }, f)),
        !s && /* @__PURE__ */ e.jsxs(
          "button",
          {
            onClick: g,
            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(ft, { size: 14 }),
              "Add Attribute"
            ]
          }
        )
      ] })
    ] })
  ] }) });
}, $n = ({ 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(Ge, { size: 32 }) : /* @__PURE__ */ e.jsx(Le, { 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(ut, { 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(Ge, { size: 32 }) : /* @__PURE__ */ e.jsx(Le, { 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: (r) => a(t.id, { suspensionReason: r.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: (r) => a(t.id, { suspensionMessage: r.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(gt, { 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(Ge, { size: 32 }) : /* @__PURE__ */ e.jsx(Le, { 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: (r) => a(t.id, { deletionReason: r.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: (r) => a(t.id, { deletionMessage: r.target.value }),
              readOnly: s
            }
          )
        ] })
      ] })
    ] })
  ] }) });
}, zn = ({ node: t }) => {
  const { onFetchMembers: s } = me(), [a, n] = S(!0), [r, i] = S([]), [x, g] = S(1), [o, c] = S(0), [f, d] = S(""), [l, p] = S(!1);
  return B(() => {
    if (!t) return;
    let b = !0;
    n(!0);
    const u = setTimeout(() => {
      s ? s(t.id, t.data.name, x, f, l).then((v) => {
        b && (i(v.data), c(v.total), n(!1));
      }) : b && (n(!1), i([]), c(0));
    }, 300);
    return () => {
      b = !1, clearTimeout(u);
    };
  }, [t, x, f, l, 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: () => {
              p(!1), g(1);
            },
            className: `flex-1 flex items-center justify-center gap-2 py-1.5 text-xs font-bold rounded-md transition-all ${l ? "text-slate-500 hover:text-slate-700" : "bg-white text-teal-600 shadow-sm"}`,
            children: [
              /* @__PURE__ */ e.jsx(yt, { size: 14 }),
              "Direct Members"
            ]
          }
        ),
        /* @__PURE__ */ e.jsxs(
          "button",
          {
            onClick: () => {
              p(!0), g(1);
            },
            className: `flex-1 flex items-center justify-center gap-2 py-1.5 text-xs font-bold rounded-md transition-all ${l ? "bg-white text-teal-600 shadow-sm" : "text-slate-500 hover:text-slate-700"}`,
            children: [
              /* @__PURE__ */ e.jsx(pt, { size: 14 }),
              "Inclusive"
            ]
          }
        )
      ] }),
      /* @__PURE__ */ e.jsxs("div", { className: "relative", children: [
        /* @__PURE__ */ e.jsx(qe, { 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: f,
            onChange: (b) => {
              d(b.target.value), g(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(Zs, { size: 24, className: "animate-spin text-teal-500" }),
      /* @__PURE__ */ e.jsx("span", { className: "text-xs font-medium", children: "Loading members..." })
    ] }) : r.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: r.map((b) => /* @__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: b.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: b.name }),
          /* @__PURE__ */ e.jsx("div", { className: "text-[10px] text-slate-500 truncate", children: b.email }),
          l && b.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: b.sourceGroup, children: b.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 ${b.status === "Active" ? "bg-emerald-50 text-emerald-600" : "bg-slate-100 text-slate-500"}`, children: b.status }),
        /* @__PURE__ */ e.jsx("span", { className: "text-[10px] text-slate-400 font-mono", children: b.role })
      ] })
    ] }, b.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, o),
        " of ",
        o
      ] }),
      /* @__PURE__ */ e.jsxs("div", { className: "flex gap-1", children: [
        /* @__PURE__ */ e.jsx(
          "button",
          {
            onClick: () => g((b) => Math.max(1, b - 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($s, { size: 16, className: "text-slate-600" })
          }
        ),
        /* @__PURE__ */ e.jsx(
          "button",
          {
            onClick: () => g((b) => b + 1),
            disabled: x * 10 >= o || 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(Ts, { size: 16, className: "text-slate-600" })
          }
        )
      ] })
    ] })
  ] }) : null;
}, Tn = ({ open: t, onClose: s, onSubmit: a, saving: n }) => {
  const [r, i] = S("Configuration Update"), [x, g] = S("");
  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(Os, { 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(Z, { 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: r,
              onChange: (o) => i(o.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: (o) => g(o.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(r, x),
            disabled: n || !r,
            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;
}, In = ({ open: t, parentNode: s, candidates: a, onClose: n, onConfirm: r }) => {
  const [i, x] = S(""), [g, o] = S(/* @__PURE__ */ new Set());
  pe.useEffect(() => {
    t && (x(""), o(/* @__PURE__ */ new Set()));
  }, [t]);
  const { matches: c, error: f } = X(() => {
    if (!i.trim()) return { matches: [], error: null };
    let p;
    try {
      p = new RegExp(i, "i");
    } catch (b) {
      return { matches: [], error: b.message };
    }
    return {
      matches: a.filter((b) => p.test(b.data.name || "")),
      error: null
    };
  }, [i, a]);
  if (!t) return null;
  const d = c.filter((p) => !g.has(p.id)).map((p) => p.id), l = (p) => {
    o((b) => {
      const u = new Set(b);
      return u.has(p) ? u.delete(p) : u.add(p), u;
    });
  };
  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(mt, { 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(Z, { 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(qe, { 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 ${f ? "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: (p) => x(p.target.value)
            }
          )
        ] }),
        f && /* @__PURE__ */ e.jsxs("div", { className: "mt-2 flex items-center gap-1.5 text-xs text-red-600", children: [
          /* @__PURE__ */ e.jsx(dt, { size: 13 }),
          /* @__PURE__ */ e.jsxs("span", { children: [
            "Invalid regex: ",
            f
          ] })
        ] }),
        !f && 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: d.length }),
          " of ",
          c.length,
          " matched group",
          c.length === 1 ? "" : "s",
          " selected"
        ] })
      ] }),
      /* @__PURE__ */ e.jsxs("div", { className: "flex-1 overflow-y-auto px-6 min-h-[80px]", children: [
        i.trim() && !f && c.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: c.map((p) => {
          const b = !g.has(p.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: b,
                onChange: () => l(p.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 ${b ? "text-slate-700" : "text-slate-400 line-through"}`, children: p.data.name || "(unnamed)" })
          ] }) }, p.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: () => r(d),
            disabled: d.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 ${d.length === 0 ? "opacity-50 cursor-not-allowed" : "hover:bg-teal-700 active:scale-95"}`,
            children: [
              "Connect ",
              d.length > 0 ? `(${d.length})` : ""
            ]
          }
        )
      ] })
    ] })
  ] });
};
class Nt {
  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(), r = [], i = (x) => {
      a.add(x), n.add(x), r.push(x);
      const g = this.adj.get(x) || [];
      for (const o of g)
        if (!a.has(o))
          i(o);
        else if (n.has(o)) {
          const c = r.indexOf(o);
          c !== -1 && s.push(r.slice(c));
        }
      n.delete(x), r.pop();
    };
    for (const x of this.adj.keys())
      a.has(x) || i(x);
    return s;
  }
  getDeepChildren(s) {
    const a = /* @__PURE__ */ new Set(), n = [s], r = /* @__PURE__ */ new Set();
    for (; n.length > 0; ) {
      const i = n.pop();
      if (r.has(i)) continue;
      r.add(i);
      const x = this.adj.get(i) || [];
      for (const g of x)
        a.add(g), n.push(g);
    }
    return a.delete(s), Array.from(a);
  }
}
const _e = (t, s, a) => ({
  id: t || ue(),
  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: []
  }
}), Dn = (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
  };
}, ot = (t, s, a) => {
  var p, b;
  const i = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Set();
  s.forEach((u) => {
    const v = i.get(u.source) || [];
    v.push(u.target), i.set(u.source, v), x.add(u.target);
  });
  const g = a && t.some((u) => u.id === a) ? a : ((p = t.find((u) => !x.has(u.id))) == null ? void 0 : p.id) ?? ((b = t[0]) == null ? void 0 : b.id), o = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set(), f = { val: 0 }, d = (u, v) => {
    if (c.has(u)) return;
    c.add(u);
    const j = i.get(u) || [];
    if (j.length === 0) {
      o.set(u, { x: v * 300, y: f.val }), f.val += 180;
      return;
    }
    j.forEach((O) => d(O, v + 1));
    const P = j.map((O) => {
      var G;
      return (G = o.get(O)) == null ? void 0 : G.y;
    }).filter((O) => O !== void 0), D = P.length ? (Math.min(...P) + Math.max(...P)) / 2 : f.val;
    o.set(u, { x: v * 300, y: D });
  };
  g && d(g, 0);
  let l = f.val + 180;
  return t.forEach((u) => {
    o.has(u.id) || (o.set(u.id, { x: 0, y: l }), l += 180);
  }), t.map((u) => ({ ...u, position: o.get(u.id) || u.position }));
}, Qn = (t) => {
  const s = [], a = [], n = {};
  t.nodes.forEach((l) => {
    n[l.id] = { ...l, _children: [] };
  });
  let r = null;
  t.nodes.forEach((l) => {
    l.parent && n[l.parent] ? n[l.parent]._children.push(l.id) : r = l.id;
  }), !r && t.rootGroupId && (r = t.rootGroupId);
  const i = /* @__PURE__ */ new Map(), x = (l) => {
    if (i.has(l))
      return i.get(l);
    const p = n[l];
    if (!p) return 0;
    let b = p.memberCount || 0;
    const u = p._children || [];
    for (const v of u)
      b += x(v);
    return i.set(l, b), b;
  };
  t.nodes.forEach((l) => {
    x(l.id);
  });
  const g = 300, o = 180, c = (l, p, b) => {
    const u = n[l];
    if (!u) return;
    const v = b.val, j = l === r, P = u.attributes || [];
    s.push({
      id: l,
      type: "group",
      position: { x: p * g, y: v },
      data: {
        name: u.name,
        // Removed type injection. Description can come from JSON or be empty.
        description: u.description || "",
        iconPath: j ? "Building" : u.iconPath || "Users",
        color: "#0d9488",
        isRootNode: j,
        inCycle: !1,
        // Map Status Flags
        isActive: u.isActive !== void 0 ? u.isActive : !0,
        isDeleted: u.isDeleted || !1,
        isSuspended: u.isSuspended || !1,
        deletionReason: u.deletionReason || null,
        deletionMessage: u.deletionMessage || null,
        suspensionReason: u.suspensionReason || null,
        suspensionMessage: u.suspensionMessage || null,
        attributes: P,
        properties: [],
        memberCount: u.memberCount,
        inclusiveMemberCount: i.get(l),
        descendants: []
      }
    }), u.parent && n[u.parent] && a.push({
      id: `e-${u.parent}-${l}`,
      source: u.parent,
      target: l,
      type: "base",
      markerEnd: { type: H.ArrowClosed }
    });
    const D = u._children || [];
    D.length > 0 ? D.forEach((O) => {
      c(O, p + 1, b);
    }) : b.val += o;
  };
  r && c(r, 0, { val: 0 });
  const f = new Set(s.map((l) => l.id));
  let d = 0;
  return t.nodes.forEach((l) => {
    f.has(l.id) || (s.push({
      id: l.id,
      type: "group",
      position: { x: 0, y: d + 500 },
      // Place them below
      data: {
        name: l.name,
        description: "Detached Node",
        iconPath: "AlertTriangle",
        color: "#ef4444",
        isRootNode: !1,
        inCycle: !1,
        isActive: l.isActive !== void 0 ? l.isActive : !0,
        isDeleted: l.isDeleted || !1,
        isSuspended: l.isSuspended || !1,
        deletionReason: l.deletionReason || null,
        deletionMessage: l.deletionMessage || null,
        suspensionReason: l.suspensionReason || null,
        suspensionMessage: l.suspensionMessage || null,
        attributes: [],
        properties: [],
        memberCount: l.memberCount,
        inclusiveMemberCount: l.memberCount,
        descendants: []
      }
    }), d += o);
  }), { nodes: s, edges: a };
}, Ve = "", On = (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 r = n.endsWith("*"), i = Number(r ? 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: r });
  }
  return { lengths: a, error: null };
}, Ln = (t, s) => {
  const a = t.trim();
  if (!a || s.length === 0)
    return null;
  const n = [];
  let r = 0;
  for (const i of s) {
    if (r >= a.length) break;
    do {
      const x = a.length - r, g = Math.min(i.length, x);
      n.push(a.slice(r, r + g)), r += g;
    } while (i.repeat && r < a.length);
  }
  return n.length > 0 ? n : null;
}, Gn = (t, s) => {
  const a = (t.data.name || "").trim();
  let n = "";
  const r = s.map((x) => (n += x, n)), i = r[r.length - 1] === a ? r.slice(0, -1) : r;
  return {
    node: t,
    chunks: s,
    prefixes: r,
    generatedPath: i,
    pathKey: i[i.length - 1] || null
  };
}, wt = (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));
}, Vn = (t) => {
  const s = /* @__PURE__ */ new Map();
  return t.forEach((a) => {
    a.generatedPath.forEach((n, r) => {
      s.has(n) || s.set(n, r === 0 ? null : a.generatedPath[r - 1]);
    });
  }), s;
}, kt = (t, s = []) => {
  const a = /* @__PURE__ */ new Map();
  [...t.map((r) => r.node), ...s].forEach((r) => {
    const i = (r.data.name || "").trim();
    if (!i) return;
    const x = a.get(i) || [];
    x.push(r), a.set(i, x);
  });
  const n = /* @__PURE__ */ new Map();
  return a.forEach((r, i) => {
    r.length === 1 && n.set(i, r[0]);
  }), n;
}, Ct = (t, s, a = []) => {
  const n = [], r = [];
  t.forEach((o) => {
    const c = Ln(o.data.name || "", s);
    if (!c) {
      r.push({ node: o, reason: "Name is blank." });
      return;
    }
    n.push(Gn(o, c));
  });
  const i = wt(n), x = kt(n, a), g = i.filter((o) => !x.has(o)).length;
  return {
    matches: n,
    skipped: r,
    generatedPathCount: g,
    totalPathCount: i.length
  };
}, Un = (t, s, a, n, r) => {
  const i = t.find((j) => j.id === a) || null, x = Ct(n, r, i ? [i] : []);
  if (x.matches.length === 0) return null;
  const g = wt(x.matches), o = Vn(x.matches), c = kt(x.matches, i ? [i] : []), f = /* @__PURE__ */ new Map(), d = [];
  g.forEach((j) => {
    const P = c.get(j);
    if (P) {
      f.set(j, P.id);
      return;
    }
    const D = ue(), O = _e(D, null, !1);
    d.push({
      ...O,
      data: {
        ...O.data,
        name: j,
        iconPath: "Layout",
        color: "#0d9488"
      }
    }), f.set(j, D);
  });
  const l = t.concat(d), p = new Set(f.values());
  x.matches.forEach((j) => p.add(j.node.id)), p.delete(a);
  const b = s.filter((j) => !p.has(j.target)), u = new Set(b.map((j) => `${j.source}${Ve}${j.target}`)), v = [];
  return g.forEach((j) => {
    const P = f.get(j);
    if (!P) return;
    const D = o.get(j) || null, O = D ? f.get(D) : a;
    if (!O || O === P) return;
    const G = `${O}${Ve}${P}`;
    u.has(G) || (u.add(G), v.push({
      id: `e-${O}-${P}`,
      source: O,
      target: P,
      type: "base",
      markerEnd: { type: H.ArrowClosed }
    }));
  }), x.matches.forEach((j) => {
    const P = j.pathKey ? f.get(j.pathKey) : a;
    if (!P || P === j.node.id) return;
    const D = `${P}${Ve}${j.node.id}`;
    u.has(D) || (u.add(D), v.push({
      id: `e-${P}-${j.node.id}`,
      source: P,
      target: j.node.id,
      type: "base",
      markerEnd: { type: H.ArrowClosed }
    }));
  }), {
    nodes: l,
    edges: [...b, ...v],
    affectedCount: x.matches.length,
    generatedCount: d.length
  };
}, Yn = ({
  open: t,
  parentNode: s,
  candidates: a,
  onClose: n,
  onConfirm: r
}) => {
  const [i, x] = S("");
  pe.useEffect(() => {
    t && x("");
  }, [t]);
  const g = X(() => On(i), [i]), o = X(() => g.error || g.lengths.length === 0 ? null : Ct(a, g.lengths, s ? [s] : []), [a, s, g.error, g.lengths]);
  if (!t) return null;
  const c = (o == null ? void 0 : o.matches.slice(0, 20)) || [], f = (o == null ? void 0 : o.skipped.slice(0, 5)) || [], d = !g.error && g.lengths.length > 0 && !!o && o.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(ht, { 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(Z, { 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 ${g.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: (l) => x(l.target.value)
          }
        ),
        g.error && /* @__PURE__ */ e.jsxs("div", { className: "mt-2 flex items-center gap-1.5 text-xs text-red-600", children: [
          /* @__PURE__ */ e.jsx(dt, { size: 13 }),
          /* @__PURE__ */ e.jsx("span", { children: g.error })
        ] }),
        !g.error && g.lengths.length > 0 && o && /* @__PURE__ */ e.jsxs("div", { className: "mt-2 text-xs text-slate-500", children: [
          /* @__PURE__ */ e.jsx("span", { className: "font-bold text-slate-700", children: o.matches.length }),
          " group",
          o.matches.length === 1 ? "" : "s",
          " arranged,",
          " ",
          /* @__PURE__ */ e.jsx("span", { className: "font-bold text-slate-700", children: o.generatedPathCount }),
          " prefix node",
          o.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." }),
        o && o.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." }),
        c.length > 0 && /* @__PURE__ */ e.jsxs("ul", { className: "space-y-1 pb-3", children: [
          c.map((l) => /* @__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: l.node.data.name || "(unnamed)" }),
            /* @__PURE__ */ e.jsx("div", { className: "text-sm font-medium text-slate-700 truncate", children: [...l.generatedPath, l.node.data.name || "(unnamed)"].join(" / ") })
          ] }, l.node.id)),
          o && o.matches.length > c.length && /* @__PURE__ */ e.jsxs("li", { className: "text-xs text-slate-400 px-3 py-2", children: [
            "+",
            o.matches.length - c.length,
            " more"
          ] })
        ] }),
        f.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: f.map(({ node: l, reason: p }) => /* @__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: l.data.name || "(unnamed)" }),
            " - ",
            p
          ] }, l.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: () => r(g.lengths),
            disabled: !d,
            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 ${d ? "hover:bg-teal-700 active:scale-95" : "opacity-50 cursor-not-allowed"}`,
            children: [
              "Restructure ",
              o && o.matches.length > 0 ? `(${o.matches.length})` : ""
            ]
          }
        )
      ] })
    ] })
  ] });
}, Et = [
  "name",
  "description",
  "iconPath",
  "color",
  "isActive",
  "isDeleted",
  "isSuspended",
  "deletionReason",
  "deletionMessage",
  "suspensionReason",
  "suspensionMessage",
  "attributes",
  "memberCount"
], qn = "group";
function C(t) {
  return { ok: !1, rejected: !0, reason: t };
}
function U(t) {
  return { ok: !0, result: t };
}
function Fn(t, s) {
  const a = s.filter((r) => r.source === t.id).map((r) => r.target), n = s.find((r) => r.target === t.id);
  return {
    id: t.id,
    name: t.data.name,
    description: t.data.description,
    iconPath: t.data.iconPath,
    isActive: t.data.isActive,
    isDeleted: t.data.isDeleted,
    isSuspended: t.data.isSuspended,
    memberCount: t.data.memberCount,
    isRoot: t.data.isRootNode,
    parent: n ? n.source : null,
    children: a
  };
}
function Ye(t, s, a) {
  const n = [], r = new Nt();
  t.forEach((c) => r.addVertex(c.id)), s.forEach((c) => r.addEdge(c.source, c.target)), r.findCycles().length > 0 && n.push({ message: "Cycles detected in hierarchy.", blocking: !0 });
  const i = /* @__PURE__ */ new Map();
  s.forEach((c) => i.set(c.target, (i.get(c.target) || 0) + 1)), t.filter((c) => (i.get(c.id) || 0) > 1).length > 0 && n.push({ message: "A group can only have one parent.", blocking: !0 });
  const g = new Set(s.map((c) => c.target)), o = t.filter((c) => !g.has(c.id));
  return t.length > 0 && o.length !== 1 ? n.push({
    message: `Graph disconnected: Found ${o.length} root-like nodes. Ensure all groups are connected.`,
    blocking: !1
  }) : o.length === 1 && a && o[0].id !== a && n.push({
    message: `The single root must be the designated root group (${a}).`,
    blocking: !1
  }), n;
}
function at(t, s, a) {
  return Ye(t, s, a).map((n) => n.message);
}
function de(t, s, a) {
  const n = t.getRootId(), r = new Set(
    Ye(t.getNodes(), t.getEdges(), n).filter((g) => g.blocking).map((g) => g.message)
  ), x = Ye(s, a, n).filter((g) => g.blocking).find((g) => !r.has(g.message));
  return x ? C(x.message) : (t.takeSnapshot(), t.setNodes(s), t.setEdges(a), U());
}
function it(t) {
  if (t == null || typeof t != "object")
    return { data: {}, error: "Expected an object of fields." };
  const s = {};
  for (const a of Object.keys(t)) {
    if (!Et.includes(a))
      return { data: {}, error: `Unknown or non-editable field "${a}".` };
    s[a] = t[a];
  }
  return "name" in s && (typeof s.name != "string" || !s.name.trim()) ? { data: {}, error: 'Field "name" must be a non-empty string.' } : "attributes" in s && !Array.isArray(s.attributes) ? { data: {}, error: 'Field "attributes" must be an array.' } : "memberCount" in s && typeof s.memberCount != "number" ? { data: {}, error: 'Field "memberCount" must be a number.' } : { data: s };
}
const Bn = `This is the GROUP / hierarchy editor. The model is a directed acyclic tree of group nodes (the only node type is "group") connected by parent->child edges. Each group has a single parent (one-parent rule) and exactly one designated root group exists and cannot be deleted. Valid editable node fields are: name (required, non-empty), description, iconPath, color, isActive, isDeleted, isSuspended, deletion/suspension reason+message, attributes (array of {role,value}), memberCount. Tools route through the editor's real mutation and validation logic: connecting a node that already has a parent, creating a cycle, deleting the root, or unknown node ids/fields are rejected with a reason and the model is left unchanged. Navigation tools (focus_node, select_nodes, clear_selection, fit_view, zoom) only move the viewport or the editor selection so the user can see what you mean — they never change the hierarchy, and reject unknown node ids without throwing.`;
function Hn(t) {
  return {
    kind: "group",
    guidelines: Bn,
    tools: [
      {
        name: "get_model",
        description: "Return the current group hierarchy (nodes + parent/child links) as compact JSON.",
        parameters: { type: "object", properties: {}, additionalProperties: !1 }
      },
      {
        name: "list_node_types",
        description: "List the node/element types this editor supports.",
        parameters: { type: "object", properties: {}, additionalProperties: !1 }
      },
      {
        name: "add_node",
        description: "Add a new group node. Optionally connect it under a parent group (the parent must exist and the child must not already have a parent).",
        parameters: {
          type: "object",
          properties: {
            name: { type: "string", description: "Group name (required, non-empty)." },
            parentId: { type: "string", description: "Optional id of the parent group to connect under." },
            description: { type: "string" },
            iconPath: { type: "string" },
            memberCount: { type: "number" }
          },
          required: ["name"],
          additionalProperties: !0
        }
      },
      {
        name: "update_node",
        description: "Update editable fields of an existing group node by id.",
        parameters: {
          type: "object",
          properties: {
            id: { type: "string", description: "Target node id." },
            fields: { type: "object", description: "Map of editable fields to set." }
          },
          required: ["id", "fields"],
          additionalProperties: !1
        }
      },
      {
        name: "delete_node",
        description: "Delete a group node by id (and any edges touching it). The designated root cannot be deleted.",
        parameters: {
          type: "object",
          properties: { id: { type: "string" } },
          required: ["id"],
          additionalProperties: !1
        }
      },
      {
        name: "connect_nodes",
        description: "Connect a parent group to a child group (parent->child edge). Rejected if the child already has a parent or the link would create a cycle.",
        parameters: {
          type: "object",
          properties: {
            parentId: { type: "string" },
            childId: { type: "string" }
          },
          required: ["parentId", "childId"],
          additionalProperties: !1
        }
      },
      {
        name: "disconnect_nodes",
        description: "Remove the parent->child edge between two groups.",
        parameters: {
          type: "object",
          properties: {
            parentId: { type: "string" },
            childId: { type: "string" }
          },
          required: ["parentId", "childId"],
          additionalProperties: !1
        }
      },
      {
        name: "validate",
        description: "Run the editor validation rules and return the list of current validation errors (empty = valid).",
        parameters: { type: "object", properties: {}, additionalProperties: !1 }
      },
      {
        name: "replace_model",
        description: "Replace the whole hierarchy from JSON ({ nodes: [{id?,name,parent?,...}] }). Validated before applying; rejected if it would be cyclic or has no/ambiguous root.",
        parameters: {
          type: "object",
          properties: {
            nodes: {
              type: "array",
              items: {
                type: "object",
                properties: {
                  id: { type: "string" },
                  name: { type: "string" },
                  parent: { type: "string" }
                },
                required: ["name"]
              }
            }
          },
          required: ["nodes"],
          additionalProperties: !1
        }
      },
      // --- Navigation / viewport / selection (no model mutation) ----------------
      {
        name: "focus_node",
        description: "Center the viewport on a single group node and select it (so the user sees what the assistant is referring to). Does not change the hierarchy. Rejected if the node id does not exist.",
        parameters: {
          type: "object",
          properties: {
            id: { type: "string", description: "Id of the group node to focus." },
            zoom: { type: "number", description: "Optional zoom level to apply while centering (clamped to 0.1..2).", minimum: 0.1, maximum: 2 }
          },
          required: ["id"],
          additionalProperties: !1
        }
      },
      {
        name: "select_nodes",
        description: "Highlight/select one or more group nodes in the editor (so the user sees which groups the assistant means). Does not change the hierarchy. Rejected if any id is unknown.",
        parameters: {
          type: "object",
          properties: {
            ids: {
              type: "array",
              items: { type: "string" },
              minItems: 1,
              description: "Ids of the group nodes to select."
            }
          },
          required: ["ids"],
          additionalProperties: !1
        }
      },
      {
        name: "clear_selection",
        description: "Clear the current selection/highlight in the editor. Does not change the hierarchy.",
        parameters: { type: "object", properties: {}, additionalProperties: !1 }
      },
      {
        name: "fit_view",
        description: "Zoom/pan the viewport to fit the whole hierarchy on screen. Does not change the hierarchy.",
        parameters: { type: "object", properties: {}, additionalProperties: !1 }
      },
      {
        name: "zoom",
        description: "Adjust the viewport zoom: step in, step out, or set an absolute level. Does not change the hierarchy.",
        parameters: {
          type: "object",
          properties: {
            direction: {
              type: "string",
              enum: ["in", "out", "level"],
              description: 'in/out to step, or "level" to set an absolute zoom (requires "level").'
            },
            level: { type: "number", description: 'Absolute zoom level when direction="level" (clamped to 0.1..2).', minimum: 0.1, maximum: 2 }
          },
          required: ["direction"],
          additionalProperties: !1
        }
      }
    ],
    invoke: async (n, r) => {
      const i = t.getNodes(), x = t.getEdges(), g = t.getRootId();
      switch (n) {
        case "get_model":
          return U({
            rootId: g,
            nodes: i.map((o) => Fn(o, x))
          });
        case "list_node_types":
          return U({
            nodeTypes: [
              {
                type: qn,
                description: "A group / hierarchy node. Connected to its parent by a single parent->child edge.",
                editableFields: [...Et]
              }
            ]
          });
        case "add_node": {
          const { data: o, error: c } = it(
            // pull only editable keys, ignore parentId which is structural
            Object.fromEntries(
              Object.entries(r || {}).filter(([v]) => v !== "parentId")
            )
          );
          if (c) return C(c);
          if (!o.name) return C('Field "name" is required.');
          const f = r == null ? void 0 : r.parentId;
          if (f != null && !i.some((v) => v.id === f))
            return C(`Parent node "${f}" does not exist.`);
          const d = ue(), l = _e(d, { x: 0, y: 0 }, !1);
          l.data = { ...l.data, ...o };
          const p = [...i, l];
          let b = x;
          f != null && (b = [
            ...x,
            {
              id: `e-${f}-${d}`,
              source: f,
              target: d,
              type: "base",
              markerEnd: { type: H.ArrowClosed }
            }
          ]);
          const u = de(t, p, b);
          return u.ok ? U({ id: d }) : u;
        }
        case "update_node": {
          const o = r == null ? void 0 : r.id;
          if (!i.some((p) => p.id === o))
            return C(`Node "${o}" does not exist.`);
          const { data: c, error: f } = it(r == null ? void 0 : r.fields);
          if (f) return C(f);
          if (Object.keys(c).length === 0)
            return C("No editable fields supplied.");
          const d = i.map(
            (p) => p.id === o ? { ...p, data: { ...p.data, ...c } } : p
          ), l = de(t, d, x);
          return l.ok ? U({ id: o }) : l;
        }
        case "delete_node": {
          const o = r == null ? void 0 : r.id;
          if (!i.some((l) => l.id === o))
            return C(`Node "${o}" does not exist.`);
          if (o === g)
            return C("The designated root group cannot be deleted.");
          const c = i.filter((l) => l.id !== o), f = x.filter((l) => l.source !== o && l.target !== o), d = de(t, c, f);
          return d.ok ? U({ id: o }) : d;
        }
        case "connect_nodes": {
          const { parentId: o, childId: c } = r || {};
          if (!i.some((l) => l.id === o))
            return C(`Parent node "${o}" does not exist.`);
          if (!i.some((l) => l.id === c))
            return C(`Child node "${c}" does not exist.`);
          if (o === c)
            return C("A group cannot be connected to itself.");
          if (x.some((l) => l.target === c))
            return C("A group can only have one parent.");
          const f = [
            ...x,
            {
              id: `e-${o}-${c}`,
              source: o,
              target: c,
              type: "base",
              markerEnd: { type: H.ArrowClosed }
            }
          ], d = de(t, i, f);
          return d.ok ? U({ parentId: o, childId: c }) : d;
        }
        case "disconnect_nodes": {
          const { parentId: o, childId: c } = r || {};
          if (!x.some((p) => p.source === o && p.target === c))
            return C(`No edge from "${o}" to "${c}".`);
          const d = x.filter(
            (p) => !(p.source === o && p.target === c)
          ), l = de(t, i, d);
          return l.ok ? U({ parentId: o, childId: c }) : l;
        }
        case "validate": {
          const o = at(i, x, g);
          return U({ valid: o.length === 0, errors: o });
        }
        case "replace_model": {
          const o = r == null ? void 0 : r.nodes;
          if (!Array.isArray(o))
            return C("Expected { nodes: [...] }.");
          const c = [], f = [], d = /* @__PURE__ */ new Set();
          for (let b = 0; b < o.length; b++) {
            const u = o[b];
            if (u == null || typeof u != "object")
              return C(`nodes[${b}] is not an object.`);
            if (typeof u.name != "string" || !u.name.trim())
              return C(`nodes[${b}].name must be a non-empty string.`);
            const v = typeof u.id == "string" && u.id ? u.id : ue();
            if (d.has(v)) return C(`Duplicate node id "${v}".`);
            d.add(v), f[b] = v;
            const j = _e(v, { x: 0, y: 0 }, !1);
            j.data = { ...j.data, name: u.name }, typeof u.description == "string" && (j.data.description = u.description), typeof u.iconPath == "string" && (j.data.iconPath = u.iconPath), c.push(j);
          }
          const l = [];
          for (let b = 0; b < o.length; b++) {
            const u = o[b].parent;
            if (u == null) continue;
            if (!d.has(u))
              return C(`nodes[${b}].parent "${u}" is not a node in the model.`);
            const v = f[b];
            if (l.some((j) => j.target === v))
              return C(`Node "${v}" has more than one parent.`);
            l.push({
              id: `e-${u}-${v}`,
              source: u,
              target: v,
              type: "base",
              markerEnd: { type: H.ArrowClosed }
            });
          }
          c.forEach((b) => {
            b.data.isRootNode = b.id === g;
          });
          const p = at(c, l, g);
          return p.length > 0 ? C(p.join(" ")) : (t.takeSnapshot(), t.setNodes(c), t.setEdges(l), U({ nodeCount: c.length }));
        }
        case "focus_node": {
          const o = r == null ? void 0 : r.id;
          if (!i.find((l) => l.id === o))
            return C(`Node "${o}" does not exist.`);
          if (!t.focusNode)
            return C("Viewport not available in this host.");
          let f = r == null ? void 0 : r.zoom;
          if (f != null) {
            if (typeof f != "number" || Number.isNaN(f))
              return C('Field "zoom" must be a number.');
            f = Math.min(2, Math.max(0.1, f));
          }
          return t.focusNode(o, f) ? U({ id: o, zoom: f ?? null }) : C(`Could not focus node "${o}" (not on the current canvas).`);
        }
        case "select_nodes": {
          const o = r == null ? void 0 : r.ids;
          if (!Array.isArray(o) || o.length === 0)
            return C('Field "ids" must be a non-empty array of node ids.');
          const c = new Set(i.map((d) => d.id)), f = o.filter((d) => !c.has(d));
          return f.length > 0 ? C(`Unknown node id(s): ${f.join(", ")}.`) : t.setSelection ? (t.setSelection(o), U({ selected: o })) : C("Selection not available in this host.");
        }
        case "clear_selection":
          return t.setSelection ? (t.setSelection([]), U({ selected: [] })) : C("Selection not available in this host.");
        case "fit_view":
          return t.fitView ? (t.fitView(), U()) : C("Viewport not available in this host.");
        case "zoom": {
          const o = r == null ? void 0 : r.direction;
          if (o !== "in" && o !== "out" && o !== "level")
            return C('Field "direction" must be one of: in, out, level.');
          let c = r == null ? void 0 : r.level;
          if (o === "level") {
            if (typeof c != "number" || Number.isNaN(c))
              return C('direction="level" requires a numeric "level".');
            c = Math.min(2, Math.max(0.1, c));
          }
          return t.setZoom ? t.setZoom(o, c) ? U({ direction: o, level: o === "level" ? c : null }) : C("Could not apply zoom (viewport not ready).") : C("Viewport not available in this host.");
        }
        default:
          return C(`Unknown tool "${n}".`);
      }
    }
  };
}
const Wn = () => {
  const [t, s] = S([]), [a, n] = S([]), r = M((g, o) => {
    s((c) => [...c.length > 50 ? c.slice(1) : c, { nodes: g, edges: o }]), n([]);
  }, []), i = M((g, o) => {
    if (t.length === 0) return null;
    const c = t[t.length - 1], f = t.slice(0, t.length - 1);
    return s(f), n((d) => [{ nodes: g, edges: o }, ...d]), c;
  }, [t]), x = M((g, o) => {
    if (a.length === 0) return null;
    const c = a[0], f = a.slice(1);
    return n(f), s((d) => [...d, { nodes: g, edges: o }]), c;
  }, [a]);
  return { takeSnapshot: r, undo: i, redo: x, canUndo: t.length > 0, canRedo: a.length > 0 };
}, Xn = ({
  groupData: t,
  nodes: s,
  edges: a = [],
  onSave: n,
  onExport: r,
  onBack: i,
  isValidated: x,
  enableForce: g = !0,
  onFetchMembers: o,
  icons: c,
  onAiCapabilityReady: f
}) => {
  const [d, l] = S(s), [p, b] = S(a), [u, v] = S(null), [j, P] = S(!1), [D, O] = S(!1), [G, Se] = S(null), [Re, se] = S(!1), [Q, xe] = S(!1), [Me, J] = S(!1), [fe, ne] = S(!1), [_, ge] = S(null), be = X(() => ({ group: Sn }), []), ye = X(() => ({ base: Mn }), []), { takeSnapshot: R, undo: re, redo: m, canUndo: w, canRedo: A } = Wn(), [T, ee] = S(""), [Y, I] = S([]), [q, K] = S(0), ve = W(null), Pe = W(null), oe = W(null), je = W(!0), Ae = W(d), $e = W(p);
  Ae.current = d, $e.current = p;
  const Ne = W(null);
  Ne.current = _;
  const ze = M(() => {
    const h = re(d, p);
    h && (l(h.nodes), b(h.edges));
  }, [re, d, p]), we = M(() => {
    const h = m(d, p);
    h && (l(h.nodes), b(h.edges));
  }, [m, d, p]);
  B(() => {
    const h = (y) => {
      y.target instanceof HTMLInputElement || y.target instanceof HTMLTextAreaElement || ((y.ctrlKey || y.metaKey) && y.key.toLowerCase() === "z" ? (y.shiftKey ? we() : ze(), y.preventDefault()) : (y.ctrlKey || y.metaKey) && y.key.toLowerCase() === "y" && (we(), y.preventDefault()));
    };
    return window.addEventListener("keydown", h), () => window.removeEventListener("keydown", h);
  }, [ze, we]);
  const _t = M((h, y) => {
    const N = new Nt();
    h.forEach(($) => N.addVertex($.id)), y.forEach(($) => N.addEdge($.source, $.target));
    const k = N.findCycles(), z = new Set(k.flat()), V = k.length === 0, Ie = new Set(y.map(($) => $.target)), Ce = h.filter(($) => !Ie.has($.id)), ae = Ce.length === 1;
    let De = null;
    V ? h.length > 0 && !ae && (De = `Graph disconnected: Found ${Ce.length} root-like nodes. Ensure all groups are connected.`) : De = "Cycles detected in hierarchy.", Se(De);
    let Je = !1;
    const Xt = h.map(($) => {
      const F = $.id === t.id, ie = z.has($.id);
      return $.deletable === !F && $.data.inCycle === ie && $.data.isRootNode === F ? $ : (Je = !0, {
        ...$,
        deletable: !F,
        data: {
          ...$.data,
          inCycle: ie,
          isRootNode: F
        }
      });
    });
    let Ke = !1;
    const Jt = y.map(($) => {
      var ie;
      const F = z.has($.source) && z.has($.target);
      return $.animated === F && ((ie = $.data) == null ? void 0 : ie.inCycle) === F ? $ : (Ke = !0, {
        ...$,
        animated: F,
        data: {
          ...$.data,
          inCycle: F
        }
      });
    });
    Je && l(Xt), Ke && b(Jt);
  }, [t.id]), St = M(
    (h) => {
      l((y) => os(h, y));
    },
    []
  ), Rt = M(
    (h) => {
      b((y) => as(h, y));
    },
    []
  );
  B(() => {
    _t(d, p);
  }, [
    d.length,
    p.length,
    p.map((h) => h.source + h.target).join(",")
  ]), B(() => {
    const h = (y) => {
      var N;
      (y.ctrlKey || y.metaKey) && y.key === "f" && (y.preventDefault(), (N = ve.current) == null || N.focus());
    };
    return window.addEventListener("keydown", h), () => window.removeEventListener("keydown", h);
  }, []);
  const Fe = (h) => {
    if (ee(h), !h.trim()) {
      I([]), K(0);
      return;
    }
    const y = d.filter(
      (N) => N.data.name.toLowerCase().includes(h.toLowerCase()) || N.data.description.toLowerCase().includes(h.toLowerCase())
    ).map((N) => N.id);
    I(y), K(0), y.length > 0 && ke(y[0]);
  }, ke = (h) => {
    if (!_) return;
    const y = _.getNode(h);
    y && (v(h), _.setCenter(
      y.position.x + (y.width || 200) / 2,
      y.position.y + (y.height || 100) / 2,
      { zoom: 1.2, duration: 800 }
    ));
  }, Mt = () => {
    if (Y.length === 0) return;
    const h = (q + 1) % Y.length;
    K(h), ke(Y[h]);
  }, Pt = () => {
    if (G) {
      if (G.includes("Disconnected") || G.includes("disconnected")) {
        const h = new Set(p.map((N) => N.target)), y = d.filter((N) => !h.has(N.id) && N.id !== t.id);
        y.length > 0 && ke(y[0].id);
      } else if (G.includes("Cycles") || G.includes("Cycle")) {
        const h = d.find((y) => y.data.inCycle);
        h && ke(h.id);
      }
    }
  };
  B(() => {
    if (u && _) {
      const h = _.getNode(u);
      h && _.setCenter(
        h.position.x + (h.width || 200) / 2,
        h.position.y + (h.height || 100) / 2,
        { zoom: 1.2, duration: 600 }
      );
    }
  }, [u, _]);
  const At = M((h) => {
    if (j) return;
    if (p.some((N) => N.target === h.target)) {
      alert("A group can only have one parent.");
      return;
    }
    R(d, p), b((N) => is({
      ...h,
      type: "base",
      markerEnd: { type: H.ArrowClosed }
    }, N));
  }, [p, j, d, R]), $t = M((h, { nodeId: y }) => {
    oe.current = y;
  }, []), zt = M((h) => {
    if (!oe.current || j) return;
    if (h.target.classList.contains("react-flow__pane") && _ && Pe.current) {
      const { top: N, left: k } = Pe.current.getBoundingClientRect(), z = ue(), V = _.project({
        x: h.clientX - k,
        y: h.clientY - N
      });
      R(d, p);
      const Ie = _e(z, V, !1), Ce = {
        id: `e-${oe.current}-${z}`,
        source: oe.current,
        target: z,
        type: "base",
        markerEnd: { type: H.ArrowClosed }
      };
      l((ae) => ae.concat(Ie)), b((ae) => ae.concat(Ce)), v(z);
    }
    oe.current = null;
  }, [_, j, d, p, R]), Tt = M((h, y) => {
    je.current = !1;
  }, []), It = M((h, y) => {
    je.current = !0, R(d, p), b((N) => ls(h, y, N));
  }, [d, p, R]), Dt = M((h, y) => {
    je.current || (R(d, p), b((N) => N.filter((k) => k.id !== y.id))), je.current = !0;
  }, [d, p, R]), Ot = M((h, y) => {
    v(y.id);
  }, []), Lt = M(() => {
    v(null);
  }, []), Be = (h, y) => {
    R(d, p), l((N) => N.map((k) => k.id === h ? { ...k, data: { ...k.data, ...y } } : k));
  }, Gt = M((h) => {
    R(d, p), b((y) => y.filter((N) => N.id !== h));
  }, [d, p, R]), Vt = M((h) => {
    h.length > 0 && R(d, p);
  }, [d, p, R]), Ut = M((h) => {
    h.length > 0 && R(d, p);
  }, [d, p, R]), Yt = M(() => {
    R(d, p);
  }, [d, p, R]), qt = M(() => {
    d.length !== 0 && (R(d, p), l(ot(d, p, t.id)), setTimeout(() => _ == null ? void 0 : _.fitView({ duration: 800 }), 50));
  }, [d, p, t.id, R, _]), He = M((h) => {
    const y = /* @__PURE__ */ new Map();
    p.forEach((z) => {
      const V = y.get(z.target) || [];
      V.push(z.source), y.set(z.target, V);
    });
    const N = /* @__PURE__ */ new Set(), k = [h];
    for (; k.length; ) {
      const z = k.pop();
      for (const V of y.get(z) || [])
        N.has(V) || (N.add(V), k.push(V));
    }
    return N;
  }, [p]), Ft = X(() => {
    if (!u) return [];
    const h = He(u);
    return d.filter(
      (y) => y.id !== u && y.id !== t.id && !h.has(y.id)
    );
  }, [u, d, t.id, He]), te = X(() => {
    if (!u) return [];
    const h = /* @__PURE__ */ new Map();
    p.forEach((k) => {
      const z = h.get(k.source) || [];
      z.push(k.target), h.set(k.source, z);
    });
    const y = /* @__PURE__ */ new Set(), N = [...h.get(u) || []];
    for (; N.length; ) {
      const k = N.pop();
      y.has(k) || (y.add(k), N.push(...h.get(k) || []));
    }
    return d.filter((k) => y.has(k.id));
  }, [u, d, p]), Bt = M((h) => {
    if (!u || h.length === 0) return;
    const y = new Set(h);
    R(d, p), b((N) => {
      const k = N.filter((V) => !y.has(V.target)), z = h.map((V) => ({
        id: `e-${u}-${V}`,
        source: u,
        target: V,
        type: "base",
        markerEnd: { type: H.ArrowClosed }
      }));
      return [...k, ...z];
    }), J(!1);
  }, [u, d, p, R]), Ht = M((h) => {
    if (!u || h.length === 0) return;
    const y = Un(
      d,
      p,
      u,
      te,
      h
    );
    y && (R(d, p), l(ot(y.nodes, y.edges, t.id)), b(y.edges), ne(!1), setTimeout(() => _ == null ? void 0 : _.fitView({ duration: 800 }), 50));
  }, [u, d, p, te, R, t.id, _]), Wt = (h, y) => {
    xe(!0);
    const N = d.find((z) => z.id === t.id) || d[0], k = {
      ...t,
      id: N.id,
      reason: h,
      message: y,
      nodes: d.map((z) => Dn(z, p))
    };
    setTimeout(() => {
      n(k), xe(!1), se(!1);
    }, 800);
  }, We = X(
    () => Hn({
      getNodes: () => Ae.current,
      getEdges: () => $e.current,
      getRootId: () => t.id,
      takeSnapshot: () => R(Ae.current, $e.current),
      setNodes: (h) => l(h),
      setEdges: (h) => b(h),
      // --- Viewport / selection: route to the LIVE reactflow instance and the
      // editor's selection state. None of these touch the hierarchy model. ---
      focusNode: (h, y) => {
        const N = Ne.current;
        if (!N) return !1;
        const k = N.getNode(h);
        return k ? (v(h), N.setCenter(
          k.position.x + (k.width || 200) / 2,
          k.position.y + (k.height || 100) / 2,
          { zoom: y ?? 1.2, duration: 800 }
        ), !0) : !1;
      },
      setSelection: (h) => {
        const y = new Set(h);
        l(
          (N) => N.map(
            (k) => k.selected === y.has(k.id) ? k : { ...k, selected: y.has(k.id) }
          )
        ), v(h.length > 0 ? h[0] : null);
      },
      fitView: () => {
        var h;
        (h = Ne.current) == null || h.fitView({ duration: 800 });
      },
      setZoom: (h, y) => {
        const N = Ne.current;
        return N ? (h === "in" ? N.zoomIn({ duration: 300 }) : h === "out" ? N.zoomOut({ duration: 300 }) : N.zoomTo(y ?? 1, { duration: 300 }), !0) : !1;
      }
    }),
    // nodesRef/edgesRef/reactFlowInstanceRef are stable refs; the closures read
    // .current at call time.
    [t.id, R]
  );
  B(() => {
    if (f)
      return f(We), () => {
        f(null);
      };
  }, [f, We]);
  const Te = d.find((h) => h.id === u) || null, Xe = !!G || !x || Q;
  return /* @__PURE__ */ e.jsx("div", { className: "flex flex-col h-full bg-white text-slate-900 font-sans", children: /* @__PURE__ */ e.jsxs(
    En,
    {
      onFetchMembers: o,
      iconMap: c,
      onRemoveEdge: Gt,
      onUpdateNode: Be,
      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(Rs, { 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: [
                  d.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: ze,
                disabled: !w,
                className: `p-2 rounded-lg transition-colors ${w ? "text-slate-600 hover:bg-slate-100" : "text-slate-300 cursor-not-allowed"}`,
                title: "Undo (Ctrl+Z)",
                children: /* @__PURE__ */ e.jsx(vn, { size: 18 })
              }
            ),
            /* @__PURE__ */ e.jsx(
              "button",
              {
                onClick: we,
                disabled: !A,
                className: `p-2 mr-2 rounded-lg transition-colors ${A ? "text-slate-600 hover:bg-slate-100" : "text-slate-300 cursor-not-allowed"}`,
                title: "Redo (Ctrl+Y)",
                children: /* @__PURE__ */ e.jsx(an, { size: 18 })
              }
            ),
            /* @__PURE__ */ e.jsx("div", { className: "h-6 w-px bg-slate-200 mx-1 hidden sm:block" }),
            /* @__PURE__ */ e.jsx(
              "button",
              {
                onClick: qt,
                className: "p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-50 rounded-lg",
                title: "Auto-arrange layout",
                children: /* @__PURE__ */ e.jsx(Xs, { size: 18 })
              }
            ),
            /* @__PURE__ */ e.jsx(
              "button",
              {
                onClick: () => J(!0),
                disabled: !u || u === t.id,
                className: `p-2 rounded-lg transition-colors ${u && u !== t.id ? "text-slate-400 hover:text-slate-600 hover:bg-slate-50" : "text-slate-300 cursor-not-allowed"}`,
                title: u && u !== t.id ? "Connect matching groups by regex" : "Select a group first to connect matches under it",
                children: /* @__PURE__ */ e.jsx(mt, { size: 18 })
              }
            ),
            /* @__PURE__ */ e.jsx(
              "button",
              {
                onClick: () => ne(!0),
                disabled: !u || te.length === 0,
                className: `p-2 rounded-lg transition-colors ${u && te.length > 0 ? "text-slate-400 hover:text-slate-600 hover:bg-slate-50" : "text-slate-300 cursor-not-allowed"}`,
                title: u && te.length > 0 ? "Restructure this group's children by prefix chunks" : "Select a group with child groups first",
                children: /* @__PURE__ */ e.jsx(ht, { 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(hn, { 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(Nn, { size: 18 })
              }
            ),
            /* @__PURE__ */ e.jsx(
              "button",
              {
                onClick: () => r({ id: t.id, nodes: d, edges: p }),
                className: "p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-50 rounded-lg mr-4",
                children: /* @__PURE__ */ e.jsx(Ys, { size: 18 })
              }
            ),
            /* @__PURE__ */ e.jsxs(
              "button",
              {
                onClick: () => se(!0),
                disabled: Xe,
                className: `
              flex items-center gap-2 px-4 py-2 rounded-lg font-medium text-sm transition-all shadow-sm
              ${Xe ? "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(cn, { 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: Pe, 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(qe, { size: 16 }) }),
                /* @__PURE__ */ e.jsx(
                  "input",
                  {
                    ref: ve,
                    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: T,
                    onChange: (h) => Fe(h.target.value),
                    onKeyDown: (h) => {
                      h.key === "Enter" && (h.preventDefault(), Mt());
                    }
                  }
                ),
                Y.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: [
                  q + 1,
                  "/",
                  Y.length
                ] }),
                T && Y.length === 0 && /* @__PURE__ */ e.jsx("div", { className: "absolute right-2 top-1/2 -translate-y-1/2 text-slate-300", children: /* @__PURE__ */ e.jsx(Z, { size: 14, className: "cursor-pointer hover:text-red-500", onClick: () => Fe("") }) })
              ] }),
              G && /* @__PURE__ */ e.jsxs(
                "div",
                {
                  onClick: Pt,
                  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(bt, { 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: G })
                    ] })
                  ]
                }
              )
            ] }),
            /* @__PURE__ */ e.jsxs(
              Qt,
              {
                nodes: d,
                edges: p,
                onNodesChange: St,
                onEdgesChange: Rt,
                onNodesDelete: Vt,
                onEdgesDelete: Ut,
                onNodeDragStart: Yt,
                onConnect: At,
                onConnectStart: $t,
                onConnectEnd: zt,
                onEdgeUpdate: It,
                onEdgeUpdateStart: Tt,
                onEdgeUpdateEnd: Dt,
                onNodeClick: Ot,
                onPaneClick: Lt,
                nodeTypes: be,
                edgeTypes: ye,
                onInit: ge,
                connectionMode: cs.Loose,
                onlyRenderVisibleElements: !0,
                fitView: !0,
                snapToGrid: !0,
                snapGrid: [15, 15],
                nodesDraggable: !D,
                nodesConnectable: !j,
                elementsSelectable: !0,
                deleteKeyCode: ["Delete", "Backspace"],
                className: "bg-slate-50",
                proOptions: { hideAttribution: !0 },
                zoomOnScroll: !0,
                panOnScroll: !1,
                children: [
                  /* @__PURE__ */ e.jsx(ds, { color: "#cbd5e1", gap: 20 }),
                  /* @__PURE__ */ e.jsx(
                    us,
                    {
                      nodeColor: (h) => h.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(hs, { 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: () => _ == null ? void 0 : _.zoomIn(), className: "p-2 hover:bg-slate-100 rounded text-slate-600", children: /* @__PURE__ */ e.jsx(ft, { size: 18 }) }),
                    /* @__PURE__ */ e.jsx("button", { onClick: () => _ == null ? void 0 : _.zoomOut(), className: "p-2 hover:bg-slate-100 rounded text-slate-600", children: /* @__PURE__ */ e.jsx(sn, { size: 18 }) }),
                    /* @__PURE__ */ e.jsx("div", { className: "h-px bg-slate-200 my-0.5 mx-2" }),
                    /* @__PURE__ */ e.jsx("button", { onClick: () => _ == null ? void 0 : _.fitView({ duration: 800 }), className: "p-2 hover:bg-slate-100 rounded text-slate-600", children: /* @__PURE__ */ e.jsx(en, { size: 18 }) })
                  ] })
                ]
              }
            )
          ] }),
          u && /* @__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(
            Pn,
            {
              node: Te,
              readOnly: j,
              onUpdateNode: Be,
              onClose: () => v(null)
            }
          ) })
        ] }),
        /* @__PURE__ */ e.jsx(
          Tn,
          {
            open: Re,
            onClose: () => se(!1),
            onSubmit: Wt,
            saving: Q
          }
        ),
        /* @__PURE__ */ e.jsx(
          In,
          {
            open: Me,
            parentNode: Te,
            candidates: Ft,
            onClose: () => J(!1),
            onConfirm: Bt
          }
        ),
        /* @__PURE__ */ e.jsx(
          Yn,
          {
            open: fe,
            parentNode: Te,
            candidates: te,
            onClose: () => ne(!1),
            onConfirm: Ht
          }
        )
      ]
    }
  ) });
}, er = ({ localKey: t, onFetchMembers: s, icons: a, ...n }) => /* @__PURE__ */ e.jsx(rs, { children: /* @__PURE__ */ e.jsx(
  Xn,
  {
    ...n,
    groupData: n.groupData,
    onFetchMembers: s,
    icons: a
  }
) });
var Jn = /* @__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))(Jn || {});
export {
  Nt as DiGraph,
  Jn as LocalKeys,
  Hn as buildGroupAiCapability,
  _e as createEmptyNode,
  er as default,
  Dn as groupFromNode,
  ot as layoutNodes,
  Qn as transformJsonToGraph
};
//# sourceMappingURL=index.js.map
