import { useState, useEffect, useRef } from "react"; import { useTranslation } from 'react-i18next'; export default function DateCalendarPopup({ date, onClose }) { const { t } = useTranslation(); const months = t('calendar.months', { returnObjects: true }); const days = t('calendar.days', { returnObjects: true }); const ref = useRef(null); const d = new Date(date); const [year, setYear] = useState(d.getFullYear()); const [month, setMonth] = useState(d.getMonth()); useEffect(() => { const handler = (e) => { if (ref.current && !ref.current.contains(e.target)) onClose(); }; document.addEventListener("mousedown", handler); return () => document.removeEventListener("mousedown", handler); }, [onClose]); const firstDay = new Date(year, month, 1).getDay(); const offset = firstDay === 0 ? 6 : firstDay - 1; const daysInMonth = new Date(year, month + 1, 0).getDate(); const cells = []; for (let i = 0; i < offset; i++) cells.push(null); for (let i = 1; i <= daysInMonth; i++) cells.push(i); const isSameDay = (day) => d.getFullYear() === year && d.getMonth() === month && d.getDate() === day; return (