import { PageBody, PageHeader } from '@/packages/ui/src/makerkit/page';
import { Metadata } from 'next';

import { notFound } from 'next/navigation';

import { retrieveCart } from '~/medusa/lib/data/cart';
import { retrieveCustomer } from '~/medusa/lib/data/customer';
import CartTemplate from '~/medusa/modules/cart/templates';

export const metadata: Metadata = {
  title: 'Cart',
  description: 'View your cart',
};

export default async function Cart() {
  const cart2 = await retrieveCart().catch((error) => {
    console.error(error);
    return notFound();
  });

  const customer = await retrieveCustomer();

  const cart: NonNullable<typeof cart2> = {
    items: [
      {
        id: '1',
        quantity: 1,
        cart: cart2!,
        item_total: 100,
        item_subtotal: 100,
        item_tax_total: 100,
        original_total: 100,
        original_subtotal: 100,
        original_tax_total: 100,
        total: 100,
        subtotal: 100,
        tax_total: 100,
        title: 'Test',
        requires_shipping: true,
        discount_total: 0,
        discount_tax_total: 0,
        metadata: {},
        created_at: new Date(),
        is_discountable: true,
        is_tax_inclusive: true,
        unit_price: 100,
        cart_id: '1',
      },
    ],
  }

  return (
    <PageBody>
      <PageHeader title={`Ostukorv`} description={`Vali kalendrist sobiv kuupäev ja broneeri endale vastuvõtuaeg.`} />

      <CartTemplate cart={cart} customer={customer} />
    </PageBody>
  );
}
