"use client"; import { motion } from "framer-motion"; import { Layers3, MapPin, Plus, Tags, User, X } from "lucide-react"; import { useSession } from "next-auth/react"; import { useState } from "react"; import { createProject } from "../actions"; const PREDEF = ["build", "usine", "spawn"] as const; type TagColor = (typeof PREDEF)[number]; const palette: Record = { build: "bg-emerald-600/90", usine: "bg-orange-600/90", spawn: "bg-fuchsia-700/90", }; const isValidCoord = (value: string) => /^-?\d*$/.test(value); export default function AddProjectForm() { const { data: session } = useSession(); const [tags, setTags] = useState([]); const [tagInput, setInput] = useState(""); const [x, setX] = useState(""); const [y, setY] = useState(""); const [z, setZ] = useState(""); const addTag = (t: string) => { const val = t.trim().toLowerCase(); if (!val || tags.includes(val) || tags.length >= 5) return; setTags([...tags, val]); }; const del = (t: string) => setTags(tags.filter((x) => x !== t)); const getTagClass = (t: string) => { return palette[t as TagColor] ?? "bg-gray-600"; }; return ( {/* nom */}
{/* joueur */} {session?.user?.email === "ultralionfr@gmail.com" && (
)} {/* coords */}
{[ { name: "x", value: x, setValue: setX }, { name: "y", value: y, setValue: setY }, { name: "z", value: z, setValue: setZ }, ].map(({ name, value, setValue }) => (
{ if (isValidCoord(e.target.value)) setValue(e.target.value); }} className="w-full rounded-lg bg-gray-700 py-2 pl-9 pr-3 text-amber-50 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-indigo-500" />
))}
{/* Tags */}
{tags.map((t) => ( ))}
setInput(e.target.value)} onKeyDown={(e) => e.key === "Enter" && (e.preventDefault(), addTag(tagInput), setInput("")) } placeholder="Ajouter un tag personnalisé" className="w-full rounded-lg bg-gray-700 py-2 pl-3 pr-12 text-amber-50 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-indigo-500" />
{/* description */}