"use client"; import { useEffect, useRef, useState, useCallback, memo } from "react"; import { Plus } from "lucide-react"; import { cls, shouldUseInvertedText } from "@/lib/utils"; import { useTheme } from "@/providers/themeProvider/ThemeProvider"; interface AccordionProps { index: number; isActive?: boolean; onToggle?: (index: number) => void; title: string; content: string; animationType?: "smooth" | "instant"; showCard?: boolean; useInvertedBackground?: "noInvert" | "invertDefault" | "invertCard"; className?: string; titleClassName?: string; iconContainerClassName?: string; iconClassName?: string; contentClassName?: string; } const Accordion = ({ index, isActive: controlledIsActive, onToggle, title, content, animationType = "smooth", showCard = true, useInvertedBackground, className = "", titleClassName = "", iconContainerClassName = "", iconClassName = "", contentClassName = "", }: AccordionProps) => { const contentRef = useRef(null); const [height, setHeight] = useState("0px"); const [internalIsActive, setInternalIsActive] = useState(false); const isActive = controlledIsActive !== undefined ? controlledIsActive : internalIsActive; const theme = useTheme(); const shouldUseLightText = showCard ? shouldUseInvertedText(useInvertedBackground, theme.cardStyle) : useInvertedBackground; useEffect(() => { if (animationType === "smooth") { setHeight(isActive ? `${contentRef.current?.scrollHeight}px` : "0px"); } }, [isActive, animationType]); const handleClick = useCallback(() => { if (controlledIsActive === undefined) { setInternalIsActive(!internalIsActive); } if (onToggle) { onToggle(index); } }, [controlledIsActive, internalIsActive, onToggle, index]); const headerContent = (

{title}

); const contentElement = (
); if (animationType === "instant") { return (
{isActive &&
{contentElement}
}
); } return (
{headerContent}
{contentElement}
); }; Accordion.displayName = "Accordion"; export default memo(Accordion);