"use client"; import * as React from "react"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; interface CustomCalendarProps { selected?: Date; onSelect?: (date: Date | undefined) => void; className?: string; mode?: "single"; size?: "sm" | "default" | "lg"; } const DAYS = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]; const MONTHS = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ]; export function CustomCalendar({ selected, onSelect, className, mode = "single", size = "default", }: CustomCalendarProps) { // 크기별 클래스 정의 const sizeClasses = { sm: { cell: "h-7 w-7 text-xs", header: "text-xs", day: "text-[0.7rem]", nav: "h-6 w-6", }, default: { cell: "h-9 w-9 text-sm", header: "text-[0.8rem]", day: "text-sm", nav: "h-7 w-7", }, lg: { cell: "h-11 w-11 text-base", header: "text-sm", day: "text-base", nav: "h-8 w-8", }, }; const currentSize = sizeClasses[size]; const [currentDate, setCurrentDate] = React.useState(selected || new Date()); const [viewYear, setViewYear] = React.useState(currentDate.getFullYear()); const [viewMonth, setViewMonth] = React.useState(currentDate.getMonth()); const getDaysInMonth = (year: number, month: number) => { return new Date(year, month + 1, 0).getDate(); }; const getFirstDayOfMonth = (year: number, month: number) => { return new Date(year, month, 1).getDay(); }; const generateCalendarDays = () => { const daysInMonth = getDaysInMonth(viewYear, viewMonth); const firstDay = getFirstDayOfMonth(viewYear, viewMonth); const daysInPrevMonth = getDaysInMonth(viewYear, viewMonth - 1); const days: Array<{ date: number; month: "prev" | "current" | "next"; fullDate: Date; }> = []; // Previous month days for (let i = firstDay - 1; i >= 0; i--) { const date = daysInPrevMonth - i; days.push({ date, month: "prev", fullDate: new Date(viewYear, viewMonth - 1, date), }); } // Current month days for (let i = 1; i <= daysInMonth; i++) { days.push({ date: i, month: "current", fullDate: new Date(viewYear, viewMonth, i), }); } // Next month days const remainingDays = 42 - days.length; // 6 rows * 7 days for (let i = 1; i <= remainingDays; i++) { days.push({ date: i, month: "next", fullDate: new Date(viewYear, viewMonth + 1, i), }); } return days; }; const handlePrevMonth = () => { if (viewMonth === 0) { setViewMonth(11); setViewYear(viewYear - 1); } else { setViewMonth(viewMonth - 1); } }; const handleNextMonth = () => { if (viewMonth === 11) { setViewMonth(0); setViewYear(viewYear + 1); } else { setViewMonth(viewMonth + 1); } }; const handleDateClick = (date: Date) => { if (onSelect) { onSelect(date); } }; const isToday = (date: Date) => { const today = new Date(); return ( date.getDate() === today.getDate() && date.getMonth() === today.getMonth() && date.getFullYear() === today.getFullYear() ); }; const isSelected = (date: Date) => { if (!selected) return false; return ( date.getDate() === selected.getDate() && date.getMonth() === selected.getMonth() && date.getFullYear() === selected.getFullYear() ); }; const calendarDays = generateCalendarDays(); return (