'use client';

import { RequireRole } from '@/lib/auth-context';
import { useMyPatient } from '@/lib/use-my-patient';
import DocumentsTab from '@/components/app/patient/DocumentsTab';
import { ErrorAlert, Loading, PageHeader } from '@/components/app/ui';

export default function DocumentosPage() {
  return (
    <RequireRole roles={['patient']}>
      <Documentos />
    </RequireRole>
  );
}

function Documentos() {
  const { patient, loading, error, reload } = useMyPatient();

  if (loading) return <Loading />;
  if (error) return <ErrorAlert message={error} onRetry={reload} />;
  if (!patient) return null;

  return (
    <>
      <PageHeader
        title="Meus documentos"
        subtitle="Exames, radiografias e termos anexados ao seu prontuário"
      />
      <DocumentsTab patientId={patient.id} canManage={false} />
    </>
  );
}
