'use client'; import { useState } from 'react'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import type { RecipeSection } from '@/lib/parseRecipe'; interface RecipeTabsProps { sections: RecipeSection[]; folderPath: string; } export default function RecipeTabs({ sections, folderPath }: RecipeTabsProps) { const tabOrder = ['Photos', 'Ingredients', 'Instructions', 'Notes', 'References']; const orderedSections = tabOrder .map(tabName => sections.find(s => s.title === tabName)) .filter((s): s is RecipeSection => s !== undefined); const [activeTab, setActiveTab] = useState(orderedSections[0]?.title || ''); if (orderedSections.length === 0) { return null; } const activeSection = orderedSections.find(s => s.title === activeTab); return (
{activeSection && (
(
    {children}
), ul: ({ children, ...props }) => (
    {children}
), li: ({ children, ...props }) => (
  • {children}
  • ), img: ({ src, alt }) => { // Convert relative paths to public URLs const srcString = typeof src === 'string' ? src : ''; const imageSrc = srcString.startsWith('./') ? `/recipes/${folderPath}/${srcString.replace('./', '')}`.replace(/\\/g, '/') : srcString; // Use img directly to avoid nesting issues with paragraphs return ( {alt ); }, em: ({ children }) => { if (activeSection.title === 'Photos') { return ( {children} ); } return {children}; }, h3: ({ children }) => (

    {children}

    ), h4: ({ children }) => (

    {children}

    ), code: ({ inline, children, ...props }: any) => { if (inline) { return ( {children} ); } return ( {children} ); }, }} > {activeSection.content}
    )}
    ); }