import { cookies } from 'next/headers'
import { getIronSession } from 'iron-session'
import { redirect } from 'next/navigation'
import { SessionData, sessionOptions } from '@/lib/session'
import { ProductForm } from '@/components/products/product-form'
import { createProductFormAction } from '@/actions/products'

export default async function NewProductPage() {
  const session = await getIronSession<SessionData>(await cookies(), sessionOptions)
  if (session.isDemo) redirect('/dashboard')

  return (
    <div className="p-6 max-w-2xl mx-auto w-full">
      <h1 className="text-xl font-medium text-foreground mb-6">Nieuw product</h1>
      <ProductForm action={createProductFormAction} submitLabel="Product aanmaken" />
    </div>
  )
}
