"use client"; import { useState, type FormEvent } from "react"; import { Plus, Save, X } from "lucide-react"; import { Button } from "@/components/ui/Button"; import { Textarea } from "@/components/ui/Textarea"; import { ExperienceItem } from "@/components/cv/ExperienceItem"; import type { Experience } from "@/lib/types/cv"; type ExperienceEditor = | { mode: "closed" } | { mode: "new" } | { mode: "edit"; id: Experience["id"] }; interface ExperienceManagerProps { experiences: Experience[]; onAdd: (titre: string, contenu: string) => void; onUpdate: (id: string, titre: string, contenu: string) => void; onRemove: (id: string) => void; } export function ExperienceManager({ experiences, onAdd, onUpdate, onRemove, }: ExperienceManagerProps) { const [editor, setEditor] = useState({ mode: "closed" }); const [titre, setTitre] = useState(""); const [contenu, setContenu] = useState(""); const isEditing = editor.mode !== "closed"; const editingId = editor.mode === "edit" ? editor.id : null; function startNew() { setEditor({ mode: "new" }); setTitre(""); setContenu(""); } function startEdit(id: string) { const experience = experiences.find((exp) => exp.id === id); if (!experience) return; setEditor({ mode: "edit", id }); setTitre(experience.titre); setContenu(experience.contenu); } function close() { setEditor({ mode: "closed" }); setTitre(""); setContenu(""); } function handleSubmit(event: FormEvent) { event.preventDefault(); const trimmedTitre = titre.trim(); const title = trimmedTitre || "Expérience"; if (editor.mode === "new") { onAdd(title, contenu); } else if (editor.mode === "edit") { onUpdate(editor.id, title, contenu); } close(); } return (

Expériences professionnelles

{isEditing && (
setTitre(event.target.value)} placeholder="Développeur Full-Stack" autoFocus className="rounded-md border border-border px-3 py-2 text-sm text-ink placeholder:text-muted focus:outline-2 focus:outline-offset-2 focus:outline-accent" />