import Link from "next/link"; import { api, type RouteListItem } from "@/lib/api"; import { VisitTracker } from "@/lib/visit-tracker"; // Map route_group_code to visual tone const ZONE_TONES: Record = { bangkok: "sky", interprovincial: "purple", in_province: "pink", municipal: "mint", }; const ZONE_DESCS: Record = { bangkok: "เส้นทางเชื่อมต่อกรุงเทพมหานคร", interprovincial: "เส้นทางเชื่อมต่อจังหวัดใกล้เคียง", in_province: "เส้นทางภายในจังหวัดอ่างทอง", municipal: "เส้นทางภายในเขตเทศบาล", }; // Display order: bangkok → interprovincial → in_province → municipal const ZONE_ORDER = ["bangkok", "interprovincial", "in_province", "municipal"]; // Cycle chip colors within a zone for visual rhythm const CHIP_CYCLE = ["purple", "sky", "pink", "mint"] as const; export default async function HomePage() { const [groupsRes, routesRes] = await Promise.allSettled([ api.routeGroups(), api.routes(), ]); const groups = groupsRes.status === "fulfilled" ? groupsRes.value.items : []; const routes = routesRes.status === "fulfilled" ? routesRes.value.items : []; // Group routes by code const byCode = new Map(); for (const r of routes) { const list = byCode.get(r.route_group_code) ?? []; list.push(r); byCode.set(r.route_group_code, list); } const orderedGroups = [...groups].sort((a, b) => { const ai = ZONE_ORDER.indexOf(a.code); const bi = ZONE_ORDER.indexOf(b.code); return (ai === -1 ? 99 : ai) - (bi === -1 ? 99 : bi); }); return ( <>
✨ ยินดีต้อนรับ

สถานีขนส่งผู้โดยสารภายใน
จังหวัดอ่างทอง

ดูสายรถ, ค้นหาป้าย และเปิดตัวอย่างเส้นทางได้ทันทีจากหน้าแรก

ดูรายละเอียดสายรถ ค้นหาป้ายหยุดรถ {routes[0] && ( ดูตัวอย่างสายรถ )}
{orderedGroups.map((g) => { const items = byCode.get(g.code) ?? []; if (items.length === 0) return null; const tone = ZONE_TONES[g.code] ?? "purple"; return (
{g.label_th}

{ZONE_DESCS[g.code] ?? ""} · {items.length} เส้นทาง

{items.map((r, i) => (

{r.route_id}

{r.name_th}

✅ ดูตาราง
))}
); })}
); }