"use client" import type React from "react" import { useState, useEffect } from "react" import type { StackCategory } from "@/lib/types" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { X, Plus } from "lucide-react" interface StackFormProps { category?: StackCategory | null onSubmit: (data: Omit) => void onCancel: () => void } export function StackForm({ category, onSubmit, onCancel }: StackFormProps) { const [title, setTitle] = useState("") const [items, setItems] = useState([]) const [newItem, setNewItem] = useState("") useEffect(() => { if (category) { setTitle(category.title) setItems(category.items) } }, [category]) const handleSubmit = (e: React.FormEvent) => { e.preventDefault() onSubmit({ title, items }) } const addItem = () => { if (newItem.trim()) { setItems((prev) => [...prev, newItem.trim()]) setNewItem("") } } const removeItem = (index: number) => { setItems((prev) => prev.filter((_, i) => i !== index)) } return (
setTitle(e.target.value)} placeholder="e.g. Backend, Infrastructure, Databases" required />
setNewItem(e.target.value)} placeholder="Add a technology..." onKeyDown={(e) => e.key === "Enter" && (e.preventDefault(), addItem())} />
{items.length > 0 && (
{items.map((item, i) => ( {item} ))}
)} {items.length === 0 && (

Add at least one technology to this category.

)}
) }