create-brainerce-store 1.50.5 → 1.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/README.md +72 -0
  2. package/dist/index.js +146 -100
  3. package/messages/en.json +36 -1
  4. package/messages/he.json +36 -1
  5. package/package.json +1 -1
  6. package/templates/nextjs/base/.claude/commands/design.md +60 -0
  7. package/templates/nextjs/base/.env.local.ejs +5 -0
  8. package/templates/nextjs/base/.eslintrc.json +57 -3
  9. package/templates/nextjs/base/AGENTS.md +41 -0
  10. package/templates/nextjs/base/AI-GUIDE.md +143 -0
  11. package/templates/nextjs/base/CLAUDE.md +52 -0
  12. package/templates/nextjs/base/TRANSLATIONS.md +1 -1
  13. package/templates/nextjs/base/next.config.ts +2 -2
  14. package/templates/nextjs/base/package.json.ejs +52 -39
  15. package/templates/nextjs/base/src/app/account/page.tsx +5 -5
  16. package/templates/nextjs/base/src/app/api/auth/logout/route.ts +1 -1
  17. package/templates/nextjs/base/src/app/api/auth/reset-password/route.ts +2 -2
  18. package/templates/nextjs/base/src/app/api/store/[...path]/route.ts +1 -1
  19. package/templates/nextjs/base/src/app/auth/callback/page.tsx +4 -4
  20. package/templates/nextjs/base/src/app/blog/[slug]/page.tsx.ejs +4 -4
  21. package/templates/nextjs/base/src/app/blog/page.tsx.ejs +2 -2
  22. package/templates/nextjs/base/src/app/cart/page.tsx +2 -173
  23. package/templates/nextjs/base/src/app/checkout/page.tsx +12 -11
  24. package/templates/nextjs/base/src/app/contact/page.tsx +3 -3
  25. package/templates/nextjs/base/src/app/faq/page.tsx.ejs +2 -2
  26. package/templates/nextjs/base/src/app/forgot-password/page.tsx +4 -4
  27. package/templates/nextjs/base/src/app/globals.css +36 -30
  28. package/templates/nextjs/base/src/app/layout.tsx.ejs +12 -12
  29. package/templates/nextjs/base/src/app/login/page.tsx +4 -4
  30. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +19 -12
  31. package/templates/nextjs/base/src/app/page.tsx +4 -4
  32. package/templates/nextjs/base/src/app/pages/[slug]/page.tsx.ejs +3 -3
  33. package/templates/nextjs/base/src/app/payment-complete/page.tsx +1 -1
  34. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +6 -6
  35. package/templates/nextjs/base/src/app/products/page.tsx +4 -623
  36. package/templates/nextjs/base/src/app/register/page.tsx +4 -4
  37. package/templates/nextjs/base/src/app/reset-password/page.tsx +5 -5
  38. package/templates/nextjs/base/src/app/sitemap.ts +1 -1
  39. package/templates/nextjs/base/src/app/verify-email/page.tsx +5 -5
  40. package/templates/nextjs/base/src/components/account/address-book.tsx +3 -3
  41. package/templates/nextjs/base/src/components/account/order-customizations.tsx +3 -3
  42. package/templates/nextjs/base/src/components/account/order-history.tsx +13 -5
  43. package/templates/nextjs/base/src/components/account/order-payment-block.tsx +2 -2
  44. package/templates/nextjs/base/src/components/account/order-shipping-block.tsx +2 -2
  45. package/templates/nextjs/base/src/components/account/order-status-timeline.tsx +2 -2
  46. package/templates/nextjs/base/src/components/account/profile-section.tsx +3 -3
  47. package/templates/nextjs/base/src/components/auth/login-form.tsx +4 -4
  48. package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +4 -4
  49. package/templates/nextjs/base/src/components/auth/register-form.tsx +4 -4
  50. package/templates/nextjs/base/src/components/brainerce-bot.tsx +2 -2
  51. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +24 -3
  52. package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +2 -2
  53. package/templates/nextjs/base/src/components/checkout/delivery-method-step.tsx +2 -2
  54. package/templates/nextjs/base/src/components/checkout/order-bump-card.tsx +4 -4
  55. package/templates/nextjs/base/src/components/checkout/payment-step.tsx +20 -16
  56. package/templates/nextjs/base/src/components/checkout/pickup-step.tsx +3 -3
  57. package/templates/nextjs/base/src/components/checkout/shipping-step.tsx +3 -3
  58. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +3 -3
  59. package/templates/nextjs/base/src/components/seo/organization-json-ld.tsx +2 -2
  60. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +3 -3
  61. package/templates/nextjs/base/src/components/ui/accordion.tsx +53 -0
  62. package/templates/nextjs/base/src/components/ui/badge.tsx +32 -0
  63. package/templates/nextjs/base/src/components/ui/button.tsx +49 -0
  64. package/templates/nextjs/base/src/components/ui/card.tsx +55 -0
  65. package/templates/nextjs/base/src/components/ui/checkbox.tsx +28 -0
  66. package/templates/nextjs/base/src/components/ui/dialog.tsx +107 -0
  67. package/templates/nextjs/base/src/components/ui/input.tsx +22 -0
  68. package/templates/nextjs/base/src/components/ui/label.tsx +21 -0
  69. package/templates/nextjs/base/src/components/ui/radio-group.tsx +38 -0
  70. package/templates/nextjs/base/src/components/ui/select.tsx +153 -0
  71. package/templates/nextjs/base/src/components/ui/separator.tsx +26 -0
  72. package/templates/nextjs/base/src/components/ui/sheet.tsx +125 -0
  73. package/templates/nextjs/base/src/components/ui/skeleton.tsx +7 -0
  74. package/templates/nextjs/base/src/components/ui/tabs.tsx +55 -0
  75. package/templates/nextjs/base/src/components/ui/textarea.tsx +21 -0
  76. package/templates/nextjs/base/src/components/ui/tooltip.tsx +32 -0
  77. package/templates/nextjs/base/src/core/hooks/use-cart-page.ts +58 -0
  78. package/templates/nextjs/base/src/core/hooks/use-home-data.ts +51 -0
  79. package/templates/nextjs/base/src/core/hooks/use-product-listing.ts +295 -0
  80. package/templates/nextjs/base/src/core/hooks/use-product-page.ts +278 -0
  81. package/templates/nextjs/base/src/{hooks → core/hooks}/use-search.ts +1 -1
  82. package/templates/nextjs/base/src/{lib → core/lib}/brainerce.ts.ejs +1 -1
  83. package/templates/nextjs/base/src/core/lib/product-options.ts +121 -0
  84. package/templates/nextjs/base/src/{lib → core/lib}/resolve-currency.ts +1 -1
  85. package/templates/nextjs/base/src/{lib → core/lib}/safe-redirect.ts +1 -1
  86. package/templates/nextjs/base/src/{lib → core/lib}/sanitize.ts.ejs +1 -1
  87. package/templates/nextjs/base/src/{lib → core/lib}/use-currency.ts +1 -1
  88. package/templates/nextjs/base/src/{providers → core/providers}/store-provider.tsx.ejs +4 -4
  89. package/templates/nextjs/base/src/{components → ui}/cart/cart-bundle-offer.tsx +22 -16
  90. package/templates/nextjs/base/src/{components → ui}/cart/cart-item.tsx +8 -14
  91. package/templates/nextjs/base/src/{components → ui}/cart/cart-nudges.tsx +28 -39
  92. package/templates/nextjs/base/src/{components → ui}/cart/cart-summary.tsx +7 -5
  93. package/templates/nextjs/base/src/{components → ui}/cart/cart-upgrade-banner.tsx +13 -28
  94. package/templates/nextjs/base/src/ui/cart/cart-view.tsx +140 -0
  95. package/templates/nextjs/base/src/{components → ui}/cart/coupon-input.tsx +14 -25
  96. package/templates/nextjs/base/src/{components → ui}/cart/free-shipping-bar.tsx +6 -7
  97. package/templates/nextjs/base/src/{components → ui}/cart/reservation-countdown.tsx +95 -103
  98. package/templates/nextjs/base/src/ui/home/discount-banner-strip.tsx +20 -0
  99. package/templates/nextjs/base/src/ui/home/featured-products-section.tsx +24 -0
  100. package/templates/nextjs/base/src/ui/home/hero-section.tsx +27 -0
  101. package/templates/nextjs/base/src/ui/home/home-client.tsx +29 -0
  102. package/templates/nextjs/base/src/{components/content → ui/layout}/announcement-bar.tsx.ejs +116 -125
  103. package/templates/nextjs/base/src/ui/layout/faq-section.tsx.ejs +90 -0
  104. package/templates/nextjs/base/src/{components/content → ui/layout}/header-account.tsx +5 -20
  105. package/templates/nextjs/base/src/ui/layout/language-switcher.tsx.ejs +80 -0
  106. package/templates/nextjs/base/src/{components/content → ui/layout}/rich-text-block.tsx.ejs +1 -1
  107. package/templates/nextjs/base/src/{components/content → ui/layout}/site-footer.tsx.ejs +144 -164
  108. package/templates/nextjs/base/src/{components/content → ui/layout}/site-header.tsx.ejs +152 -182
  109. package/templates/nextjs/base/src/{components/products → ui/product}/customization-fields.tsx +457 -478
  110. package/templates/nextjs/base/src/{components/products → ui/product}/discount-badge.tsx +18 -22
  111. package/templates/nextjs/base/src/{components/products → ui/product}/frequently-bought-together.tsx +21 -33
  112. package/templates/nextjs/base/src/ui/product/modifier-group-selector.tsx +206 -0
  113. package/templates/nextjs/base/src/{components/shared → ui/product}/price-display.tsx +5 -4
  114. package/templates/nextjs/base/src/{components/products → ui/product}/product-card.tsx +238 -271
  115. package/templates/nextjs/base/src/{app/products/[slug] → ui/product}/product-client-section.tsx +455 -631
  116. package/templates/nextjs/base/src/{components/products → ui/product}/product-grid.tsx +3 -3
  117. package/templates/nextjs/base/src/ui/product/product-listing.tsx +446 -0
  118. package/templates/nextjs/base/src/{components/products → ui/product}/recommendation-section.tsx +102 -107
  119. package/templates/nextjs/base/src/{components/reviews → ui/product}/review-form.tsx +46 -45
  120. package/templates/nextjs/base/src/{components/reviews/reviews-section.tsx → ui/product/reviews-section.tsx.ejs} +38 -15
  121. package/templates/nextjs/base/src/{components/products → ui/product}/stock-badge.tsx +61 -63
  122. package/templates/nextjs/base/src/{components/products → ui/product}/variant-selector.tsx +3 -3
  123. package/templates/nextjs/base/src/{components → ui}/shared/cdn-image.tsx +1 -1
  124. package/templates/nextjs/base/src/{components → ui}/shared/loading-spinner.tsx +2 -2
  125. package/templates/nextjs/base/tailwind.config.ts +69 -30
  126. package/templates/nextjs/designs/atelier/app-overlay/layout.tsx.ejs +251 -0
  127. package/templates/nextjs/designs/atelier/globals.css +396 -0
  128. package/templates/nextjs/designs/atelier/messages-patch/en.json +99 -0
  129. package/templates/nextjs/designs/atelier/messages-patch/he.json +99 -0
  130. package/templates/nextjs/designs/atelier/ui/cart/cart-bundle-offer.tsx +110 -0
  131. package/templates/nextjs/designs/atelier/ui/cart/cart-drawer.tsx +163 -0
  132. package/templates/nextjs/designs/atelier/ui/cart/cart-item.tsx +140 -0
  133. package/templates/nextjs/designs/atelier/ui/cart/cart-nudges.tsx +34 -0
  134. package/templates/nextjs/designs/atelier/ui/cart/cart-summary.tsx +107 -0
  135. package/templates/nextjs/designs/atelier/ui/cart/cart-upgrade-banner.tsx +123 -0
  136. package/templates/nextjs/designs/atelier/ui/cart/cart-view.tsx +147 -0
  137. package/templates/nextjs/designs/atelier/ui/cart/coupon-input.tsx +142 -0
  138. package/templates/nextjs/designs/atelier/ui/cart/free-shipping-bar.tsx +77 -0
  139. package/templates/nextjs/designs/atelier/ui/cart/reservation-countdown.tsx +89 -0
  140. package/templates/nextjs/designs/atelier/ui/home/benefits-band.tsx +34 -0
  141. package/templates/nextjs/designs/atelier/ui/home/category-tiles.tsx +148 -0
  142. package/templates/nextjs/designs/atelier/ui/home/discount-banner-strip.tsx +27 -0
  143. package/templates/nextjs/designs/atelier/ui/home/editorial-band.tsx +73 -0
  144. package/templates/nextjs/designs/atelier/ui/home/featured-products-section.tsx +36 -0
  145. package/templates/nextjs/designs/atelier/ui/home/hero-section.tsx +148 -0
  146. package/templates/nextjs/designs/atelier/ui/home/home-client.tsx +54 -0
  147. package/templates/nextjs/designs/atelier/ui/home/newsletter-section.tsx +78 -0
  148. package/templates/nextjs/designs/atelier/ui/home/testimonials-band.tsx +46 -0
  149. package/templates/nextjs/designs/atelier/ui/layout/announcement-bar.tsx +118 -0
  150. package/templates/nextjs/designs/atelier/ui/layout/faq-section.tsx +96 -0
  151. package/templates/nextjs/designs/atelier/ui/layout/header-account.tsx +36 -0
  152. package/templates/nextjs/designs/atelier/ui/layout/header-cart.tsx +36 -0
  153. package/templates/nextjs/designs/atelier/ui/layout/language-switcher.tsx.ejs +137 -0
  154. package/templates/nextjs/designs/atelier/ui/layout/nav-url.ts +14 -0
  155. package/templates/nextjs/designs/atelier/ui/layout/rich-text-block.tsx +34 -0
  156. package/templates/nextjs/designs/atelier/ui/layout/site-footer.tsx.ejs +141 -0
  157. package/templates/nextjs/designs/atelier/ui/layout/site-header.tsx.ejs +138 -0
  158. package/templates/nextjs/designs/atelier/ui/product/customization-fields.tsx +466 -0
  159. package/templates/nextjs/designs/atelier/ui/product/discount-badge.tsx +17 -0
  160. package/templates/nextjs/designs/atelier/ui/product/frequently-bought-together.tsx +196 -0
  161. package/templates/nextjs/designs/atelier/ui/product/modifier-group-selector.tsx +193 -0
  162. package/templates/nextjs/designs/atelier/ui/product/price-display.tsx +69 -0
  163. package/templates/nextjs/designs/atelier/ui/product/product-card.tsx +260 -0
  164. package/templates/nextjs/designs/atelier/ui/product/product-client-section.tsx +471 -0
  165. package/templates/nextjs/designs/atelier/ui/product/product-grid.tsx +47 -0
  166. package/templates/nextjs/designs/atelier/ui/product/product-listing.tsx +260 -0
  167. package/templates/nextjs/designs/atelier/ui/product/recommendation-section.tsx +95 -0
  168. package/templates/nextjs/designs/atelier/ui/product/review-form.tsx +267 -0
  169. package/templates/nextjs/designs/atelier/ui/product/reviews-section.tsx.ejs +148 -0
  170. package/templates/nextjs/designs/atelier/ui/product/stock-badge.tsx +66 -0
  171. package/templates/nextjs/designs/atelier/ui/product/variant-selector.tsx +206 -0
  172. package/templates/nextjs/designs/atelier/ui/shared/cdn-image.tsx +29 -0
  173. package/templates/nextjs/designs/atelier/ui/shared/fly-to-cart.ts +86 -0
  174. package/templates/nextjs/designs/atelier/ui/shared/icons.tsx +269 -0
  175. package/templates/nextjs/designs/atelier/ui/shared/loading-spinner.tsx +64 -0
  176. package/templates/nextjs/designs/atelier/ui/shared/reveal.tsx +71 -0
  177. package/templates/nextjs/designs/atelier/ui/shared/select-menu.tsx +125 -0
  178. package/templates/nextjs/themes/luxury/globals.css +405 -399
  179. package/templates/nextjs/themes/minimal/globals.css +36 -30
  180. package/templates/nextjs/themes/playful/globals.css +406 -400
  181. package/templates/nextjs/ui-canvas/cart/cart-bundle-offer.tsx +89 -0
  182. package/templates/nextjs/ui-canvas/cart/cart-item.tsx +123 -0
  183. package/templates/nextjs/ui-canvas/cart/cart-nudges.tsx +27 -0
  184. package/templates/nextjs/ui-canvas/cart/cart-summary.tsx +99 -0
  185. package/templates/nextjs/ui-canvas/cart/cart-upgrade-banner.tsx +105 -0
  186. package/templates/nextjs/ui-canvas/cart/cart-view.tsx +106 -0
  187. package/templates/nextjs/ui-canvas/cart/coupon-input.tsx +119 -0
  188. package/templates/nextjs/ui-canvas/cart/free-shipping-bar.tsx +54 -0
  189. package/templates/nextjs/ui-canvas/cart/reservation-countdown.tsx +81 -0
  190. package/templates/nextjs/ui-canvas/home/discount-banner-strip.tsx +19 -0
  191. package/templates/nextjs/ui-canvas/home/featured-products-section.tsx +23 -0
  192. package/templates/nextjs/ui-canvas/home/hero-section.tsx +21 -0
  193. package/templates/nextjs/ui-canvas/home/home-client.tsx +26 -0
  194. package/templates/nextjs/ui-canvas/layout/announcement-bar.tsx.ejs +101 -0
  195. package/templates/nextjs/ui-canvas/layout/faq-section.tsx.ejs +71 -0
  196. package/templates/nextjs/ui-canvas/layout/header-account.tsx +31 -0
  197. package/templates/nextjs/{base/src/components → ui-canvas}/layout/language-switcher.tsx.ejs +76 -70
  198. package/templates/nextjs/ui-canvas/layout/rich-text-block.tsx.ejs +36 -0
  199. package/templates/nextjs/ui-canvas/layout/site-footer.tsx.ejs +82 -0
  200. package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +119 -0
  201. package/templates/nextjs/ui-canvas/product/customization-fields.tsx +445 -0
  202. package/templates/nextjs/ui-canvas/product/discount-badge.tsx +19 -0
  203. package/templates/nextjs/ui-canvas/product/frequently-bought-together.tsx +168 -0
  204. package/templates/nextjs/ui-canvas/product/modifier-group-selector.tsx +165 -0
  205. package/templates/nextjs/ui-canvas/product/price-display.tsx +52 -0
  206. package/templates/nextjs/ui-canvas/product/product-card.tsx +197 -0
  207. package/templates/nextjs/ui-canvas/product/product-client-section.tsx +352 -0
  208. package/templates/nextjs/ui-canvas/product/product-grid.tsx +27 -0
  209. package/templates/nextjs/ui-canvas/product/product-listing.tsx +224 -0
  210. package/templates/nextjs/ui-canvas/product/recommendation-section.tsx +99 -0
  211. package/templates/nextjs/ui-canvas/product/review-form.tsx +266 -0
  212. package/templates/nextjs/ui-canvas/product/reviews-section.tsx.ejs +96 -0
  213. package/templates/nextjs/ui-canvas/product/stock-badge.tsx +45 -0
  214. package/templates/nextjs/ui-canvas/product/variant-selector.tsx +212 -0
  215. package/templates/nextjs/ui-canvas/shared/cdn-image.tsx +31 -0
  216. package/templates/nextjs/ui-canvas/shared/loading-spinner.tsx +27 -0
  217. package/templates/nextjs/base/src/app/home-client.tsx +0 -98
  218. package/templates/nextjs/base/src/components/content/faq-section.tsx.ejs +0 -103
  219. package/templates/nextjs/base/src/components/products/modifier-group-selector.tsx +0 -238
  220. /package/templates/nextjs/base/src/{lib → core/lib}/auth.ts +0 -0
  221. /package/templates/nextjs/base/src/{lib → core/lib}/csrf.ts +0 -0
  222. /package/templates/nextjs/base/src/{lib → core/lib}/image-hosts.ts +0 -0
  223. /package/templates/nextjs/base/src/{lib → core/lib}/navigation.tsx.ejs +0 -0
  224. /package/templates/nextjs/base/src/{lib → core/lib}/nonce.ts +0 -0
  225. /package/templates/nextjs/base/src/{lib → core/lib}/sanitize-html.ts +0 -0
  226. /package/templates/nextjs/base/src/{lib → core/lib}/seo.ts +0 -0
  227. /package/templates/nextjs/base/src/{lib → core/lib}/store-info.ts +0 -0
  228. /package/templates/nextjs/base/src/{lib → core/lib}/translations.ts.ejs +0 -0
  229. /package/templates/nextjs/base/src/{lib → core/lib}/utils.ts +0 -0
  230. /package/templates/nextjs/base/src/{lib → core/lib}/validation.ts +0 -0
