import type { Metadata } from "next";
import { get } from "lodash";

import MenuItems from "@/components/MenuItems/MenuItems";

import { apiEndpoints } from "@/lib/api";
import { canonicalUrls } from "@/lib/canonical";
import { Product } from "@/types";

export async function generateMetadata(): Promise<Metadata> {
  return {
    title: "Menu - La Tarte",
    description:
      "We Invite You To La Tarte. Take A Journey To The Exquisite Taste Of Hand-Crafted Pastries And Savor The Magic. Whether It Is A Luscious Tart, A Delicious Croissant, Or A Savory Delight, We Promise You To Provide The Best In Every Taste.",
    alternates: {
      canonical: canonicalUrls.menu(),
    },
    openGraph: {
      title: "Menu - La Tarte",
      description:
        "We Invite You To La Tarte. Take A Journey To The Exquisite Taste Of Hand-Crafted Pastries And Savor The Magic. Whether It Is A Luscious Tart, A Delicious Croissant, Or A Savory Delight, We Promise You To Provide The Best In Every Taste.",
      url: canonicalUrls.menu(),
    },
  };
}

export default async function Menu() {
  const { data: menu } = await apiEndpoints.menus("0");

  const products = get(menu, ["products"], []);

  if (products.length === 0) {
    return <div>No menu found</div>;
  }

  return <MenuItems products={products as Array<Product>} />;
}
