"use client"; import { useState, useRef, useEffect } from "react"; import { useTranslations } from "next-intl"; import { Globe } from "lucide-react"; import { cn } from "@/lib/utils"; import type { Calendar } from "@/lib/jmap/types"; import { CalendarColorPicker } from "@/components/settings/calendar-management-settings"; import { useCalendarStore } from "@/stores/calendar-store"; interface CalendarSidebarPanelProps { calendars: Calendar[]; selectedCalendarIds: string[]; onToggleVisibility: (id: string) => void; onColorChange?: (calendarId: string, color: string) => void; } export function CalendarSidebarPanel({ calendars, selectedCalendarIds, onToggleVisibility, onColorChange, }: CalendarSidebarPanelProps) { const t = useTranslations("calendar"); const isSubscriptionCalendar = useCalendarStore((s) => s.isSubscriptionCalendar); const [colorPickerId, setColorPickerId] = useState(null); const colorPickerRef = useRef(null); useEffect(() => { if (!colorPickerId) return; const handleClick = (e: MouseEvent) => { if (colorPickerRef.current && !colorPickerRef.current.contains(e.target as Node)) { setColorPickerId(null); } }; const handleKey = (e: KeyboardEvent) => { if (e.key === 'Escape') setColorPickerId(null); }; document.addEventListener('mousedown', handleClick); document.addEventListener('keydown', handleKey); return () => { document.removeEventListener('mousedown', handleClick); document.removeEventListener('keydown', handleKey); }; }, [colorPickerId]); if (calendars.length === 0) return null; return (

{t("my_calendars")}

{calendars.map((cal) => { const isVisible = selectedCalendarIds.includes(cal.id); const color = cal.color || "#3b82f6"; return (
{/* Color picker popover on right-click */} {colorPickerId === cal.id && onColorChange && (

{t("management.change_color")}

{ onColorChange(cal.id, c); setColorPickerId(null); }} allowCustom />
)}
); })}
); }