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