"use client"; import { useState } from "react"; import { format, startOfWeek, endOfWeek, startOfMonth, endOfMonth, eachDayOfInterval, isSameMonth, isSameDay, addMonths, subMonths, addWeeks, subWeeks } from "date-fns"; import { ChevronLeft, ChevronRight, Calendar as CalendarIcon, Clock, CheckCircle } from "lucide-react"; import Image from "next/image"; type ViewMode = "month" | "week"; export default function CalendarView({ posts }: { posts: any[] }) { const [currentDate, setCurrentDate] = useState(new Date()); const [viewMode, setViewMode] = useState("month"); // Navigation const next = () => { if (viewMode === "month") setCurrentDate(addMonths(currentDate, 1)); else setCurrentDate(addWeeks(currentDate, 1)); }; const prev = () => { if (viewMode === "month") setCurrentDate(subMonths(currentDate, 1)); else setCurrentDate(subWeeks(currentDate, 1)); }; // Calculate Days to Show const start = viewMode === "month" ? startOfWeek(startOfMonth(currentDate)) : startOfWeek(currentDate); const end = viewMode === "month" ? endOfWeek(endOfMonth(currentDate)) : endOfWeek(currentDate); // Ensure we don't have a massive range (safety) const days = eachDayOfInterval({ start, end }); return (
{/* Header */}

{format(currentDate, "MMMM yyyy")}

{/* Grid Header (Days of Week) */}
{["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"].map(day => (
{day}
))}
{/* Calendar Grid */}
{days.map((day, dayIdx) => { const dayPosts = posts.filter(p => p.scheduledAt && isSameDay(new Date(p.scheduledAt), day)); const isOutsideMonth = viewMode === "month" && !isSameMonth(day, currentDate); const isToday = isSameDay(day, new Date()); return (
{format(day, "d")} {dayPosts.length > 0 && ( {dayPosts.length} posts )}
{dayPosts.map(post => (
{/* Thumbnail */}
{post.mediaType === "VIDEO" ? (
{/* Info */}
{post.status === "PUBLISHED" ? ( ) : post.status === "SCHEDULED" ? ( ) : (
)} {format(new Date(post.scheduledAt), "p")}

{post.caption || "Untitled"}

))}
); })}
); }