import type { Metadata } from "next";
import { MenuBrowser } from "@/components/menu-browser";
import { DeliveryAddressCheck } from "@/components/delivery-address-check";
import { getWebsiteMenu } from "@/lib/menu-db";
import { getBotInfo } from "@/lib/bot-api";
import { getSiteContactSettings } from "@/lib/site-settings";

export const metadata: Metadata = {
  title: "Меню и доставка",
  description: "Актуальное меню ресторана КИЛН, самовывоз и расчёт доставки по адресу."
};

export default async function MenuPage() {
  const [menu, contact, info] = await Promise.all([
    getWebsiteMenu(),
    getSiteContactSettings(),
    getBotInfo().catch(() => null)
  ]);
  const prepMin = (info?.delivery.cook_time_min || 0) + (info?.delivery.assembly_time_min || 0);
  const prepMax = prepMin + (info?.delivery.highload_cook_add_min || 0) + (info?.delivery.highload_assembly_add_min || 0);
  const orderHours = info?.hours.orders;
  return (
    <section id="menu-top" className="section scroll-mt-16">
      <div className="site-container">
        <h1 className="display-title text-5xl text-kiln-flame md:text-7xl">Меню и доставка</h1>
        <div className="mt-8 w-full">
          <DeliveryAddressCheck pickup={{ address: contact.address, hours: orderHours?.start && orderHours?.end ? `${orderHours.start}–${orderHours.end}` : "сейчас уточняются", prepMin, prepMax }} />
        </div>
      </div>
      <div className="site-container mt-8">
        <MenuBrowser menu={menu} adminMode={false} />
      </div>
    </section>
  );
}
