"use client"; import { useState } from "react"; import { DashboardElement, CalendarConfig } from "../types"; import { MonthView } from "./MonthView"; import { CalendarSettings } from "./CalendarSettings"; import { generateCalendarDays, getMonthName, navigateMonth } from "./calendarUtils"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { Button } from "@/components/ui/button"; import { Settings, ChevronLeft, ChevronRight, Calendar } from "lucide-react"; import { useDashboard } from "@/contexts/DashboardContext"; interface CalendarWidgetProps { element: DashboardElement; onConfigUpdate?: (config: CalendarConfig) => void; } /** * 달력 위젯 메인 컴포넌트 * - 월간/주간/일간 뷰 지원 * - 네비게이션 (이전/다음 월, 오늘) * - 내장 설정 UI */ export function CalendarWidget({ element, onConfigUpdate }: CalendarWidgetProps) { // Context에서 선택된 날짜 관리 const { selectedDate, setSelectedDate } = useDashboard(); // 현재 표시 중인 년/월 const today = new Date(); const [currentYear, setCurrentYear] = useState(today.getFullYear()); const [currentMonth, setCurrentMonth] = useState(today.getMonth()); const [settingsOpen, setSettingsOpen] = useState(false); // 날짜 클릭 핸들러 const handleDateClick = (date: Date) => { setSelectedDate(date); }; // 기본 설정값 const config = element.calendarConfig || { view: "month", startWeekOn: "sunday", highlightWeekends: true, highlightToday: true, showHolidays: true, theme: "light", }; // 설정 저장 핸들러 const handleSaveSettings = (newConfig: CalendarConfig) => { onConfigUpdate?.(newConfig); setSettingsOpen(false); }; // 이전 월로 이동 const handlePrevMonth = () => { const { year, month } = navigateMonth(currentYear, currentMonth, "prev"); setCurrentYear(year); setCurrentMonth(month); }; // 다음 월로 이동 const handleNextMonth = () => { const { year, month } = navigateMonth(currentYear, currentMonth, "next"); setCurrentYear(year); setCurrentMonth(month); }; // 오늘로 돌아가기 const handleToday = () => { setCurrentYear(today.getFullYear()); setCurrentMonth(today.getMonth()); }; // 달력 날짜 생성 const calendarDays = generateCalendarDays(currentYear, currentMonth, config.startWeekOn); // 크기에 따른 컴팩트 모드 판단 const isCompact = element.size.width < 400 || element.size.height < 400; return (
{/* 헤더 - 네비게이션 */}
{/* 이전 월 버튼 */} {/* 현재 년월 표시 */}
{currentYear}년 {getMonthName(currentMonth)} {!isCompact && ( )}
{/* 다음 월 버튼 */}
{/* 달력 콘텐츠 */}
{config.view === "month" && ( )} {/* 추후 WeekView, DayView 추가 가능 */}
{/* 설정 버튼 - 우측 하단 */}
setSettingsOpen(false)} />
); }