import { jsx as e, jsxs as t, Fragment as er } from "react/jsx-runtime";
import Le, { useState as d, useMemo as te, useCallback as S, createRef as rr, useEffect as je } from "react";
import { useParams as tr, useNavigate as ar, Link as Ee } from "react-router-dom";
import { useTranslation as He } from "react-i18next";
import { o as sr, s as lr, x as nr, y as or, k as N, B as ir } from "./index-CwSaRXXg.js";
import { Loader2 as g, AlertCircle as Ue, Check as Ge, X as Ne, Save as _e, Star as cr, Eye as $e, Ban as dr, ChevronRight as Ie, ChevronDown as Me, FolderOpen as mr, Database as ur, FileText as vr, Box as pr, Play as xr, UserPlus as br, Trash2 as we, Edit as hr, Plus as Ce, Shield as Pe, Settings as gr, Users as Oe, UsersRound as Te, Languages as fr, ArrowLeft as yr, Lock as Be, AlertTriangle as Nr, CheckCircle as wr, Search as ze, Edit2 as Cr } from "lucide-react";
import { g as Dr } from "./groupsApi-BgCk2fsp.js";
import { d as kr, c as Sr, g as Rr, a as Ar, P as Tr, b as Lr } from "./PermissionPopover-CR6SD8ch.js";
const $r = {
  "*": /* @__PURE__ */ e(Pe, { className: "h-3 w-3" }),
  read: /* @__PURE__ */ e($e, { className: "h-3 w-3" }),
  create: /* @__PURE__ */ e(Ce, { className: "h-3 w-3" }),
  update: /* @__PURE__ */ e(hr, { className: "h-3 w-3" }),
  delete: /* @__PURE__ */ e(we, { className: "h-3 w-3" }),
  assign: /* @__PURE__ */ e(br, { className: "h-3 w-3" }),
  execute: /* @__PURE__ */ e(xr, { className: "h-3 w-3" })
}, Pr = {
  "*": "bg-[var(--accent-bg)] text-[var(--accent-text)] border-[var(--accent-border)]",
  read: "bg-[var(--info-bg)] text-[var(--info-text)] border-[var(--info-border)]",
  create: "bg-[var(--success-bg)] text-[var(--success-text)] border-[var(--success-border)]",
  update: "bg-[var(--warning-bg)] text-[var(--warning-text)] border-[var(--warning-border)]",
  delete: "bg-[var(--error-bg)] text-[var(--error-text)] border-[var(--error-border)]",
  assign: "bg-[var(--accent-bg)] text-[var(--accent-text)] border-[var(--accent-border)]",
  execute: "bg-[var(--warning-bg)] text-[var(--warning-text)] border-[var(--warning-border)]"
};
function Fr(a, l, p) {
  return a.filter((i) => l === "all" || i.application === l).map((i) => ({
    ...i,
    modules: i.modules.filter((R) => p === "all" || R.module.moduleLabel === p)
  })).filter((i) => i.modules.length > 0);
}
function jr(a, l, p) {
  return a.map((i) => ({
    ...i,
    modules: i.modules.filter((R) => {
      const { status: P } = p(R);
      return l.has(P);
    })
  })).filter((i) => i.modules.length > 0);
}
function Er({
  section: a,
  resources: l,
  moduleIndex: p,
  sectionIndex: i,
  collapsedSections: R,
  renderResourceRow: P
}) {
  const M = l.length > 0, O = R.has(a.id);
  return /* @__PURE__ */ t(Le.Fragment, { children: [
    P(a, p + i + 1, "section", M, O),
    M && !O && l.map(
      (_, m) => P(_, p + i + m + 2, "resource", !1, !1)
    )
  ] }, a.id);
}
function Ur({ roleId: a }) {
  const { t: l } = He("admin"), { user: p } = sr(), { collapsedApps: i, toggleApp: R } = lr(), [P, M] = d(/* @__PURE__ */ new Set()), [O, _] = d(/* @__PURE__ */ new Set()), [m, de] = d(/* @__PURE__ */ new Set()), [ae, x] = d(null), [F, w] = d("all"), [b, A] = d("all"), se = te(() => p ? nr(p.permissions) : !1, [p]), {
    loading: De,
    error: me,
    roles: C,
    filteredResources: q,
    hasChanges: K,
    saving: T,
    saveSuccess: V,
    saveError: X,
    togglePermission: h,
    saveChanges: D,
    resetChanges: Y,
    getPermissionInheritance: j
  } = or({ canEditSystemRoles: se }), u = te(() => C.find((s) => s.id === a), [C, a]), f = te(() => !(!u || u.isSystem && !se), [u, se]), E = (s) => {
    de((c) => {
      const n = new Set(c);
      return n.has(s) ? n.delete(s) : n.add(s), n;
    });
  }, J = (s) => {
    M((c) => {
      const n = new Set(c);
      return n.has(s) ? n.delete(s) : n.add(s), n;
    });
  }, ue = (s) => {
    _((c) => {
      const n = new Set(c);
      return n.has(s) ? n.delete(s) : n.add(s), n;
    });
  }, B = te(() => {
    const s = [], c = [];
    return q.forEach((n) => {
      if (n.level === "module") {
        const v = n.applicationLabel;
        s.find((k) => k.app === v) || s.push({
          app: n.applicationLabel,
          label: n.applicationLabel
        }), c.push({
          app: n.applicationLabel,
          module: n.moduleLabel,
          label: n.moduleLabel
        });
      }
    }), {
      applications: s.sort((n, v) => n.label.localeCompare(v.label)),
      modules: c.sort((n, v) => n.label.localeCompare(v.label))
    };
  }, [q]), ke = S((s) => {
    !u || !f || h(u.id, s);
  }, [u, f, h]), Q = S((s) => {
    if (!u) return !1;
    const c = j(u.id, s);
    return c.isDirect || c.isInherited;
  }, [u, j]), ve = S((s) => kr(
    s.module,
    s.sections,
    Q
  ), [Q]), pe = S((s) => Sr(s, Q), [Q]), Z = S((s) => u ? s.permissions.filter((c) => {
    const n = j(u.id, c.id);
    return n.isDirect || n.isInherited;
  }).map((c) => c.action) : [], [u, j]), le = S((s) => Fr(s, F, b), [F, b]), U = S((s) => m.size === 0 ? s : jr(s, m, ve), [m, ve]), z = te(() => {
    let s = Rr(q);
    return s = le(s), s = U(s), s;
  }, [q, le, U]), ne = te(() => z.reduce((s, c) => s + c.modules.length, 0), [z]), xe = S((s, c) => {
    c === "module" ? J(s) : c === "section" && ue(s);
  }, [J, ue]), be = (s) => {
    x(ae === s ? null : s);
  };
  if (De)
    return /* @__PURE__ */ e("div", { className: "flex items-center justify-center py-12", children: /* @__PURE__ */ t("div", { className: "text-center", children: [
      /* @__PURE__ */ e(g, { className: "h-8 w-8 animate-spin text-[var(--color-accent-500)] mx-auto mb-4" }),
      /* @__PURE__ */ e("p", { className: "text-[var(--text-secondary)]", children: l("userPermissions.loading") })
    ] }) });
  if (me)
    return /* @__PURE__ */ e("div", { className: "p-4 rounded-[var(--radius-card)] bg-[var(--error-bg)] border border-[var(--error-border)]", children: /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
      /* @__PURE__ */ e(Ue, { className: "h-5 w-5 text-[var(--error-text)]" }),
      /* @__PURE__ */ e("p", { className: "text-[var(--error-text)]", children: me })
    ] }) });
  if (!u)
    return /* @__PURE__ */ e("div", { className: "text-center py-12 text-[var(--text-secondary)]", children: l("roleDetail.notFound") });
  const he = (s) => s === "resource" ? /* @__PURE__ */ e(ur, { className: "h-3.5 w-3.5 text-[var(--text-muted)]" }) : s === "section" ? /* @__PURE__ */ e(vr, { className: "h-3.5 w-3.5 text-[var(--text-muted)]" }) : /* @__PURE__ */ e(pr, { className: "h-3.5 w-3.5 text-[var(--text-secondary)]" }), Se = (s) => s === "resource" ? "text-[var(--text-muted)] italic" : s === "section" ? "text-[var(--text-secondary)]" : "font-medium text-[var(--text-primary)]", ee = (s) => s === "resource" ? "pl-28" : s === "section" ? "pl-22" : "pl-16", Re = (s, c, n, v) => s ? /* @__PURE__ */ e(
    "button",
    {
      onClick: () => xe(c, n),
      className: "p-0.5 hover:bg-[var(--bg-hover)] rounded",
      children: v ? /* @__PURE__ */ e(Ie, { className: "h-3 w-3 text-[var(--text-muted)]" }) : /* @__PURE__ */ e(Me, { className: "h-3 w-3 text-[var(--text-muted)]" })
    }
  ) : null, Ae = (s) => s.length === 0 ? /* @__PURE__ */ e("span", { className: "text-xs text-[var(--text-muted)] italic", children: l("assignments.noPermissions") }) : s.map((c) => {
    const n = Pr[c] || "bg-[var(--bg-secondary)] text-[var(--text-secondary)] border-[var(--border-color)]", v = $r[c] || /* @__PURE__ */ e($e, { className: "h-3 w-3" });
    return /* @__PURE__ */ t(
      "div",
      {
        className: `inline-flex items-center gap-1.5 px-2 py-0.5 rounded-[var(--radius-badge)] border text-xs font-medium ${n}`,
        title: l(`assignments.actions.${c === "*" ? "all" : c}.description`),
        children: [
          v,
          /* @__PURE__ */ e("span", { className: "capitalize", children: l(`assignments.actions.${c === "*" ? "all" : c}.label`) })
        ]
      },
      c
    );
  }), ge = (s, c, n, v = !1, k = !1) => {
    const { status: L, grantedCount: G } = pe(s), I = ae === s.id, W = rr(), y = Ar(L), oe = Z(s), $ = ee(n), re = c % 2 === 0 ? "item-light" : "item-medium";
    return /* @__PURE__ */ t(
      "tr",
      {
        className: `hover:bg-[var(--bg-hover)] ${re}`,
        children: [
          /* @__PURE__ */ e(
            "td",
            {
              className: `sticky left-0 z-10 ${re} px-3 py-2 ${$}`,
              style: { width: "280px", minWidth: "280px", maxWidth: "280px" },
              children: /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
                Re(v, s.id, n, k),
                he(n),
                /* @__PURE__ */ e("span", { className: `text-sm ${Se(n)}`, children: s.moduleLabel }),
                /* @__PURE__ */ t("span", { className: "text-xs text-[var(--text-muted)]", children: [
                  "(",
                  s.permissions.length,
                  ")"
                ] })
              ] })
            }
          ),
          /* @__PURE__ */ t(
            "td",
            {
              className: `px-0 py-1 text-center relative ${y}`,
              style: { width: "60px", minWidth: "60px", maxWidth: "60px" },
              children: [
                /* @__PURE__ */ e(
                  "button",
                  {
                    ref: W,
                    type: "button",
                    onClick: () => f && be(s.id),
                    disabled: !f,
                    className: `w-full h-full min-h-[36px] flex items-center justify-center rounded transition-colors ${f ? "hover:opacity-80" : "cursor-not-allowed opacity-50"} ${I ? "ring-2 ring-[var(--color-accent-500)]" : ""}`,
                    title: f ? `${u.name} - ${s.moduleLabel}: ${G}/${s.permissions.length}` : `${u.name} - ${l("assignments.systemRoleReadOnly")}`,
                    children: /* @__PURE__ */ e(
                      Tr,
                      {
                        status: L,
                        grantedCount: G,
                        totalCount: s.permissions.length
                      }
                    )
                  }
                ),
                I && f && /* @__PURE__ */ e(
                  Lr,
                  {
                    mode: "editable",
                    role: u,
                    resource: s,
                    onTogglePermission: ke,
                    onClose: () => x(null),
                    getPermissionInheritance: (fe, ye) => j(u.id, ye)
                  }
                )
              ]
            }
          ),
          /* @__PURE__ */ e("td", { className: "px-3 py-2", children: /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-1.5", children: Ae(oe) }) })
        ]
      },
      s.id
    );
  };
  return /* @__PURE__ */ t("div", { className: "space-y-4", children: [
    /* @__PURE__ */ t("div", { className: "min-h-[52px]", children: [
      V && /* @__PURE__ */ e("div", { className: "flex items-center justify-between p-3 rounded-[var(--radius-card)] bg-[var(--success-bg)] border border-[var(--success-border)]", children: /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
        /* @__PURE__ */ e(Ge, { className: "h-4 w-4 text-[var(--success-text)]" }),
        /* @__PURE__ */ e("p", { className: "text-sm text-[var(--success-text)] font-medium", children: l("common.savedSuccessfully", "Sauvegardé avec succès !") })
      ] }) }),
      !V && T && /* @__PURE__ */ e("div", { className: "flex items-center justify-between p-3 rounded-[var(--radius-card)] bg-[var(--info-bg)] border border-[var(--info-border)]", children: /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
        /* @__PURE__ */ e(g, { className: "h-4 w-4 animate-spin text-[var(--info-text)]" }),
        /* @__PURE__ */ e("p", { className: "text-sm text-[var(--info-text)] font-medium", children: l("common.saving", "Sauvegarde en cours...") })
      ] }) }),
      !V && !T && K && /* @__PURE__ */ t("div", { className: "flex items-center justify-between p-3 rounded-[var(--radius-card)] bg-[var(--warning-bg)] border border-[var(--warning-border)]", children: [
        /* @__PURE__ */ e("p", { className: "text-sm text-[var(--warning-text)]", children: l("assignments.unsavedChanges", "You have unsaved changes") }),
        /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
          /* @__PURE__ */ t(
            "button",
            {
              onClick: Y,
              disabled: T,
              className: "inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded-[var(--radius-button)] bg-[var(--bg-secondary)] border border-[var(--border-color)] text-[var(--text-secondary)] hover:bg-[var(--bg-hover)] disabled:opacity-50",
              children: [
                /* @__PURE__ */ e(Ne, { className: "h-4 w-4" }),
                l("common.cancel")
              ]
            }
          ),
          /* @__PURE__ */ t(
            "button",
            {
              onClick: D,
              disabled: T,
              className: "inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded-[var(--radius-button)] bg-[var(--color-accent-600)] text-white hover:bg-[var(--color-accent-700)] disabled:opacity-50",
              children: [
                T ? /* @__PURE__ */ e(g, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ e(_e, { className: "h-4 w-4" }),
                l("common.save")
              ]
            }
          )
        ] })
      ] }),
      !V && !T && !K && /* @__PURE__ */ e("div", { className: "h-[52px]" })
    ] }),
    X && /* @__PURE__ */ e("div", { className: "p-3 rounded-[var(--radius-card)] bg-[var(--error-bg)] border border-[var(--error-border)]", children: /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
      /* @__PURE__ */ e(Ue, { className: "h-4 w-4 text-[var(--error-text)]" }),
      /* @__PURE__ */ e("p", { className: "text-sm text-[var(--error-text)]", children: X })
    ] }) }),
    /* @__PURE__ */ t("div", { className: "flex flex-wrap items-center gap-4", children: [
      /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
        /* @__PURE__ */ t("label", { className: "text-sm text-[var(--text-secondary)]", children: [
          l("userPermissions.filters.application"),
          ":"
        ] }),
        /* @__PURE__ */ t(
          "select",
          {
            value: F,
            onChange: (s) => {
              w(s.target.value), A("all");
            },
            className: "px-3 py-1.5 text-sm bg-[var(--bg-secondary)] border border-[var(--border-color)] rounded-[var(--radius-input)] text-[var(--text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--color-accent-500)]",
            children: [
              /* @__PURE__ */ e("option", { value: "all", children: l("userPermissions.filters.allApplications") }),
              B.applications.map((s) => /* @__PURE__ */ e("option", { value: s.app, children: s.label }, s.app))
            ]
          }
        )
      ] }),
      /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
        /* @__PURE__ */ t("label", { className: "text-sm text-[var(--text-secondary)]", children: [
          l("userPermissions.filters.module"),
          ":"
        ] }),
        /* @__PURE__ */ t(
          "select",
          {
            value: b,
            onChange: (s) => A(s.target.value),
            className: "px-3 py-1.5 text-sm bg-[var(--bg-secondary)] border border-[var(--border-color)] rounded-[var(--radius-input)] text-[var(--text-primary)] focus:outline-none focus:ring-1 focus:ring-[var(--color-accent-500)]",
            children: [
              /* @__PURE__ */ e("option", { value: "all", children: l("userPermissions.filters.allModules") }),
              B.modules.filter(
                (s) => F === "all" || s.app === F
              ).map((s) => /* @__PURE__ */ e("option", { value: s.module, children: s.label }, `${s.app}:${s.module}`))
            ]
          }
        )
      ] })
    ] }),
    /* @__PURE__ */ t("div", { className: "flex flex-wrap items-center gap-3", children: [
      /* @__PURE__ */ t("span", { className: "text-sm font-medium text-[var(--text-secondary)]", children: [
        l("userPermissions.filterByStatus"),
        ":"
      ] }),
      /* @__PURE__ */ t("div", { className: "flex flex-wrap gap-2", children: [
        /* @__PURE__ */ t(
          "button",
          {
            onClick: () => E("all"),
            className: `inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded-full border transition-colors ${m.has("all") ? "bg-[var(--success-bg)] border-[var(--success-border)] text-[var(--success-text)]" : "bg-[var(--bg-tertiary)] border-[var(--border-color)] text-[var(--text-secondary)] hover:border-[var(--success-border)]"}`,
            children: [
              /* @__PURE__ */ e(Ge, { className: `h-3.5 w-3.5 ${m.has("all") ? "" : "text-[var(--success-dot)]"}` }),
              l("assignments.complete")
            ]
          }
        ),
        /* @__PURE__ */ t(
          "button",
          {
            onClick: () => E("some"),
            className: `inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded-full border transition-colors ${m.has("some") ? "bg-[var(--warning-bg)] border-[var(--warning-border)] text-[var(--warning-text)]" : "bg-[var(--bg-tertiary)] border-[var(--border-color)] text-[var(--text-secondary)] hover:border-[var(--warning-border)]"}`,
            children: [
              /* @__PURE__ */ e(cr, { className: `h-3.5 w-3.5 ${m.has("some") ? "" : "text-[var(--warning-dot)]"}` }),
              l("assignments.partial")
            ]
          }
        ),
        /* @__PURE__ */ t(
          "button",
          {
            onClick: () => E("read-only"),
            className: `inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded-full border transition-colors ${m.has("read-only") ? "bg-[var(--info-bg)] border-[var(--info-border)] text-[var(--info-text)]" : "bg-[var(--bg-tertiary)] border-[var(--border-color)] text-[var(--text-secondary)] hover:border-[var(--info-border)]"}`,
            children: [
              /* @__PURE__ */ e($e, { className: `h-3.5 w-3.5 ${m.has("read-only") ? "" : "text-[var(--info-dot)]"}` }),
              l("assignments.readOnly")
            ]
          }
        ),
        /* @__PURE__ */ t(
          "button",
          {
            onClick: () => E("none"),
            className: `inline-flex items-center gap-1.5 px-3 py-1.5 text-sm rounded-full border transition-colors ${m.has("none") ? "bg-[var(--error-bg)] border-[var(--error-border)] text-[var(--error-text)]" : "bg-[var(--bg-tertiary)] border-[var(--border-color)] text-[var(--text-secondary)] hover:border-[var(--error-border)]"}`,
            children: [
              /* @__PURE__ */ e(dr, { className: `h-3.5 w-3.5 ${m.has("none") ? "" : "text-[var(--text-muted)]"}` }),
              l("assignments.none")
            ]
          }
        )
      ] }),
      m.size > 0 && /* @__PURE__ */ e(
        "button",
        {
          onClick: () => de(/* @__PURE__ */ new Set()),
          className: "text-xs text-[var(--color-accent-500)] hover:text-[var(--color-accent-600)] underline",
          children: l("assignments.clearFilters")
        }
      )
    ] }),
    /* @__PURE__ */ e("div", { className: "flex items-center gap-3", children: /* @__PURE__ */ t("span", { className: "px-2.5 py-1 text-xs font-semibold rounded-full bg-[var(--bg-tertiary)] text-[var(--text-secondary)]", children: [
      ne,
      " ",
      l("assignments.modules")
    ] }) }),
    /* @__PURE__ */ e("div", { className: "overflow-x-auto overflow-y-visible", children: /* @__PURE__ */ t("table", { className: "border-collapse", style: { width: "auto" }, children: [
      /* @__PURE__ */ e("thead", { className: "item-medium border-b border-[var(--item-color-border)]", children: /* @__PURE__ */ t("tr", { children: [
        /* @__PURE__ */ e(
          "th",
          {
            scope: "col",
            className: "sticky left-0 z-20 item-medium px-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",
            style: { width: "280px", minWidth: "280px", maxWidth: "280px", height: "48px", verticalAlign: "middle" },
            children: l("assignments.resource")
          }
        ),
        /* @__PURE__ */ e(
          "th",
          {
            scope: "col",
            className: "px-2 text-center text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",
            style: { width: "60px", minWidth: "60px", maxWidth: "60px", height: "48px", verticalAlign: "middle" },
            children: l("userPermissions.status")
          }
        ),
        /* @__PURE__ */ e(
          "th",
          {
            scope: "col",
            className: "px-3 text-left text-xs font-medium text-[var(--text-secondary)] uppercase tracking-wider",
            style: { height: "48px", verticalAlign: "middle" },
            children: l("assignments.permissions")
          }
        )
      ] }) }),
      /* @__PURE__ */ e("tbody", { className: "divide-y divide-[var(--item-color-border)]", children: z.map((s) => {
        const c = s.application, n = i.has(c);
        return /* @__PURE__ */ t(Le.Fragment, { children: [
          /* @__PURE__ */ t("tr", { className: "bg-[var(--bg-tertiary)]", children: [
            /* @__PURE__ */ e(
              "td",
              {
                className: "sticky left-0 z-10 px-3 py-2 bg-[var(--bg-tertiary)]",
                style: { width: "280px", minWidth: "280px", maxWidth: "280px" },
                children: /* @__PURE__ */ t(
                  "button",
                  {
                    onClick: () => R(c),
                    className: "flex items-center gap-3 w-full text-left hover:opacity-80",
                    children: [
                      n ? /* @__PURE__ */ e(Ie, { className: "h-4 w-4 text-[var(--text-secondary)]" }) : /* @__PURE__ */ e(Me, { className: "h-4 w-4 text-[var(--text-secondary)]" }),
                      /* @__PURE__ */ e(mr, { className: "h-4 w-4 text-[var(--text-secondary)]" }),
                      /* @__PURE__ */ e("span", { className: "text-sm font-semibold text-[var(--text-primary)]", children: s.application }),
                      /* @__PURE__ */ t("span", { className: "text-xs text-[var(--text-muted)] ml-auto", children: [
                        s.modules.length,
                        " module",
                        s.modules.length > 1 ? "s" : ""
                      ] })
                    ]
                  }
                )
              }
            ),
            /* @__PURE__ */ e("td", { className: "px-0 py-2" }),
            /* @__PURE__ */ e("td", { className: "px-0 py-2" })
          ] }),
          !n && s.modules.map((v, k) => {
            const { module: L, sections: G } = v, I = G.length > 0, W = P.has(L.id);
            return /* @__PURE__ */ t(Le.Fragment, { children: [
              ge(L, k, "module", I, W),
              I && !W && G.map((y, oe) => {
                const { section: $, resources: re } = y;
                return /* @__PURE__ */ e(
                  Er,
                  {
                    section: $,
                    resources: re,
                    moduleIndex: k,
                    sectionIndex: oe,
                    collapsedSections: O,
                    renderResourceRow: ge
                  },
                  $.id
                );
              })
            ] }, L.id);
          })
        ] }, c);
      }) })
    ] }) }),
    ne === 0 && /* @__PURE__ */ e("div", { className: "text-center py-12 text-[var(--text-secondary)]", children: l("assignments.noResources") })
  ] });
}
const We = [
  { code: "fr", label: "Français" },
  { code: "en", label: "English" },
  { code: "it", label: "Italiano" },
  { code: "de", label: "Deutsch" }
];
function _r() {
  const { t: a } = He("admin"), { id: l } = tr(), p = ar(), [i, R] = d(null), [P, M] = d(!0), [O, _] = d(!1), [m, de] = d("info"), [ae, x] = d(null), [F, w] = d(null), [b, A] = d({
    name: "",
    shortName: "",
    category: "Custom",
    description: "",
    parentRoleId: null
  }), [se, De] = d([]), me = ["Global", "Admin", "Manager", "Contributor", "Viewer", "Custom"], [C, q] = d([]), [K, T] = d(!1), [V, X] = d(null), [h, D] = d({
    name: "",
    shortName: "",
    description: ""
  }), [Y, j] = d(!1), [u, f] = d(!1), [E, J] = d(""), [ue, B] = d(!1), [ke, Q] = d([]), [ve, pe] = d(!1), [Z, le] = d(""), [U, z] = d(null), [ne, xe] = d(!1), [be, he] = d(null), [Se, ee] = d(!1), [Re, Ae] = d([]), [ge, s] = d(!1), [c, n] = d(""), [v, k] = d(null), [L, G] = d(!1), [I, W] = d(null), y = S(async () => {
    if (l)
      try {
        M(!0);
        const [r, o] = await Promise.all([
          N.roles.getById(l),
          N.roles.getAll()
        ]);
        R(r), De(o.filter((ie) => ie.id !== l)), A({
          name: r.name,
          shortName: r.shortName,
          category: r.category,
          description: r.description || "",
          parentRoleId: r.parentRoleId
        });
      } catch (r) {
        console.error("Failed to load role:", r), x(a("roleDetail.errors.loadFailed"));
      } finally {
        M(!1);
      }
  }, [l, a]);
  je(() => {
    y();
  }, [y]);
  const oe = async (r) => {
    if (r.preventDefault(), !(!l || !i)) {
      _(!0), x(null), w(null);
      try {
        const o = {
          name: b.name,
          shortName: b.shortName,
          category: b.category,
          description: b.description || void 0,
          parentRoleId: b.parentRoleId || void 0
        };
        await N.roles.update(l, o), w(a("roleDetail.success.saved")), y();
      } catch (o) {
        x(o instanceof Error ? o.message : a("roleDetail.errors.saveFailed"));
      } finally {
        _(!1);
      }
    }
  }, $ = S(async () => {
    if (l) {
      T(!0);
      try {
        const r = await N.roles.getTranslations(l);
        q(r);
      } catch (r) {
        console.error("Failed to load translations:", r);
      } finally {
        T(!1);
      }
    }
  }, [l]);
  je(() => {
    m === "translations" && C.length === 0 && $();
  }, [m, C.length, $]);
  const re = (r) => {
    X(r.languageCode), D({
      name: r.name,
      shortName: r.shortName,
      description: r.description || ""
    });
  }, fe = () => {
    X(null), f(!1), D({ name: "", shortName: "", description: "" }), J("");
  }, ye = async (r) => {
    if (l) {
      j(!0), x(null);
      try {
        await N.roles.upsertTranslation(l, r, h), w(a("roleDetail.translations.saved")), X(null), f(!1), J(""), $();
      } catch (o) {
        x(o instanceof Error ? o.message : a("roleDetail.errors.saveFailed"));
      } finally {
        j(!1);
      }
    }
  }, qe = async (r) => {
    if (l && confirm(a("roleDetail.translations.confirmDelete")))
      try {
        await N.roles.deleteTranslation(l, r), w(a("roleDetail.translations.deleted")), $();
      } catch (o) {
        x(o instanceof Error ? o.message : a("roleDetail.errors.saveFailed"));
      }
  }, Fe = We.filter(
    (r) => !C.some((o) => o.languageCode === r.code)
  ), Ke = async () => {
    B(!0), z(null), le(""), pe(!0);
    try {
      const r = await N.users.getAll({ globalScope: !0 });
      Q(r.items);
    } catch (r) {
      console.error("Failed to load users:", r);
    } finally {
      pe(!1);
    }
  }, Ve = async () => {
    if (!(!l || !U)) {
      xe(!0);
      try {
        await N.roles.assignUser(l, U), B(!1), z(null), w(a("roleDetail.users.assigned")), y();
      } catch (r) {
        x(r instanceof Error ? r.message : a("roleDetail.errors.assignFailed"));
      } finally {
        xe(!1);
      }
    }
  }, Xe = async (r) => {
    if (l && confirm(a("roleDetail.users.confirmRemove"))) {
      he(r);
      try {
        await N.roles.removeUser(l, r), w(a("roleDetail.users.removed")), y();
      } catch (o) {
        x(o instanceof Error ? o.message : a("roleDetail.errors.removeFailed"));
      } finally {
        he(null);
      }
    }
  }, Ye = async () => {
    ee(!0), k(null), n(""), s(!0);
    try {
      const r = await Dr.getAll();
      Ae(r);
    } catch (r) {
      console.error("Failed to load groups:", r);
    } finally {
      s(!1);
    }
  }, Je = async () => {
    if (!(!l || !v)) {
      G(!0);
      try {
        await N.roles.assignGroup(l, v), ee(!1), k(null), w(a("roleDetail.groups.assigned")), y();
      } catch (r) {
        x(r instanceof Error ? r.message : a("roleDetail.errors.assignFailed"));
      } finally {
        G(!1);
      }
    }
  }, Qe = async (r) => {
    if (l && confirm(a("roleDetail.groups.confirmRemove"))) {
      W(r);
      try {
        await N.roles.removeGroup(l, r), w(a("roleDetail.groups.removed")), y();
      } catch (o) {
        x(o instanceof Error ? o.message : a("roleDetail.errors.removeFailed"));
      } finally {
        W(null);
      }
    }
  }, Ze = [
    { id: "info", label: a("roleDetail.tabs.info"), icon: /* @__PURE__ */ e(gr, { className: "w-4 h-4" }) },
    { id: "permissions", label: a("roleDetail.tabs.permissions"), icon: /* @__PURE__ */ e(Pe, { className: "w-4 h-4" }) },
    { id: "users", label: a("roleDetail.tabs.users"), icon: /* @__PURE__ */ e(Oe, { className: "w-4 h-4" }) },
    { id: "groups", label: a("roleDetail.tabs.groups"), icon: /* @__PURE__ */ e(Te, { className: "w-4 h-4" }) },
    { id: "translations", label: a("roleDetail.tabs.translations"), icon: /* @__PURE__ */ e(fr, { className: "w-4 h-4" }) }
  ];
  return P ? /* @__PURE__ */ e("div", { className: "flex items-center justify-center h-64", children: /* @__PURE__ */ e(g, { className: "w-8 h-8 animate-spin text-[var(--color-accent-500)]" }) }) : i ? /* @__PURE__ */ t("div", { className: "space-y-6", children: [
    /* @__PURE__ */ e(
      ir,
      {
        items: [
          { label: a("header.title"), href: "/administration" },
          { label: a("roles.title", "Roles"), href: "/administration/permissions/roles" },
          { label: i?.name || "Detail" }
        ]
      }
    ),
    /* @__PURE__ */ t("div", { className: "flex items-center gap-4", children: [
      /* @__PURE__ */ e(
        "button",
        {
          onClick: () => p("/administration/permissions/roles"),
          className: "p-2 rounded-[var(--radius-button)] hover:bg-[var(--bg-hover)] transition-colors",
          children: /* @__PURE__ */ e(yr, { className: "w-5 h-5 text-[var(--text-secondary)]" })
        }
      ),
      /* @__PURE__ */ t("div", { className: "flex-1", children: [
        /* @__PURE__ */ t("div", { className: "flex items-center gap-3", children: [
          /* @__PURE__ */ e("h1", { className: "text-xl sm:text-2xl font-bold text-[var(--text-primary)]", children: i.name }),
          i.isSystem && /* @__PURE__ */ t("span", { className: "flex items-center gap-1 px-2 py-1 rounded-[var(--radius-badge)] text-xs bg-[var(--warning-bg)] text-[var(--warning-text)] border border-[var(--warning-border)]", children: [
            /* @__PURE__ */ e(Be, { className: "w-3 h-3" }),
            a("roles.system")
          ] })
        ] }),
        i.description && /* @__PURE__ */ e("p", { className: "text-sm sm:text-base text-[var(--text-secondary)] mt-1", children: i.description })
      ] }),
      /* @__PURE__ */ t("div", { className: "flex items-center gap-4 text-sm text-[var(--text-secondary)]", children: [
        /* @__PURE__ */ t("div", { className: "flex items-center gap-1", children: [
          /* @__PURE__ */ e(Oe, { className: "w-4 h-4" }),
          /* @__PURE__ */ t("span", { children: [
            i.users.length,
            " ",
            a("roleDetail.usersCount")
          ] })
        ] }),
        /* @__PURE__ */ t("div", { className: "flex items-center gap-1", children: [
          /* @__PURE__ */ e(Te, { className: "w-4 h-4" }),
          /* @__PURE__ */ t("span", { children: [
            i.groups?.length || 0,
            " ",
            a("roleDetail.groupsCount")
          ] })
        ] }),
        /* @__PURE__ */ t("div", { className: "flex items-center gap-1", children: [
          /* @__PURE__ */ e(Pe, { className: "w-4 h-4" }),
          /* @__PURE__ */ t("span", { children: [
            i.permissions.length,
            " ",
            a("roles.permissions")
          ] })
        ] })
      ] })
    ] }),
    ae && /* @__PURE__ */ t("div", { className: "p-4 rounded-[var(--radius-card)] bg-[var(--error-bg)] border border-[var(--error-border)] text-[var(--error-text)] flex items-center gap-2", children: [
      /* @__PURE__ */ e(Nr, { className: "w-5 h-5 flex-shrink-0" }),
      ae
    ] }),
    F && /* @__PURE__ */ t("div", { className: "p-4 rounded-[var(--radius-card)] bg-[var(--success-bg)] border border-[var(--success-border)] text-[var(--success-text)] flex items-center gap-2", children: [
      /* @__PURE__ */ e(wr, { className: "w-5 h-5 flex-shrink-0" }),
      F
    ] }),
    /* @__PURE__ */ e("div", { className: "flex gap-1 p-1 bg-[var(--bg-secondary)] rounded-[var(--radius-card)] border border-[var(--border-color)]", children: Ze.map((r) => /* @__PURE__ */ t(
      "button",
      {
        onClick: () => de(r.id),
        className: `flex items-center gap-2 px-4 py-2 rounded-[var(--radius-button)] font-medium transition-colors ${m === r.id ? "bg-[var(--color-accent-600)] text-white" : "text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]"}`,
        children: [
          r.icon,
          /* @__PURE__ */ e("span", { className: "hidden sm:inline", children: r.label })
        ]
      },
      r.id
    )) }),
    /* @__PURE__ */ t("div", { className: "bg-[var(--bg-secondary)] rounded-[var(--radius-card)] border border-[var(--border-color)] p-4 sm:p-6", children: [
      m === "info" && /* @__PURE__ */ t("form", { onSubmit: oe, className: "space-y-6 max-w-2xl", children: [
        /* @__PURE__ */ t("div", { children: [
          /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: a("roleDetail.info.id") }),
          /* @__PURE__ */ e("div", { className: "px-4 py-2 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-tertiary)] text-[var(--text-secondary)] font-mono text-sm", children: i.id })
        ] }),
        /* @__PURE__ */ t("div", { children: [
          /* @__PURE__ */ t("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: [
            a("roles.form.name"),
            " *"
          ] }),
          /* @__PURE__ */ e(
            "input",
            {
              type: "text",
              required: !0,
              value: b.name,
              onChange: (r) => A((o) => ({ ...o, name: r.target.value })),
              className: "w-full px-4 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__ */ t("div", { children: [
          /* @__PURE__ */ t("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: [
            a("roleDetail.info.shortName"),
            " *"
          ] }),
          /* @__PURE__ */ e(
            "input",
            {
              type: "text",
              required: !0,
              value: b.shortName,
              onChange: (r) => A((o) => ({ ...o, shortName: r.target.value })),
              className: "w-full px-4 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__ */ e("p", { className: "mt-1 text-xs text-[var(--text-tertiary)]", children: a("roleDetail.info.shortNameHelp") })
        ] }),
        /* @__PURE__ */ t("div", { children: [
          /* @__PURE__ */ t("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: [
            a("roleDetail.info.category"),
            " *"
          ] }),
          /* @__PURE__ */ e(
            "select",
            {
              value: b.category,
              onChange: (r) => A((o) => ({ ...o, category: r.target.value })),
              className: "w-full px-4 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: me.map((r) => /* @__PURE__ */ e("option", { value: r, children: a(`roleDetail.categories.${r.toLowerCase()}`) }, r))
            }
          ),
          /* @__PURE__ */ e("p", { className: "mt-1 text-xs text-[var(--text-tertiary)]", children: a("roleDetail.info.categoryHelp") })
        ] }),
        /* @__PURE__ */ t("div", { children: [
          /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: a("roleDetail.info.parentRole") }),
          /* @__PURE__ */ t(
            "select",
            {
              value: b.parentRoleId || "",
              onChange: (r) => A((o) => ({ ...o, parentRoleId: r.target.value || null })),
              className: "w-full px-4 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__ */ e("option", { value: "", children: a("roleDetail.info.noParent") }),
                se.map((r) => /* @__PURE__ */ t("option", { value: r.id, children: [
                  r.name,
                  " (",
                  a(`roleDetail.categories.${r.category.toLowerCase()}`),
                  ")"
                ] }, r.id))
              ]
            }
          ),
          /* @__PURE__ */ e("p", { className: "mt-1 text-xs text-[var(--text-tertiary)]", children: a("roleDetail.info.parentRoleHelp") })
        ] }),
        /* @__PURE__ */ t("div", { children: [
          /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: a("roles.form.description") }),
          /* @__PURE__ */ e(
            "textarea",
            {
              value: b.description,
              onChange: (r) => A((o) => ({ ...o, description: r.target.value })),
              rows: 3,
              className: "w-full px-4 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__ */ t("div", { children: [
          /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: a("roleDetail.info.systemRole") }),
          /* @__PURE__ */ e("div", { className: "flex items-center gap-2", children: i.isSystem ? /* @__PURE__ */ t("span", { className: "flex items-center gap-1.5 px-3 py-1.5 rounded-[var(--radius-badge)] text-sm bg-[var(--warning-bg)] text-[var(--warning-text)] border border-[var(--warning-border)]", children: [
            /* @__PURE__ */ e(Be, { className: "w-4 h-4" }),
            a("roleDetail.info.isSystemRole")
          ] }) : /* @__PURE__ */ e("span", { className: "flex items-center gap-1.5 px-3 py-1.5 rounded-[var(--radius-badge)] text-sm bg-[var(--bg-tertiary)] text-[var(--text-secondary)]", children: a("roleDetail.info.isCustomRole") }) })
        ] }),
        /* @__PURE__ */ t("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-4 pt-4 border-t border-[var(--border-color)]", children: [
          /* @__PURE__ */ t("div", { children: [
            /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: a("roleDetail.createdAt") }),
            /* @__PURE__ */ e("div", { className: "text-sm text-[var(--text-primary)]", children: new Date(i.createdAt).toLocaleString() })
          ] }),
          i.updatedAt && /* @__PURE__ */ t("div", { children: [
            /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: a("roleDetail.updatedAt") }),
            /* @__PURE__ */ e("div", { className: "text-sm text-[var(--text-primary)]", children: new Date(i.updatedAt).toLocaleString() })
          ] })
        ] }),
        /* @__PURE__ */ e("div", { className: "flex justify-end pt-4", children: /* @__PURE__ */ t(
          "button",
          {
            type: "submit",
            disabled: O,
            className: "flex items-center gap-2 px-4 py-2 rounded-[var(--radius-button)] bg-[var(--color-accent-600)] hover:bg-[var(--color-accent-700)] text-white font-medium transition-colors disabled:opacity-50",
            children: [
              O ? /* @__PURE__ */ e(g, { className: "w-4 h-4 animate-spin" }) : /* @__PURE__ */ e(_e, { className: "w-4 h-4" }),
              a("common.save")
            ]
          }
        ) })
      ] }),
      m === "permissions" && l && /* @__PURE__ */ e(Ur, { roleId: l }),
      m === "groups" && /* @__PURE__ */ t("div", { className: "space-y-4", children: [
        /* @__PURE__ */ t("div", { className: "flex items-center justify-between", children: [
          /* @__PURE__ */ t("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: [
            a("roleDetail.groups.title"),
            " (",
            i.groups?.length || 0,
            ")"
          ] }),
          /* @__PURE__ */ t(
            "button",
            {
              onClick: Ye,
              className: "flex items-center gap-2 px-3 py-1.5 rounded-[var(--radius-button)] bg-[var(--color-accent-600)] hover:bg-[var(--color-accent-700)] text-white text-sm font-medium transition-colors",
              children: [
                /* @__PURE__ */ e(Ce, { className: "w-4 h-4" }),
                a("roleDetail.groups.add")
              ]
            }
          )
        ] }),
        !i.groups || i.groups.length === 0 ? /* @__PURE__ */ e("div", { className: "text-center py-12 text-[var(--text-secondary)]", children: a("roleDetail.groups.noGroups") }) : /* @__PURE__ */ e("div", { className: "grid gap-3", children: i.groups.map((r) => /* @__PURE__ */ t(
          "div",
          {
            className: "flex items-center gap-4 p-4 rounded-[var(--radius-card)] bg-[var(--bg-primary)] border border-[var(--border-color)]",
            children: [
              /* @__PURE__ */ t(
                Ee,
                {
                  to: `/administration/users/groups/${r.id}`,
                  className: "flex items-center gap-4 flex-1 min-w-0 hover:opacity-80 transition-opacity",
                  children: [
                    /* @__PURE__ */ e("div", { className: "w-10 h-10 rounded-full bg-[var(--color-accent-100)] flex items-center justify-center", children: /* @__PURE__ */ e(Te, { className: "w-5 h-5 text-[var(--color-accent-700)]" }) }),
                    /* @__PURE__ */ t("div", { className: "flex-1 min-w-0", children: [
                      /* @__PURE__ */ e("div", { className: "font-medium text-[var(--text-primary)] truncate", children: r.name }),
                      /* @__PURE__ */ t("div", { className: "text-sm text-[var(--text-secondary)] truncate", children: [
                        r.membersCount,
                        " ",
                        a("roleDetail.groups.members"),
                        r.description && ` · ${r.description}`
                      ] })
                    ] })
                  ]
                }
              ),
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => Qe(r.id),
                  disabled: I === r.id,
                  className: "p-2 rounded-[var(--radius-button)] hover:bg-[var(--bg-hover)] text-[var(--text-secondary)] hover:text-[var(--error-text)] transition-colors disabled:opacity-50",
                  title: a("roleDetail.groups.remove"),
                  children: I === r.id ? /* @__PURE__ */ e(g, { className: "w-4 h-4 animate-spin" }) : /* @__PURE__ */ e(we, { className: "w-4 h-4" })
                }
              )
            ]
          },
          r.id
        )) }),
        Se && /* @__PURE__ */ e("div", { className: "fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50", children: /* @__PURE__ */ t("div", { className: "bg-[var(--bg-secondary)] rounded-[var(--radius-card)] border border-[var(--border-color)] w-full max-w-md p-6 m-4 max-h-[90vh] overflow-y-auto", children: [
          /* @__PURE__ */ t("div", { className: "flex items-center justify-between mb-6", children: [
            /* @__PURE__ */ e("h2", { className: "text-xl font-bold text-[var(--text-primary)]", children: a("roleDetail.groups.addTitle") }),
            /* @__PURE__ */ e(
              "button",
              {
                onClick: () => ee(!1),
                className: "p-2 rounded-[var(--radius-button)] hover:bg-[var(--bg-hover)] transition-colors",
                children: /* @__PURE__ */ e(Ne, { className: "w-5 h-5 text-[var(--text-tertiary)]" })
              }
            )
          ] }),
          /* @__PURE__ */ e("div", { className: "mb-4", children: /* @__PURE__ */ t("div", { className: "relative", children: [
            /* @__PURE__ */ e(ze, { className: "absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)]" }),
            /* @__PURE__ */ e(
              "input",
              {
                type: "text",
                value: c,
                onChange: (r) => n(r.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)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)]",
                placeholder: a("roleDetail.groups.searchPlaceholder")
              }
            )
          ] }) }),
          ge ? /* @__PURE__ */ e("div", { className: "flex items-center justify-center py-8", children: /* @__PURE__ */ e(g, { className: "w-6 h-6 animate-spin text-[var(--color-accent-500)]" }) }) : /* @__PURE__ */ e("div", { className: "space-y-2 max-h-64 overflow-y-auto", children: Re.filter(
            (r) => !i.groups?.some((o) => o.id === r.id) && (c === "" || r.name.toLowerCase().includes(c.toLowerCase()) || (r.description || "").toLowerCase().includes(c.toLowerCase()))
          ).map((r) => /* @__PURE__ */ t(
            "label",
            {
              className: `flex items-center gap-3 cursor-pointer p-3 rounded-[var(--radius-button)] transition-colors ${v === r.id ? "bg-[var(--color-accent-500)]/10 border border-[var(--color-accent-500)]" : "hover:bg-[var(--bg-hover)] border border-transparent"}`,
              htmlFor: `group-${r.id}`,
              children: [
                /* @__PURE__ */ e(
                  "input",
                  {
                    id: `group-${r.id}`,
                    type: "radio",
                    name: "selectedGroup",
                    checked: v === r.id,
                    onChange: () => k(r.id),
                    className: "w-4 h-4 text-[var(--color-accent-600)] focus:ring-[var(--color-accent-500)]"
                  }
                ),
                /* @__PURE__ */ t("div", { className: "flex-1 min-w-0", children: [
                  /* @__PURE__ */ e("span", { className: "text-[var(--text-primary)] font-medium", children: r.name }),
                  /* @__PURE__ */ t("p", { className: "text-xs text-[var(--text-tertiary)]", children: [
                    r.memberCount,
                    " ",
                    a("roleDetail.groups.members"),
                    r.description && ` · ${r.description}`
                  ] })
                ] })
              ]
            },
            r.id
          )) }),
          /* @__PURE__ */ t("div", { className: "flex justify-end gap-3 mt-6", children: [
            /* @__PURE__ */ e(
              "button",
              {
                onClick: () => ee(!1),
                className: "px-4 py-2 rounded-[var(--radius-button)] bg-[var(--bg-tertiary)] hover:bg-[var(--bg-hover)] text-[var(--text-primary)] font-medium transition-colors",
                children: a("common.cancel")
              }
            ),
            /* @__PURE__ */ t(
              "button",
              {
                onClick: Je,
                disabled: !v || L,
                className: "flex items-center gap-2 px-4 py-2 rounded-[var(--radius-button)] bg-[var(--color-accent-600)] hover:bg-[var(--color-accent-700)] text-white font-medium transition-colors disabled:opacity-50",
                children: [
                  L && /* @__PURE__ */ e(g, { className: "w-4 h-4 animate-spin" }),
                  a("common.add")
                ]
              }
            )
          ] })
        ] }) })
      ] }),
      m === "users" && /* @__PURE__ */ t("div", { className: "space-y-4", children: [
        /* @__PURE__ */ t("div", { className: "flex items-center justify-between", children: [
          /* @__PURE__ */ t("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: [
            a("roleDetail.users.title"),
            " (",
            i.users.length,
            ")"
          ] }),
          /* @__PURE__ */ t(
            "button",
            {
              onClick: Ke,
              className: "flex items-center gap-2 px-3 py-1.5 rounded-[var(--radius-button)] bg-[var(--color-accent-600)] hover:bg-[var(--color-accent-700)] text-white text-sm font-medium transition-colors",
              children: [
                /* @__PURE__ */ e(Ce, { className: "w-4 h-4" }),
                a("roleDetail.users.add")
              ]
            }
          )
        ] }),
        i.users.length === 0 ? /* @__PURE__ */ e("div", { className: "text-center py-12 text-[var(--text-secondary)]", children: a("roleDetail.users.noUsers") }) : /* @__PURE__ */ e("div", { className: "grid gap-3", children: i.users.map((r) => /* @__PURE__ */ t(
          "div",
          {
            className: "flex items-center gap-4 p-4 rounded-[var(--radius-card)] bg-[var(--bg-primary)] border border-[var(--border-color)]",
            children: [
              /* @__PURE__ */ t(
                Ee,
                {
                  to: `/administration/users/${r.id}`,
                  className: "flex items-center gap-4 flex-1 min-w-0 hover:opacity-80 transition-opacity",
                  children: [
                    /* @__PURE__ */ e("div", { className: "w-10 h-10 rounded-full bg-[var(--color-accent-100)] flex items-center justify-center", children: /* @__PURE__ */ e("span", { className: "text-sm font-medium text-[var(--color-accent-700)]", children: r.fullName.split(" ").map((o) => o.at(0)).join("").toUpperCase().slice(0, 2) }) }),
                    /* @__PURE__ */ t("div", { className: "flex-1 min-w-0", children: [
                      /* @__PURE__ */ e("div", { className: "font-medium text-[var(--text-primary)] truncate", children: r.fullName }),
                      /* @__PURE__ */ e("div", { className: "text-sm text-[var(--text-secondary)] truncate", children: r.email })
                    ] })
                  ]
                }
              ),
              /* @__PURE__ */ e(
                "button",
                {
                  onClick: () => Xe(r.id),
                  disabled: be === r.id,
                  className: "p-2 rounded-[var(--radius-button)] hover:bg-[var(--bg-hover)] text-[var(--text-secondary)] hover:text-[var(--error-text)] transition-colors disabled:opacity-50",
                  title: a("roleDetail.users.remove"),
                  children: be === r.id ? /* @__PURE__ */ e(g, { className: "w-4 h-4 animate-spin" }) : /* @__PURE__ */ e(we, { className: "w-4 h-4" })
                }
              )
            ]
          },
          r.id
        )) }),
        ue && /* @__PURE__ */ e("div", { className: "fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50", children: /* @__PURE__ */ t("div", { className: "bg-[var(--bg-secondary)] rounded-[var(--radius-card)] border border-[var(--border-color)] w-full max-w-md p-6 m-4 max-h-[90vh] overflow-y-auto", children: [
          /* @__PURE__ */ t("div", { className: "flex items-center justify-between mb-6", children: [
            /* @__PURE__ */ e("h2", { className: "text-xl font-bold text-[var(--text-primary)]", children: a("roleDetail.users.addTitle") }),
            /* @__PURE__ */ e(
              "button",
              {
                onClick: () => B(!1),
                className: "p-2 rounded-[var(--radius-button)] hover:bg-[var(--bg-hover)] transition-colors",
                children: /* @__PURE__ */ e(Ne, { className: "w-5 h-5 text-[var(--text-tertiary)]" })
              }
            )
          ] }),
          /* @__PURE__ */ e("div", { className: "mb-4", children: /* @__PURE__ */ t("div", { className: "relative", children: [
            /* @__PURE__ */ e(ze, { className: "absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)]" }),
            /* @__PURE__ */ e(
              "input",
              {
                type: "text",
                value: Z,
                onChange: (r) => le(r.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)] focus:outline-none focus:ring-2 focus:ring-[var(--color-accent-500)]",
                placeholder: a("roleDetail.users.searchPlaceholder")
              }
            )
          ] }) }),
          ve ? /* @__PURE__ */ e("div", { className: "flex items-center justify-center py-8", children: /* @__PURE__ */ e(g, { className: "w-6 h-6 animate-spin text-[var(--color-accent-500)]" }) }) : /* @__PURE__ */ e("div", { className: "space-y-2 max-h-64 overflow-y-auto", children: ke.filter(
            (r) => !i.users.some((o) => o.id === r.id) && (Z === "" || r.fullName.toLowerCase().includes(Z.toLowerCase()) || r.email.toLowerCase().includes(Z.toLowerCase()))
          ).map((r) => /* @__PURE__ */ t(
            "label",
            {
              className: `flex items-center gap-3 cursor-pointer p-3 rounded-[var(--radius-button)] transition-colors ${U === r.id ? "bg-[var(--color-accent-500)]/10 border border-[var(--color-accent-500)]" : "hover:bg-[var(--bg-hover)] border border-transparent"}`,
              htmlFor: `user-${r.id}`,
              children: [
                /* @__PURE__ */ e(
                  "input",
                  {
                    id: `user-${r.id}`,
                    type: "radio",
                    name: "selectedUser",
                    checked: U === r.id,
                    onChange: () => z(r.id),
                    className: "w-4 h-4 text-[var(--color-accent-600)] focus:ring-[var(--color-accent-500)]"
                  }
                ),
                /* @__PURE__ */ t("div", { className: "flex-1 min-w-0", children: [
                  /* @__PURE__ */ e("span", { className: "text-[var(--text-primary)] font-medium", children: r.fullName }),
                  /* @__PURE__ */ e("p", { className: "text-xs text-[var(--text-tertiary)]", children: r.email })
                ] })
              ]
            },
            r.id
          )) }),
          /* @__PURE__ */ t("div", { className: "flex justify-end gap-3 mt-6", children: [
            /* @__PURE__ */ e(
              "button",
              {
                onClick: () => B(!1),
                className: "px-4 py-2 rounded-[var(--radius-button)] bg-[var(--bg-tertiary)] hover:bg-[var(--bg-hover)] text-[var(--text-primary)] font-medium transition-colors",
                children: a("common.cancel")
              }
            ),
            /* @__PURE__ */ t(
              "button",
              {
                onClick: Ve,
                disabled: !U || ne,
                className: "flex items-center gap-2 px-4 py-2 rounded-[var(--radius-button)] bg-[var(--color-accent-600)] hover:bg-[var(--color-accent-700)] text-white font-medium transition-colors disabled:opacity-50",
                children: [
                  ne && /* @__PURE__ */ e(g, { className: "w-4 h-4 animate-spin" }),
                  a("common.add")
                ]
              }
            )
          ] })
        ] }) })
      ] }),
      m === "translations" && /* @__PURE__ */ t("div", { className: "space-y-6", children: [
        /* @__PURE__ */ t("div", { className: "flex items-center justify-between", children: [
          /* @__PURE__ */ t("h3", { className: "text-lg font-semibold text-[var(--text-primary)]", children: [
            a("roleDetail.translations.title"),
            " (",
            C.length,
            ")"
          ] }),
          Fe.length > 0 && /* @__PURE__ */ t(
            "button",
            {
              onClick: () => f(!0),
              className: "flex items-center gap-2 px-3 py-1.5 rounded-[var(--radius-button)] bg-[var(--color-accent-600)] hover:bg-[var(--color-accent-700)] text-white text-sm font-medium transition-colors",
              children: [
                /* @__PURE__ */ e(Ce, { className: "w-4 h-4" }),
                a("roleDetail.translations.add")
              ]
            }
          )
        ] }),
        u && /* @__PURE__ */ t("div", { className: "p-4 rounded-[var(--radius-card)] bg-[var(--bg-primary)] border border-[var(--color-accent-500)]", children: [
          /* @__PURE__ */ t("div", { className: "flex items-center justify-between mb-4", children: [
            /* @__PURE__ */ e("h4", { className: "font-medium text-[var(--text-primary)]", children: a("roleDetail.translations.addNew") }),
            /* @__PURE__ */ e(
              "button",
              {
                onClick: fe,
                className: "p-1 rounded hover:bg-[var(--bg-hover)]",
                children: /* @__PURE__ */ e(Ne, { className: "w-4 h-4 text-[var(--text-secondary)]" })
              }
            )
          ] }),
          /* @__PURE__ */ t("div", { className: "grid gap-4", children: [
            /* @__PURE__ */ t("div", { children: [
              /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: a("roleDetail.translations.language") }),
              /* @__PURE__ */ t(
                "select",
                {
                  value: E,
                  onChange: (r) => J(r.target.value),
                  className: "w-full px-3 py-2 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-secondary)] text-[var(--text-primary)]",
                  children: [
                    /* @__PURE__ */ e("option", { value: "", children: a("roleDetail.translations.selectLanguage") }),
                    Fe.map((r) => /* @__PURE__ */ e("option", { value: r.code, children: r.label }, r.code))
                  ]
                }
              )
            ] }),
            E && /* @__PURE__ */ t(er, { children: [
              /* @__PURE__ */ t("div", { children: [
                /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: a("roleDetail.translations.name") }),
                /* @__PURE__ */ e(
                  "input",
                  {
                    type: "text",
                    value: h.name,
                    onChange: (r) => D((o) => ({ ...o, name: r.target.value })),
                    className: "w-full px-3 py-2 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-secondary)] text-[var(--text-primary)]"
                  }
                )
              ] }),
              /* @__PURE__ */ t("div", { children: [
                /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: a("roleDetail.translations.shortName") }),
                /* @__PURE__ */ e(
                  "input",
                  {
                    type: "text",
                    value: h.shortName,
                    onChange: (r) => D((o) => ({ ...o, shortName: r.target.value })),
                    className: "w-full px-3 py-2 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-secondary)] text-[var(--text-primary)]"
                  }
                )
              ] }),
              /* @__PURE__ */ t("div", { children: [
                /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: a("roleDetail.translations.description") }),
                /* @__PURE__ */ e(
                  "textarea",
                  {
                    value: h.description || "",
                    onChange: (r) => D((o) => ({ ...o, description: r.target.value })),
                    rows: 2,
                    className: "w-full px-3 py-2 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-secondary)] text-[var(--text-primary)] resize-none"
                  }
                )
              ] }),
              /* @__PURE__ */ t("div", { className: "flex justify-end gap-2", children: [
                /* @__PURE__ */ e(
                  "button",
                  {
                    onClick: fe,
                    className: "px-3 py-1.5 rounded-[var(--radius-button)] bg-[var(--bg-tertiary)] hover:bg-[var(--bg-hover)] text-[var(--text-primary)] text-sm font-medium",
                    children: a("common.cancel")
                  }
                ),
                /* @__PURE__ */ t(
                  "button",
                  {
                    onClick: () => ye(E),
                    disabled: Y || !h.name || !h.shortName,
                    className: "flex items-center gap-2 px-3 py-1.5 rounded-[var(--radius-button)] bg-[var(--color-accent-600)] hover:bg-[var(--color-accent-700)] text-white text-sm font-medium disabled:opacity-50",
                    children: [
                      Y && /* @__PURE__ */ e(g, { className: "w-4 h-4 animate-spin" }),
                      a("common.save")
                    ]
                  }
                )
              ] })
            ] })
          ] })
        ] }),
        K && /* @__PURE__ */ e("div", { className: "flex items-center justify-center py-12", children: /* @__PURE__ */ e(g, { className: "w-6 h-6 animate-spin text-[var(--color-accent-500)]" }) }),
        !K && C.length === 0 && /* @__PURE__ */ e("div", { className: "text-center py-12 text-[var(--text-secondary)]", children: a("roleDetail.translations.noTranslations") }),
        !K && C.length > 0 && /* @__PURE__ */ e("div", { className: "space-y-3", children: C.map((r) => {
          const o = We.find((H) => H.code === r.languageCode), ie = V === r.languageCode;
          return /* @__PURE__ */ t(
            "div",
            {
              className: `p-4 rounded-[var(--radius-card)] border ${ie ? "bg-[var(--bg-primary)] border-[var(--color-accent-500)]" : "bg-[var(--bg-primary)] border-[var(--border-color)]"}`,
              children: [
                /* @__PURE__ */ t("div", { className: "flex items-center justify-between mb-2", children: [
                  /* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
                    /* @__PURE__ */ e("span", { className: "px-2 py-0.5 text-xs font-medium rounded bg-[var(--bg-tertiary)] text-[var(--text-secondary)] uppercase", children: r.languageCode }),
                    /* @__PURE__ */ e("span", { className: "text-sm text-[var(--text-secondary)]", children: o?.label || r.languageCode })
                  ] }),
                  !ie && /* @__PURE__ */ t("div", { className: "flex items-center gap-1", children: [
                    /* @__PURE__ */ e(
                      "button",
                      {
                        onClick: () => re(r),
                        className: "p-1.5 rounded hover:bg-[var(--bg-hover)] text-[var(--text-secondary)] hover:text-[var(--color-accent-600)]",
                        title: a("common.edit"),
                        children: /* @__PURE__ */ e(Cr, { className: "w-4 h-4" })
                      }
                    ),
                    /* @__PURE__ */ e(
                      "button",
                      {
                        onClick: () => qe(r.languageCode),
                        className: "p-1.5 rounded hover:bg-[var(--bg-hover)] text-[var(--text-secondary)] hover:text-[var(--error-text)]",
                        title: a("common.delete"),
                        children: /* @__PURE__ */ e(we, { className: "w-4 h-4" })
                      }
                    )
                  ] })
                ] }),
                ie ? /* @__PURE__ */ t("div", { className: "grid gap-3 mt-3", children: [
                  /* @__PURE__ */ t("div", { children: [
                    /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: a("roleDetail.translations.name") }),
                    /* @__PURE__ */ e(
                      "input",
                      {
                        type: "text",
                        value: h.name,
                        onChange: (H) => D((ce) => ({ ...ce, name: H.target.value })),
                        className: "w-full px-3 py-2 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-secondary)] text-[var(--text-primary)]"
                      }
                    )
                  ] }),
                  /* @__PURE__ */ t("div", { children: [
                    /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: a("roleDetail.translations.shortName") }),
                    /* @__PURE__ */ e(
                      "input",
                      {
                        type: "text",
                        value: h.shortName,
                        onChange: (H) => D((ce) => ({ ...ce, shortName: H.target.value })),
                        className: "w-full px-3 py-2 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-secondary)] text-[var(--text-primary)]"
                      }
                    )
                  ] }),
                  /* @__PURE__ */ t("div", { children: [
                    /* @__PURE__ */ e("label", { className: "block text-sm font-medium text-[var(--text-secondary)] mb-1", children: a("roleDetail.translations.description") }),
                    /* @__PURE__ */ e(
                      "textarea",
                      {
                        value: h.description || "",
                        onChange: (H) => D((ce) => ({ ...ce, description: H.target.value })),
                        rows: 2,
                        className: "w-full px-3 py-2 rounded-[var(--radius-input)] border border-[var(--border-color)] bg-[var(--bg-secondary)] text-[var(--text-primary)] resize-none"
                      }
                    )
                  ] }),
                  /* @__PURE__ */ t("div", { className: "flex justify-end gap-2", children: [
                    /* @__PURE__ */ e(
                      "button",
                      {
                        onClick: fe,
                        className: "px-3 py-1.5 rounded-[var(--radius-button)] bg-[var(--bg-tertiary)] hover:bg-[var(--bg-hover)] text-[var(--text-primary)] text-sm font-medium",
                        children: a("common.cancel")
                      }
                    ),
                    /* @__PURE__ */ t(
                      "button",
                      {
                        onClick: () => ye(r.languageCode),
                        disabled: Y || !h.name || !h.shortName,
                        className: "flex items-center gap-2 px-3 py-1.5 rounded-[var(--radius-button)] bg-[var(--color-accent-600)] hover:bg-[var(--color-accent-700)] text-white text-sm font-medium disabled:opacity-50",
                        children: [
                          Y && /* @__PURE__ */ e(g, { className: "w-4 h-4 animate-spin" }),
                          a("common.save")
                        ]
                      }
                    )
                  ] })
                ] }) : /* @__PURE__ */ t("div", { className: "grid gap-1", children: [
                  /* @__PURE__ */ e("div", { className: "font-medium text-[var(--text-primary)]", children: r.name }),
                  /* @__PURE__ */ t("div", { className: "text-sm text-[var(--text-secondary)]", children: [
                    a("roleDetail.translations.shortName"),
                    ": ",
                    r.shortName
                  ] }),
                  r.description && /* @__PURE__ */ e("div", { className: "text-sm text-[var(--text-tertiary)] mt-1", children: r.description })
                ] })
              ]
            },
            r.languageCode
          );
        }) })
      ] })
    ] })
  ] }) : /* @__PURE__ */ t("div", { className: "text-center py-12", children: [
    /* @__PURE__ */ e("p", { className: "text-[var(--text-secondary)]", children: a("roleDetail.notFound") }),
    /* @__PURE__ */ e(
      "button",
      {
        onClick: () => p("/administration/permissions/roles"),
        className: "mt-4 px-4 py-2 rounded-[var(--radius-button)] bg-[var(--color-accent-600)] text-white",
        children: a("roleDetail.backToList")
      }
    )
  ] });
}
export {
  _r as RoleDetailPage
};
//# sourceMappingURL=RoleDetailPage-Blau6_4c.js.map
