'use client'; import { useState } from 'react'; import type { ProductCustomizationField } from 'brainerce'; import { useTranslations } from '@/core/lib/translations'; import { LoadingSpinner } from '@/ui/shared/loading-spinner'; import type { CustomizationValues } from '@/core/lib/product-options'; // The pure validation logic lives in core (zero markup) so that // `core/hooks/use-product-page` never imports from `ui/`. Re-exported here // for backward compatibility with existing imports. export { validateCustomization } from '@/core/lib/product-options'; export type { CustomizationValues } from '@/core/lib/product-options'; interface CustomizationFieldsProps { fields: ProductCustomizationField[]; values: CustomizationValues; onChange: (values: CustomizationValues) => void; errors?: Record; } /** * DESIGN ME — buyer-input customization fields on the product page * (engraving text, gift date, uploaded artwork, …). Field definitions, * values and validation errors come from useProductPage(); every input type * below must stay functional (including the image/gallery uploads). * * Building blocks: shadcn/ui primitives in src/components/ui (Button, Card, Badge, Input, Select, Accordion, Dialog, Skeleton, ...) + lucide-react icons are installed and ready to compose with. */ export function CustomizationFields({ fields, values, onChange, errors = {}, }: CustomizationFieldsProps) { const t = useTranslations('customization'); if (fields.length === 0) return null; const sorted = [...fields].sort((a, b) => a.position - b.position); const setValue = (key: string, value: unknown) => { onChange({ ...values, [key]: value }); }; return (
{t('title')}
{sorted.map((field) => ( setValue(field.key, v)} /> ))}
); } interface RowProps { field: ProductCustomizationField; value: unknown; error?: string; onChange: (value: unknown) => void; } function CustomizationFieldRow({ field, value, error, onChange }: RowProps) { const t = useTranslations('customization'); const labelText = ( {field.name} {field.required && } ); const help = field.description ?

{field.description}

: null; const errorHint = error ?

{error}

: null; switch (field.type) { case 'TEXTAREA': return (