import { Metadata } from "next";

import { getStoresServer } from "@/services/coupon.service.server";
import { toTitleCase } from "@/utils/helper";

import "@/styles/deal-style.css";

type Props = {
  params: Promise<{ slug: string; alphabet?: string }>;
};

export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const resolvedParams = await params;
  const categoryId = decodeURIComponent(resolvedParams.slug || "all");
  const alphabet = resolvedParams?.alphabet || "all";

  const data = await getStoresServer(categoryId, alphabet);

  return {
    title: toTitleCase(data?.page_title || `${categoryId} Stores | Rebates.com`),
    description: data?.meta_description || `Browse ${categoryId} stores and find the best deals`,
    openGraph: {
      title: data?.page_title || `${categoryId} Stores`,
      description: data?.meta_description || "",
      type: "website",
    },
  };
}

export default function CategoryCouponsLayout({ children }: { children: React.ReactNode }) {
  return <>{children}</>;
}
