'use client' import { CalendarIcon, X } from 'lucide-react' import { Button } from '@/components/ui/button' import { Calendar } from '@/components/ui/calendar' import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover' import { cn } from '@/lib/utils' export type KriDateRange = { from: string to: string } export type KriDateRangePickerProps = { value: KriDateRange onChange: (value: KriDateRange) => void placeholder?: string className?: string triggerClassName?: string contentClassName?: string disabled?: boolean } const parseDate = (value: string) => { if (!value) return undefined const [year, month, day] = value.split('-').map(Number) if (!year || !month || !day) return undefined const date = new Date(year, month - 1, day) if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) { return undefined } return date } const formatDate = (date: Date | undefined) => { if (!date) return '' const year = date.getFullYear() const month = String(date.getMonth() + 1).padStart(2, '0') const day = String(date.getDate()).padStart(2, '0') return `${year}-${month}-${day}` } export function KriDateRangePicker({ value, onChange, placeholder = '조회 기간 선택', className, triggerClassName, contentClassName, disabled = false, }: KriDateRangePickerProps) { const selected = { from: parseDate(value.from), to: parseDate(value.to), } const selectedRange = selected.from || selected.to ? selected : undefined const displayText = value.from && value.to ? `${value.from} ~ ${value.to}` : value.from ? `${value.from} ~` : value.to ? `~ ${value.to}` : placeholder const hasValue = value.from.length > 0 || value.to.length > 0 return (