'use client';

import ClinicalRecordForm from '@/app/components/Patient/ClinicalRecordForm';
import { api } from '@/lib/api';
import { useParams, useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';

export default function NewClinicalRecordPage() {
    const router = useRouter();
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const params = useParams() as any;
    const [patient, setPatient] = useState<any>(null);

    useEffect(() => {
        api.patients.getById(params.id).then(res => {
            if (res.success && res.data) setPatient(res.data);
        });
    }, [params.id]);

    const handleSuccess = () => {
        router.push(`/patients/${params.id}?tab=history`);
    };

    const handleCancel = () => {
        router.back();
    };

    return (
        <div className="container mx-auto py-8">
            <ClinicalRecordForm
                patientId={params.id}
                patient={patient}
                onSuccess={handleSuccess}
                onCancel={handleCancel}
            />
        </div>
    );
}
