"use client";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { format } from "date-fns";
import {
  Table,
  TableBody,
  TableCell,
  TableHead,
  TableHeader,
  TableRow
} from "../../ui/table";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuSeparator,
  DropdownMenuTrigger
} from "../../ui/dropdown-menu";
import { Button } from "../../ui/button";
import { Badge } from "../../ui/badge";
import { Avatar, AvatarFallback, AvatarImage } from "../../ui/avatar";
import {
  MoreHorizontal,
  Shield,
  Mail,
  Calendar,
  Eye,
  Settings,
  AlertTriangle
} from "lucide-react";
import { useRoleTranslations } from "../../../lib/role-helpers";
function SuperAdminsTable({
  superadmins,
  isLoading,
  currentUserId
}) {
  const getRoleName = useRoleTranslations();
  const getUserInitials = (user) => {
    if (user.firstName && user.lastName) {
      return `${user.firstName[0]}${user.lastName[0]}`.toUpperCase();
    }
    if (user.firstName) {
      return user.firstName.slice(0, 2).toUpperCase();
    }
    return user.email.slice(0, 2).toUpperCase();
  };
  if (isLoading) {
    return /* @__PURE__ */ jsx("div", { className: "space-y-3", children: [...Array(3)].map((_, i) => /* @__PURE__ */ jsxs("div", { className: "flex items-center space-x-4 p-4", children: [
      /* @__PURE__ */ jsx("div", { className: "w-10 h-10 bg-red-100 rounded-full animate-pulse" }),
      /* @__PURE__ */ jsxs("div", { className: "space-y-2 flex-1", children: [
        /* @__PURE__ */ jsx("div", { className: "h-4 bg-muted rounded w-1/4 animate-pulse" }),
        /* @__PURE__ */ jsx("div", { className: "h-3 bg-muted rounded w-1/3 animate-pulse" })
      ] }),
      /* @__PURE__ */ jsx("div", { className: "w-20 h-6 bg-red-100 rounded animate-pulse" }),
      /* @__PURE__ */ jsx("div", { className: "w-8 h-8 bg-muted rounded animate-pulse" })
    ] }, i)) });
  }
  if (superadmins.length === 0) {
    return /* @__PURE__ */ jsxs("div", { className: "text-center py-8", children: [
      /* @__PURE__ */ jsx(Shield, { className: "mx-auto h-12 w-12 text-red-500" }),
      /* @__PURE__ */ jsx("h3", { className: "mt-4 text-lg font-medium", children: "No superadmins found" }),
      /* @__PURE__ */ jsx("p", { className: "mt-2 text-sm text-muted-foreground", children: "This is unusual - there should be at least one superadmin." })
    ] });
  }
  return /* @__PURE__ */ jsxs("div", { className: "rounded-md border border-red-200", children: [
    /* @__PURE__ */ jsxs(Table, { children: [
      /* @__PURE__ */ jsx(TableHeader, { className: "bg-red-50", children: /* @__PURE__ */ jsxs(TableRow, { children: [
        /* @__PURE__ */ jsx(TableHead, { children: "Administrator" }),
        /* @__PURE__ */ jsx(TableHead, { children: "Email" }),
        /* @__PURE__ */ jsx(TableHead, { children: "Role" }),
        /* @__PURE__ */ jsx(TableHead, { children: "Status" }),
        /* @__PURE__ */ jsx(TableHead, { children: "Since" }),
        /* @__PURE__ */ jsx(TableHead, { className: "text-right", children: "Actions" })
      ] }) }),
      /* @__PURE__ */ jsx(TableBody, { children: superadmins.map((admin) => {
        const isCurrentUser = admin.id === currentUserId;
        return /* @__PURE__ */ jsxs(TableRow, { className: isCurrentUser ? "bg-blue-50" : "", children: [
          /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
            /* @__PURE__ */ jsxs(Avatar, { className: "h-9 w-9 border-2 border-red-200", children: [
              /* @__PURE__ */ jsx(AvatarImage, { src: "", alt: admin.fullName }),
              /* @__PURE__ */ jsx(AvatarFallback, { className: "text-xs bg-red-100 text-red-700", children: getUserInitials(admin) })
            ] }),
            /* @__PURE__ */ jsxs("div", { children: [
              /* @__PURE__ */ jsxs("div", { className: "font-medium flex items-center gap-2", children: [
                admin.fullName || "No name",
                isCurrentUser && /* @__PURE__ */ jsx(Badge, { variant: "outline", className: "text-xs text-blue-600 border-blue-600", children: "You" })
              ] }),
              /* @__PURE__ */ jsxs("div", { className: "text-sm text-muted-foreground", children: [
                "ID: ",
                admin.id.slice(0, 8),
                "..."
              ] })
            ] })
          ] }) }),
          /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
            /* @__PURE__ */ jsx(Mail, { className: "h-4 w-4 text-muted-foreground" }),
            /* @__PURE__ */ jsx("span", { className: "font-mono text-sm", children: admin.email })
          ] }) }),
          /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs(Badge, { variant: "destructive", className: "bg-red-600", children: [
            /* @__PURE__ */ jsx(Shield, { className: "mr-1 h-3 w-3" }),
            getRoleName(admin.role)
          ] }) }),
          /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: admin.emailVerified ? /* @__PURE__ */ jsxs(Badge, { variant: "default", className: "bg-green-100 text-green-800", children: [
            /* @__PURE__ */ jsx(Shield, { className: "mr-1 h-3 w-3" }),
            "Verified"
          ] }) : /* @__PURE__ */ jsxs(Badge, { variant: "outline", className: "text-red-600 border-red-600", children: [
            /* @__PURE__ */ jsx(AlertTriangle, { className: "mr-1 h-3 w-3" }),
            "Unverified"
          ] }) }) }),
          /* @__PURE__ */ jsx(TableCell, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: [
            /* @__PURE__ */ jsx(Calendar, { className: "h-4 w-4" }),
            admin.createdAt ? format(new Date(admin.createdAt), "MMM dd, yyyy") : "Unknown"
          ] }) }),
          /* @__PURE__ */ jsx(TableCell, { className: "text-right", children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [
            /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", className: "h-8 w-8 p-0", children: [
              /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Open menu" }),
              /* @__PURE__ */ jsx(MoreHorizontal, { className: "h-4 w-4" })
            ] }) }),
            /* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", children: [
              /* @__PURE__ */ jsx(DropdownMenuLabel, { children: "Admin Actions" }),
              /* @__PURE__ */ jsxs(
                DropdownMenuItem,
                {
                  className: "cursor-pointer",
                  children: [
                    /* @__PURE__ */ jsx(Eye, { className: "mr-2 h-4 w-4" }),
                    "View Profile"
                  ]
                }
              ),
              /* @__PURE__ */ jsxs(DropdownMenuItem, { className: "cursor-pointer", children: [
                /* @__PURE__ */ jsx(Settings, { className: "mr-2 h-4 w-4" }),
                "Admin Settings"
              ] }),
              /* @__PURE__ */ jsxs(DropdownMenuItem, { className: "cursor-pointer", children: [
                /* @__PURE__ */ jsx(Mail, { className: "mr-2 h-4 w-4" }),
                "Send Message"
              ] }),
              !isCurrentUser && /* @__PURE__ */ jsxs(Fragment, { children: [
                /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
                /* @__PURE__ */ jsxs(DropdownMenuItem, { className: "cursor-pointer text-orange-600", children: [
                  /* @__PURE__ */ jsx(AlertTriangle, { className: "mr-2 h-4 w-4" }),
                  "Revoke Admin"
                ] })
              ] })
            ] })
          ] }) })
        ] }, admin.id);
      }) })
    ] }),
    /* @__PURE__ */ jsx("div", { className: "bg-red-50 border-t border-red-200 p-3", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-red-700 text-sm", children: [
      /* @__PURE__ */ jsx(Shield, { className: "h-4 w-4" }),
      /* @__PURE__ */ jsx("span", { className: "font-medium", children: "Security Notice:" }),
      /* @__PURE__ */ jsx("span", { children: "Superadmin access grants full system control. Handle with extreme caution." })
    ] }) })
  ] });
}
export {
  SuperAdminsTable
};
