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 = { main_terminal: "purple", local_stop: "sky", market: "pink", private_stop: "amber", other: "mint", }; const TYPE_ICON: Record = { main_terminal: "bus-front", local_stop: "map-pin", market: "store", private_stop: "bus", other: "map-pin", }; const TYPE_LABEL: Record = { main_terminal: "สถานีขนส่ง", local_stop: "ป้ายหลัก", market: "ตลาด/ชุมชน", private_stop: "จุดรับส่ง", other: "อื่น ๆ", }; export default async function StopsPage({ searchParams, }: { searchParams: Promise<{ q?: string }>; }) { const sp = await searchParams; const q = sp.q ?? ""; const { items } = await api.stops(q ? { q } : {}).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 && !q && (
)}
{q && ( ✕ )}
{Object.entries(typeCounts).map(([t, n]) => ( {TYPE_LABEL[t] ?? t} · {n} ))}
{items.length === 0 ? (

ไม่พบป้ายที่ตรงกับ “{q}”

) : (
{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; const body = ( <>

{s.name_th}

{place || "—"}

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