import Link from "next/link"; import { cookies } from "next/headers"; import type { SpaceConfig } from "@/lib/spaces"; const API_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8000/api"; interface Product { slug: string; name: string; description: string; category: string; product_type: string; image_url: string; base_price: number; } async function getProducts(spaceId: string): Promise { try { const params = new URLSearchParams(); if (spaceId && spaceId !== "default") { params.set("space", spaceId); } const url = `${API_URL}/products${params.toString() ? `?${params}` : ""}`; const res = await fetch(url, { next: { revalidate: 60 } }); if (!res.ok) return []; return res.json(); } catch { return []; } } async function getSpaceConfig(spaceId: string): Promise { try { const res = await fetch(`${API_URL}/spaces/${spaceId}`, { next: { revalidate: 300 }, }); if (res.ok) return res.json(); } catch {} return null; } export default async function HomePage() { const cookieStore = await cookies(); const spaceId = cookieStore.get("space_id")?.value || "default"; const [products, space] = await Promise.all([ getProducts(spaceId), getSpaceConfig(spaceId), ]); const name = space?.name || "rSwag"; const description = space?.description || "Merch for the rSpace ecosystem. Stickers, shirts, and more — designed by the community, printed on demand."; return (

{name}

{description}

Browse Products Design Your Own Upload Your Own

Featured Products

Print-on-demand — fulfilled by Printful, shipped worldwide.

{products.length === 0 ? (

No products available yet. Check back soon!

) : (
{products.map((product) => (
{product.name}
{product.product_type}

{product.name}

{product.description}

${product.base_price.toFixed(2)} View Details →
))}
)}
); }