// 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 (
{/* Header Banner */} {headerUrl && (
Header Image
)} {/* Title */}

{entry.product_make}

{entry.product_model}

{entry.product_price && (

{entry.product_price.startsWith("Starting at") ? entry.product_price : `Starting at ${entry.product_price}`}

)} ← Back to Buying Guide
{/* Links & Score Summary */} {(Array.isArray(entry.links) || Array.isArray(entry.scores)) && (
{Array.isArray(entry.links) && entry.links.length > 0 && (

Links

)} {(Array.isArray(entry.scores) && entry.scores.length > 0) && (

Score Summary

    {entry.scores.map((s: any, idx: number) => (
  • {s.cat} {s.value}/10
  • ))}

Total: {avgScore}

)}
)} {/* Overview */} {entry.review_overview_text && (

Overview

{entry.review_overview_text}
)} {/* Intro */} {entry.review_intro_text && (

{`${entry.product_make}, ${entry.product_model} Review by ${entry.author}`}

{entry.review_intro_text}
)} {/* Detailed Scores */} {(Array.isArray(entry.scores) && entry.scores.length > 0) && (
{entry.scores.map((s: any, idx: number) => (

{s.cat} – {s.value}/10

{s.body}
))}
)} {/* Recommendation */} {entry.rec_text && (

Recommendation

{entry.rec_text}
)} {/* Updates */} {entry.updates && (

Updates

{entry.updates}
)} {/* Video */} {entry.video_review_url && (

Video Review