'use client'; import React, { useState, type ReactNode } from 'react'; interface Section { title: string; children: ReactNode[]; } function extractText(node: ReactNode): string { if (typeof node === 'string') return node; if (typeof node === 'number') return String(node); if (Array.isArray(node)) return node.map(extractText).join(''); if (React.isValidElement(node)) { const props = node.props as { children?: ReactNode }; if (props.children) return extractText(props.children); } return ''; } export default function RecipeCard({ children }: { children: ReactNode }) { const childArray = React.Children.toArray(children); const sections: Section[] = []; let currentSection: Section | null = null; for (const child of childArray) { if (React.isValidElement(child) && child.type === 'h2') { const title = extractText((child.props as { children?: ReactNode }).children); currentSection = { title, children: [] }; sections.push(currentSection); } else if (currentSection) { currentSection.children.push(child); } } const tabOrder = ['Photos', 'Ingredients', 'Instructions', 'Notes', 'References']; const orderedSections = tabOrder .map(name => sections.find(s => s.title === name)) .filter((s): s is Section => s !== undefined); const [activeTab, setActiveTab] = useState(orderedSections[0]?.title || ''); if (orderedSections.length === 0) return null; const activeSection = orderedSections.find(s => s.title === activeTab); return (