"use client"; import { IconCheck, IconLibrary, IconMovie, IconPlayerPlay, } from "@tabler/icons-react"; import { useEffect, useState } from "react"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { getStatsAction } from "@/lib/actions/watchlist"; import type { DashboardStats, HistoryBucket, TimePeriod, } from "@/lib/services/discovery"; import { Sparkline } from "./sparkline"; const periodLabels: Record = { today: "Today", this_week: "This Week", this_month: "This Month", this_year: "This Year", }; const periods: TimePeriod[] = ["today", "this_week", "this_month", "this_year"]; interface StatCardProps { icon: React.ComponentType<{ className?: string }>; color: string; bgColor: string; value: number; index: number; label: React.ReactNode; loading?: boolean; sparklineData?: HistoryBucket[]; } function StatCard({ icon: Icon, color, bgColor, value, index, label, sparklineData, }: StatCardProps) { return (
{sparklineData && }
{label}

{value}

); } const inlineTriggerClass = "h-auto w-auto gap-0.5 rounded-none border-0 bg-transparent py-1 px-0.5 -my-1 -mx-0.5 sm:p-0 sm:m-0 [font-size:inherit] [line-height:inherit] shadow-none underline decoration-dotted decoration-muted-foreground/50 underline-offset-4 hover:bg-transparent hover:text-foreground hover:decoration-foreground/50 focus-visible:ring-0 focus-visible:decoration-solid focus-visible:decoration-foreground dark:bg-transparent dark:hover:bg-transparent"; function PeriodSelector({ noun, period, onPeriodChange, }: { noun: string; period: TimePeriod; onPeriodChange: (period: TimePeriod) => void; }) { return ( {noun}{" "} ); } export function StatsDisplay({ stats }: { stats: DashboardStats }) { const [moviePeriod, setMoviePeriod] = useState("this_month"); const [episodePeriod, setEpisodePeriod] = useState("this_week"); const [movieStats, setMovieStats] = useState<{ count: number; history: HistoryBucket[]; } | null>(null); const [episodeStats, setEpisodeStats] = useState<{ count: number; history: HistoryBucket[]; } | null>(null); useEffect(() => { void getStatsAction("movies", moviePeriod).then(setMovieStats); }, [moviePeriod]); useEffect(() => { void getStatsAction("episodes", episodePeriod).then(setEpisodeStats); }, [episodePeriod]); const movieCount = movieStats?.count ?? stats.moviesThisMonth; const movieHistory = movieStats?.history; const episodeCount = episodeStats?.count ?? stats.episodesThisWeek; const episodeHistory = episodeStats?.history; return (
} /> } />
); }