import { useState } from 'react'; import { ChevronDown, ChevronUp, Star, Package, Syringe, User, Baby, AlertCircle, Share2 } from 'lucide-react'; import { Drug } from '@/data/drugs'; import Badge from '@/components/shared/Badge'; import { cn } from '@/lib/utils'; import { useFavorites } from '@/hooks/useFavorites'; import { toast } from 'sonner'; interface DrugCardProps { drug: Drug; defaultExpanded?: boolean; } const DrugCard = ({ drug, defaultExpanded = false }: DrugCardProps) => { const [isExpanded, setIsExpanded] = useState(defaultExpanded); const { isFavorite, toggleFavorite: toggleFavoriteHook } = useFavorites(); const toggleFavorite = (e: React.MouseEvent) => { e.stopPropagation(); toggleFavoriteHook({ id: drug.id, type: 'drug', title: drug.genericName, path: `/farmacos?id=${drug.id}`, }); }; const handleShare = async (e: React.MouseEvent) => { e.stopPropagation(); const url = `${window.location.origin}/farmacos?id=${drug.id}`; const shareData = { title: `${drug.genericName} - EMERGES TES`, text: `Fármaco: ${drug.genericName} (${drug.tradeName})\n\nCategoría: ${drug.category}\nDosis adulto: ${drug.adultDose}`, url: url, }; try { // Intentar usar Web Share API nativa (móviles) if (navigator.share) { await navigator.share(shareData); toast.success('Fármaco compartido'); } else { // Fallback: copiar al portapapeles await navigator.clipboard.writeText(`${shareData.title}\n${shareData.text}\n${url}`); toast.success('Enlace copiado al portapapeles'); } } catch (error: any) { // El usuario canceló el share o hubo un error if (error.name !== 'AbortError') { // Si no es cancelación, intentar copiar al portapapeles try { await navigator.clipboard.writeText(`${shareData.title}\n${shareData.text}\n${url}`); toast.success('Enlace copiado al portapapeles'); } catch (clipboardError) { toast.error('No se pudo compartir'); } } } }; const isFav = isFavorite(drug.id); return (
{isExpanded ? ( ) : ( )}
{isExpanded && (
{/* Presentation */}

Presentación

{drug.presentation}

{/* Adult Dose */}

Dosis Adulto

{drug.adultDose}

{/* Pediatric Dose */} {drug.pediatricDose && (

Dosis Pediátrica

{drug.pediatricDose}

)} {/* Routes */}

Vías de Administración

{drug.routes.map((route) => ( {route} ))}
{/* Dilution */} {drug.dilution && (

Dilución

{drug.dilution}

)} {/* Indications */}

Indicaciones

{/* Contraindications */}

Contraindicaciones

{/* Antidote */} {drug.antidote && (

Antídoto: {drug.antidote}

)} {/* Critical Points */} {drug.criticalPoints && drug.criticalPoints.length > 0 && (

Puntos TES Críticos

)} {/* Notes */} {drug.notes && drug.notes.length > 0 && (

Notas

)}
)} ); }; export default DrugCard;