import { router } from '@inertiajs/react'; import { Pencil, Plus, Trash2 } from 'lucide-react'; import { useState } from 'react'; import { MarkerDialog } from '@/components/planner/marker-dialog'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { daysInYear } from '@/lib/calendar'; import { cn } from '@/lib/utils'; import { destroy } from '@/routes/markers'; import type { Marker, VacationPeriod } from '@/types/planner'; type Props = { markers: Marker[]; periods: VacationPeriod[]; year: number; activeMarkerId: number | null; onSelect: (id: number | null) => void; }; export function MarkerPanel({ markers, periods, year, activeMarkerId, onSelect, }: Props) { const [dialogOpen, setDialogOpen] = useState(false); const [editing, setEditing] = useState(null); const [deleting, setDeleting] = useState(null); const dayCount = (markerId: number) => periods .filter((p) => p.marker_id === markerId) .reduce( (sum, p) => sum + daysInYear(p.start_date, p.end_date, year), 0, ); const confirmDelete = () => { if (!deleting) { return; } router.delete(destroy.url(deleting.id), { preserveScroll: true, only: ['markers', 'periods'], onSuccess: () => setDeleting(null), }); }; return (
{markers.map((marker) => { const active = marker.id === activeMarkerId; return (
); })}
!open && setDeleting(null)} > Удалить маркер? Маркер «{deleting?.name}» и все его отметки на календарях будут удалены. Это действие необратимо.
); }