// src/app/(dashboard)/user-accounts/columns.tsx "use client"; import { Column } from "@/components/ui/DataTable"; import { type ManagedUser } from "@/lib/admin-api"; import { Eye, Loader2 } from "lucide-react"; interface GetColumnsProps { role: string | null; currentUsername?: string | null; viewAsLoading?: string | null; onEditClick: (user: ManagedUser) => void; onViewAsClick?: (user: ManagedUser) => void; } export function getColumns({ role, currentUsername, viewAsLoading, onEditClick, onViewAsClick, }: GetColumnsProps): Column[] { return [ { header: "#", className: "w-[5%] text-center", accessor: (_, i) => {i + 1} }, { header: "Account Name", className: "w-[22%] text-center", accessor: (row) => ( {row.account_name || row.username} ) }, { header: "Username", className: "w-[18%] text-center", accessor: (row) => {row.username} }, { header: "Role", className: "w-[18%] text-center", accessor: (row) => { let badgeColor = "bg-slate-500/20 text-slate-400 border-slate-500/30"; if (row.role === "COMPANY_ADMIN") badgeColor = "bg-purple-500/20 text-purple-400 border-purple-500/30"; if (row.role === "COMPANY_OPERATOR") badgeColor = "bg-amber-500/20 text-amber-400 border-amber-500/30"; if (row.role === "COMPANY_VIEWER") badgeColor = "bg-blue-500/20 text-blue-400 border-blue-500/30"; return ( {row.role.replace(/_/g, " ")} ); } }, { header: "Assigned Devices", className: "w-[15%] text-center", accessor: (row) => { const uuids = row.agent_uuids || []; if (uuids.length === 0) return No device assigned; return ( {uuids.length} Device{uuids.length > 1 ? "s" : ""} ); } }, { header: "View As", className: "w-[10%] text-center", accessor: (row) => { const isSelf = currentUsername && row.username === currentUsername; const isCompanyAdmin = row.role === "COMPANY_ADMIN"; // View-As tersedia untuk COMPANY_OPERATOR dan COMPANY_VIEWER (bukan diri sendiri, bukan admin) const canViewAs = onViewAsClick && !isSelf && !isCompanyAdmin && (row.role === "COMPANY_OPERATOR" || row.role === "COMPANY_VIEWER") && (role === "SUPER_ADMIN" || role === "COMPANY_ADMIN"); if (!canViewAs) { return —; } const isLoading = viewAsLoading === row.username; return ( ); } }, { header: "Actions", className: "w-[12%] text-center", accessor: (row) => { const isSelf = currentUsername && row.username === currentUsername; const isDisabled = role === "EXECUTIVE" || isSelf; return ( ); } } ]; }