'use client';
import { PageLayout } from '@/components/common/PageLayout';
import { Layout } from '@/src/components/common/Layout';
import { ProjectForm } from '@/src/components/projects/ProjectForm';
import { useApiWithToast } from '@/src/hooks/useApiWithToast';
import { ProjectService } from '@/src/services/ProjectService';
import { ProjectFormValues } from '@/src/types/project';
import { Project } from '@prisma/client';
import { useRouter } from 'next/navigation';

export default function Page() {
  const router = useRouter();
  const { handle } = useApiWithToast();

  const handleSubmit = async (data: ProjectFormValues) => {
    return await handle<Project>(ProjectService.createProject(data), {
      redirectTo: '/dashboard',
    });
  };

  return (
    <Layout>
      <PageLayout title='Add Project'>
        <ProjectForm onSubmit={handleSubmit} cancelAction={() => router.back()} className='text-neutral-200' />
      </PageLayout>
    </Layout>
  );
}
