// app/buying-guide/product/[id]/page.tsx import Link from "next/link"; import ReactMarkdown from "react-markdown"; const API_URL = process.env.NEXT_PUBLIC_API_BASE_URL; const ASSET_URL = process.env.NEXT_PUBLIC_ASSET_URL; async function getEntry(id: string) { const res = await fetch( `${API_URL}/items/bg_entries/${id}?fields=*,links.id,links.text,links.url,links.target,scores.id,scores.cat,scores.value,scores.body,header.id,date_updated`, { cache: "no-store", } ); if (!res.ok) { const error = await res.text(); console.error(`Failed to fetch entry: ${error}`); throw new Error(`Error fetching entry ${id}`); } const { data } = await res.json(); return data; } export default async function ProductDetail({ params, }: { params: Promise<{ id: string }>; }) { const id = (await params).id; const entry = await getEntry(id); const avgScore = entry?.scores?.length > 0 ? ( entry.scores.reduce((sum: number, s: any) => sum + Number(s.value), 0) / entry.scores.length ).toFixed(1) : "N/A"; const headerUrl = entry.header?.id ? `${ASSET_URL}/assets/${entry.header.id}?cache-buster=${entry.date_updated}&key=system-large-contain` : null; return (
{entry.product_price.startsWith("Starting at") ? entry.product_price : `Starting at ${entry.product_price}`}
)} ← Back to Buying GuideTotal: {avgScore}
{s.cat} – {s.value}/10