"use client"; import { useState, type FormEvent } from "react"; import { useRouter } from "next/navigation"; import { mutate } from "swr"; import { FolderKanban } from "lucide-react"; import { api } from "@/lib/client/fetcher"; import { useModels } from "@/lib/client/use-models"; import { Button, Input, Textarea, toast } from "@/components/ui"; import { ColorPicker, PROJECT_COLORS } from "@/components/projects/project-shared"; export default function NewProjectPage() { const router = useRouter(); const { chat } = useModels(); const [name, setName] = useState(""); const [description, setDescription] = useState(""); const [instructions, setInstructions] = useState(""); const [color, setColor] = useState(PROJECT_COLORS[0]); const [defaultModel, setDefaultModel] = useState(""); const [busy, setBusy] = useState(false); async function submit(e: FormEvent) { e.preventDefault(); setBusy(true); try { const r = await api<{ project: { id: string } }>("/api/projects", { method: "POST", json: { name: name.trim(), description: description.trim() || undefined, instructions: instructions.trim() || undefined, color, defaultModel: defaultModel || null } }); void mutate("/api/projects"); toast("Projet créé", "ok"); router.push(`/projects/${r.project.id}`); } catch (err) { toast((err as Error).message, "error"); setBusy(false); } } return (