import React, { useState, useRef, useEffect } from 'react'; import { ChevronDownIcon, MinusIcon, ClockIcon, CheckCircleIcon, ArchiveBoxIcon, CalendarIcon, PlayIcon, XCircleIcon, } from '@heroicons/react/24/outline'; import { StatusType } from '../../entities/Task'; import { useTranslation } from 'react-i18next'; import { getStatusString } from '../../constants/taskStatus'; interface StatusDropdownProps { value: StatusType | number; onChange: (value: StatusType) => void; } const StatusDropdown: React.FC = ({ value, onChange }) => { const { t } = useTranslation(); const statusString = getStatusString(value); const statuses = [ { value: 'not_started', label: t('status.notStarted', 'Not Started'), icon: ( ), }, { value: 'planned', label: t('status.planned', 'Planned'), icon: ( ), }, { value: 'in_progress', label: t('status.inProgress', 'In Progress'), icon: ( ), }, { value: 'waiting', label: t('status.waiting', 'Waiting'), icon: ( ), }, { value: 'done', label: t('status.done', 'Done'), icon: ( ), }, { value: 'cancelled', label: t('status.cancelled', 'Cancelled'), 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 === statusString); return (
{isOpen && (
{statuses.map((status) => ( ))}
)}
); }; export default StatusDropdown;