import { Head } from '@inertiajs/react'; import { useMemo, useState } from 'react'; import { DayDialog } from '@/components/planner/day-dialog'; import { MarkerPanel } from '@/components/planner/marker-panel'; import { MonthCalendar, type DayInfo, } from '@/components/planner/month-calendar'; import { YearSelect } from '@/components/planner/year-select'; import { Button } from '@/components/ui/button'; import { usePlanner } from '@/hooks/use-planner'; import { addDays } from '@/lib/calendar'; import type { PlannerPageProps } from '@/types/planner'; export default function Planner({ year, years, markers, periods, }: PlannerPageProps) { const planner = usePlanner({ markers, periods }); const [inspectDate, setInspectDate] = useState(null); const dayMap = useMemo(() => { const markerById = new Map(markers.map((m) => [m.id, m])); const map = new Map(); for (const period of periods) { const marker = markerById.get(period.marker_id); if (!marker) { continue; } let date = period.start_date; let guard = 0; while (date <= period.end_date && guard < 400) { const list = map.get(date) ?? []; list.push({ marker, period }); map.set(date, list); date = addDays(date, 1); guard++; } } return map; }, [markers, periods]); const brushColor = planner.activeMarker?.color ?? null; return ( <>

План отпусков{' '} {year}

{planner.activeMarker ? ( <> Кисть «{planner.activeMarker.name}»: клик — один день, протяжка — период. На сенсорном экране: два касания — начало и конец. {planner.touchAnchor && ( )} ) : markers.length > 0 ? ( Выберите маркер, чтобы отмечать даты, или нажмите на день, чтобы посмотреть отметки. ) : ( Добавьте первый маркер — цвет и имя человека, — чтобы начать планирование. )}
{Array.from({ length: 12 }, (_, month0) => ( planner.dayPointerDown(date, 'touch') } onDayInspect={setInspectDate} /> ))}
setInspectDate(null)} onDelete={planner.deletePeriod} onReschedule={planner.reschedulePeriod} /> ); }