'use client'; import { Check, Plus } from 'lucide-react'; import { cn } from '@/lib/cn'; import { COMPARE_MAX, type TrayItem, trayType, useCompareTray } from './compare-store'; /** * Small toggle that adds/removes an entity from the compare tray (localStorage-backed, mirrored into `/compare?ids=`). * `size="sm"` for table rows (still a ≥ 44 px hit area through padding on touch), default for entity headers. * Renders a neutral placeholder before hydration so server and client markup match. */ export function CompareButton({ e, size = 'md', className, label = 'Compare' }: { e: TrayItem | { slug: string; name: string; entity_type: string; organization?: { name: string } | null }; size?: 'sm' | 'md'; className?: string; label?: string }) { const tray = useCompareTray(); const item: TrayItem = { slug: e.slug, name: e.name, entity_type: e.entity_type, organization: typeof e.organization === 'string' || e.organization === null || e.organization === undefined ? (e.organization as string | null | undefined) : e.organization.name }; const on = tray.ready && tray.has(item.slug); const otherType = tray.ready && tray.type !== null && tray.type !== trayType(item.entity_type) && !on; const full = tray.ready && tray.full && !on; const title = on ? 'Remove from comparison' : otherType ? `Start a new ${item.entity_type} comparison (replaces the current tray)` : full ? `The tray holds at most ${COMPARE_MAX} items` : 'Add to comparison'; return ( ); }