'use client'
import { useMemo } from 'react'
import { useCalendarStore } from '@/lib/store'
import { TemporalGranularity } from '@/lib/types'
import { clsx } from 'clsx'
interface MonthGridProps {
year: number
month: number // 1-indexed
onDayClick?: (date: Date) => void
}
function MonthGrid({ year, month, onDayClick }: MonthGridProps) {
const today = new Date()
today.setHours(0, 0, 0, 0)
const monthData = useMemo(() => {
const firstDay = new Date(year, month - 1, 1)
const lastDay = new Date(year, month, 0)
const daysInMonth = lastDay.getDate()
const startDay = firstDay.getDay()
const days: { day: number; date: Date; isToday: boolean }[] = []
for (let day = 1; day <= daysInMonth; day++) {
const date = new Date(year, month - 1, day)
days.push({
day,
date,
isToday: date.getTime() === today.getTime(),
})
}
return { days, startDay, daysInMonth }
}, [year, month, today])
const monthName = new Date(year, month - 1).toLocaleDateString('en-US', { month: 'long' })
return (
{/* Month header */}
{monthName}
{/* Calendar grid */}
{/* Weekday headers */}
{['S', 'M', 'T', 'W', 'T', 'F', 'S'].map((day, i) => (
{day}
))}
{/* Day grid */}
{/* Empty cells for start offset */}
{Array.from({ length: monthData.startDay }).map((_, i) => (
))}
{/* Day cells */}
{monthData.days.map(({ day, date, isToday }) => (
))}
)
}
export function SeasonView() {
const {
currentDate,
setCurrentDate,
setTemporalGranularity,
} = useCalendarStore()
const year = currentDate.getFullYear()
// Determine current quarter
const currentMonth = currentDate.getMonth() + 1
const currentQuarter = Math.ceil(currentMonth / 3)
// Get the months for this quarter
const quarterMonths = useMemo(() => {
const startMonth = (currentQuarter - 1) * 3 + 1
return [startMonth, startMonth + 1, startMonth + 2]
}, [currentQuarter])
const seasonName = ['Winter', 'Spring', 'Summer', 'Fall'][currentQuarter - 1] || 'Quarter'
const handleDayClick = (date: Date) => {
setCurrentDate(date)
setTemporalGranularity(TemporalGranularity.DAY)
}
return (
{/* Season header */}
{seasonName} {year}
Q{currentQuarter} • Gregorian •{' '}
{quarterMonths.length} months
{/* Three month grid */}
{quarterMonths.map((month) => (
))}
{/* Navigation hint */}
Click any day to zoom in • Use arrow keys to navigate quarters
)
}