import { createForm } from "@chrisluyi/template/runtime" import { OrderSchema } from "./schema" import { PaymentMethodField, QuantityField, ShippingAddressField, } from "./widgets" /** * Order form instance — created once at module level. * * Usage in a tab component: * const { config, forms } = useRegional() * * * To submit to a real API, replace the console.log with: * await apiClient("/api/orders", { method: "POST", body: JSON.stringify(data) }) * where `apiClient` is created by createApiClient() in ../../../services/client.ts */ export const orderForm = createForm({ schema: OrderSchema, labels: { quantity: "Quantity", shippingAddress: "Shipping address", paymentMethod: "Payment method", }, defaultWidgets: { quantity: QuantityField, shippingAddress: ShippingAddressField, paymentMethod: PaymentMethodField, }, onSubmit: (_regionConfig) => async (data) => { // Demo submit — replace with a real API call. console.log("Order submitted:", data) await new Promise((resolve) => setTimeout(resolve, 600)) }, options: { validationMode: "onSubmit", resetOnSuccess: true, }, })