'use client' import { PencilSquareIcon } from '@heroicons/react/24/outline' import type { UserRole, UserRow, UserStatus, UserType } from '../hooks/useUserManagementPageState' import { getUserStatusBadgeClass, getUserStatusLabel, getUserTypeBadgeClass, getUserTypeLabel, getUserRoleBadgeClass, getUserRoleLabel, type ManagedUserStatus, type ManagedUserType, type ManagedUserRole, } from '../constants/userStatusPresentation' type TFunction = (key: string) => string type Props = { t: TFunction loading: boolean users: UserRow[] totalFiltered: number page: number totalPages: number onPageChange: (nextPage: number) => void onEdit: (id: string) => void normalizeStatus: (status: string) => UserStatus } function badge(text: string, color: 'blue' | 'amber' | 'green' | 'gray' | 'rose' | 'indigo' | 'violet') { const base = 'inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold tracking-wide' const colorMap: Record = { blue: 'bg-sky-100 text-sky-700', amber: 'bg-amber-100 text-amber-700', green: 'bg-green-100 text-green-700', gray: 'bg-slate-100 text-slate-700', rose: 'bg-rose-100 text-rose-700', indigo: 'bg-indigo-100 text-indigo-700', violet: 'bg-violet-100 text-violet-700', } return {text} } function statusBadge(status: UserStatus, t: TFunction) { if (status === 'disabled') return badge(t('autofix.k2fc06d90'), 'gray') const managedStatus = status as ManagedUserStatus return ( {getUserStatusLabel(t, managedStatus)} ) } function typeBadge(type: UserType, t: TFunction) { const managedType = type as ManagedUserType return ( {getUserTypeLabel(t, managedType)} ) } function roleBadge(role: UserRole, t: TFunction) { const managedRole = role as ManagedUserRole return ( {getUserRoleLabel(t, managedRole)} ) } export default function UserManagementTable({ t, loading, users, totalFiltered, page, totalPages, onPageChange, onEdit, normalizeStatus, }: Props) { return (

{t('autofix.k10ccb626')}

{t('autofix.k2e41c8dc').replace('{current}', String(users.length)).replace('{total}', String(totalFiltered))}
{loading ? ( ) : users.length === 0 ? ( ) : ( users.map((user) => { const displayName = user.user_type === 'company' ? user.company_name || t('autofix.k835f1c86') : `${user.first_name || t('autofix.k76870ea8')} ${user.last_name || t('autofix.k2bf5e6ec')}` const initials = user.user_type === 'company' ? (user.company_name?.[0] || 'C').toUpperCase() : `${user.first_name?.[0] || 'U'}${user.last_name?.[0] || 'U'}`.toUpperCase() const createdDate = new Date(user.created_at).toLocaleDateString() const lastLoginDate = user.last_login_at ? new Date(user.last_login_at).toLocaleDateString() : t('autofix.k768f3f4a') const normalizedStatus = normalizeStatus(user.status) return ( ) }) )}
{t('autofix.k91f49568')} {t('autofix.kec4fe9ef')} {t('autofix.k81c0b74b')} {t('autofix.ked760737')} {t('autofix.kf123704b')} {t('autofix.kb24782ec')} {t('autofix.k0afbbac4')}
{t('autofix.k7fa2c4af')}
{t('autofix.k748bf541')}
{initials}
{displayName}
{user.email}
{typeBadge(user.user_type, t)} {statusBadge(normalizedStatus, t)} {roleBadge(user.role, t)} {createdDate} {lastLoginDate}
{t('autofix.kf03c39b7').replace('{page}', String(page)).replace('{pages}', String(totalPages)).replace('{total}', String(totalFiltered))}
) }