import type { Metadata } from "next"; import { getCurrentCustomer } from "@/lib/auth"; import { getAddressesForCustomer } from "@/lib/account-data"; import { getShippingTiers } from "@/lib/shipping"; import { getBulkDiscountTiers } from "@/lib/bulk-discount"; import { getLocale } from "@/i18n/locale"; import { getDictionary } from "@/i18n/get-dictionary"; import { CheckoutForm, type CheckoutInitialValues } from "./checkout-form"; import { isPackstationSearchConfigured } from "@/lib/dhl-locations"; // Vorausfuellen aus Kundendaten aendert sich pro Nutzer/Anmeldestatus, und // Versandstaffeln koennen sich im Admin-Bereich jederzeit aendern — // Rendering pro Request statt statischem Build entkoppelt zudem den // Docker-Build-Schritt von einer zur Build-Zeit erreichbaren Datenbank. export const dynamic = "force-dynamic"; export async function generateMetadata(): Promise { const t = getDictionary(await getLocale()); return { title: t.checkoutPage.eyebrow }; } export default async function CheckoutPage() { const [tiers, bulkDiscountTiers] = await Promise.all([getShippingTiers(), getBulkDiscountTiers()]); const tierValues = tiers.map((t) => ({ minQuantity: t.minQuantity, maxQuantity: t.maxQuantity, priceCents: t.priceCents, })); const customer = await getCurrentCustomer(); if (!customer) return ; // getAddressesForCustomer sortiert Standardadresse (isDefault) zuerst, sonst // die zuletzt angelegte — die erste Adresse in der Liste ist also immer die // sinnvollste Vorbelegung fuer den Checkout. const addresses = await getAddressesForCustomer(customer.id); const defaultAddress = addresses[0]; const initialValues: CheckoutInitialValues = { firstName: customer.firstName, lastName: customer.lastName, email: customer.email, phone: customer.phone ?? "", street: defaultAddress?.street ?? "", zip: defaultAddress?.zip ?? "", city: defaultAddress?.city ?? "", }; return ; }