import { jsx as r, jsxs as a } from "react/jsx-runtime";
import { useState as n, useCallback as re, useEffect as fe } from "react";
import { useTranslation as Ne } from "react-i18next";
import { useNavigate as we, Link as Ge } from "react-router-dom";
import { a as Ce, k as te, B as Se } from "./index-CwSaRXXg.js";
import { Loader2 as L, Users as M, RefreshCw as ke, Plus as I, AlertTriangle as Ee, X as T, Search as Ae, Filter as Fe, Cloud as V, LayoutGrid as De, List as Me, CornerDownRight as ae, Shield as P, Building2 as se, GitBranch as ne, CloudOff as oe, Trash2 as ie, ChevronUp as Pe, ChevronDown as $e, Check as Re } from "lucide-react";
import { g as h } from "./groupsApi-BgCk2fsp.js";
const le = (t) => t ? "bg-[var(--color-accent-500)] text-white" : "text-[var(--text-tertiary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-hover)]";
function je(t) {
  const d = /* @__PURE__ */ new Map();
  for (const i of t) {
    const l = i.parentGroupId;
    d.has(l) || d.set(l, []), d.get(l).push(i);
  }
  const v = [], f = (i, l) => {
    const w = d.get(i) || [];
    for (const x of w)
      v.push({ item: x, depth: l }), f(x.id, l + 1);
  }, $ = new Set(t.map((i) => i.id)), N = t.filter((i) => !i.parentGroupId || !$.has(i.parentGroupId));
  for (const i of N)
    v.push({ item: i, depth: 0 }), f(i.id, 1);
  return v;
}
function Oe() {
  const { t } = Ne(["admin", "common"]), d = we(), { currentTenant: v, isGlobalView: f } = Ce(), [$, N] = n(!0), [i, l] = n([]), [w, x] = n([]), [B, c] = n(null), [G, ce] = n(""), [m, C] = n(null), [de, R] = n(!1), [me, S] = n(!1), [k, U] = n(null), [u, ue] = n({}), [j, z] = n(null), [E, O] = n("cards"), [b, pe] = n("all"), [g, xe] = n("all"), [A, Q] = n(""), [H, K] = n(""), [F, X] = n(!0), [q, J] = n(""), [W, Y] = n(!1), y = re(async () => {
    try {
      N(!0), c(null);
      const [e, s] = await Promise.all([
        h.getAll(),
        te.roles.getAssignable()
      ]);
      l(Array.isArray(e) ? e : []), x(Array.isArray(s) ? s : []);
    } catch (e) {
      console.error("Failed to load groups:", e), l([]), x([]);
      const s = e;
      s.response?.status === 401 ? c(t("common:errors.sessionExpired")) : s.response?.status === 403 ? c(t("common:errors.noPermission")) : c(t("admin:groups.loadError"));
    } finally {
      N(!1);
    }
  }, [t, v?.id, f]);
  fe(() => {
    y();
  }, [y]);
  const he = async (e) => {
    if (u[e]) {
      U(k === e ? null : e);
      return;
    }
    z(e);
    try {
      const s = await h.getMembers(e);
      ue((o) => ({ ...o, [e]: s })), U(e);
    } catch (s) {
      console.error("Failed to load members:", s), c(t("admin:groups.loadError"));
    } finally {
      z(null);
    }
  }, ve = re(async () => {
    const [e, s] = await Promise.all([
      h.getAll(),
      te.roles.getAssignable()
    ]), o = Array.isArray(e) ? e : [];
    return l(o), x(Array.isArray(s) ? s : []), o;
  }, []), be = async () => {
    if (A.trim()) {
      Y(!0);
      try {
        await h.create({
          name: A.trim(),
          description: H.trim() || void 0,
          isSecurityGroup: F,
          parentGroupId: q || void 0
        }), await y(), S(!1), Q(""), K(""), X(!0), J("");
      } catch (e) {
        console.error("Failed to create group:", e);
        const s = e;
        s.response?.status === 409 ? c(s.response.data?.message || t("admin:groups.createError")) : c(t("admin:groups.createError"));
      } finally {
        Y(!1);
      }
    }
  }, Z = async (e, s, o = !1) => {
    const p = o ? t("admin:groups.deleteConfirmEntra", { name: s, defaultValue: `Le groupe "${s}" est synchronisé depuis Entra ID. Il sera recréé lors de la prochaine synchronisation.

Êtes-vous sûr de vouloir le supprimer ?` }) : t("admin:groups.deleteConfirm", { name: s });
    if (confirm(p))
      try {
        await h.delete(e), await y();
      } catch (ye) {
        console.error("Failed to delete group:", ye), c(t("admin:groups.deleteError"));
      }
  }, ge = async (e) => {
    if (m)
      try {
        await h.assignRole(m.id, { roleId: e });
        const o = (await ve()).find((p) => p.id === m.id);
        o && C(o);
      } catch (s) {
        console.error("Failed to assign role:", s), c(t("admin:groups.assignError"));
      }
  }, D = i.filter((e) => {
    const s = e.name.toLowerCase().includes(G.toLowerCase()) || e.description?.toLowerCase().includes(G.toLowerCase()), o = b === "all" || b === "security" && e.isSecurityGroup || b === "distribution" && !e.isSecurityGroup, p = g === "all" || g === "local" && !e.isSyncedFromEntra || g === "synced" && e.isSyncedFromEntra;
    return s && o && p;
  }), _ = je(D), ee = (e) => e ? new Intl.DateTimeFormat("fr-FR", {
    dateStyle: "medium",
    timeStyle: "short"
  }).format(new Date(e)) : "-";
  return $ ? /* @__PURE__ */ r("div", { className: "flex items-center justify-center min-h-[400px]", children: /* @__PURE__ */ r(L, { className: "w-8 h-8 animate-spin text-[var(--color-accent-500)]" }) }) : /* @__PURE__ */ a("div", { className: "space-y-6", children: [
    /* @__PURE__ */ r(
      Se,
      {
        items: [
          { label: t("admin:header.title"), href: "/administration" },
          { label: t("admin:users.title", "Users"), href: "/administration/users" },
          { label: t("admin:groups.title", "Groups") }
        ]
      }
    ),
    /* @__PURE__ */ a("div", { className: "flex items-center justify-between", children: [
      /* @__PURE__ */ a("div", { className: "flex items-center gap-3", children: [
        /* @__PURE__ */ r("div", { className: "p-2 rounded-[var(--radius-button)] bg-[var(--color-accent-500)]/10", children: /* @__PURE__ */ r(M, { className: "w-6 h-6 text-[var(--color-accent-500)]" }) }),
        /* @__PURE__ */ a("div", { children: [
          /* @__PURE__ */ r("h1", { className: "text-2xl font-bold text-[var(--text-primary)]", children: t("admin:groups.title") }),
          /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-secondary)]", children: t("admin:groups.subtitle", { count: i.length }) })
        ] })
      ] }),
      /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
        /* @__PURE__ */ a(
          "button",
          {
            onClick: y,
            className: "inline-flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-[var(--radius-button)] border border-[var(--border-color)] bg-[var(--bg-secondary)] text-[var(--text-primary)] hover:bg-[var(--bg-hover)] transition-colors",
            children: [
              /* @__PURE__ */ r(ke, { className: "w-4 h-4" }),
              t("common:refresh")
            ]
          }
        ),
        /* @__PURE__ */ a(
          "button",
          {
            onClick: () => S(!0),
            className: "inline-flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-[var(--radius-button)] bg-[var(--color-accent-600)] text-white hover:bg-[var(--color-accent-700)] transition-colors",
            children: [
              /* @__PURE__ */ r(I, { className: "w-4 h-4" }),
              t("admin:groups.createGroup")
            ]
          }
        )
      ] })
    ] }),
    B && /* @__PURE__ */ r("div", { className: "p-4 rounded-[var(--radius-card)] bg-[var(--error-bg)] border border-[var(--error-border)]", children: /* @__PURE__ */ a("div", { className: "flex items-center gap-2 text-[var(--error-text)]", children: [
      /* @__PURE__ */ r(Ee, { className: "w-5 h-5" }),
      /* @__PURE__ */ r("span", { children: B }),
      /* @__PURE__ */ r(
        "button",
        {
          onClick: () => c(null),
          className: "ml-auto p-1 hover:bg-[var(--error-text)]/10 rounded",
          children: /* @__PURE__ */ r(T, { className: "w-4 h-4" })
        }
      )
    ] }) }),
    /* @__PURE__ */ a("div", { className: "flex flex-col sm:flex-row gap-4", children: [
      /* @__PURE__ */ a("div", { className: "relative flex-1", children: [
        /* @__PURE__ */ r(Ae, { className: "absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-[var(--text-tertiary)]" }),
        /* @__PURE__ */ r(
          "input",
          {
            type: "text",
            placeholder: t("admin:groups.searchPlaceholder"),
            value: G,
            onChange: (e) => ce(e.target.value),
            className: "w-full pl-10 pr-4 py-2 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-primary)] text-[var(--text-primary)] placeholder:text-[var(--text-tertiary)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)]"
          }
        )
      ] }),
      /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
        /* @__PURE__ */ r(Fe, { className: "w-4 h-4 text-[var(--text-tertiary)]" }),
        /* @__PURE__ */ a(
          "select",
          {
            value: b,
            onChange: (e) => pe(e.target.value),
            className: "px-3 py-2 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-primary)] text-[var(--text-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)]",
            children: [
              /* @__PURE__ */ r("option", { value: "all", children: t("admin:groups.allTypes") }),
              /* @__PURE__ */ r("option", { value: "security", children: t("admin:groups.securityGroup") }),
              /* @__PURE__ */ r("option", { value: "distribution", children: t("admin:groups.distributionGroup") })
            ]
          }
        )
      ] }),
      /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
        /* @__PURE__ */ r(V, { className: "w-4 h-4 text-[var(--text-tertiary)]" }),
        /* @__PURE__ */ a(
          "select",
          {
            value: g,
            onChange: (e) => xe(e.target.value),
            className: "px-3 py-2 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-primary)] text-[var(--text-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)]",
            children: [
              /* @__PURE__ */ r("option", { value: "all", children: t("admin:groups.allSyncStatus") }),
              /* @__PURE__ */ r("option", { value: "local", children: t("admin:groups.localOnly") }),
              /* @__PURE__ */ r("option", { value: "synced", children: t("admin:groups.syncedFromEntra") })
            ]
          }
        )
      ] }),
      /* @__PURE__ */ a("div", { className: "flex items-center gap-1 p-1 rounded-[var(--radius-button)] bg-[var(--bg-secondary)] border border-[var(--border-color)]", children: [
        /* @__PURE__ */ r(
          "button",
          {
            onClick: () => O("cards"),
            className: `p-2 rounded-[var(--radius-button)] transition-colors ${le(E === "cards")}`,
            title: t("admin:groups.cardView"),
            children: /* @__PURE__ */ r(De, { className: "w-4 h-4" })
          }
        ),
        /* @__PURE__ */ r(
          "button",
          {
            onClick: () => O("table"),
            className: `p-2 rounded-[var(--radius-button)] transition-colors ${le(E === "table")}`,
            title: t("admin:groups.tableView"),
            children: /* @__PURE__ */ r(Me, { className: "w-4 h-4" })
          }
        )
      ] })
    ] }),
    D.length === 0 && /* @__PURE__ */ r("div", { className: "text-center py-12 text-[var(--text-secondary)]", children: t(G || b !== "all" || g !== "all" ? "admin:groups.noResults" : "admin:groups.noGroups") }),
    D.length > 0 && E === "table" && /* Table View */
    /* @__PURE__ */ r("div", { className: "rounded-[var(--radius-card)] border border-[var(--border-color)] overflow-hidden", children: /* @__PURE__ */ a("table", { className: "w-full", children: [
      /* @__PURE__ */ r("thead", { className: "bg-[var(--bg-secondary)]", children: /* @__PURE__ */ a("tr", { children: [
        /* @__PURE__ */ r("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: t("admin:groups.groupName") }),
        /* @__PURE__ */ r("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: t("admin:groups.parentGroup") }),
        /* @__PURE__ */ r("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: t("common:type") }),
        /* @__PURE__ */ r("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: t("admin:groups.source") }),
        /* @__PURE__ */ r("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: t("admin:groups.members") }),
        /* @__PURE__ */ r("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: t("admin:groups.assignedRoles") }),
        /* @__PURE__ */ r("th", { className: "px-4 py-3 text-right text-sm font-medium text-[var(--text-secondary)]", children: t("common:actionsColumn") })
      ] }) }),
      /* @__PURE__ */ r("tbody", { className: "divide-y divide-[var(--border-color)]", children: _.map(({ item: e, depth: s }) => /* @__PURE__ */ a("tr", { className: "hover:bg-[var(--bg-hover)] cursor-pointer", onClick: () => d(`/administration/users/groups/${e.id}`), children: [
        /* @__PURE__ */ r("td", { className: "px-4 py-3", children: /* @__PURE__ */ a("div", { className: "flex items-center gap-3", style: { paddingLeft: `${s * 24}px` }, children: [
          s > 0 && /* @__PURE__ */ r(ae, { className: "w-4 h-4 text-[var(--text-tertiary)] flex-shrink-0" }),
          /* @__PURE__ */ r("div", { className: `w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0 ${e.isSecurityGroup ? "bg-blue-500/10 text-blue-500" : "bg-[var(--color-accent-500)]/10 text-[var(--color-accent-500)]"}`, children: e.isSecurityGroup ? /* @__PURE__ */ r(P, { className: "w-4 h-4" }) : /* @__PURE__ */ r(se, { className: "w-4 h-4" }) }),
          /* @__PURE__ */ a("div", { children: [
            /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
              /* @__PURE__ */ r("span", { className: "font-medium text-[var(--text-primary)] hover:text-[var(--color-accent-500)] hover:underline", children: e.name }),
              e.childCount > 0 && /* @__PURE__ */ a("span", { className: "flex items-center gap-0.5 px-1.5 py-0.5 text-xs rounded-[var(--radius-badge)] bg-[var(--bg-tertiary)] text-[var(--text-tertiary)]", children: [
                /* @__PURE__ */ r(ne, { className: "w-3 h-3" }),
                e.childCount
              ] })
            ] }),
            e.description && /* @__PURE__ */ r("p", { className: "text-xs text-[var(--text-tertiary)] truncate max-w-xs", children: e.description })
          ] })
        ] }) }),
        /* @__PURE__ */ r("td", { className: "px-4 py-3 text-sm text-[var(--text-secondary)]", children: e.parentGroupName ? /* @__PURE__ */ r("span", { className: "text-[var(--text-secondary)]", children: e.parentGroupName }) : /* @__PURE__ */ r("span", { className: "text-[var(--text-tertiary)]", children: "-" }) }),
        /* @__PURE__ */ r("td", { className: "px-4 py-3", children: /* @__PURE__ */ r("span", { className: `px-2 py-1 text-xs rounded-[var(--radius-badge)] ${e.isSecurityGroup ? "bg-blue-500/10 text-blue-500" : "bg-purple-500/10 text-purple-500"}`, children: e.isSecurityGroup ? t("admin:groups.securityGroup") : t("admin:groups.distributionGroup") }) }),
        /* @__PURE__ */ r("td", { className: "px-4 py-3", children: e.isSyncedFromEntra ? /* @__PURE__ */ a("span", { className: "flex items-center gap-1 text-sm text-blue-500", children: [
          /* @__PURE__ */ r(V, { className: "w-4 h-4" }),
          "Entra"
        ] }) : /* @__PURE__ */ a("span", { className: "flex items-center gap-1 text-sm text-[var(--text-tertiary)]", children: [
          /* @__PURE__ */ r(oe, { className: "w-4 h-4" }),
          t("admin:groups.local")
        ] }) }),
        /* @__PURE__ */ r("td", { className: "px-4 py-3 text-sm text-[var(--text-secondary)]", children: /* @__PURE__ */ a("span", { className: "flex items-center gap-1", children: [
          /* @__PURE__ */ r(M, { className: "w-4 h-4" }),
          e.memberCount
        ] }) }),
        /* @__PURE__ */ r("td", { className: "px-4 py-3", children: /* @__PURE__ */ a("div", { className: "flex flex-wrap gap-1", children: [
          e.roles.slice(0, 2).map((o, p) => /* @__PURE__ */ r(
            "span",
            {
              className: "px-2 py-0.5 text-xs rounded-[var(--radius-badge)] bg-[var(--color-accent-500)]/10 text-[var(--color-accent-500)]",
              children: o
            },
            `${e.id}-role-${p}`
          )),
          e.roles.length > 2 && /* @__PURE__ */ a("span", { className: "px-2 py-0.5 text-xs rounded-[var(--radius-badge)] bg-[var(--bg-tertiary)] text-[var(--text-tertiary)]", children: [
            "+",
            e.roles.length - 2
          ] })
        ] }) }),
        /* @__PURE__ */ r("td", { className: "px-4 py-3 text-right", onClick: (o) => o.stopPropagation(), children: /* @__PURE__ */ a("div", { className: "flex items-center justify-end gap-2", children: [
          /* @__PURE__ */ r(
            "button",
            {
              onClick: () => {
                C(e), R(!0);
              },
              className: "p-2 rounded-[var(--radius-button)] text-[var(--text-tertiary)] hover:text-[var(--color-accent-500)] hover:bg-[var(--bg-hover)] transition-colors",
              title: t("admin:groups.assignRole"),
              children: /* @__PURE__ */ r(I, { className: "w-4 h-4" })
            }
          ),
          /* @__PURE__ */ r(
            "button",
            {
              onClick: () => Z(e.id, e.name, e.isSyncedFromEntra),
              className: "p-2 rounded-[var(--radius-button)] text-[var(--text-tertiary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)] transition-colors",
              title: t("common:delete"),
              children: /* @__PURE__ */ r(ie, { className: "w-4 h-4" })
            }
          )
        ] }) })
      ] }, e.id)) })
    ] }) }),
    D.length > 0 && E !== "table" && /* Cards View */
    /* @__PURE__ */ r("div", { className: "grid grid-cols-1 lg:grid-cols-2 gap-4", children: _.map(({ item: e }) => /* @__PURE__ */ a(
      "div",
      {
        role: "button",
        tabIndex: 0,
        className: "rounded-[var(--radius-card)] border border-[var(--border-color)] bg-[var(--bg-secondary)] overflow-hidden hover:border-[var(--color-accent-500)] transition-colors cursor-pointer text-left flex flex-col",
        onClick: () => d(`/administration/users/groups/${e.id}`),
        onKeyDown: (s) => {
          (s.key === "Enter" || s.key === " ") && (s.preventDefault(), d(`/administration/users/groups/${e.id}`));
        },
        children: [
          /* @__PURE__ */ a("div", { className: "p-4 flex-1", children: [
            /* @__PURE__ */ a("div", { className: "flex items-start justify-between gap-4", children: [
              /* @__PURE__ */ a("div", { className: "flex items-start gap-3 min-w-0", children: [
                /* @__PURE__ */ r("div", { className: `p-2.5 rounded-[var(--radius-button)] flex-shrink-0 ${e.isSecurityGroup ? "bg-blue-500/10 text-blue-500" : "bg-[var(--color-accent-500)]/10 text-[var(--color-accent-500)]"}`, children: e.isSecurityGroup ? /* @__PURE__ */ r(P, { className: "w-5 h-5" }) : /* @__PURE__ */ r(se, { className: "w-5 h-5" }) }),
                /* @__PURE__ */ a("div", { className: "min-w-0", children: [
                  /* @__PURE__ */ a("div", { className: "flex items-center gap-2 flex-wrap", children: [
                    /* @__PURE__ */ r("span", { className: "font-semibold text-[var(--text-primary)] truncate", children: e.name }),
                    e.isSecurityGroup && /* @__PURE__ */ r("span", { className: "px-2 py-0.5 text-xs rounded-[var(--radius-badge)] bg-blue-500/10 text-blue-500 border border-blue-500/20", children: t("admin:groups.securityGroup") }),
                    !e.isActive && /* @__PURE__ */ r("span", { className: "px-2 py-0.5 text-xs rounded-[var(--radius-badge)] bg-[var(--warning-bg)] text-[var(--warning-text)] border border-[var(--warning-border)]", children: t("common:inactive") }),
                    e.isSyncedFromEntra ? /* @__PURE__ */ a("span", { className: "px-2 py-0.5 text-xs rounded-[var(--radius-badge)] bg-blue-500/10 text-blue-500 border border-blue-500/20 flex items-center gap-1", children: [
                      /* @__PURE__ */ r(V, { className: "w-3 h-3" }),
                      "Entra"
                    ] }) : /* @__PURE__ */ a("span", { className: "px-2 py-0.5 text-xs rounded-[var(--radius-badge)] bg-[var(--bg-tertiary)] text-[var(--text-tertiary)] border border-[var(--border-color)] flex items-center gap-1", children: [
                      /* @__PURE__ */ r(oe, { className: "w-3 h-3" }),
                      t("admin:groups.local")
                    ] }),
                    e.parentGroupName && /* @__PURE__ */ a("span", { className: "px-2 py-0.5 text-xs rounded-[var(--radius-badge)] bg-[var(--bg-tertiary)] text-[var(--text-tertiary)] border border-[var(--border-color)] flex items-center gap-1", children: [
                      /* @__PURE__ */ r(ae, { className: "w-3 h-3" }),
                      e.parentGroupName
                    ] }),
                    e.childCount > 0 && /* @__PURE__ */ a("span", { className: "px-2 py-0.5 text-xs rounded-[var(--radius-badge)] bg-[var(--bg-tertiary)] text-[var(--text-tertiary)] border border-[var(--border-color)] flex items-center gap-1", children: [
                      /* @__PURE__ */ r(ne, { className: "w-3 h-3" }),
                      t("admin:groups.childGroupCount", { count: e.childCount })
                    ] })
                  ] }),
                  e.description && /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-secondary)] mt-1 line-clamp-2", children: e.description }),
                  /* @__PURE__ */ r("div", { className: "flex items-center gap-4 mt-2 text-sm text-[var(--text-tertiary)] flex-wrap", onClick: (s) => s.stopPropagation(), children: /* @__PURE__ */ a(
                    "button",
                    {
                      onClick: (s) => {
                        s.stopPropagation(), he(e.id);
                      },
                      className: "flex items-center gap-1 hover:text-[var(--color-accent-500)] transition-colors",
                      children: [
                        /* @__PURE__ */ r(M, { className: "w-4 h-4" }),
                        t("admin:groups.memberCount", { count: e.memberCount }),
                        j === e.id && /* @__PURE__ */ r(L, { className: "w-3 h-3 animate-spin ml-1" }),
                        j !== e.id && k === e.id && /* @__PURE__ */ r(Pe, { className: "w-3 h-3 ml-1" }),
                        j !== e.id && k !== e.id && /* @__PURE__ */ r($e, { className: "w-3 h-3 ml-1" })
                      ]
                    }
                  ) }),
                  e.isSyncedFromEntra && e.lastEntraSyncAt && /* @__PURE__ */ r("p", { className: "text-xs text-[var(--text-tertiary)] mt-1", children: t("admin:groups.lastSynced", { date: ee(e.lastEntraSyncAt) }) }),
                  !e.isSyncedFromEntra && /* @__PURE__ */ r("p", { className: "text-xs text-[var(--text-tertiary)] mt-1", children: t("admin:groups.createdAt", { date: ee(e.createdAt) }) })
                ] })
              ] }),
              /* @__PURE__ */ a("div", { className: "flex flex-col gap-2 flex-shrink-0", onClick: (s) => s.stopPropagation(), children: [
                /* @__PURE__ */ a(
                  "button",
                  {
                    onClick: (s) => {
                      s.stopPropagation(), C(e), R(!0);
                    },
                    className: "inline-flex items-center gap-1 px-3 py-1.5 text-sm font-medium rounded-[var(--radius-button)] bg-[var(--color-accent-600)] text-white hover:bg-[var(--color-accent-700)] transition-colors",
                    children: [
                      /* @__PURE__ */ r(I, { className: "w-4 h-4" }),
                      t("admin:groups.assignRole")
                    ]
                  }
                ),
                /* @__PURE__ */ a(
                  "button",
                  {
                    onClick: (s) => {
                      s.stopPropagation(), Z(e.id, e.name, e.isSyncedFromEntra);
                    },
                    className: "inline-flex items-center gap-1 px-3 py-1.5 text-sm font-medium rounded-[var(--radius-button)] border border-[var(--error-border)] text-[var(--error-text)] hover:bg-[var(--error-bg)] transition-colors",
                    children: [
                      /* @__PURE__ */ r(ie, { className: "w-4 h-4" }),
                      t("common:delete")
                    ]
                  }
                )
              ] })
            ] }),
            e.roles.length > 0 && /* @__PURE__ */ a("div", { className: "mt-4 pt-4 border-t border-[var(--border-color)]", children: [
              /* @__PURE__ */ r("h4", { className: "text-sm font-medium text-[var(--text-primary)] mb-2", children: t("admin:groups.assignedRoles") }),
              /* @__PURE__ */ r("div", { className: "flex flex-wrap gap-2", children: e.roles.map((s, o) => /* @__PURE__ */ a(
                "span",
                {
                  className: "inline-flex items-center gap-2 px-3 py-1.5 rounded-[var(--radius-badge)] bg-[var(--bg-primary)] border border-[var(--border-color)]",
                  children: [
                    /* @__PURE__ */ r(P, { className: "w-4 h-4 text-[var(--color-accent-500)]" }),
                    /* @__PURE__ */ r("span", { className: "text-sm text-[var(--text-primary)]", children: s })
                  ]
                },
                `${e.id}-role-${o}`
              )) })
            ] })
          ] }),
          k === e.id && u[e.id] && /* @__PURE__ */ r("div", { className: "border-t border-[var(--border-color)] bg-[var(--bg-primary)]", children: /* @__PURE__ */ a("div", { className: "p-4", children: [
            /* @__PURE__ */ a("h4", { className: "text-sm font-medium text-[var(--text-primary)] mb-3 flex items-center gap-2", children: [
              /* @__PURE__ */ r(M, { className: "w-4 h-4" }),
              t("admin:groups.members"),
              " (",
              u[e.id].length,
              ")"
            ] }),
            u[e.id].length === 0 ? /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-tertiary)]", children: t("admin:groups.noMembers") }) : /* @__PURE__ */ r("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-2 max-h-64 overflow-y-auto", children: u[e.id].slice(0, 10).map((s) => /* @__PURE__ */ a(
              Ge,
              {
                to: `/administration/users/${s.userId}`,
                className: "flex items-center gap-3 p-2 rounded-[var(--radius-button)] hover:bg-[var(--bg-hover)] transition-colors",
                children: [
                  /* @__PURE__ */ r("div", { className: "w-8 h-8 rounded-full flex items-center justify-center text-sm font-medium bg-[var(--color-accent-500)]/10 text-[var(--color-accent-500)]", children: s.fullName.charAt(0).toUpperCase() }),
                  /* @__PURE__ */ a("div", { className: "min-w-0", children: [
                    /* @__PURE__ */ r("p", { className: "text-sm font-medium text-[var(--text-primary)] truncate", children: s.fullName }),
                    /* @__PURE__ */ r("p", { className: "text-xs text-[var(--text-tertiary)] truncate", children: s.email })
                  ] })
                ]
              },
              s.userId
            )) }),
            u[e.id].length > 10 && /* @__PURE__ */ r("p", { className: "mt-3 text-center text-sm text-[var(--text-tertiary)]", children: t("admin:groups.showingMembers", {
              shown: 10,
              total: u[e.id].length
            }) })
          ] }) })
        ]
      },
      e.id
    )) }),
    me && /* @__PURE__ */ r("div", { className: "fixed inset-0 z-50 flex items-center justify-center bg-black/50", children: /* @__PURE__ */ a("div", { className: "w-full max-w-md rounded-[var(--radius-card)] bg-[var(--bg-secondary)] border border-[var(--border-color)] shadow-xl", children: [
      /* @__PURE__ */ a("div", { className: "flex items-center justify-between p-4 border-b border-[var(--border-color)]", children: [
        /* @__PURE__ */ r("h2", { className: "text-lg font-semibold text-[var(--text-primary)]", children: t("admin:groups.createGroup") }),
        /* @__PURE__ */ r(
          "button",
          {
            onClick: () => S(!1),
            className: "p-1 rounded hover:bg-[var(--bg-hover)] text-[var(--text-tertiary)]",
            children: /* @__PURE__ */ r(T, { className: "w-5 h-5" })
          }
        )
      ] }),
      /* @__PURE__ */ a("div", { className: "p-4 space-y-4", children: [
        /* @__PURE__ */ a("div", { children: [
          /* @__PURE__ */ a("label", { className: "block text-sm font-medium text-[var(--text-primary)] mb-1", children: [
            t("admin:groups.groupName"),
            " *"
          ] }),
          /* @__PURE__ */ r(
            "input",
            {
              type: "text",
              value: A,
              onChange: (e) => Q(e.target.value),
              placeholder: t("admin:groups.groupNamePlaceholder"),
              className: "w-full px-3 py-2 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-primary)] text-[var(--text-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)]"
            }
          )
        ] }),
        /* @__PURE__ */ a("div", { children: [
          /* @__PURE__ */ r("label", { className: "block text-sm font-medium text-[var(--text-primary)] mb-1", children: t("common:description") }),
          /* @__PURE__ */ r(
            "textarea",
            {
              value: H,
              onChange: (e) => K(e.target.value),
              placeholder: t("admin:groups.descriptionPlaceholder"),
              rows: 3,
              className: "w-full px-3 py-2 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-primary)] text-[var(--text-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)] resize-none"
            }
          )
        ] }),
        /* @__PURE__ */ a("div", { className: "flex items-center gap-3", children: [
          /* @__PURE__ */ r(
            "button",
            {
              type: "button",
              onClick: () => X(!F),
              className: `relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${F ? "bg-[var(--color-accent-500)]" : "bg-[var(--bg-tertiary)]"}`,
              children: /* @__PURE__ */ r(
                "span",
                {
                  className: `inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${F ? "translate-x-6" : "translate-x-1"}`
                }
              )
            }
          ),
          /* @__PURE__ */ r("span", { className: "text-sm text-[var(--text-primary)]", children: t("admin:groups.isSecurityGroup") })
        ] }),
        /* @__PURE__ */ a("div", { children: [
          /* @__PURE__ */ r("label", { className: "block text-sm font-medium text-[var(--text-primary)] mb-1", children: t("admin:groups.parentGroup") }),
          /* @__PURE__ */ a(
            "select",
            {
              value: q,
              onChange: (e) => J(e.target.value),
              className: "w-full px-3 py-2 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-primary)] text-[var(--text-primary)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)]",
              children: [
                /* @__PURE__ */ r("option", { value: "", children: t("admin:groups.noParent") }),
                i.filter((e) => e.isActive).map((e) => /* @__PURE__ */ r("option", { value: e.id, children: e.name }, e.id))
              ]
            }
          )
        ] })
      ] }),
      /* @__PURE__ */ a("div", { className: "flex items-center justify-end gap-3 p-4 border-t border-[var(--border-color)]", children: [
        /* @__PURE__ */ r(
          "button",
          {
            onClick: () => S(!1),
            className: "px-4 py-2 text-sm font-medium rounded-[var(--radius-button)] border border-[var(--border-color)] text-[var(--text-primary)] hover:bg-[var(--bg-hover)] transition-colors",
            children: t("common:cancel")
          }
        ),
        /* @__PURE__ */ a(
          "button",
          {
            onClick: be,
            disabled: !A.trim() || W,
            className: "inline-flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-[var(--radius-button)] bg-[var(--color-accent-600)] text-white hover:bg-[var(--color-accent-700)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",
            children: [
              W ? /* @__PURE__ */ r(L, { className: "w-4 h-4 animate-spin" }) : /* @__PURE__ */ r(Re, { className: "w-4 h-4" }),
              t("common:create")
            ]
          }
        )
      ] })
    ] }) }),
    de && m && /* @__PURE__ */ r("div", { className: "fixed inset-0 z-50 flex items-center justify-center bg-black/50", children: /* @__PURE__ */ a("div", { className: "w-full max-w-md rounded-[var(--radius-card)] bg-[var(--bg-secondary)] border border-[var(--border-color)] shadow-xl", children: [
      /* @__PURE__ */ a("div", { className: "flex items-center justify-between p-4 border-b border-[var(--border-color)]", children: [
        /* @__PURE__ */ r("h2", { className: "text-lg font-semibold text-[var(--text-primary)]", children: t("admin:groups.assignRoleTitle") }),
        /* @__PURE__ */ r(
          "button",
          {
            onClick: () => {
              R(!1), C(null);
            },
            className: "p-1 rounded hover:bg-[var(--bg-hover)] text-[var(--text-tertiary)]",
            children: /* @__PURE__ */ r(T, { className: "w-5 h-5" })
          }
        )
      ] }),
      /* @__PURE__ */ a("div", { className: "p-4", children: [
        /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-secondary)] mb-4", children: t("admin:groups.assignRoleDescription", { group: m.name }) }),
        /* @__PURE__ */ a("div", { className: "space-y-2 max-h-64 overflow-y-auto", children: [
          w.filter((e) => !m.roles.includes(e.name)).map((e) => /* @__PURE__ */ a(
            "button",
            {
              onClick: () => ge(e.id),
              className: "w-full flex items-center gap-3 p-3 rounded-[var(--radius-button)] border border-[var(--border-color)] hover:border-[var(--color-accent-500)] hover:bg-[var(--bg-hover)] transition-colors text-left",
              children: [
                /* @__PURE__ */ r(P, { className: "w-5 h-5 text-[var(--color-accent-500)]" }),
                /* @__PURE__ */ a("div", { children: [
                  /* @__PURE__ */ r("p", { className: "font-medium text-[var(--text-primary)]", children: e.name }),
                  e.description && /* @__PURE__ */ r("p", { className: "text-xs text-[var(--text-tertiary)]", children: e.description })
                ] })
              ]
            },
            e.id
          )),
          w.filter((e) => !m.roles.includes(e.name)).length === 0 && /* @__PURE__ */ r("p", { className: "text-sm text-[var(--text-tertiary)] text-center py-4", children: t("admin:groups.allRolesAssigned") })
        ] })
      ] })
    ] }) })
  ] });
}
export {
  Oe as UsersGroupsPage
};
//# sourceMappingURL=UsersGroupsPage-CmdaU-z-.js.map
