import type { Metadata } from "next";
import { db } from "@/lib/db";
import TicketsPageClient from "./TicketsPageClient";

export const metadata: Metadata = { title: "Flight Tickets - KC Systems" };

export default async function TicketsPage() {
  const [countriesFromDb, slidesFromDb] = await Promise.all([
    db.ticketCountry.findMany({
      where: { isActive: true },
      include: {
        cities: {
          where: { isActive: true },
          orderBy: { name: "asc" },
          select: { id: true, name: true },
        },
      },
      orderBy: { name: "asc" },
    }),
    db.ticketSlide.findMany({ where: { isActive: true }, orderBy: [{ sortOrder: "asc" }, { createdAt: "desc" }] }),
  ]);

  const countries = countriesFromDb.map((country) => ({
    id: country.id,
    name: country.name,
    cities: country.cities,
  }));

  const slides = slidesFromDb.map((s) => ({
    id: s.id,
    imageUrl: s.imageUrl,
    title: s.title || "Manual Flight Ticketing",
    subtitle: s.subtitle || "Submit your route and travel date. Our team handles the booking manually.",
    ctaText: s.ctaText || "Create Request",
    ctaLink: s.ctaLink || "#ticket-request",
  }));

  return <TicketsPageClient countries={countries} slides={slides} />;
}
