import { useRef, useEffect, useState } from 'react' import { Plus, Baby, Heart, Users, MapPin } from 'lucide-react' import './AddPersonButton.css' /** * Bouton FAB draggable pour ajouter une personne * Utilisé en mode édition pour drag-and-drop dans la galaxie * * @param {Object} props * @param {boolean} props.isDragging - État dragging (du hook) * @param {Object} props.dragPosition - Position drag {x, y} * @param {Function} props.onDragStart - Handler début drag * @param {string} props.linkType - Type de lien détecté ('child', 'spouse', 'sibling') */ function AddPersonButton({ isDragging, dragPosition, onDragStart, linkType }) { const buttonRef = useRef(null) const [entering, setEntering] = useState(true) // Animation d'entrée useEffect(() => { const timer = setTimeout(() => setEntering(false), 500) return () => clearTimeout(timer) }, []) const handleMouseDown = (e) => { e.preventDefault() if (!buttonRef.current) return const rect = buttonRef.current.getBoundingClientRect() const buttonPosition = { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2, } onDragStart?.(e, buttonPosition) } // Position inline si dragging const style = isDragging ? { left: `${dragPosition.x - 32}px`, top: `${dragPosition.y - 32}px`, transition: 'none', } : {} // Message tooltip selon linkType let tooltipText = 'Glisser pour ajouter une personne' if (isDragging) { if (linkType === 'child') tooltipText = 'Ajouter un enfant' else if (linkType === 'spouse') tooltipText = 'Ajouter un conjoint' else if (linkType === 'sibling') tooltipText = 'Ajouter un frère/sœur' else tooltipText = 'Relâcher pour créer' } return ( <> {/* Hint pendant drag */} {isDragging && (
{linkType === 'child' && <> Enfant} {linkType === 'spouse' && <> Conjoint} {linkType === 'sibling' && <> Frère·Sœur} {!linkType && <> Positionnez la personne}
)} ) } export default AddPersonButton