import React, { useState, useRef, useEffect } from 'react'; import { ChevronDownIcon, MinusIcon, ClockIcon, CheckCircleIcon, ArchiveBoxIcon, } from '@heroicons/react/24/outline'; import { StatusType } from '../../entities/Task'; import { useTranslation } from 'react-i18next'; interface StatusDropdownProps { value: StatusType; onChange: (value: StatusType) => void; } const StatusDropdown: React.FC = ({ value, onChange }) => { const { t } = useTranslation(); const statuses = [ { value: 'not_started', label: t('status.notStarted', 'Not Started'), icon: ( ), }, { value: 'in_progress', label: t('status.inProgress', 'In Progress'), icon: ( ), }, { value: 'done', label: t('status.done', 'Done'), icon: ( ), }, { value: 'archived', label: t('status.archived', 'Archived'), icon: ( ), }, ]; const [isOpen, setIsOpen] = useState(false); const dropdownRef = useRef(null); const handleToggle = () => { setIsOpen(!isOpen); }; const handleClickOutside = (event: MouseEvent) => { if ( dropdownRef.current && !dropdownRef.current.contains(event.target as Node) ) { setIsOpen(false); } }; const handleSelect = (status: StatusType) => { onChange(status); setIsOpen(false); }; useEffect(() => { if (isOpen) { document.addEventListener('mousedown', handleClickOutside); } else { document.removeEventListener('mousedown', handleClickOutside); } return () => { document.removeEventListener('mousedown', handleClickOutside); }; }, [isOpen]); const selectedStatus = statuses.find((s) => s.value === value); return (
{isOpen && (
{statuses.map((status) => ( ))}
)}
); }; export default StatusDropdown;