import { Pencil, Trash2 } from 'lucide-react'; import { useState } from 'react'; import type { DayInfo } from '@/components/planner/month-calendar'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import { daysInclusive, formatRangeRu, formatRu } from '@/lib/calendar'; import type { Marker, VacationPeriod } from '@/types/planner'; type Props = { date: string | null; entries: DayInfo[]; markers: Marker[]; onClose: () => void; onDelete: (period: VacationPeriod) => void; onReschedule: ( period: VacationPeriod, data: { start_date: string; end_date: string; marker_id: number }, ) => void; }; export function DayDialog({ date, entries, markers, onClose, onDelete, onReschedule, }: Props) { const [editing, setEditing] = useState(null); const [start, setStart] = useState(''); const [end, setEnd] = useState(''); const [markerId, setMarkerId] = useState(null); const startEdit = (period: VacationPeriod) => { setEditing(period); setStart(period.start_date); setEnd(period.end_date); setMarkerId(period.marker_id); }; const save = () => { if (!editing || !markerId || end < start) { return; } onReschedule(editing, { start_date: start, end_date: end, marker_id: markerId, }); setEditing(null); }; const close = () => { setEditing(null); onClose(); }; return ( !open && close()}> {date ? formatRu(date, true) : ''} {entries.length > 0 ? 'Отметки на этот день' : 'На этот день нет отметок'} {editing ? (
setStart(e.target.value)} />
setEnd(e.target.value)} />
{end < start && (

Дата окончания не может быть раньше начала.

)}
) : (
{entries.map(({ marker, period }) => (
{marker.name}
{formatRangeRu( period.start_date, period.end_date, )}{' '} ·{' '} {daysInclusive( period.start_date, period.end_date, )}{' '} дн.
))}
)}
); }