@@ -1,478 +1,457 @@
1
- 'use client';
2
-
3
- import { useState } from 'react';
4
- import type { ProductCustomizationField } from 'brainerce';
5
- import { useTranslations } from '@/lib/translations';
6
- import { cn } from '@/lib/utils';
7
- import { LoadingSpinner } from '@/components/shared/loading-spinner';
8
-
9
- export type CustomizationValues = Record<string, unknown>;
10
-
11
- interface CustomizationFieldsProps {
12
- fields: ProductCustomizationField[];
13
- values: CustomizationValues;
14
- onChange: (values: CustomizationValues) => void;
15
- errors?: Record<string, string>;
16
- }
17
-
18
- export function CustomizationFields({
19
- fields,
20
- values,
21
- onChange,
22
- errors = {},
23
- }: CustomizationFieldsProps) {
24
- const t = useTranslations('customization');
25
-
26
- if (fields.length === 0) return null;
27
-
28
- const sorted = [...fields].sort((a, b) => a.position - b.position);
29
-
30
- const setValue = (key: string, value: unknown) => {
31
- onChange({ ...values, [key]: value });
32
- };
33
-
34
- return (
35
- <div className="border-border space-y-4 border-t pt-4">
36
- <h2 className="text-foreground text-lg font-semibold">{t('title')}</h2>
37
- <div className="space-y-4">
38
- {sorted.map((field) => (
39
- <CustomizationFieldRow
40
- key={field.definitionId}
41
- field={field}
42
- value={values[field.key]}
43
- error={errors[field.key]}
44
- onChange={(v) => setValue(field.key, v)}
45
- />
46
- ))}
47
- </div>
48
- </div>
49
- );
50
- }
51
-
52
- interface RowProps {
53
- field: ProductCustomizationField;
54
- value: unknown;
55
- error?: string;
56
- onChange: (value: unknown) => void;
57
- }
58
-
59
- function CustomizationFieldRow({ field, value, error, onChange }: RowProps) {
60
- const t = useTranslations('customization');
61
- const labelText = (
62
- <span className="text-foreground mb-1.5 block text-sm font-medium">
63
- {field.name}
64
- {field.required && <span className="text-destructive ms-1">*</span>}
65
- </span>
66
- );
67
-
68
- const help = field.description ? (
69
- <p className="text-muted-foreground mt-1 text-xs">{field.description}</p>
70
- ) : null;
71
-
72
- const errorHint = error ? <p className="text-destructive mt-1 text-xs">{error}</p> : null;
73
-
74
- const inputBase =
75
- 'border-border bg-background focus:border-primary w-full rounded border px-3 py-2 text-sm outline-none focus:ring-1';
76
-
77
- switch (field.type) {
78
- case 'TEXTAREA':
79
- return (
80
- <div>
81
- {labelText}
82
- <textarea
83
- value={typeof value === 'string' ? value : ''}
84
- onChange={(e) => onChange(e.target.value)}
85
- minLength={field.minLength ?? undefined}
86
- maxLength={field.maxLength ?? undefined}
87
- required={field.required}
88
- rows={3}
89
- className={cn(inputBase, 'resize-y')}
90
- />
91
- {help}
92
- {errorHint}
93
- </div>
94
- );
95
-
96
- case 'NUMBER':
97
- return (
98
- <div>
99
- {labelText}
100
- <input
101
- type="number"
102
- value={typeof value === 'number' ? value : ''}
103
- onChange={(e) => onChange(e.target.value === '' ? undefined : Number(e.target.value))}
104
- min={field.minValue ?? undefined}
105
- max={field.maxValue ?? undefined}
106
- required={field.required}
107
- className={inputBase}
108
- />
109
- {help}
110
- {errorHint}
111
- </div>
112
- );
113
-
114
- case 'BOOLEAN':
115
- return (
116
- <div>
117
- <label className="inline-flex items-center gap-2">
118
- <input
119
- type="checkbox"
120
- checked={value === true}
121
- onChange={(e) => onChange(e.target.checked)}
122
- className="h-4 w-4"
123
- />
124
- <span className="text-foreground text-sm font-medium">
125
- {field.name}
126
- {field.required && <span className="text-destructive ms-1">*</span>}
127
- </span>
128
- </label>
129
- {help}
130
- {errorHint}
131
- </div>
132
- );
133
-
134
- case 'DATE':
135
- return (
136
- <div>
137
- {labelText}
138
- <input
139
- type="date"
140
- value={typeof value === 'string' ? value : ''}
141
- onChange={(e) => onChange(e.target.value)}
142
- required={field.required}
143
- className={inputBase}
144
- />
145
- {help}
146
- {errorHint}
147
- </div>
148
- );
149
-
150
- case 'DATETIME':
151
- return (
152
- <div>
153
- {labelText}
154
- <input
155
- type="datetime-local"
156
- value={typeof value === 'string' ? value : ''}
157
- onChange={(e) => onChange(e.target.value)}
158
- required={field.required}
159
- className={inputBase}
160
- />
161
- {help}
162
- {errorHint}
163
- </div>
164
- );
165
-
166
- case 'COLOR':
167
- return (
168
- <div>
169
- {labelText}
170
- <input
171
- type="color"
172
- value={typeof value === 'string' && value ? value : '#000000'}
173
- onChange={(e) => onChange(e.target.value)}
174
- required={field.required}
175
- className="border-border h-10 w-20 rounded border p-1"
176
- />
177
- {help}
178
- {errorHint}
179
- </div>
180
- );
181
-
182
- case 'SELECT': {
183
- const options = field.enumValues ?? [];
184
- return (
185
- <div>
186
- {labelText}
187
- <select
188
- value={typeof value === 'string' ? value : ''}
189
- onChange={(e) => onChange(e.target.value || undefined)}
190
- required={field.required}
191
- className={inputBase}
192
- >
193
- <option value="">{t('selectPlaceholder')}</option>
194
- {options.map((opt) => (
195
- <option key={opt} value={opt}>
196
- {opt}
197
- </option>
198
- ))}
199
- </select>
200
- {help}
201
- {errorHint}
202
- </div>
203
- );
204
- }
205
-
206
- case 'MULTI_SELECT': {
207
- const options = field.enumValues ?? [];
208
- const current = Array.isArray(value) ? (value as string[]) : [];
209
- const toggle = (opt: string) => {
210
- onChange(current.includes(opt) ? current.filter((v) => v !== opt) : [...current, opt]);
211
- };
212
- return (
213
- <div>
214
- {labelText}
215
- <div className="space-y-1.5">
216
- {options.map((opt) => (
217
- <label key={opt} className="me-4 inline-flex items-center gap-2">
218
- <input
219
- type="checkbox"
220
- checked={current.includes(opt)}
221
- onChange={() => toggle(opt)}
222
- className="h-4 w-4"
223
- />
224
- <span className="text-foreground text-sm">{opt}</span>
225
- </label>
226
- ))}
227
- </div>
228
- {help}
229
- {errorHint}
230
- </div>
231
- );
232
- }
233
-
234
- case 'IMAGE':
235
- return (
236
- <SingleImageField
237
- field={field}
238
- value={typeof value === 'string' ? value : undefined}
239
- onChange={onChange}
240
- labelText={labelText}
241
- help={help}
242
- errorHint={errorHint}
243
- />
244
- );
245
-
246
- case 'GALLERY':
247
- return (
248
- <GalleryField
249
- field={field}
250
- value={Array.isArray(value) ? (value as string[]) : []}
251
- onChange={onChange}
252
- labelText={labelText}
253
- help={help}
254
- errorHint={errorHint}
255
- />
256
- );
257
-
258
- case 'URL':
259
- return (
260
- <div>
261
- {labelText}
262
- <input
263
- type="url"
264
- value={typeof value === 'string' ? value : ''}
265
- onChange={(e) => onChange(e.target.value)}
266
- required={field.required}
267
- className={inputBase}
268
- />
269
- {help}
270
- {errorHint}
271
- </div>
272
- );
273
-
274
- default:
275
- return (
276
- <div>
277
- {labelText}
278
- <input
279
- type="text"
280
- value={typeof value === 'string' ? value : ''}
281
- onChange={(e) => onChange(e.target.value)}
282
- minLength={field.minLength ?? undefined}
283
- maxLength={field.maxLength ?? undefined}
284
- required={field.required}
285
- className={inputBase}
286
- />
287
- {help}
288
- {errorHint}
289
- </div>
290
- );
291
- }
292
- }
293
-
294
- interface FileFieldProps {
295
- field: ProductCustomizationField;
296
- labelText: React.ReactNode;
297
- help: React.ReactNode;
298
- errorHint: React.ReactNode;
299
- onChange: (value: unknown) => void;
300
- }
301
-
302
- function SingleImageField({
303
- field,
304
- value,
305
- onChange,
306
- labelText,
307
- help,
308
- errorHint,
309
- }: FileFieldProps & { value?: string }) {
310
- const t = useTranslations('customization');
311
- const [uploading, setUploading] = useState(false);
312
- const [uploadError, setUploadError] = useState<string | null>(null);
313
-
314
- async function handleFile(file: File | null) {
315
- if (!file) return;
316
- setUploading(true);
317
- setUploadError(null);
318
- try {
319
- const { getClient } = await import('@/lib/brainerce');
320
- const client = getClient();
321
- const result = await client.uploadCustomizationFile(file);
322
- onChange(result.url);
323
- } catch (err) {
324
- console.error('Upload failed', err);
325
- setUploadError(t('uploadFailed'));
326
- } finally {
327
- setUploading(false);
328
- }
329
- }
330
-
331
- return (
332
- <div>
333
- {labelText}
334
- <input
335
- type="file"
336
- accept="image/*"
337
- onChange={(e) => handleFile(e.target.files?.[0] ?? null)}
338
- disabled={uploading}
339
- required={field.required && !value}
340
- className="text-foreground text-sm"
341
- />
342
- {uploading && (
343
- <span className="text-muted-foreground mt-2 inline-flex items-center gap-2 text-xs">
344
- <LoadingSpinner size="sm" />
345
- {t('uploading')}
346
- </span>
347
- )}
348
- {value && !uploading && (
349
- <div className="mt-2">
350
- <img src={value} alt="" className="border-border h-20 w-20 rounded border object-cover" />
351
- </div>
352
- )}
353
- {uploadError && <p className="text-destructive mt-1 text-xs">{uploadError}</p>}
354
- {help}
355
- {errorHint}
356
- </div>
357
- );
358
- }
359
-
360
- function GalleryField({
361
- field,
362
- value,
363
- onChange,
364
- labelText,
365
- help,
366
- errorHint,
367
- }: FileFieldProps & { value: string[] }) {
368
- const t = useTranslations('customization');
369
- const [uploading, setUploading] = useState(false);
370
- const [uploadError, setUploadError] = useState<string | null>(null);
371
-
372
- async function handleFiles(fileList: FileList | null) {
373
- if (!fileList || fileList.length === 0) return;
374
- setUploading(true);
375
- setUploadError(null);
376
- try {
377
- const { getClient } = await import('@/lib/brainerce');
378
- const client = getClient();
379
- const newUrls: string[] = [];
380
- for (const file of Array.from(fileList)) {
381
- const result = await client.uploadCustomizationFile(file);
382
- newUrls.push(result.url);
383
- }
384
- onChange([...value, ...newUrls]);
385
- } catch (err) {
386
- console.error('Upload failed', err);
387
- setUploadError(t('uploadFailed'));
388
- } finally {
389
- setUploading(false);
390
- }
391
- }
392
-
393
- function removeAt(idx: number) {
394
- onChange(value.filter((_, i) => i !== idx));
395
- }
396
-
397
- return (
398
- <div>
399
- {labelText}
400
- <input
401
- type="file"
402
- accept="image/*"
403
- multiple
404
- onChange={(e) => handleFiles(e.target.files)}
405
- disabled={uploading}
406
- className="text-foreground text-sm"
407
- />
408
- {uploading && (
409
- <span className="text-muted-foreground mt-2 inline-flex items-center gap-2 text-xs">
410
- <LoadingSpinner size="sm" />
411
- {t('uploading')}
412
- </span>
413
- )}
414
- {value.length > 0 && (
415
- <div className="mt-2 flex flex-wrap gap-2">
416
- {value.map((url, idx) => (
417
- <div key={`${url}-${idx}`} className="relative">
418
- <img
419
- src={url}
420
- alt=""
421
- className="border-border h-16 w-16 rounded border object-cover"
422
- />
423
- <button
424
- type="button"
425
- onClick={() => removeAt(idx)}
426
- aria-label={t('removeImage')}
427
- className="bg-destructive text-destructive-foreground absolute -end-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-full text-xs"
428
- >
429
- ×
430
- </button>
431
- </div>
432
- ))}
433
- </div>
434
- )}
435
- {uploadError && <p className="text-destructive mt-1 text-xs">{uploadError}</p>}
436
- {help}
437
- {errorHint}
438
- </div>
439
- );
440
- }
441
-
442
- export function validateCustomization(
443
- fields: ProductCustomizationField[],
444
- values: CustomizationValues
445
- ): Record<string, string> {
446
- const errors: Record<string, string> = {};
447
- for (const field of fields) {
448
- const value = values[field.key];
449
- const empty =
450
- value === undefined ||
451
- value === null ||
452
- value === '' ||
453
- (Array.isArray(value) && value.length === 0);
454
-
455
- if (field.required && empty) {
456
- errors[field.key] = 'required';
457
- continue;
458
- }
459
- if (empty) continue;
460
-
461
- if (field.type === 'SELECT') {
462
- const allowed = field.enumValues ?? [];
463
- if (typeof value !== 'string' || !allowed.includes(value)) {
464
- errors[field.key] = 'invalidOption';
465
- }
466
- }
467
- if (field.type === 'MULTI_SELECT') {
468
- const allowed = field.enumValues ?? [];
469
- if (
470
- !Array.isArray(value) ||
471
- !(value as unknown[]).every((v) => typeof v === 'string' && allowed.includes(v as string))
472
- ) {
473
- errors[field.key] = 'invalidOption';
474
- }
475
- }
476
- }
477
- return errors;
478
- }
1
+ 'use client';
2
+
3
+ import { useState } from 'react';
4
+ import type { ProductCustomizationField } from 'brainerce';
5
+ import { useTranslations } from '@/core/lib/translations';
6
+ import { LoadingSpinner } from '@/ui/shared/loading-spinner';
7
+ import { Checkbox } from '@/components/ui/checkbox';
8
+ import { Input } from '@/components/ui/input';
9
+ import { Label } from '@/components/ui/label';
10
+ import {
11
+ Select,
12
+ SelectContent,
13
+ SelectItem,
14
+ SelectTrigger,
15
+ SelectValue,
16
+ } from '@/components/ui/select';
17
+ import { Textarea } from '@/components/ui/textarea';
18
+ import type { CustomizationValues } from '@/core/lib/product-options';
19
+
20
+ // The pure validation logic lives in core (zero markup) so that
21
+ // `core/hooks/use-product-page` never imports from `ui/`. Re-exported here
22
+ // for backward compatibility with existing imports.
23
+ export { validateCustomization } from '@/core/lib/product-options';
24
+ export type { CustomizationValues } from '@/core/lib/product-options';
25
+
26
+ interface CustomizationFieldsProps {
27
+ fields: ProductCustomizationField[];
28
+ values: CustomizationValues;
29
+ onChange: (values: CustomizationValues) => void;
30
+ errors?: Record<string, string>;
31
+ }
32
+
33
+ export function CustomizationFields({
34
+ fields,
35
+ values,
36
+ onChange,
37
+ errors = {},
38
+ }: CustomizationFieldsProps) {
39
+ const t = useTranslations('customization');
40
+
41
+ if (fields.length === 0) return null;
42
+
43
+ const sorted = [...fields].sort((a, b) => a.position - b.position);
44
+
45
+ const setValue = (key: string, value: unknown) => {
46
+ onChange({ ...values, [key]: value });
47
+ };
48
+
49
+ return (
50
+ <div className="border-border space-y-4 border-t pt-4">
51
+ <h2 className="text-foreground text-lg font-semibold">{t('title')}</h2>
52
+ <div className="space-y-4">
53
+ {sorted.map((field) => (
54
+ <CustomizationFieldRow
55
+ key={field.definitionId}
56
+ field={field}
57
+ value={values[field.key]}
58
+ error={errors[field.key]}
59
+ onChange={(v) => setValue(field.key, v)}
60
+ />
61
+ ))}
62
+ </div>
63
+ </div>
64
+ );
65
+ }
66
+
67
+ interface RowProps {
68
+ field: ProductCustomizationField;
69
+ value: unknown;
70
+ error?: string;
71
+ onChange: (value: unknown) => void;
72
+ }
73
+
74
+ /** Radix Select items can't carry an empty-string value, so "no choice"
75
+ * round-trips through this sentinel and is written back as undefined. */
76
+ const NONE = '__none__';
77
+
78
+ function CustomizationFieldRow({ field, value, error, onChange }: RowProps) {
79
+ const t = useTranslations('customization');
80
+ const labelText = (
81
+ <Label className="text-foreground mb-1.5 block text-sm font-medium">
82
+ {field.name}
83
+ {field.required && <span className="text-destructive ms-1">*</span>}
84
+ </Label>
85
+ );
86
+
87
+ const help = field.description ? (
88
+ <p className="text-muted-foreground mt-1 text-xs">{field.description}</p>
89
+ ) : null;
90
+
91
+ const errorHint = error ? <p className="text-destructive mt-1 text-xs">{error}</p> : null;
92
+
93
+ switch (field.type) {
94
+ case 'TEXTAREA':
95
+ return (
96
+ <div>
97
+ {labelText}
98
+ <Textarea
99
+ value={typeof value === 'string' ? value : ''}
100
+ onChange={(e) => onChange(e.target.value)}
101
+ minLength={field.minLength ?? undefined}
102
+ maxLength={field.maxLength ?? undefined}
103
+ required={field.required}
104
+ rows={3}
105
+ className="rounded"
106
+ />
107
+ {help}
108
+ {errorHint}
109
+ </div>
110
+ );
111
+
112
+ case 'NUMBER':
113
+ return (
114
+ <div>
115
+ {labelText}
116
+ <Input
117
+ type="number"
118
+ value={typeof value === 'number' ? value : ''}
119
+ onChange={(e) => onChange(e.target.value === '' ? undefined : Number(e.target.value))}
120
+ min={field.minValue ?? undefined}
121
+ max={field.maxValue ?? undefined}
122
+ required={field.required}
123
+ className="rounded"
124
+ />
125
+ {help}
126
+ {errorHint}
127
+ </div>
128
+ );
129
+
130
+ case 'BOOLEAN':
131
+ return (
132
+ <div>
133
+ <Label className="inline-flex items-center gap-2">
134
+ <Checkbox
135
+ checked={value === true}
136
+ onCheckedChange={(checked) => onChange(checked === true)}
137
+ />
138
+ <span className="text-foreground text-sm font-medium">
139
+ {field.name}
140
+ {field.required && <span className="text-destructive ms-1">*</span>}
141
+ </span>
142
+ </Label>
143
+ {help}
144
+ {errorHint}
145
+ </div>
146
+ );
147
+
148
+ case 'DATE':
149
+ return (
150
+ <div>
151
+ {labelText}
152
+ <Input
153
+ type="date"
154
+ value={typeof value === 'string' ? value : ''}
155
+ onChange={(e) => onChange(e.target.value)}
156
+ required={field.required}
157
+ className="rounded"
158
+ />
159
+ {help}
160
+ {errorHint}
161
+ </div>
162
+ );
163
+
164
+ case 'DATETIME':
165
+ return (
166
+ <div>
167
+ {labelText}
168
+ <Input
169
+ type="datetime-local"
170
+ value={typeof value === 'string' ? value : ''}
171
+ onChange={(e) => onChange(e.target.value)}
172
+ required={field.required}
173
+ className="rounded"
174
+ />
175
+ {help}
176
+ {errorHint}
177
+ </div>
178
+ );
179
+
180
+ case 'COLOR':
181
+ return (
182
+ <div>
183
+ {labelText}
184
+ <Input
185
+ type="color"
186
+ value={typeof value === 'string' && value ? value : '#000000'}
187
+ onChange={(e) => onChange(e.target.value)}
188
+ required={field.required}
189
+ className="h-10 w-20 rounded p-1"
190
+ />
191
+ {help}
192
+ {errorHint}
193
+ </div>
194
+ );
195
+
196
+ case 'SELECT': {
197
+ const options = field.enumValues ?? [];
198
+ return (
199
+ <div>
200
+ {labelText}
201
+ <Select
202
+ value={typeof value === 'string' && value ? value : NONE}
203
+ onValueChange={(v) => onChange(v === NONE ? undefined : v)}
204
+ >
205
+ <SelectTrigger className="rounded" aria-label={field.name}>
206
+ <SelectValue placeholder={t('selectPlaceholder')} />
207
+ </SelectTrigger>
208
+ <SelectContent>
209
+ <SelectItem value={NONE}>{t('selectPlaceholder')}</SelectItem>
210
+ {options.map((opt) => (
211
+ <SelectItem key={opt.value} value={opt.value}>
212
+ {opt.label || opt.value}
213
+ </SelectItem>
214
+ ))}
215
+ </SelectContent>
216
+ </Select>
217
+ {help}
218
+ {errorHint}
219
+ </div>
220
+ );
221
+ }
222
+
223
+ case 'MULTI_SELECT': {
224
+ const options = field.enumValues ?? [];
225
+ const current = Array.isArray(value) ? (value as string[]) : [];
226
+ const toggle = (opt: string) => {
227
+ onChange(current.includes(opt) ? current.filter((v) => v !== opt) : [...current, opt]);
228
+ };
229
+ return (
230
+ <div>
231
+ {labelText}
232
+ <div className="space-y-1.5">
233
+ {options.map((opt) => (
234
+ <Label key={opt.value} className="me-4 inline-flex items-center gap-2">
235
+ <Checkbox
236
+ checked={current.includes(opt.value)}
237
+ onCheckedChange={() => toggle(opt.value)}
238
+ />
239
+ <span className="text-foreground text-sm font-normal">
240
+ {opt.label || opt.value}
241
+ </span>
242
+ </Label>
243
+ ))}
244
+ </div>
245
+ {help}
246
+ {errorHint}
247
+ </div>
248
+ );
249
+ }
250
+
251
+ case 'IMAGE':
252
+ return (
253
+ <SingleImageField
254
+ field={field}
255
+ value={typeof value === 'string' ? value : undefined}
256
+ onChange={onChange}
257
+ labelText={labelText}
258
+ help={help}
259
+ errorHint={errorHint}
260
+ />
261
+ );
262
+
263
+ case 'GALLERY':
264
+ return (
265
+ <GalleryField
266
+ field={field}
267
+ value={Array.isArray(value) ? (value as string[]) : []}
268
+ onChange={onChange}
269
+ labelText={labelText}
270
+ help={help}
271
+ errorHint={errorHint}
272
+ />
273
+ );
274
+
275
+ case 'URL':
276
+ return (
277
+ <div>
278
+ {labelText}
279
+ <Input
280
+ type="url"
281
+ value={typeof value === 'string' ? value : ''}
282
+ onChange={(e) => onChange(e.target.value)}
283
+ required={field.required}
284
+ className="rounded"
285
+ />
286
+ {help}
287
+ {errorHint}
288
+ </div>
289
+ );
290
+
291
+ default:
292
+ return (
293
+ <div>
294
+ {labelText}
295
+ <Input
296
+ type="text"
297
+ value={typeof value === 'string' ? value : ''}
298
+ onChange={(e) => onChange(e.target.value)}
299
+ minLength={field.minLength ?? undefined}
300
+ maxLength={field.maxLength ?? undefined}
301
+ required={field.required}
302
+ className="rounded"
303
+ />
304
+ {help}
305
+ {errorHint}
306
+ </div>
307
+ );
308
+ }
309
+ }
310
+
311
+ interface FileFieldProps {
312
+ field: ProductCustomizationField;
313
+ labelText: React.ReactNode;
314
+ help: React.ReactNode;
315
+ errorHint: React.ReactNode;
316
+ onChange: (value: unknown) => void;
317
+ }
318
+
319
+ function SingleImageField({
320
+ field,
321
+ value,
322
+ onChange,
323
+ labelText,
324
+ help,
325
+ errorHint,
326
+ }: FileFieldProps & { value?: string }) {
327
+ const t = useTranslations('customization');
328
+ const [uploading, setUploading] = useState(false);
329
+ const [uploadError, setUploadError] = useState<string | null>(null);
330
+
331
+ async function handleFile(file: File | null) {
332
+ if (!file) return;
333
+ setUploading(true);
334
+ setUploadError(null);
335
+ try {
336
+ const { getClient } = await import('@/core/lib/brainerce');
337
+ const client = getClient();
338
+ const result = await client.uploadCustomizationFile(file);
339
+ onChange(result.url);
340
+ } catch (err) {
341
+ console.error('Upload failed', err);
342
+ setUploadError(t('uploadFailed'));
343
+ } finally {
344
+ setUploading(false);
345
+ }
346
+ }
347
+
348
+ return (
349
+ <div>
350
+ {labelText}
351
+ <input
352
+ type="file"
353
+ accept="image/*"
354
+ onChange={(e) => handleFile(e.target.files?.[0] ?? null)}
355
+ disabled={uploading}
356
+ required={field.required && !value}
357
+ className="text-foreground text-sm"
358
+ />
359
+ {uploading && (
360
+ <span className="text-muted-foreground mt-2 inline-flex items-center gap-2 text-xs">
361
+ <LoadingSpinner size="sm" />
362
+ {t('uploading')}
363
+ </span>
364
+ )}
365
+ {value && !uploading && (
366
+ <div className="mt-2">
367
+ <img src={value} alt="" className="border-border h-20 w-20 rounded border object-cover" />
368
+ </div>
369
+ )}
370
+ {uploadError && <p className="text-destructive mt-1 text-xs">{uploadError}</p>}
371
+ {help}
372
+ {errorHint}
373
+ </div>
374
+ );
375
+ }
376
+
377
+ function GalleryField({
378
+ field,
379
+ value,
380
+ onChange,
381
+ labelText,
382
+ help,
383
+ errorHint,
384
+ }: FileFieldProps & { value: string[] }) {
385
+ const t = useTranslations('customization');
386
+ const [uploading, setUploading] = useState(false);
387
+ const [uploadError, setUploadError] = useState<string | null>(null);
388
+
389
+ async function handleFiles(fileList: FileList | null) {
390
+ if (!fileList || fileList.length === 0) return;
391
+ setUploading(true);
392
+ setUploadError(null);
393
+ try {
394
+ const { getClient } = await import('@/core/lib/brainerce');
395
+ const client = getClient();
396
+ const newUrls: string[] = [];
397
+ for (const file of Array.from(fileList)) {
398
+ const result = await client.uploadCustomizationFile(file);
399
+ newUrls.push(result.url);
400
+ }
401
+ onChange([...value, ...newUrls]);
402
+ } catch (err) {
403
+ console.error('Upload failed', err);
404
+ setUploadError(t('uploadFailed'));
405
+ } finally {
406
+ setUploading(false);
407
+ }
408
+ }
409
+
410
+ function removeAt(idx: number) {
411
+ onChange(value.filter((_, i) => i !== idx));
412
+ }
413
+
414
+ return (
415
+ <div>
416
+ {labelText}
417
+ <input
418
+ type="file"
419
+ accept="image/*"
420
+ multiple
421
+ onChange={(e) => handleFiles(e.target.files)}
422
+ disabled={uploading}
423
+ className="text-foreground text-sm"
424
+ />
425
+ {uploading && (
426
+ <span className="text-muted-foreground mt-2 inline-flex items-center gap-2 text-xs">
427
+ <LoadingSpinner size="sm" />
428
+ {t('uploading')}
429
+ </span>
430
+ )}
431
+ {value.length > 0 && (
432
+ <div className="mt-2 flex flex-wrap gap-2">
433
+ {value.map((url, idx) => (
434
+ <div key={`${url}-${idx}`} className="relative">
435
+ <img
436
+ src={url}
437
+ alt=""
438
+ className="border-border h-16 w-16 rounded border object-cover"
439
+ />
440
+ <button
441
+ type="button"
442
+ onClick={() => removeAt(idx)}
443
+ aria-label={t('removeImage')}
444
+ className="bg-destructive text-destructive-foreground absolute -end-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-full text-xs"
445
+ >
446
+ ×
447
+ </button>
448
+ </div>
449
+ ))}
450
+ </div>
451
+ )}
452
+ {uploadError && <p className="text-destructive mt-1 text-xs">{uploadError}</p>}
453
+ {help}
454
+ {errorHint}
455
+ </div>
456
+ );
457
+ }