'use client';

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

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

function Consentimentos() {
  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 consentimentos"
        subtitle="Controle os termos que você concedeu (LGPD)"
      />
      <ConsentsTab patientId={patient.id} canManage />
    </>
  );
}
