feat(ui): province→station selector, filter, share, visitor, lang, nav+pages

- HomeClient (client): จังหวัด→สถานี cascade selector (default อ่างทอง),
  กรองเส้นทางตามจังหวัด/สถานี, โชว์โซนว่างเป็น N/A card, ปุ่มแชร์ลิงก์สั้น
- page.tsx: fetch provinces/stops/routeStops + searchParams (p/s) for share link
- Header: nav 6 เมนู + สลับภาษา ไทย/EN (localStorage)
- Footer: ตัวนับผู้เข้าชม (visitsSummary) + เมนู 6 รายการ
- หน้าใหม่ /about /blog /credits (เนื้อหา+รูปจาก mock about-data/blog-data)
- globals.css: selector/share/empty-card/about/blog/credit styles
This commit is contained in:
phattaranun.a committed 2026-10-10 19:38:32 +07:00
1 parent 490e6c7d71
commit b022a85178
27 files changed
+1481 -199

No files matched your search

+82
View File
@@ -0,0 +1,82 @@
import { HERO_MAP } from "@/lib/images";
const BLOCKS = [
{
title: "เราคือใคร? คิดอย่างไรถึงเริ่มทำเว็บนี้",
pic: "/images/about/pic1.jpg",
body: [
"สวัสดีผู้อ่านทุกคน ขอบคุณที่เข้ามาดูเว็ปตั้งแต่แรกเริ่ม เปลี่ยนชื่อหลายรอบ สำหรับข้อมูลส่วนตัวว่าเราคือใครเราไม่อยากเปิดเผยตัวตน เก็บความเป็นส่วนตัว",
"ส่วนที่ว่าคิดยังไงถึงเริ่มทำเว็บนี้ เรามีประสบการณ์รอ รถมินิบัส อ่างทอง-กรุงเทพ(สายใน) หน้าสำนักงานที่ดินจังหวัดอ่างทอง ตอน 4โมงเช้า-5โมงเช้า ถ้าคนทั่วไปอาจจะไม่รู้ แต่ถ้าคนที่ขึ้นสายนี้ประจำจะรู้ แต่เราไม่รู้ไง! และตอนนั้นเป็นวันเสาร์ก็ไม่มีสองแถวด้วย รู้สึกว่าอยากขึ้นทำอะไรซักอย่าง",
],
},
{
title: "ไม่มีจิตรกรคนไหนนั่งวาดภาพจากอากาศ",
pic: "/images/about/pic2.jpg",
body: [
"บางคนอาจจะสงสัยว่าวลีนี้เกี่ยวกับเว็ปเราอย่างไร อย่างที่สำนวนบอกไม่มีจิตรกรวาดรูปจากอากาศ เว็ปเราก็ไม่ได้มโนจากอากาศเหมือนกันจะสร้างอะไรได้มันต้องมีต้นแบบให้ดู ขอให้เครดิตและขอบคุณต้นแบบของเราทุกๆคน",
"- Mayday กลุ่มคนรณรงค์เรื่องรถเมล์ในกรุงเทพ ปริมณฑล",
"- AyuthayaBusMap เป็นธุรกิจในอยุธยาทำแผนที่รถประจำทางบริการนักท่องเที่ยว",
"- กลุ่มไลน์รถตู้ กรุงเทพ-อ่างทอง (สายใน) เป็นต้นแบบว่าถึงเราไม่ใช่ผู้ประกอบการเราก็ลุกขึ้นมาทำอะไรซักอย่างได้",
],
},
{
title: "ความตั้งใจในปัจจุบัน",
pic: "/images/about/pic3.jpg",
body: [
"ความตั้งใจของเราคือ พยายามรวบรวมช่องทางการติดต่อถามเวลาเดินรถหรือติดตามข่าวสาร เช่น เบอร์โทร เพจFB กลุ่มFBหรือline หรือwww ที่รถประจำทางแต่ละสายประกาศไว้",
"ส่วนเรื่องตารางเวลาเดินรถที่เวปเราบอกตรงๆว่า เราอยากทำเป็นไอเดีย ว่าถ้าอ่างทองมีตารางเดินรถออนไลน์คงจะดีแต่ไม่ต้องไปเชื่อมาก เราคาดสีสถานะใว้",
"สีแดง คือตารางเวลาที่ไม่ได้อัปเดตเกิน 1 อาทิตย์ น่าจะเป็นสีที่เห็นได้บ่อยที่สุด",
"สีเขียว คือตารางเวลาที่ได้อัปเดตไม่เกิน 1 วัน",
"สีส้ม คือตารางเวลาที่ไม่ได้อัปเดตเกิน 1 วันแต่น้อยกว่า 1 อาทิตย์",
],
},
{
title: "แผนพัฒนาในอนาคต",
pic: "/images/about/pic4.jpg",
body: [
"ถ้ามีคนถามถึงแผนพัฒนาในอนาคตมั้ยก็ต้องบอกตรงๆว่าไม่มีการที่ใครเข้าเวปมาแล้วได้โทรถามเวลาเดินรถ หรือเข้ากลุ่มไลน์รถสองแถว รถมินิบัส ถือว่าเว็ปนี้ทำหน้าที่ครบแล้ว จริงๆเว็ปนี้ตอนแรกตั้งใจเป็นเว็บชั่วคราว เราอยากให้หน่วยงานราชการและเอกชนใช้กฎหมาย PPP ร่วมทุนระหว่างราชการและเอกชนเพื่อสร้างระบบขนส่งมวลชนของอ่างทอง มีเว็ปแบบเรา มีสถานีขนส่งผู้โดยสารประจำอำเภอ มีรถประจำทางเส้นเลือดฝอยที่ให้บริการได้ทั้งวัน มีเรือโดยสารแม่น้ำน้อย มีเรือข้ามฟากไชโย หรือใครมีไอเดียก็เมลล์มาบอกได้เผื่อจะนำไปปรับปรุงอนาคต",
],
},
];
export default function AboutPage() {
return (
<>
<section className="hero hero--short">
<img className="hero__map" src={HERO_MAP} alt="" aria-hidden="true" />
<div className="hero__blob one" aria-hidden />
<div className="hero__blob two" aria-hidden />
<div className="hero__blob three" aria-hidden />
<div className="container hero__inner">
<span className="hero__badge">เกี่ยวกับเรา</span>
<h1>
เกี่ยวกับเรา
<br />
<span className="hero__grad">เมื่อไหร่รถจะมา</span>
</h1>
<p className="hero__lead">เรื่องราวและที่มาของเว็บนี้ — อ่านเรียงตามบล็อกด้านล่างได้เลย</p>
</div>
</section>
<main className="main">
<div className="container">
<div className="about-wrap">
{BLOCKS.map((b) => (
<article className="about-block" key={b.title}>
<div className="about-block__text">
<h2>{b.title}</h2>
{b.body.map((p, i) => (
<p key={i}>{p}</p>
))}
</div>
<div className="about-media">
<img src={b.pic} alt={b.title} loading="lazy" decoding="async" />
</div>
</article>
))}
</div>
</div>
</main>
</>
);
}
+71
View File
@@ -0,0 +1,71 @@
import { HERO_MAP } from "@/lib/images";
import t1 from "@/data/blog/text1.json";
import t2 from "@/data/blog/text2.json";
import t3 from "@/data/blog/text3.json";
import t4 from "@/data/blog/text4.json";
import t5 from "@/data/blog/text5.json";
import t6 from "@/data/blog/text6.json";
import t7 from "@/data/blog/text7.json";
type Post = { date: string; th: { title: string; tag?: string; body: string[] } };
const POSTS: (Post & { pic: string })[] = [
{ ...(t1 as Post), pic: "/images/blog/pic1.jpg" },
{ ...(t2 as Post), pic: "/images/blog/pic2.jpg" },
{ ...(t3 as Post), pic: "/images/blog/pic3.jpg" },
{ ...(t4 as Post), pic: "/images/blog/pic4.jpg" },
{ ...(t5 as Post), pic: "/images/blog/pic5.jpg" },
{ ...(t6 as Post), pic: "/images/blog/pic6.jpg" },
{ ...(t7 as Post), pic: "/images/blog/pic7.jpg" },
].sort((a, b) => (a.date < b.date ? 1 : -1));
function fmtDate(d: string) {
const [y, m, dd] = d.split("-");
const months = ["ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค."];
return `${Number(dd)} ${months[Number(m) - 1]} ${Number(y) + 543}`;
}
export default function BlogPage() {
return (
<>
<section className="hero hero--short">
<img className="hero__map" src={HERO_MAP} alt="" aria-hidden="true" />
<div className="hero__blob one" aria-hidden />
<div className="hero__blob two" aria-hidden />
<div className="hero__blob three" aria-hidden />
<div className="container hero__inner">
<span className="hero__badge">บ่นไปเรื่อย</span>
<h1>
บ่นไปเรื่อย
<br />
<span className="hero__grad">เรื่องเล่าระหว่างทาง</span>
</h1>
<p className="hero__lead">รวมข้อเขียน ความฝัน และความกังวลเกี่ยวกับรถโดยสารในจังหวัดอ่างทอง</p>
</div>
</section>
<main className="main">
<div className="container">
<div className="blog-wrap">
{POSTS.map((p, i) => (
<article className="blog-card" key={p.date + p.th.title}>
<div className="blog-card__media">
<img src={p.pic} alt={p.th.title} loading="lazy" decoding="async" />
</div>
<div className="blog-card__body">
<div className="blog-card__meta">
<time dateTime={p.date}>{fmtDate(p.date)}</time>
{p.th.tag && <span className="blog-card__tag">{p.th.tag}</span>}
</div>
<h2>{p.th.title}</h2>
{p.th.body.slice(0, 2).map((para, j) => (
<p key={j}>{para}</p>
))}
</div>
</article>
))}
</div>
</div>
</main>
</>
);
}
+80
View File
@@ -0,0 +1,80 @@
import { HERO_MAP } from "@/lib/images";
export default function CreditsPage() {
return (
<>
<section className="hero hero--short">
<img className="hero__map" src={HERO_MAP} alt="" aria-hidden="true" />
<div className="hero__blob one" aria-hidden />
<div className="hero__blob two" aria-hidden />
<div className="hero__blob three" aria-hidden />
<div className="container hero__inner">
<span className="hero__badge">เครดิต</span>
<h1>
เครดิตและแหล่งที่มา
<br />
<span className="hero__grad">ขอบคุณทุกทรัพยากร</span>
</h1>
<p className="hero__lead">รายการทรัพยากรทั้งหมดที่ใช้ในเว็บนี้ พร้อมใบอนุญาตตามข้อกำหนดของเจ้าของแต่ละราย</p>
</div>
</section>
<main className="main">
<div className="container credit-wrap">
<section className="credit-section">
<h2>ไอคอน — Lucide</h2>
<p className="src">
แหล่งที่มา: <a href="https://lucide.dev" rel="noopener">lucide.dev</a> · ใบอนุญาต:{" "}
<a href="https://github.com/lucide-icons/lucide/blob/main/LICENSE" rel="noopener">MIT License</a>
</p>
<ul>
<li>ไอคอนที่ใช้ทั้งหมด 15 รายการ: alarm-clock, arrow-right, bus, bus-front, check, clock, globe, hourglass, map, map-pin, message-circle, phone, refresh-cw, search, triangle-alert</li>
</ul>
<div className="license">
<strong>MIT License (สรุป):</strong> อนุญาตให้ใช้ คัดลอก แก้ไข ผสาน เผยแพร่ แจกจ่าย ขาย และ/หรือให้สิทธิ์ใช้งานซอฟต์แวร์นี้ โดยมีเงื่อนไขให้ข้อความแสดงลิขสิทธิ์และข้อความอนุญาตข้างต้นปรากฏอยู่ในสำเนาทั้งหมด ซอฟต์แวร์นี้ให้บริการ "ตามสภาพ" โดยไม่มีการรับประกันใด ๆ
</div>
</section>
<section className="credit-section">
<h2>ฟอนต์ — Google Fonts</h2>
<p className="src">
แหล่งที่มา: <a href="https://fonts.google.com" rel="noopener">fonts.google.com</a> · ใบอนุญาต:{" "}
<a href="https://openfontlicense.org" rel="noopener">SIL Open Font License 1.1</a>
</p>
<ul>
<li><strong>K2D</strong> — ฟอนต์หลักของเว็บ (เนื้อหา + หัวเรื่อง)</li>
<li><strong>Noto Sans Thai</strong> — ตัวสำรองเนื้อหา</li>
<li><strong>Prompt</strong> — ตัวสำรองหัวเรื่อง/ตัวหนา</li>
<li><strong>IBM Plex Mono</strong> — เวลา · เลขสาย · ตัวเลข</li>
</ul>
</section>
<section className="credit-section">
<h2>แผนที่</h2>
<p className="src">
ใบอนุญาต: Leaflet <a href="https://github.com/Leaflet/Leaflet/blob/main/LICENSE" rel="noopener">BSD-2-Clause</a> · ชุดแผนที่:{" "}
<a href="https://www.openstreetmap.org/copyright" rel="noopener">OpenStreetMap © ผู้มีส่วนร่วม (ODbL)</a>
</p>
<ul>
<li>Leaflet — ไลบรารีแผนที่แบบ open-source</li>
<li>OpenStreetMap — ภาพ tiles และข้อมูลแผนที่</li>
<li>เส้นทางเดินรถ จุดจอด และหมุดสถานี วาดจากข้อมูล GIS ของทีม (GeoJSON)</li>
</ul>
</section>
<section className="credit-section">
<h2>ขอขอบคุณภาพรถประจำทาง</h2>
<p className="src">ภาพรถโดยสารที่แสดงในหน้ารายละเอียดสาย มาจากแหล่งข้อมูลสาธารณะด้านล่างนี้</p>
<ul>
<li><strong>สาย 2194</strong> หัวเวียง-อยุธยา — จาก <a href="http://www.bangkokbusclub.com/cms/showthread.php?t=4968" rel="noopener">bangkokbusclub.com</a></li>
<li><strong>สาย 8</strong> กรุงเทพ-สรรคบุรี-ชัยนาท — จากกลุ่ม Facebook (web.facebook.com)</li>
<li><strong>สาย 954</strong> กรุงเทพ-ท่าช้าง — จาก <a href="https://gogo.town/route/bangkok-rangsit-angthong-thachang/" rel="noopener">gogo.town</a></li>
<li><strong>รถไฟฟ้าสายสีแดง</strong> กรุงเทพ-ชุมทางบ้านภาชี — จาก <a href="https://thelist.group" rel="noopener">thelist.group</a></li>
</ul>
<div className="license">และสายอื่น ๆ ที่ไม่ได้ระบุ ขอขอบคุณมา ณ ที่นี้</div>
</section>
</div>
</main>
</>
);
}
+119 -2
View File
@@ -70,14 +70,25 @@ img { max-width: 100%; display: block; }
.brand__title { margin: 0; font-weight: 800; font-size: 1.05rem; color: var(--ink); }
.brand__subtitle { margin: 0; font-size: .72rem; color: var(--muted); }
.nav { margin-left: auto; display: flex; gap: 28px; }
.nav { margin-left: auto; display: flex; gap: 20px; }
.nav a {
color: var(--ink-muted); font-size: .92rem; font-weight: 600;
padding: 6px 4px; border-bottom: 2px solid transparent; transition: color .15s;
white-space: nowrap;
}
.nav a.active { color: var(--pink-700); border-bottom-color: #ec4899; }
.nav a:hover { color: var(--ink); }
.topbar__actions { display: flex; align-items: center; gap: 12px; }
.lang-switch {
display: inline-flex; align-items: center; gap: 4px;
background: #f3f0fb; border: 1px solid #e6dff5; border-radius: 999px;
padding: 6px 12px; font: inherit; font-size: .8rem; font-weight: 700;
color: #9a8ab8; cursor: pointer; transition: color .15s;
}
.lang-switch .sep { color: #cbbce6; }
.lang-switch .on { color: #6d28d9; }
.cta-pill {
background: var(--grad-cta); color: #fff; padding: 10px 22px;
border-radius: 999px; font-weight: 700; font-size: .88rem;
@@ -517,8 +528,14 @@ img { max-width: 100%; display: block; }
.footer__bottom {
margin-top: 36px; padding: 18px 0 22px;
border-top: 1px solid rgba(255, 255, 255, .08);
text-align: center;
display: flex; align-items: center; justify-content: space-between;
gap: 12px; flex-wrap: wrap; text-align: center;
}
.footer__visitor {
display: inline-flex; align-items: center; gap: 6px;
font-size: .84rem; color: #8d96b8;
}
.footer__visitor strong { color: #d8c7ff; font-variant-numeric: tabular-nums; }
.footer__bottom p { margin: 0; color: #8d96b8; font-size: .82rem; letter-spacing: .02em; }
.footer__bottom .pill {
display: inline-block; margin-left: 10px; padding: 2px 10px;
@@ -957,4 +974,104 @@ img { max-width: 100%; display: block; }
.legend__sw--gray { background: #e4e7eb; }
.chip.gray { background: #e8eaed; color: #5b636e; }
/* ---------- Route selector (จังหวัด → สถานี) ---------- */
.route-selector {
display: flex; align-items: flex-end; justify-content: center;
gap: 14px; flex-wrap: wrap; max-width: 780px; margin: 2px auto 0;
}
.select-field { flex: 1 1 250px; min-width: 240px; text-align: left; }
.select-field > label {
display: flex; align-items: center; gap: 6px; margin: 0 0 7px 8px;
font-size: .8rem; font-weight: 700; color: var(--muted); letter-spacing: .01em;
}
.select-field > label svg { color: #8b5cf6; flex: none; }
.select-box {
position: relative; display: flex; align-items: center;
background: #fff; border: 1px solid #e7e2f6; border-radius: 14px;
box-shadow: 0 8px 20px rgba(63, 43, 94, .08);
transition: border-color .18s ease, box-shadow .18s ease;
}
.select-box:focus-within { border-color: #c8b4ec; box-shadow: 0 0 0 4px rgba(122,76,192,.14); }
.select-box__icon { margin-left: 14px; color: #8b5cf6; flex: none; }
.select-box select {
flex: 1; min-width: 0; border: none; outline: none; background: transparent;
font-family: inherit; font-size: .95rem; font-weight: 600; color: var(--ink);
padding: 14px 12px; cursor: pointer; appearance: none; -webkit-appearance: none;
}
.select-box__chevron { margin-right: 14px; color: #8b5cf6; flex: none; pointer-events: none; transform: rotate(90deg); }
.select-arrow { display: none; align-self: center; color: #c4b5e6; }
@media (min-width: 720px) { .select-arrow { display: block; } }
.select-hint { margin: 12px 0 0; font-size: .84rem; color: var(--muted); min-height: 1.25em; }
/* ---------- Share + empty card ---------- */
.share-row { display: flex; justify-content: flex-end; margin: 22px 0 44px; }
.share-btn {
display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px;
border: 1px solid #7a4cc0; border-radius: 8px; background: #7a4cc0; color: #fff;
font: inherit; font-size: .9rem; font-weight: 700; cursor: pointer;
transition: background .15s ease;
}
.share-btn:hover { background: #6a3cae; }
.card__head.gray { background: #e4e7eb; }
.card--empty { cursor: default; }
.card--empty .card__head { background: #e4e7eb; }
.card--empty .card__num { color: #5b636e !important; font-size: 42px !important; text-shadow: none !important; }
/* ---------- Page hero (short) + about / blog / credits ---------- */
.hero--short { padding: 120px 0 56px; min-height: 0; }
.hero--short .hero__inner { padding: 0 20px; }
.about-wrap { padding: 16px 0 52px; display: flex; flex-direction: column; gap: 26px; }
.about-block {
display: grid; grid-template-columns: 1fr; gap: 16px; align-items: center;
background: #fff; border: 1px solid #ebe8f4; border-radius: 18px;
padding: 16px; box-shadow: 0 10px 26px rgba(63, 43, 94, .07);
}
.about-media img {
width: 100%; height: auto; max-height: 420px; object-fit: cover;
border-radius: 14px; display: block; box-shadow: 0 10px 24px rgba(63, 43, 94, .14);
}
.about-block h2 { margin: 0 0 10px; font-size: 1.2rem; color: #1f2a44; font-weight: 800; line-height: 1.35; }
.about-block p { margin: 0 0 10px; color: #4a5568; font-size: .95rem; line-height: 1.8; }
.about-block p:last-child { margin-bottom: 0; }
@media (min-width: 768px) {
.about-block { grid-template-columns: 1.05fr .95fr; gap: 28px; padding: 24px 26px; }
.about-block:nth-child(even) .about-media { order: -1; }
}
.blog-wrap { padding: 16px 0 52px; display: grid; gap: 24px; }
.blog-card {
display: grid; grid-template-columns: 1fr; gap: 16px;
background: #fff; border: 1px solid #ebe8f4; border-radius: 18px;
padding: 16px; box-shadow: 0 10px 26px rgba(63, 43, 94, .07);
}
.blog-card__media img { width: 100%; height: 220px; object-fit: cover; border-radius: 14px; display: block; }
.blog-card__meta { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.blog-card__meta time { font-size: .8rem; color: #8d96b8; font-variant-numeric: tabular-nums; }
.blog-card__tag {
font-size: .72rem; font-weight: 700; color: #7a4cc0; background: #f3ecff;
padding: 3px 10px; border-radius: 999px;
}
.blog-card h2 { margin: 0 0 10px; font-size: 1.15rem; color: #1f2a44; font-weight: 800; }
.blog-card p { margin: 0 0 10px; color: #4a5568; font-size: .94rem; line-height: 1.8; }
.blog-card p:last-child { margin-bottom: 0; }
@media (min-width: 768px) {
.blog-card { grid-template-columns: 320px 1fr; gap: 22px; padding: 20px 24px; }
}
.credit-wrap { padding: 16px 0 52px; max-width: 46rem; }
.credit-section {
background: #fff; border: 1px solid #e7e0f6; border-radius: 16px;
padding: 20px 22px; margin-bottom: 16px;
}
.credit-section h2 { margin: 0 0 6px; font-size: 1.05rem; color: #1f2a44; }
.credit-section .src { margin: 0 0 12px; color: #6f7b95; font-size: .85rem; }
.credit-section ul { margin: 0; padding-left: 1.2rem; color: #3a4462; font-size: .92rem; line-height: 1.7; }
.credit-section a { color: #7a4cc0; }
.license {
margin: 14px 0 0; padding: 12px 14px; background: #f9f7ff;
border-left: 3px solid #7a4cc0; border-radius: 8px;
font-size: .85rem; color: #4a5573; line-height: 1.6;
}
+36 -185
View File
@@ -1,208 +1,59 @@
import Link from "next/link";
import { api, type RouteListItem, type Schedule } from "@/lib/api";
import { VisitTracker } from "@/lib/visit-tracker";
import { HERO_MAP, PARTNERS } from "@/lib/images";
import { Icon } from "@/components/Icons";
import HomeClient from "@/components/HomeClient";
// Map route_group_code to visual tone
const ZONE_TONES: Record<string, "sky" | "purple" | "pink" | "mint"> = {
bangkok: "sky",
interprovincial: "purple",
in_province: "pink",
municipal: "mint",
};
export default async function HomePage({
searchParams,
}: {
searchParams: Promise<{ p?: string; s?: string }>;
}) {
const sp = await searchParams;
const ZONE_DESCS: Record<string, string> = {
bangkok: "เส้นทางเชื่อมต่อกรุงเทพมหานคร",
interprovincial: "เส้นทางเชื่อมต่อจังหวัดใกล้เคียง",
in_province: "เส้นทางภายในจังหวัดอ่างทอง",
municipal: "เส้นทางภายในเขตเทศบาล",
};
// Display order: municipal → bangkok → interprovincial → in_province
const ZONE_ORDER = ["municipal", "bangkok", "interprovincial", "in_province"];
// Legend rows (คำอธิบายสีการ์ดตามหมวดเส้นทาง)
const LEGEND = [
{ tone: "sky", label: "หมวดเส้นทางเข้ากรุงเทพฯ — การ์ดสีน้ำเงิน" },
{ tone: "purple", label: "หมวดเส้นทางระหว่างจังหวัด — การ์ดสีม่วง" },
{ tone: "pink", label: "หมวดเส้นทางภายในจังหวัด — การ์ดสีชมพู" },
{ tone: "mint", label: "หมวดเส้นทางภายในเทศบาล — การ์ดสีเขียวมินต์" },
{ tone: "gray", label: "ยังไม่มีข้อมูล — การ์ดสีเทา แสดง N/A แทนเลขสาย" },
];
const CHIP_CYCLE = ["purple", "sky", "pink", "mint"] as const;
/** เที่ยวถัดไปของสาย = เที่ยวแรกที่ยังไม่ผ่าน */
function nextTrip(times: string[]): string | null {
const now = new Date();
const cur = now.getHours() * 60 + now.getMinutes();
for (const t of [...times].sort()) {
const [h, m] = t.split(":").map(Number);
if (h * 60 + m >= cur) return t;
}
return null;
}
export default async function HomePage() {
const [groupsRes, routesRes, schedRes] = await Promise.allSettled([
const [groupsRes, routesRes, schedRes, provRes, stopsRes] = await Promise.allSettled([
api.routeGroups(),
api.routes(),
api.schedules({}),
api.provinces(),
api.stops(),
]);
const groups = groupsRes.status === "fulfilled" ? groupsRes.value.items : [];
const routes = routesRes.status === "fulfilled" ? routesRes.value.items : [];
const routes: RouteListItem[] = routesRes.status === "fulfilled" ? routesRes.value.items : [];
const schedules: Schedule[] = schedRes.status === "fulfilled" ? schedRes.value.items : [];
const provinces = provRes.status === "fulfilled" ? provRes.value.items : [];
const stops = stopsRes.status === "fulfilled" ? stopsRes.value.items : [];
// route_id -> all departure times (ทุกทิศทาง/จุดจอด)
const timesByRoute = new Map<string, string[]>();
// route_id -> all departure times
const timesByRoute: Record<string, string[]> = {};
for (const s of schedules) {
const list = timesByRoute.get(s.route_id) ?? [];
list.push(...s.departure_times);
timesByRoute.set(s.route_id, list);
(timesByRoute[s.route_id] ??= []).push(...s.departure_times);
}
// Group routes by code
const byCode = new Map<string, RouteListItem[]>();
for (const r of routes) {
const list = byCode.get(r.route_group_code) ?? [];
list.push(r);
byCode.set(r.route_group_code, list);
}
// route_id -> station ids (for station-level filtering)
const routeStations: Record<string, number[]> = {};
await Promise.all(
routes.map(async (r) => {
const { items } = await api.routeStops(r.route_id).catch(() => ({ items: [] }));
routeStations[r.route_id] = items.map((x) => x.station_id);
}),
);
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);
});
// Duplicate partner tiles for a seamless marquee loop
const marqueePartners = [...PARTNERS, ...PARTNERS];
const initialProvinceId = sp.p ? Number(sp.p) || undefined : undefined;
const initialStationCode = sp.s ?? undefined;
return (
<>
<VisitTracker path="/" />
<section className="hero">
{/* แผนที่เครือข่าย (จาก design: .image/network/overview-map.png) */}
<img className="hero__map" src={HERO_MAP} alt="" aria-hidden="true" />
<div className="hero__blob one" aria-hidden />
<div className="hero__blob two" aria-hidden />
<div className="hero__blob three" aria-hidden />
<div className="container hero__inner">
<span className="hero__badge">ยินดีต้อนรับ</span>
<h1>
สถานีขนส่งผู้โดยสารภายใน
<br />
<span className="hero__grad">จังหวัดอ่างทอง</span>
</h1>
<p className="hero__lead">
ดูสายรถ, ค้นหาป้าย และเปิดตัวอย่างเส้นทางได้ทันทีจากหน้าแรก
</p>
<div className="hero__actions">
<Link className="pill-link pill-link--primary" href="/routes">
ดูรายละเอียดสายรถ
</Link>
<Link className="pill-link pill-link--secondary" href="/stops">
ค้นหาป้ายหยุดรถ
</Link>
{routes[0] && (
<Link
className="pill-link pill-link--accent"
href={`/routes/${encodeURIComponent(routes[0].route_id)}`}
>
ดูตัวอย่างสายรถ
</Link>
)}
</div>
</div>
</section>
{/* ผู้สนับสนุน & พาร์ทเนอร์ (marquee — จาก design) */}
<section className="sponsor-section" aria-label="ผู้สนับสนุนและพาร์ทเนอร์">
<div className="sponsor-section__head">
<h4>ผู้สนับสนุน &amp; พาร์ทเนอร์</h4>
<p>ร่วมเป็นผู้สนับสนุนเราได้ เมื่อซื้อของออนไลน์ หรือซื้อตั๋วรถทัวร์ เครื่องบิน ออนไลน์</p>
</div>
<div className="marquee">
<div className="marquee__track">
{marqueePartners.map((p, i) => (
<span key={`${p.id}-${i}`} className="marquee__tile" aria-label={p.label}>
<img src={p.src} alt={p.label} decoding="async" loading="lazy" />
</span>
))}
</div>
</div>
</section>
<main className="main">
<div className="container">
{/* Legend — คำอธิบายสีการ์ดตามหมวดเส้นทาง (จาก design) */}
<section className="legend" aria-label="คำอธิบายสีการ์ดตามหมวดเส้นทาง">
<h2 className="legend__title">คำอธิบายสีการ์ดตามหมวดเส้นทาง</h2>
<ul className="legend__list">
{LEGEND.map((l) => (
<li key={l.tone}>
<span className={`legend__sw legend__sw--${l.tone}`} aria-hidden />
{l.label}
</li>
))}
</ul>
</section>
{orderedGroups.map((g) => {
const items = byCode.get(g.code) ?? [];
if (items.length === 0) return null;
const tone = ZONE_TONES[g.code] ?? "purple";
return (
<section key={g.id} className="zone">
<div className="zone__head">
<span className={`zone__tag ${tone}`}>{g.label_th}</span>
<p className="zone__desc">
{ZONE_DESCS[g.code] ?? ""} · {items.length} เส้นทาง
</p>
</div>
<div className="grid">
{items.map((r, i) => {
const times = timesByRoute.get(r.route_id) ?? [];
const next = nextTrip(times);
const chipTone = CHIP_CYCLE[i % CHIP_CYCLE.length];
return (
<Link
key={r.route_id}
href={`/routes/${encodeURIComponent(r.route_id)}`}
className="card"
>
<div className={`card__head ${tone}`}>
<p className="card__num">{r.route_id}</p>
</div>
<div className="card__body">
<p className="card__name">{r.name_th}</p>
{next ? (
<span className={`chip ${chipTone}`}>
<Icon name="clock" size={12} className="icon" /> เที่ยวถัดไป {next}
</span>
) : times.length > 0 ? (
<span className={`chip ${chipTone}`}>
<Icon name="check" size={12} className="icon" /> ดูตาราง
</span>
) : (
<span className="chip gray">
<Icon name="hourglass" size={12} className="icon" /> ยังไม่มีตาราง
</span>
)}
</div>
</Link>
);
})}
</div>
</section>
);
})}
</div>
</main>
<HomeClient
groups={groups}
routes={routes}
timesByRoute={timesByRoute}
provinces={provinces}
stops={stops}
routeStations={routeStations}
initialProvinceId={initialProvinceId}
initialStationCode={initialStationCode}
/>
</>
);
}