import { jsx as e, jsxs as a } from "react/jsx-runtime";
import { useState as o, useCallback as L, useEffect as R } from "react";
import { useParams as E, useNavigate as I } from "react-router-dom";
import { useTranslation as O } from "react-i18next";
import { v as U, P as m } from "./index-CeEMms9z.js";
import { U as $ } from "./UnderlinedTabs-BEbz4Kre.js";
import { Loader2 as j, ShieldCheck as p, CheckCircle as F, Copy as V, Info as W, Layers as _, Shield as i, Calendar as B, Building2 as x, Users as v, Lock as M, Play as K, UserPlus as q, Trash2 as z, Edit as H, Plus as J, Eye as Q } from "lucide-react";
const N = {
  "*": /* @__PURE__ */ e(i, { className: "h-4 w-4" }),
  Read: /* @__PURE__ */ e(Q, { className: "h-4 w-4" }),
  Create: /* @__PURE__ */ e(J, { className: "h-4 w-4" }),
  Update: /* @__PURE__ */ e(H, { className: "h-4 w-4" }),
  Delete: /* @__PURE__ */ e(z, { className: "h-4 w-4" }),
  Assign: /* @__PURE__ */ e(q, { className: "h-4 w-4" }),
  Execute: /* @__PURE__ */ e(K, { className: "h-4 w-4" })
}, y = {
  "*": "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)]"
}, X = {
  Context: "bg-[var(--info-bg)] text-[var(--info-text)] border-[var(--info-border)]",
  Application: "bg-[var(--info-bg)] text-[var(--info-text)] border-[var(--info-border)]",
  Module: "bg-[var(--success-bg)] text-[var(--success-text)] border-[var(--success-border)]",
  Section: "bg-[var(--warning-bg)] text-[var(--warning-text)] border-[var(--warning-border)]",
  Resource: "bg-[var(--warning-bg)] text-[var(--warning-text)] border-[var(--warning-border)]"
};
function ie() {
  const { t: r } = O(["admin", "common"]), { id: c } = E(), d = I(), [s, w] = o(null), [D, b] = o(!0), [h, C] = o(null), [P, u] = o(!1), [l, k] = o("roles"), g = L(async () => {
    if (c)
      try {
        b(!0);
        const t = await U.permissions.getById(c);
        w(t);
      } catch (t) {
        console.error("Failed to load permission:", t), C(r("admin:permissionDetail.errors.loadFailed", "Failed to load permission"));
      } finally {
        b(!1);
      }
  }, [c, r]);
  R(() => {
    g();
  }, [g]);
  const A = async () => {
    s?.path && (await navigator.clipboard.writeText(s.path), u(!0), setTimeout(() => u(!1), 2e3));
  };
  if (D)
    return /* @__PURE__ */ e(
      m,
      {
        title: r("admin:permissionDetail.title", "Permission Detail"),
        breadcrumbs: [
          { label: r("admin:header.title"), href: "/administration" },
          { label: r("admin:permissions.title", "Permissions"), href: "/administration/permissions/permissions" }
        ],
        icon: /* @__PURE__ */ e(p, { className: "h-6 w-6" }),
        children: /* @__PURE__ */ e("div", { className: "flex items-center justify-center min-h-[400px]", children: /* @__PURE__ */ e(j, { className: "h-8 w-8 animate-spin text-[var(--color-accent-500)]" }) })
      }
    );
  if (h || !s)
    return /* @__PURE__ */ e(
      m,
      {
        title: r("admin:permissionDetail.title", "Permission Detail"),
        breadcrumbs: [
          { label: r("admin:header.title"), href: "/administration" },
          { label: r("admin:permissions.title", "Permissions"), href: "/administration/permissions/permissions" }
        ],
        icon: /* @__PURE__ */ e(p, { className: "h-6 w-6" }),
        children: /* @__PURE__ */ a("div", { className: "bg-[var(--error-bg)] border border-[var(--error-border)] rounded-lg p-4", children: [
          /* @__PURE__ */ e("p", { className: "text-[var(--error-text)]", children: h || r("admin:permissionDetail.errors.notFound", "Permission not found") }),
          /* @__PURE__ */ e(
            "button",
            {
              onClick: () => d("/administration/permissions/permissions"),
              className: "mt-4 text-sm text-[var(--color-accent-500)] hover:underline",
              children: r("common:buttons.back")
            }
          )
        ] })
      }
    );
  const f = s.action || "*", S = y[f] || y["*"], T = N[f] || N["*"], G = X[s.level] || "bg-[var(--bg-secondary)] text-[var(--text-primary)]";
  return /* @__PURE__ */ a(
    m,
    {
      title: r("admin:permissionDetail.title", "Permission Detail"),
      breadcrumbs: [
        { label: r("admin:header.title"), href: "/administration" },
        { label: r("admin:permissions.title", "Permissions"), href: "/administration/permissions/permissions" },
        { label: s?.path || "Detail" }
      ],
      icon: /* @__PURE__ */ e(p, { className: "h-6 w-6" }),
      children: [
        /* @__PURE__ */ a("div", { className: "flex items-center gap-2", children: [
          /* @__PURE__ */ e("code", { className: "px-3 py-1.5 bg-[var(--bg-tertiary)] border border-[var(--border-color)] rounded-lg text-sm font-mono text-[var(--text-primary)]", children: s.path }),
          /* @__PURE__ */ e(
            "button",
            {
              onClick: A,
              className: "p-1.5 hover:bg-[var(--bg-hover)] rounded transition-colors",
              title: r("common:buttons.copy"),
              children: P ? /* @__PURE__ */ e(F, { className: "h-4 w-4 text-[var(--success-text)]" }) : /* @__PURE__ */ e(V, { className: "h-4 w-4 text-[var(--text-muted)]" })
            }
          )
        ] }),
        /* @__PURE__ */ a("div", { className: "bg-[var(--bg-card)] border border-[var(--border-color)] rounded-[var(--radius-card)] p-6", children: [
          /* @__PURE__ */ a("h2", { className: "text-lg font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2", children: [
            /* @__PURE__ */ e(W, { className: "h-5 w-5 text-[var(--color-accent-500)]" }),
            r("admin:permissionDetail.info", "Information")
          ] }),
          /* @__PURE__ */ a("div", { className: "grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4", children: [
            /* @__PURE__ */ a("div", { className: "space-y-1", children: [
              /* @__PURE__ */ e("label", { className: "text-xs font-medium text-[var(--text-muted)] uppercase tracking-wide", children: r("admin:permissions.level", "Level") }),
              /* @__PURE__ */ e("div", { children: /* @__PURE__ */ a("span", { className: `inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium ${G}`, children: [
                /* @__PURE__ */ e(_, { className: "h-3 w-3" }),
                s.level
              ] }) })
            ] }),
            /* @__PURE__ */ a("div", { className: "space-y-1", children: [
              /* @__PURE__ */ e("label", { className: "text-xs font-medium text-[var(--text-muted)] uppercase tracking-wide", children: r("admin:permissions.action", "Action") }),
              /* @__PURE__ */ e("div", { children: /* @__PURE__ */ a("span", { className: `inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border ${S}`, children: [
                T,
                s.action || r("admin:permissions.wildcard", "Wildcard (*)")
              ] }) })
            ] }),
            /* @__PURE__ */ a("div", { className: "space-y-1", children: [
              /* @__PURE__ */ e("label", { className: "text-xs font-medium text-[var(--text-muted)] uppercase tracking-wide", children: r("admin:permissions.type", "Type") }),
              /* @__PURE__ */ e("div", { children: s.isWildcard ? /* @__PURE__ */ a("span", { className: "inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium bg-[var(--accent-bg)] text-[var(--accent-text)] border border-[var(--accent-border)]", children: [
                /* @__PURE__ */ e(i, { className: "h-3 w-3" }),
                r("admin:permissions.wildcardType", "Wildcard")
              ] }) : /* @__PURE__ */ e("span", { className: "inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium bg-[var(--bg-secondary)] text-[var(--text-secondary)] border border-[var(--border-color)]", children: r("admin:permissions.specificType", "Specific") }) })
            ] }),
            /* @__PURE__ */ a("div", { className: "space-y-1", children: [
              /* @__PURE__ */ e("label", { className: "text-xs font-medium text-[var(--text-muted)] uppercase tracking-wide", children: r("admin:permissions.createdAt", "Created") }),
              /* @__PURE__ */ a("div", { className: "flex items-center gap-1.5 text-sm text-[var(--text-secondary)]", children: [
                /* @__PURE__ */ e(B, { className: "h-4 w-4" }),
                new Date(s.createdAt).toLocaleDateString()
              ] })
            ] }),
            s.description && /* @__PURE__ */ a("div", { className: "space-y-1 md:col-span-2", children: [
              /* @__PURE__ */ e("label", { className: "text-xs font-medium text-[var(--text-muted)] uppercase tracking-wide", children: r("admin:permissions.description", "Description") }),
              /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)]", children: s.description })
            ] })
          ] })
        ] }),
        /* @__PURE__ */ e(
          $,
          {
            tabs: [
              { id: "roles", label: r("admin:permissionDetail.tabs.roles", "Rôles"), count: s.roles.length, icon: /* @__PURE__ */ e(i, { className: "w-4 h-4" }) },
              { id: "entraGroups", label: r("admin:permissionDetail.tabs.entraGroups", "Groupes AAD"), count: s.entraGroups?.length ?? 0, icon: /* @__PURE__ */ e(x, { className: "w-4 h-4" }) },
              { id: "users", label: r("admin:permissionDetail.tabs.users", "Utilisateurs"), count: s.users.length, icon: /* @__PURE__ */ e(v, { className: "w-4 h-4" }) }
            ].map((t) => ({
              id: t.id,
              icon: t.icon,
              label: /* @__PURE__ */ a("span", { className: "flex items-center gap-2", children: [
                t.label,
                /* @__PURE__ */ e("span", { className: "px-2 py-0.5 text-xs rounded-full bg-[var(--bg-tertiary)] text-[var(--text-tertiary)]", children: t.count })
              ] })
            })),
            activeTab: l,
            onTabChange: k,
            ariaLabel: r("admin:permissionDetail.tabs.label", "Onglets de la permission")
          }
        ),
        /* @__PURE__ */ a("div", { className: "min-h-[400px]", children: [
          l === "roles" && /* @__PURE__ */ e("div", { className: "bg-[var(--bg-card)] border border-[var(--border-color)] rounded-[var(--radius-card)] p-6", children: s.roles.length === 0 ? /* @__PURE__ */ a("div", { className: "text-center py-8 text-[var(--text-muted)]", children: [
            /* @__PURE__ */ e(i, { className: "h-12 w-12 mx-auto mb-3 opacity-30" }),
            /* @__PURE__ */ e("p", { children: r("admin:permissionDetail.noRoles", "No roles have this permission") })
          ] }) : /* @__PURE__ */ e("div", { className: "rounded-[var(--radius-card)] border border-[var(--border-color)] overflow-hidden", children: /* @__PURE__ */ a("table", { className: "w-full", children: [
            /* @__PURE__ */ e("thead", { className: "bg-[var(--bg-secondary)]", children: /* @__PURE__ */ a("tr", { children: [
              /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: r("admin:roles.name", "Nom") }),
              /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: r("common:type", "Type") })
            ] }) }),
            /* @__PURE__ */ e("tbody", { className: "divide-y divide-[var(--border-color)]", children: s.roles.map((t) => /* @__PURE__ */ a(
              "tr",
              {
                onClick: () => d(`/administration/permissions/roles/${t.id}`),
                className: "hover:bg-[var(--bg-hover)] cursor-pointer transition-colors",
                children: [
                  /* @__PURE__ */ e("td", { className: "px-4 py-3", children: /* @__PURE__ */ a("div", { className: "flex items-center gap-3", children: [
                    /* @__PURE__ */ e("div", { className: "w-8 h-8 rounded-full flex items-center justify-center bg-[var(--color-accent-500)]/10 text-[var(--color-accent-500)]", children: /* @__PURE__ */ e(i, { className: "w-4 h-4" }) }),
                    /* @__PURE__ */ e("span", { className: "font-medium text-[var(--text-primary)]", children: t.name })
                  ] }) }),
                  /* @__PURE__ */ e("td", { className: "px-4 py-3", children: t.isSystem ? /* @__PURE__ */ a("span", { className: "inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium bg-[var(--info-bg)] text-[var(--info-text)] border border-[var(--info-border)]", children: [
                    /* @__PURE__ */ e(M, { className: "h-3 w-3" }),
                    r("admin:roles.system", "Système")
                  ] }) : /* @__PURE__ */ e("span", { className: "inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium bg-[var(--bg-secondary)] text-[var(--text-secondary)] border border-[var(--border-color)]", children: r("admin:roles.custom", "Personnalisé") }) })
                ]
              },
              t.id
            )) })
          ] }) }) }),
          l === "entraGroups" && /* @__PURE__ */ e("div", { className: "bg-[var(--bg-card)] border border-[var(--border-color)] rounded-[var(--radius-card)] p-6", children: !s.entraGroups || s.entraGroups.length === 0 ? /* @__PURE__ */ a("div", { className: "text-center py-8 text-[var(--text-muted)]", children: [
            /* @__PURE__ */ e(x, { className: "h-12 w-12 mx-auto mb-3 opacity-30" }),
            /* @__PURE__ */ e("p", { children: r("admin:permissionDetail.noEntraGroups", "Aucun groupe AAD n'a cette permission") })
          ] }) : /* @__PURE__ */ e("div", { className: "rounded-[var(--radius-card)] border border-[var(--border-color)] overflow-hidden", children: /* @__PURE__ */ a("table", { className: "w-full", children: [
            /* @__PURE__ */ e("thead", { className: "bg-[var(--bg-secondary)]", children: /* @__PURE__ */ a("tr", { children: [
              /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: r("entra:groups.groupName", "Nom du groupe") }),
              /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: r("common:type", "Type") }),
              /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: r("entra:groups.members", "Membres") }),
              /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: r("admin:permissionDetail.viaRoles", "Via Rôles") })
            ] }) }),
            /* @__PURE__ */ e("tbody", { className: "divide-y divide-[var(--border-color)]", children: s.entraGroups.map((t) => /* @__PURE__ */ a(
              "tr",
              {
                onClick: () => d(`/administration/entra/groups/${t.id}`),
                className: "hover:bg-[var(--bg-hover)] cursor-pointer transition-colors",
                children: [
                  /* @__PURE__ */ e("td", { className: "px-4 py-3", children: /* @__PURE__ */ a("div", { className: "flex items-center gap-3", children: [
                    /* @__PURE__ */ e("div", { className: `w-8 h-8 rounded-full flex items-center justify-center ${t.isSecurityGroup, "bg-[var(--info-bg)] text-[var(--info-text)]"}`, children: t.isSecurityGroup ? /* @__PURE__ */ e(i, { className: "w-4 h-4" }) : /* @__PURE__ */ e(x, { className: "w-4 h-4" }) }),
                    /* @__PURE__ */ e("span", { className: "font-medium text-[var(--text-primary)]", children: t.displayName })
                  ] }) }),
                  /* @__PURE__ */ e("td", { className: "px-4 py-3", children: /* @__PURE__ */ e("span", { className: `px-2 py-1 text-xs rounded-[var(--radius-badge)] ${t.isSecurityGroup, "bg-[var(--info-bg)] text-[var(--info-text)]"}`, children: t.isSecurityGroup ? r("entra:groups.securityGroup", "Sécurité") : r("entra:groups.distributionGroup", "Distribution") }) }),
                  /* @__PURE__ */ e("td", { className: "px-4 py-3 text-sm text-[var(--text-secondary)]", children: /* @__PURE__ */ a("span", { className: "flex items-center gap-1", children: [
                    /* @__PURE__ */ e(v, { className: "w-4 h-4" }),
                    t.memberCount
                  ] }) }),
                  /* @__PURE__ */ e("td", { className: "px-4 py-3", children: /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-1", children: t.roleNames.map((n) => /* @__PURE__ */ a(
                    "span",
                    {
                      className: "inline-flex items-center gap-1 px-2 py-0.5 bg-[var(--bg-tertiary)] rounded text-xs text-[var(--text-secondary)]",
                      children: [
                        /* @__PURE__ */ e(i, { className: "h-2.5 w-2.5" }),
                        n
                      ]
                    },
                    n
                  )) }) })
                ]
              },
              t.id
            )) })
          ] }) }) }),
          l === "users" && /* @__PURE__ */ e("div", { className: "bg-[var(--bg-card)] border border-[var(--border-color)] rounded-[var(--radius-card)] p-6", children: s.users.length === 0 ? /* @__PURE__ */ a("div", { className: "text-center py-8 text-[var(--text-muted)]", children: [
            /* @__PURE__ */ e(v, { className: "h-12 w-12 mx-auto mb-3 opacity-30" }),
            /* @__PURE__ */ e("p", { children: r("admin:permissionDetail.noUsers", "No users have this permission") })
          ] }) : /* @__PURE__ */ e("div", { className: "rounded-[var(--radius-card)] border border-[var(--border-color)] overflow-hidden", children: /* @__PURE__ */ a("table", { className: "w-full", children: [
            /* @__PURE__ */ e("thead", { className: "bg-[var(--bg-secondary)]", children: /* @__PURE__ */ a("tr", { children: [
              /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: r("admin:users.name", "Name") }),
              /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: r("admin:users.email", "Email") }),
              /* @__PURE__ */ e("th", { className: "px-4 py-3 text-left text-sm font-medium text-[var(--text-secondary)]", children: r("admin:permissionDetail.viaRoles", "Via Roles") })
            ] }) }),
            /* @__PURE__ */ e("tbody", { className: "divide-y divide-[var(--border-color)]", children: s.users.map((t) => /* @__PURE__ */ a(
              "tr",
              {
                onClick: () => d(`/administration/users/${t.id}`),
                className: "hover:bg-[var(--bg-hover)] cursor-pointer transition-colors",
                children: [
                  /* @__PURE__ */ e("td", { className: "px-4 py-3", children: /* @__PURE__ */ a("div", { className: "flex items-center gap-3", children: [
                    /* @__PURE__ */ e("div", { className: "h-8 w-8 rounded-full bg-[var(--color-accent-100)] dark:bg-[var(--color-accent-900)] flex items-center justify-center", children: /* @__PURE__ */ a("span", { className: "text-sm font-medium text-[var(--color-accent-700)] dark:text-[var(--color-accent-300)]", children: [
                      t.firstName.charAt(0),
                      t.lastName.charAt(0)
                    ] }) }),
                    /* @__PURE__ */ a("span", { className: "font-medium text-[var(--text-primary)]", children: [
                      t.firstName,
                      " ",
                      t.lastName
                    ] })
                  ] }) }),
                  /* @__PURE__ */ e("td", { className: "px-4 py-3 text-sm text-[var(--text-secondary)]", children: t.email }),
                  /* @__PURE__ */ e("td", { className: "px-4 py-3", children: /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-1", children: t.roleNames.map((n) => /* @__PURE__ */ a(
                    "span",
                    {
                      className: "inline-flex items-center gap-1 px-2 py-0.5 bg-[var(--bg-tertiary)] rounded text-xs text-[var(--text-secondary)]",
                      children: [
                        /* @__PURE__ */ e(i, { className: "h-2.5 w-2.5" }),
                        n
                      ]
                    },
                    n
                  )) }) })
                ]
              },
              t.id
            )) })
          ] }) }) })
        ] })
      ]
    }
  );
}
export {
  ie as PermissionDetailPage
};
//# sourceMappingURL=PermissionDetailPage-CkSTtH_N.js.map
