"use client"; import { useState } from "react"; import { motion } from "framer-motion"; import { cn } from "@/lib/utils"; import { MoveLeftIcon, Plus, Search, Trash2 } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Separator } from "@/components/ui/separator"; import { Tilt } from "@/components/ui/tilt"; import { Spotlight } from "@/components/ui/spotlight"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import * as z from "zod"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { useRouter } from "next/navigation"; // Define the form schema with Zod const searchSpaceFormSchema = z.object({ name: z.string().min(3, "Name is required"), description: z.string().min(10, "Description is required"), }); // Define the type for the form values type SearchSpaceFormValues = z.infer; interface SearchSpaceFormProps { onSubmit?: (data: { name: string; description: string }) => void; onDelete?: () => void; className?: string; isEditing?: boolean; initialData?: { name: string; description: string }; } export function SearchSpaceForm({ onSubmit, onDelete, className, isEditing = false, initialData = { name: "", description: "" } }: SearchSpaceFormProps) { const [showDeleteDialog, setShowDeleteDialog] = useState(false); const router = useRouter(); // Initialize the form with React Hook Form and Zod validation const form = useForm({ resolver: zodResolver(searchSpaceFormSchema), defaultValues: { name: initialData.name, description: initialData.description, }, }); // Handle form submission const handleFormSubmit = (values: SearchSpaceFormValues) => { if (onSubmit) { onSubmit(values); } }; // Handle delete confirmation const handleDelete = () => { if (onDelete) { onDelete(); } setShowDeleteDialog(false); }; // Animation variants const containerVariants = { hidden: { opacity: 0 }, visible: { opacity: 1, transition: { staggerChildren: 0.1, }, }, }; const itemVariants = { hidden: { y: 20, opacity: 0 }, visible: { y: 0, opacity: 1, transition: { type: "spring", stiffness: 300, damping: 24, }, }, }; return (

{isEditing ? "Edit Search Space" : "Create Search Space"}

{isEditing ? "Update your search space details" : "Create a new search space to organize your documents, chats, and podcasts."}

Search Space

{isEditing && onDelete && ( Are you sure? This action cannot be undone. This will permanently delete your search space. Cancel Delete )}

A search space allows you to organize and search through your documents, generate podcasts, and have AI-powered conversations about your content.

( Name A unique name for your search space. )} /> ( Description A brief description of what this search space will be used for. )} />
); } export default SearchSpaceForm;