import { trainData } from "@/data";
import { getTrainRouteSchema, getRouteFAQSchema, SITE_INFO } from "@/lib/schemas";
import TrainRouteClient from "@/components/TrainRouteClient";

const FROM = "dhaka";
const TO = "kalukhali";

export const metadata = {
  title: "Dhaka to Kalukhali Train Schedule & Ticket Price | ঢাকা থেকে কালুখালী",
  description: "Dhaka to Kalukhali train schedule, ticket price, and time table. Check all trains from Dhaka to Kalukhali. ঢাকা থেকে কালুখালী ট্রেনের সময়সূচী।",
  keywords: ["Dhaka to Kalukhali train", "Dhaka to Kalukhali train schedule", "Dhaka to Kalukhali ticket price", "ঢাকা থেকে কালুখালী", "trains of rajbari", "bangladesh railway schedule"],
  openGraph: {
    title: "Dhaka to Kalukhali Train Schedule | Trains of Rajbari",
    description: "Complete Dhaka to Kalukhali train schedule with ticket prices and route details.",
    url: `${SITE_INFO.url}/dhaka-to-kalukhali`,
  },
  alternates: { canonical: `${SITE_INFO.url}/dhaka-to-kalukhali` },
};

export default function DhakaToKalukhaliPage() {
  const count = trainData.filter((t) => {
    const routes = t.data.routes;
    const s = routes.findIndex((r) => r.city.toLowerCase().replace(/_/g, "") === FROM);
    const d = routes.findIndex((r) => r.city.toLowerCase().replace(/_/g, "") === TO);
    return d !== -1 && d > s;
  }).length;

  const schemas = [
    getTrainRouteSchema({ fromStation: "Dhaka", toStation: "Kalukhali", banglaFrom: "ঢাকা", banglaTo: "কালুখালী", distance: "160 km", duration: "4 hrs", availableTrains: count, url: `${SITE_INFO.url}/dhaka-to-kalukhali` }),
    getRouteFAQSchema({ fromStation: "Dhaka", toStation: "Kalukhali", availableTrains: count, duration: "4 hrs", distance: "160 km" }),
  ];

  return (
    <>
      {schemas.map((s, i) => (
        <script key={i} type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(s) }} />
      ))}
      <TrainRouteClient fromStation="dhaka" toStation="kalukhali" banglaFrom="ঢাকা" banglaTo="কালুখালী" distance="160 km" duration="4 hrs" />
    </>
  );
}
