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

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

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

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