import { PageShell, PageHeader } from '@/components/page-shell'
import { BackButton } from '@/components/back-button'
import { db } from '@/lib/db'
import { listMapsForPicker } from '@/lib/maps'
import { AddItemForm } from './add-item-form'

export const dynamic = 'force-dynamic'

export default async function NewItemPage() {
  const [locations, maps] = await Promise.all([
    db.location.findMany({
      orderBy: [{ path: 'asc' }],
      select: { id: true, path: true },
    }),
    listMapsForPicker(),
  ])

  return (
    <PageShell>
      <div className="pt-2">
        <PageHeader
          title="Add item"
          back={<BackButton fallbackHref="/" />}
        />
        <AddItemForm locations={locations} maps={maps} />
      </div>
    </PageShell>
  )
}
