import React, { ReactNode, useState, useRef } from 'react'; import { useClickOutside } from '@/app/hooks/useClickOutside'; interface DropDownListProps { children: ReactNode; value: string | number; callBack: (value: string) => void; translatedValue?: string; } interface ChildProps { value?: string; onClick?: () => void; className?: string; children?: React.ReactNode; } export default function DropDownList({ children, value, callBack, translatedValue }: DropDownListProps) { const [isOpen, setIsOpen] = useState(false) const dropdownRef = useRef(null) useClickOutside(dropdownRef, () => { setIsOpen(false); }, isOpen ); const enhancedChildren = React.Children.map(children, (child, index) => { if (React.isValidElement(child)) { const childValue = child.props.value || undefined; return React.cloneElement(child, { onClick: () => { callBack(childValue || ""); setIsOpen(false); }, className: `dropdown-item ${value === childValue ? "current" : ""}`, key: index, }); } return child; }); return (
{isOpen && (
    {enhancedChildren}
)}
) }