import type { Metadata } from "next";

import { OrderHistoryPanel } from "@/components/dashboard/order-history-panel";
import { PageShell } from "@/components/layout/page-shell";
import { getSession } from "@/lib/auth/session";
import { listOrdersByEmail } from "@/lib/db/store";

export const dynamic = "force-dynamic";

export const metadata: Metadata = {
  title: "Orders",
  robots: { index: false, follow: false },
};

type Props = {
  searchParams: Promise<{ order?: string }>;
};

export default async function DashboardOrdersPage({ searchParams }: Props) {
  const session = await getSession();
  const params = await searchParams;
  const email = session?.email ?? "";
  const orders = email ? await listOrdersByEmail(email) : [];

  return (
    <PageShell
      variant="app"
      title="Orders"
      description="Receipts and payment status for every checkout on your account."
      breadcrumbs={[
        { label: "Dashboard", href: "/dashboard" },
        { label: "Orders" },
      ]}
    >
      <OrderHistoryPanel orders={orders} highlightOrderId={params.order} />
    </PageShell>
  );
}
