import { createFileRoute, Link } from "@tanstack/react-router"
import { lazy, Suspense, useState } from "react"
import { useTranslation } from "react-i18next"
import { Bar, BarChart, XAxis, YAxis } from "recharts"
import { BarChart3, DollarSign, Globe, Hash, Share2, Star } from "lucide-react"
import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from "@/components/ui/chart"
import { BackButton } from "@/components/back-button"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { Skeleton } from "@/components/ui/skeleton"
import { RatingHistogram } from "@/components/rating-histogram"
import { RevealCard } from "@/components/reveal-card"
import { HeroCard } from "@/components/wrapup-hero"
import { FunFacts } from "@/components/wrapup-fun-facts"
import { RankCard } from "@/components/wrapup-rank-card"
import { posterUrl } from "@/lib/api/client"
import { fmtUsd } from "@/lib/format"
import { WATCH_MEDIUMS } from "@/lib/watch-mediums"
import { useWrapUpReport } from "@/features/wrapup"
import { useDocumentTitle } from "@/hooks/use-document-title"
import type { MovieRef } from "@/features/wrapup"
const WrapUpShareCard = lazy(() => import("@/components/wrapup-share-card").then((m) => ({ default: m.WrapUpShareCard })))
const monthlyChartConfig = {
count: { label: "Movies", color: "var(--primary)" },
} satisfies ChartConfig
const genreChartConfig = {
count: { label: "Movies", color: "var(--primary)" },
} satisfies ChartConfig
export const Route = createFileRoute("/_app/wrapup/$id")({
component: WrapUpReportPage,
})
function WrapUpReportPage() {
const { t } = useTranslation()
const { id } = Route.useParams()
const { data: report, isPending } = useWrapUpReport(id)
const [showShare, setShowShare] = useState(false)
useDocumentTitle(report ? `${report.date_range.start.slice(0, 4)} Wrap-Up` : undefined)
if (isPending) return
{report.avg_rating.toFixed(1)}★
{t("wrapup.averageRating")}
{fmtUsd(report.total_budget_watched!)}
{t("wrapup.totalBudget")}
{report.avg_budget != null && ({t("wrapup.avgBudget", { amount: fmtUsd(report.avg_budget) })}
)}{report.language_distribution.length}
{t("wrapup.languages")}
{report.language_distribution.slice(0, 3).map((l) => l.language.toUpperCase()).join(", ")}
{report.total_rewatches}
{t("wrapup.moviesRewatched")}
{report.most_rewatched_movie && ({t("wrapup.mostRewatched")} {report.most_rewatched_movie.title} ({report.most_rewatched_movie.year})
)}{label}
{movie.title}
{showRuntime && movie.runtime_minutes ? `${movie.runtime_minutes} min` : movie.year}