import Link from "next/link"; import { notFound } from "next/navigation"; import { api, isApiNotFoundError, resolveFileUrl, type Schedule, type StopDetail } from "@/lib/api"; import LazyMapView from "@/components/LazyMapView"; import { VisitTracker } from "@/lib/visit-tracker"; const TONES = ["sky", "purple", "pink", "mint", "amber"] as const; type StopDetailsPageProps = { searchParams: Promise<{ code?: string }>; }; export default async function StopDetailsPage({ searchParams }: StopDetailsPageProps) { const { code } = await searchParams; if (!code) notFound(); let stop: StopDetail | null = null; let schedules: Schedule[] = []; try { stop = await api.stop(code); ({ items: schedules } = await api.schedules({ stop_code: stop.code })); } catch (error) { if (isApiNotFoundError(error)) { notFound(); } stop = null; schedules = []; } if (!stop) { return (

ไม่สามารถโหลดข้อมูลป้ายนี้ได้

ระบบยังเปิดอยู่ แต่ backend ตอบกลับไม่ได้ในตอนนี้

กลับไปหน้าป้ายหยุดรถ
); } const place = [stop.city_th, stop.province_th].filter(Boolean).join(" / ") || "—"; const hasMap = stop.lat != null && stop.lng != null; const mapPoints = hasMap ? [{ id: stop.id, lat: stop.lat as number, lng: stop.lng as number, label: stop.name_th, code: stop.code }] : []; return (
{stop.station_type}

{stop.name_th}

📍 {place}{hasMap ? ` · ${stop.lat?.toFixed(4)}, ${stop.lng?.toFixed(4)}` : ""}

{stop.images.length > 0 ? (
{(stop.images[0].meta {stop.images.length > 1 && (
{stop.images.slice(1, 5).map((img) => ( {stop.name_th} ))}
)}
) : (
📷 ยังไม่มีรูปป้ายนี้
)} {hasMap ? (
) : (
🗺️ ยังไม่มีพิกัดของป้ายนี้
)}

ตารางเวลาที่จุดนี้

{schedules.length === 0 ? (

ยังไม่มีข้อมูล

) : (
{schedules.map((s, i) => { const tone = TONES[i % TONES.length]; return (
เส้นทาง {s.route_id}
🧭 {s.direction_note || "ไม่ระบุทิศทาง"} {s.schedule_note && ( 📝 {s.schedule_note} )}
{s.departure_times.length === 0 ? ( — ยังไม่มีรอบ — ) : ( s.departure_times.map((t, j) => ( 🕒 {t} )) )}
); })}
)}
); }