'use client'
import React, { useState  } from 'react';
import InscriptionFormShared from '@/components/Inscription/InscriptionFormShared';
import { useSearchParams, useRouter } from 'next/navigation';
import { useCsrfToken } from '@/context/CsrfContext';
import { FE_PARENTS_HOME_URL} from '@/utils/Url';
import { editRegisterForm} from '@/app/actions/subscriptionAction';
import logger from '@/utils/logger';

export default function Page() {
    const searchParams = useSearchParams();
    const idProfil = searchParams.get('id');
    const studentId = searchParams.get('studentId');
    const router = useRouter();
    const csrfToken = useCsrfToken();

    const handleSubmit = async (data) => {
        try {
            const result = await editRegisterForm(studentId, data, csrfToken);
            logger.debug('Success:', result);
            router.push(FE_PARENTS_HOME_URL);
        } catch (error) {
            logger.error('Error:', error);
        }
    };

    return (
        <InscriptionFormShared
            studentId={studentId}
            csrfToken={csrfToken}
            onSubmit={handleSubmit}
            cancelUrl={FE_PARENTS_HOME_URL}
        />
    );
}