"use client"; import { useState } from "react"; import { Sparkles } from "lucide-react"; import { TEMPLATE_TYPES, TEMPLATE_LABELS, type TemplateType, type GameDefinition } from "@/lib/games/types"; import type { QuizDefinition } from "@/lib/games/quiz"; import type { ClickerDefinition } from "@/lib/games/clicker"; import type { MazeDefinition } from "@/lib/games/maze"; import { QuizBuilder } from "@/components/builders/quiz-builder"; import { ClickerBuilder } from "@/components/builders/clicker-builder"; import { MazeBuilder } from "@/components/builders/maze-builder"; export function AiGenerateForm() { const [templateType, setTemplateType] = useState("quiz"); const [title, setTitle] = useState(""); const [prompt, setPrompt] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [definition, setDefinition] = useState(null); async function handleGenerate(e: React.FormEvent) { e.preventDefault(); setLoading(true); setError(null); setDefinition(null); const res = await fetch("/api/ai/generate", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ templateType, prompt }), }); setLoading(false); if (!res.ok) { const data = await res.json().catch(() => null); setError(data?.error ?? "Не удалось сгенерировать игру"); return; } const data = await res.json(); setDefinition(data.definition); } if (definition) { return (

Игра сгенерирована — проверьте и подправьте перед сохранением.

{templateType === "quiz" && ( )} {templateType === "clicker" && ( )} {templateType === "maze" && ( )}
); } return (
Тип игры
{TEMPLATE_TYPES.map((t) => ( ))}