'use client';

import PageContainer from '@/components/layout/page-container';
import { CreateTrainingForm } from '@/feactures/training/components/form';
import { useTrainingByIdQuery } from '@/feactures/training/hooks/use-training';
import { useParams, useRouter } from 'next/navigation';

export default function EditTrainingPage() {
  const router = useRouter();
  const params = useParams();
  const id = Number(params.id);

  const { data: training, isLoading } = useTrainingByIdQuery(id);

  if (isLoading) {
    return (
      <PageContainer>
        <div>Cargando...</div>
      </PageContainer>
    );
  }

  return (
    <div className="p-6 space-y-6">
      <CreateTrainingForm
        defaultValues={training}
        onSuccess={() => router.push('/dashboard/formulario')}
        onCancel={() => router.back()}
      />
    </div>
  );
}
