'use client'; import { ExternalLink, Copy, Check, ChevronDown, ChevronUp } from 'lucide-react'; import type { WaypointCategory, Waypoint } from '@/utils/waypoints'; type CategoryCardProps = { category: WaypointCategory; waypoints: Waypoint[]; isExpanded: boolean; onToggle: () => void; handle: string; collection?: string; rkey?: string; did?: string; copiedId: string | null; onCopy: (url: string, waypointId: string, e: React.MouseEvent) => void; onWaypointClick: (url: string, e: React.MouseEvent) => void; subcategories?: Array<{ category: WaypointCategory; waypoints: Waypoint[]; isExpanded: boolean; onToggle: () => void; }>; alwaysShowCategoryHeader?: boolean; }; export default function CategoryCard({ category, waypoints, isExpanded, onToggle, handle, collection, rkey, did, copiedId, onCopy, onWaypointClick, subcategories, alwaysShowCategoryHeader = false, }: CategoryCardProps) { const hasSubcategories = subcategories && subcategories.length > 0; // Safety check: if no waypoints AND no subcategories, don't render anything if ((!waypoints || waypoints.length === 0) && !hasSubcategories) { return null; } // If we have waypoints, find the default one const defaultWaypoint = waypoints && waypoints.length > 0 ? (waypoints.find(w => w.id === category.defaultWaypointId) || waypoints[0]) : null; // Additional safety check: ensure default waypoint is actually compatible const compatibleDefaultWaypoint = defaultWaypoint && defaultWaypoint.getUrl?.(handle, collection, rkey, did) ? defaultWaypoint : waypoints?.find(w => w.getUrl(handle, collection, rkey, did) !== null); const hasMultiple = waypoints && waypoints.length > 1; const hasWaypoints = waypoints && waypoints.length > 0; const renderWaypointCard = (waypoint: Waypoint, index: number) => { const url = waypoint.getUrl(handle, collection, rkey, did); if (!url) return null; const isCopied = copiedId === waypoint.id; // Organic rotation for each button const rotations = [0.3, -0.2, 0.4, -0.3, 0.2, -0.1, 0.35, -0.25]; const rotation = rotations[index % rotations.length]; return (
{category.description}
)}