import React from 'react'
import { notFound } from 'next/navigation'
import dynamic from 'next/dynamic'
import { Merchant } from '@/lib/types/merchant'

const ProductList = dynamic(
  () => import('@/components/pages/packages/ProductList'),
)

type Props = {
  params: Promise<{ username: string }>
}

export async function generateMetadata({ params }: Props) {
  const { username } = await params
  const res = await fetch(`${process.env.API_URL}/merchants/${username}`, {
    cache: 'no-store',
  })

  if (!res.ok) {
    notFound()
  }

  const { data: merchant }: { data: Merchant } = await res.json()

  return {
    title: `${merchant.name} | Tour Packages`,
  }
}

const Page: React.FC = async () => {
  return (
    <section className="max-w-7xl w-full py-10 mx-auto px-5 sm:px-10">
      <div>
        <h1 className="heading-1">Tour Packages</h1>
        <p className="mt-2 text-slate-500">
          Explore our tour packages and book your next adventure in Nusa Penida.
        </p>
      </div>

      <ProductList />
    </section>
  )
}

export default Page
