"use client" import type React from "react" import { useState, useEffect } from "react" import type { Project } from "@/lib/types" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Textarea } from "@/components/ui/textarea" import { Switch } from "@/components/ui/switch" import { X, Plus } from "lucide-react" interface ProjectFormProps { project?: Project | null onSubmit: (data: Omit) => void onCancel: () => void } export function ProjectForm({ project, onSubmit, onCancel }: ProjectFormProps) { const [formData, setFormData] = useState({ name: "", role: "", description: "", highlights: [] as string[], stack: [] as string[], website: "", github: "", featured: false, }) const [newHighlight, setNewHighlight] = useState("") const [newTech, setNewTech] = useState("") useEffect(() => { if (project) { setFormData({ name: project.name, role: project.role, description: project.description, highlights: project.highlights, stack: project.stack, website: project.website || "", github: project.github || "", featured: project.featured, }) } }, [project]) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() onSubmit({ ...formData, website: formData.website || null, github: formData.github || null, }) } const addHighlight = () => { if (newHighlight.trim()) { setFormData((prev) => ({ ...prev, highlights: [...prev.highlights, newHighlight.trim()], })) setNewHighlight("") } } const removeHighlight = (index: number) => { setFormData((prev) => ({ ...prev, highlights: prev.highlights.filter((_, i) => i !== index), })) } const addTech = () => { if (newTech.trim()) { setFormData((prev) => ({ ...prev, stack: [...prev.stack, newTech.trim()], })) setNewTech("") } } const removeTech = (index: number) => { setFormData((prev) => ({ ...prev, stack: prev.stack.filter((_, i) => i !== index), })) } return (
setFormData((prev) => ({ ...prev, name: e.target.value }))} placeholder="My Project" required />
setFormData((prev) => ({ ...prev, role: e.target.value }))} placeholder="Creator / Lead / Contributor" required />