import React, { useState } from 'react'; import { Idea, IdeaStatus, IdeaCategory } from '../types'; import { Plus, X, GripVertical, CheckCircle, Circle, Clock, Lightbulb, Search, Trash2, Edit3, Save } from 'lucide-react'; interface IdeaBoardProps { ideas: Idea[]; onUpdate: (ideas: Idea[]) => void; } const CATEGORIES: Record = { plot: { label: 'Intrigue', color: 'bg-rose-100 text-rose-800 border-rose-200', icon: Lightbulb }, character: { label: 'Personnage', color: 'bg-blue-100 text-blue-800 border-blue-200', icon: Search }, research: { label: 'Recherche', color: 'bg-amber-100 text-amber-800 border-amber-200', icon: Search }, todo: { label: 'À faire', color: 'bg-slate-100 text-slate-800 border-slate-200', icon: CheckCircle }, }; const STATUS_LABELS: Record = { todo: 'Idées / À faire', progress: 'En cours', done: 'Terminé / Validé' }; const MAX_DESCRIPTION_LENGTH = 500; const IdeaBoard: React.FC = ({ ideas, onUpdate }) => { const [newIdeaTitle, setNewIdeaTitle] = useState(''); const [newIdeaCategory, setNewIdeaCategory] = useState('plot'); // Drag and Drop State const [draggedIdeaId, setDraggedIdeaId] = useState(null); // Modal State for Edit/Quick Add const [editingItem, setEditingItem] = useState | null>(null); // --- ACTIONS --- const handleAddIdea = (e: React.FormEvent) => { e.preventDefault(); if (!newIdeaTitle.trim()) return; const newIdea: Idea = { id: `idea-${Date.now()}`, title: newIdeaTitle, description: '', category: newIdeaCategory, status: 'todo', createdAt: Date.now() }; onUpdate([...ideas, newIdea]); setNewIdeaTitle(''); }; const handleDelete = (id: string) => { if(confirm("Supprimer cette carte ?")) { onUpdate(ideas.filter(i => i.id !== id)); if (editingItem?.id === id) setEditingItem(null); } }; const handleSaveEdit = () => { if (!editingItem || !editingItem.title?.trim()) return; if (editingItem.id) { // Update existing onUpdate(ideas.map(i => i.id === editingItem.id ? { ...i, ...editingItem } as Idea : i)); } else { // Create new from modal const newIdea: Idea = { id: `idea-${Date.now()}`, title: editingItem.title || '', description: editingItem.description || '', category: editingItem.category || 'plot', status: editingItem.status || 'todo', createdAt: Date.now() }; onUpdate([...ideas, newIdea]); } setEditingItem(null); }; const openQuickAdd = (status: IdeaStatus) => { setEditingItem({ title: '', description: '', category: 'plot', status: status }); }; const openEdit = (idea: Idea) => { setEditingItem({ ...idea }); }; // --- DRAG HANDLERS --- const handleDragStart = (e: React.DragEvent, id: string) => { setDraggedIdeaId(id); e.dataTransfer.effectAllowed = 'move'; }; const handleDrop = (e: React.DragEvent, status: IdeaStatus) => { e.preventDefault(); if (draggedIdeaId) { const updatedIdeas = ideas.map(idea => idea.id === draggedIdeaId ? { ...idea, status } : idea ); onUpdate(updatedIdeas); setDraggedIdeaId(null); } }; const handleDragOver = (e: React.DragEvent) => { e.preventDefault(); e.dataTransfer.dropEffect = 'move'; }; // --- RENDERERS --- const Column = ({ title, status, icon: Icon }: { title: string, status: IdeaStatus, icon: any }) => { const columnIdeas = ideas.filter(i => i.status === status); return (
handleDrop(e, status)} onDoubleClick={() => openQuickAdd(status)} title="Double-cliquez dans le vide pour ajouter une carte ici" > {/* Column Header */}
{title}
{columnIdeas.length}
{/* Column Body */}
{columnIdeas.map(idea => { const truncatedDesc = idea.description.length > 300 ? idea.description.substring(0, 300) + '...' : idea.description; return (
handleDragStart(e, idea.id)} onDoubleClick={(e) => { e.stopPropagation(); // Prevent column double-click openEdit(idea); }} className="bg-white p-3 rounded-lg shadow-sm border border-slate-200 cursor-grab active:cursor-grabbing hover:shadow-md hover:border-blue-300 transition-all group relative animate-in zoom-in-95 duration-200" >
{CATEGORIES[idea.category].label}
{/* CARD CONTENT */}

{idea.title}

{idea.description && (

300 ? "Description tronquée (voir détail)" : undefined}> {truncatedDesc}

)}
{new Date(idea.createdAt).toLocaleDateString()}
); })} {columnIdeas.length === 0 && (
Vide Double-cliquez pour ajouter
)}
); }; return (
{/* Header & Add Form (Top Bar) */}

Boîte à Idées

Organisez vos tâches, idées de scènes et recherches.

setNewIdeaTitle(e.target.value)} placeholder="Titre de la nouvelle idée..." className="flex-1 bg-[#eef2ff] border border-indigo-200 text-slate-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 p-2.5 outline-none font-medium" />
{/* Kanban Board */}
{/* EDIT / QUICK ADD MODAL */} {editingItem && (

{editingItem.id ? : } {editingItem.id ? 'Éditer la carte' : 'Ajouter une carte'}

setEditingItem({...editingItem, title: e.target.value})} className="w-full p-3 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 outline-none font-bold text-slate-800" placeholder="Titre de la tâche ou de l'idée..." autoFocus />