import Link from "next/link"; import { api } from "@/lib/api"; import LazyMapView from "@/components/LazyMapView"; import { VisitTracker } from "@/lib/visit-tracker"; import { Icon, type IconName } from "@/components/Icons"; const TONES = ["sky", "purple", "pink", "mint", "amber"] as const; const TYPE_TONE: Record = { terminal: "purple", station: "sky", pickup: "amber", market: "pink", landmark: "mint", }; const TYPE_ICON: Record = { terminal: "bus-front", station: "map-pin", pickup: "bus", market: "store", landmark: "map-pin", }; const TYPE_LABEL: Record = { terminal: "สถานีขนส่ง", station: "ป้ายหลัก", pickup: "จุดรับส่ง", market: "ตลาด/ชุมชน", landmark: "จุดสังเกต", }; export default async function StopsPage() { const { items } = await api.stops().catch(() => ({ items: [] })); const points = items .filter((s) => s.lat != null && s.lng != null) .map((s) => ({ id: s.id, lat: s.lat as number, lng: s.lng as number, label: s.name_th, code: s.code })); const typeCounts = items.reduce>((acc, s) => { acc[s.station_type] = (acc[s.station_type] ?? 0) + 1; return acc; }, {}); return (
STOP DIRECTORY

จุดจอดทั่วประเทศ

ค้นหาป้าย / สถานีขนส่ง พร้อมแผนที่และเส้นทางที่ผ่าน

{items.length} จุดจอด {points.length} มีพิกัด {Object.keys(typeCounts).length} ประเภท
{points.length > 0 && (
)}
{Object.entries(typeCounts).map(([t, n]) => ( {TYPE_LABEL[t] ?? t} · {n} ))}
{items.map((s, i) => { const tone = TYPE_TONE[s.station_type] ?? TONES[i % TONES.length]; const icon = TYPE_ICON[s.station_type] ?? "map-pin"; const place = [s.city_th, s.province_th].filter(Boolean).join(" · "); const stopHref = s.code ? `/stops/${encodeURIComponent(s.code)}` : null; return ( stopHref ? (

{s.name_th}

{place || "—"}

{TYPE_LABEL[s.station_type] ?? s.station_type} {s.lat != null && s.lng != null && ( บนแผนที่ )}
→ ) : (

{s.name_th}

{place || "—"}

{TYPE_LABEL[s.station_type] ?? s.station_type} {s.lat != null && s.lng != null && ( บนแผนที่ )}
→
) ); })}
); }