import { useState } from 'react'; import { DemandItem, ProduceCategory } from '../../lib/demand/types'; interface SeasonalCalendarProps { items: SeasonalItem[]; currentSeason?: 'spring' | 'summer' | 'fall' | 'winter'; } export interface SeasonalItem { produceType: string; category: ProduceCategory; seasonalAvailability: { spring: boolean; summer: boolean; fall: boolean; winter: boolean; }; peakSeason?: 'spring' | 'summer' | 'fall' | 'winter'; } const SEASONS = ['spring', 'summer', 'fall', 'winter'] as const; const SEASON_COLORS: Record = { spring: { bg: 'bg-green-100', border: 'border-green-300', text: 'text-green-800', icon: '🌸' }, summer: { bg: 'bg-yellow-100', border: 'border-yellow-300', text: 'text-yellow-800', icon: '☀️' }, fall: { bg: 'bg-orange-100', border: 'border-orange-300', text: 'text-orange-800', icon: '🍂' }, winter: { bg: 'bg-blue-100', border: 'border-blue-300', text: 'text-blue-800', icon: '❄️' }, }; const CATEGORY_ICONS: Record = { leafy_greens: '🥬', root_vegetables: '🥕', nightshades: '🍅', brassicas: '🥦', alliums: '🧅', legumes: '🫘', squash: '🎃', herbs: '🌿', microgreens: '🌱', sprouts: '🌾', mushrooms: '🍄', fruits: '🍎', berries: '🍓', citrus: '🍊', tree_fruits: '🍑', melons: '🍈', edible_flowers: '🌸', }; function formatCategory(category: string): string { return category.replace(/_/g, ' ').replace(/\b\w/g, (l) => l.toUpperCase()); } function getCurrentSeason(): 'spring' | 'summer' | 'fall' | 'winter' { const month = new Date().getMonth(); if (month >= 2 && month <= 4) return 'spring'; if (month >= 5 && month <= 7) return 'summer'; if (month >= 8 && month <= 10) return 'fall'; return 'winter'; } export default function SeasonalCalendar({ items, currentSeason = getCurrentSeason(), }: SeasonalCalendarProps) { const [selectedCategory, setSelectedCategory] = useState('all'); const [viewMode, setViewMode] = useState<'calendar' | 'list'>('calendar'); // Get unique categories const categories = Array.from(new Set(items.map((item) => item.category))); // Filter items by category const filteredItems = selectedCategory === 'all' ? items : items.filter((item) => item.category === selectedCategory); // Group items by season for current view const itemsBySeason: Record = { spring: [], summer: [], fall: [], winter: [], }; filteredItems.forEach((item) => { SEASONS.forEach((season) => { if (item.seasonalAvailability[season]) { itemsBySeason[season].push(item); } }); }); // Get items available now const availableNow = filteredItems.filter( (item) => item.seasonalAvailability[currentSeason] ); return (
{/* Header */}

Seasonal Availability

Currently: {SEASON_COLORS[currentSeason].icon} {currentSeason.charAt(0).toUpperCase() + currentSeason.slice(1)}

{/* Controls */}
{/* Category filter */}
{/* View toggle */}
{/* Available Now Section */}

{SEASON_COLORS[currentSeason].icon} Available Now ({availableNow.length} items)

{availableNow.slice(0, 12).map((item, index) => ( {CATEGORY_ICONS[item.category]} {item.produceType} ))} {availableNow.length > 12 && ( +{availableNow.length - 12} more )}
{/* Calendar View */} {viewMode === 'calendar' && (
{SEASONS.map((season) => { const seasonStyle = SEASON_COLORS[season]; const isCurrentSeason = season === currentSeason; return (
{seasonStyle.icon} {season} {itemsBySeason[season].length} items
{itemsBySeason[season].length === 0 ? (

No items in this season

) : (
{itemsBySeason[season].map((item, index) => (
{CATEGORY_ICONS[item.category]} {item.produceType} {item.peakSeason === season && ( )}
))}
)}
); })}
)} {/* List View */} {viewMode === 'list' && (
{SEASONS.map((season) => ( ))} {filteredItems.map((item, index) => ( {SEASONS.map((season) => ( ))} ))}
Item Category {SEASON_COLORS[season].icon}
{season}
{CATEGORY_ICONS[item.category]} {item.produceType} {formatCategory(item.category)} {item.seasonalAvailability[season] ? ( {item.peakSeason === season ? '⭐' : '✓'} ) : ( - )}
)} {/* Legend */}
Available
Peak Season
- Not Available
); }