'use client';
import { useTranslations } from 'next-intl';
import { Box, Skeleton, Stack } from '@mui/material';
import { AdminDataTable, AdminEmptyState, AdminErrorState, AdminPageHeader } from '@/components/admin';
import type { AdminTableColumn } from '@/components/admin';
import { StatusChip } from '@/components';
import type { SponsoredNurse } from '@/services/partnerCenter/types';
import { useMySponsoredNurses } from '@/services/partnerCenter';

/**
 * Partner portal — sponsored-nurses roster (f15). The read-only list of nurses the signed-in center
 * sponsors (portal scope; server-enforced tenancy). Two columns: name + a verification `StatusChip`. Not
 * paginated (the portal roster is a bounded set), so no pager.
 */
export default function PartnerNursesPage() {
  const t = useTranslations('partner');
  const ta = useTranslations('admin');
  const nurses = useMySponsoredNurses();
  const items = nurses.data ?? [];

  const columns: AdminTableColumn<SponsoredNurse>[] = [
    {
      key: 'name',
      header: t('nurses_col_name'),
      render: (n) => n.name,
    },
    {
      key: 'verified',
      header: t('nurses_col_verified'),
      render: (n) => (
        <StatusChip
          status={n.isVerified ? 'verified' : 'neutral'}
          label={n.isVerified ? ta('center_state_verified') : ta('center_state_pending_verification')}
        />
      ),
    },
  ];

  return (
    <Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
      <AdminPageHeader title={t('nurses_title')} />

      {nurses.isLoading ? (
        <Stack sx={{ gap: 2 }}>
          {[0, 1, 2].map((k) => (
            <Skeleton key={k} variant="rounded" height={56} />
          ))}
        </Stack>
      ) : nurses.isError ? (
        <AdminErrorState message={ta('error_generic')} retryLabel={ta('retry')} onRetry={() => nurses.refetch()} />
      ) : items.length === 0 ? (
        <AdminEmptyState icon="patients" title={t('nurses_empty')} />
      ) : (
        <AdminDataTable
          columns={columns}
          rows={items}
          getRowKey={(n) => n.nurseProfileId}
          ariaLabel={t('nurses_title')}
        />
      )}
    </Box>
  );
}
