import type { Metadata } from "next";

const formatText = (text: string) =>
  text
    ?.replace(/-/g, " ")
    ?.replace(/\b\w/g, (c) => c.toUpperCase());

export async function generateMetadata({
  searchParams,
}: {
  searchParams: any;
}): Promise<Metadata> {
  const params = await searchParams;

  const getParam = (param: any) =>
    Array.isArray(param) ? param[0] : param || "";

  const city = formatText(getParam(params?.city));
  const make = formatText(getParam(params?.make));
  const model = formatText(getParam(params?.model));
  const rentalType = getParam(params?.rental_type);

  // ✅ Dynamic Title Logic
  let title = `Vehicles for Rent in ${city}`;

  if (make && model) {
    title = `${make} ${model} on Rent in ${city}`;
  } else if (make) {
    title = `${make} Vehicles on Rent in ${city}`;
  }

  // ✅ Description
  const description = `Book ${make ? make : ""} ${
    model ? model : ""
  } vehicles for rent in ${city}. Choose hourly or monthly plans with best prices, flexible booking, and instant confirmation.`;

  return {
    title,
    description,
    alternates: {
      canonical: `/vehicles?city=${params?.city}&rental_type=${params?.rental_type}`,
    },
    openGraph: {
      title,
      description,
      url: `/vehicles?city=${params?.city}`,
      siteName: "Ridoo",
      type: "website",
    },
  };
}


import VehicleClient from "@/components/VehicleClient";

export default async function Page({
  searchParams,
}: {
  searchParams: Promise<any>;
}) {
  const params = await searchParams;

  const getParam = (param: any) =>
    Array.isArray(param) ? param[0] : param || "";

  return (
    <VehicleClient
      searchParams={{
        city: getParam(params?.city),
        rental_type: getParam(params?.rental_type),
        from: getParam(params?.from),
        to: getParam(params?.to),
        months: getParam(params?.months),
        make: getParam(params?.make),
        model: getParam(params?.model),
      }}
    />
  );
}