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

export const metadata = {
  title: "Dhaka to Khulna Train Schedule 2026 | ঢাকা থেকে খুলনা ট্রেনের সময়সূচী | Ticket Price & Booking",
  description:
    "Dhaka to Khulna train schedule, ticket price, and time table 2026. Trains including Sundarban Express via Padma Bridge. Book tickets online. ঢাকা থেকে খুলনা ট্রেনের সময়সূচী ও ভাড়া।",
  keywords: [
    "dhaka to khulna train",
    "dhaka to khulna train schedule",
    "dhaka to khulna ticket price",
    "dhaka to khulna train time",
    "ঢাকা থেকে খুলনা ট্রেন",
    "dhaka khulna train",
    "khulna train from dhaka",
    "sundarban express dhaka to khulna",
    "dhaka khulna train schedule 2026",
  ],
  openGraph: {
    title: "Dhaka to Khulna Train Schedule 2026 | Trains of Rajbari",
    description:
      "Complete Dhaka to Khulna train schedule with ticket prices, booking info, and route details.",
    url: `${SITE_INFO.url}/dhaka-to-khulna`,
    images: [{ url: "/logo.png" }],
  },
  alternates: {
    canonical: `${SITE_INFO.url}/dhaka-to-khulna`,
  },
};

export default function DhakaToKhulnaPage() {
  const availableTrains = trainData.filter((t) => {
    const routes = t.data.routes;
    const sourceIndex = routes.findIndex(
      (r) => r.city.toLowerCase().replace(/_/g, "") === "dhaka"
    );
    const destIndex = routes.findIndex(
      (r) => r.city.toLowerCase().replace(/_/g, "") === "khulna"
    );
    return sourceIndex !== -1 && destIndex !== -1 && destIndex > sourceIndex;
  });

  const schemas = [
    getTrainRouteSchema({
      fromStation: "Dhaka",
      toStation: "Khulna",
      banglaFrom: "ঢাকা",
      banglaTo: "খুলনা",
      distance: "380 km",
      duration: "7-8 hours",
      availableTrains: availableTrains.length,
      url: `${SITE_INFO.url}/dhaka-to-khulna`,
    }),
    getRouteFAQSchema({
      fromStation: "Dhaka",
      toStation: "Khulna",
      availableTrains: availableTrains.length,
      duration: "7-8 hours",
      distance: "380 km",
    }),
  ];

  return (
    <>
      {schemas.map((schema, i) => (
        <script
          key={i}
          type="application/ld+json"
          dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
        />
      ))}
      <DhakaToKhulnaClient />
    </>
  );
}
