"use client"; import { ChevronDown, ChevronUp } from "lucide-react"; import { useTranslations } from "next-intl"; import { useEffect, useRef, useState } from "react"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; type ReactMarkdownContainerProps = { content: string; collapsible?: boolean; initialLines?: number; size?: "small" | "normal"; }; export function ReactMarkdownContainer({ content, collapsible = false, initialLines = 4, size = "normal", }: ReactMarkdownContainerProps) { const t = useTranslations("ui.buttons"); const [isExpanded, setIsExpanded] = useState(false); const [showExpandButton, setShowExpandButton] = useState(false); const contentRef = useRef(null); useEffect(() => { if (collapsible && contentRef.current && !isExpanded) { // Check if content exceeds the clamped height const isOverflowing = contentRef.current.scrollHeight > contentRef.current.clientHeight; setShowExpandButton(isOverflowing); } }, [collapsible, content, isExpanded]); const handleToggle = () => { setIsExpanded(!isExpanded); }; const clampStyle = collapsible && !isExpanded ? { display: "-webkit-box", WebkitLineClamp: initialLines, WebkitBoxOrient: "vertical" as const, overflow: "hidden", } : {}; return (

{children}

, li: ({ children }) =>
  • {children}
  • , table: ({ children }) => {children}
    , th: ({ children }) => ( {children} ), td: ({ children }) => ( {children} ), tr: ({ children }) => {children}, ul: ({ children }) =>
      {children}
    , ol: ({ children }) => (
      {children}
    ), h1: ({ children }) => (

    {children}

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

    {children}

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

    {children}

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

    {children}

    ), }} > {content}
    {collapsible && !isExpanded && showExpandButton && (
    )}
    {collapsible && showExpandButton && (
    )}
    ); }