create-brainerce-store 1.72.0 → 1.74.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 (88) hide show
  1. package/dist/index.js +37 -4
  2. package/messages/en.json +30 -1
  3. package/messages/he.json +30 -1
  4. package/package.json +1 -1
  5. package/templates/nextjs/base/AGENTS.md.ejs +63 -16
  6. package/templates/nextjs/base/AI-GUIDE.md +17 -4
  7. package/templates/nextjs/base/CLAUDE.md.ejs +67 -20
  8. package/templates/nextjs/base/TRANSLATIONS.md +207 -207
  9. package/templates/nextjs/base/src/app/account/page.tsx +168 -122
  10. package/templates/nextjs/base/src/app/category/[slug]/page.tsx +10 -1
  11. package/templates/nextjs/base/src/app/checkout/page.tsx +1179 -1074
  12. package/templates/nextjs/base/src/app/layout.tsx.ejs +48 -4
  13. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +98 -3
  14. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +14 -2
  15. package/templates/nextjs/base/src/components/account/loyalty-panel.tsx +226 -0
  16. package/templates/nextjs/base/src/components/account/order-history.tsx +422 -371
  17. package/templates/nextjs/base/src/components/account/order-status-timeline.tsx +85 -85
  18. package/templates/nextjs/base/src/components/account/saved-payment-methods.tsx +104 -0
  19. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +618 -612
  20. package/templates/nextjs/base/src/components/checkout/custom-fields-step.tsx +354 -306
  21. package/templates/nextjs/base/src/components/checkout/tax-display.tsx +141 -74
  22. package/templates/nextjs/base/src/core/hooks/use-cart-page.ts +218 -127
  23. package/templates/nextjs/base/src/core/hooks/use-home-data.ts +63 -51
  24. package/templates/nextjs/base/src/core/hooks/use-product-listing.ts +379 -295
  25. package/templates/nextjs/base/src/core/hooks/use-product-page.ts +33 -1
  26. package/templates/nextjs/base/src/core/lib/capabilities.ts +65 -0
  27. package/templates/nextjs/base/src/core/lib/display-price.ts +139 -0
  28. package/templates/nextjs/base/src/core/lib/region.server.ts +112 -0
  29. package/templates/nextjs/base/src/core/lib/region.ts +112 -0
  30. package/templates/nextjs/base/src/core/lib/store-info.ts +19 -0
  31. package/templates/nextjs/base/src/core/providers/store-provider.tsx.ejs +423 -243
  32. package/templates/nextjs/base/src/ui/cart/cart-item.tsx +174 -164
  33. package/templates/nextjs/base/src/ui/cart/cart-summary.tsx +109 -110
  34. package/templates/nextjs/base/src/ui/cart/cart-view.tsx +219 -176
  35. package/templates/nextjs/base/src/ui/cart/gift-card-input.tsx +191 -0
  36. package/templates/nextjs/base/src/ui/cart/reservation-countdown.tsx +137 -137
  37. package/templates/nextjs/base/src/ui/cart/tax-estimate-line.tsx +108 -0
  38. package/templates/nextjs/base/src/ui/home/home-client.tsx +27 -29
  39. package/templates/nextjs/base/src/ui/layout/header-search.tsx +249 -0
  40. package/templates/nextjs/base/src/ui/layout/region-switcher.tsx +59 -0
  41. package/templates/nextjs/base/src/ui/layout/site-header.tsx.ejs +171 -152
  42. package/templates/nextjs/base/src/ui/product/frequently-bought-together.tsx +197 -191
  43. package/templates/nextjs/base/src/ui/product/product-card.tsx +25 -52
  44. package/templates/nextjs/base/src/ui/product/product-client-section.tsx +12 -3
  45. package/templates/nextjs/base/src/ui/product/product-listing.tsx +460 -446
  46. package/templates/nextjs/base/src/ui/product/recommendation-section.tsx +108 -102
  47. package/templates/nextjs/base/src/ui/product/review-form.tsx +33 -11
  48. package/templates/nextjs/base/src/ui/product/stock-badge.tsx +15 -3
  49. package/templates/nextjs/designs/atelier/app-overlay/layout.tsx.ejs +48 -4
  50. package/templates/nextjs/designs/atelier/messages-patch/en.json +21 -25
  51. package/templates/nextjs/designs/atelier/messages-patch/he.json +21 -25
  52. package/templates/nextjs/designs/atelier/ui/cart/cart-drawer.tsx +177 -181
  53. package/templates/nextjs/designs/atelier/ui/cart/cart-item.tsx +168 -158
  54. package/templates/nextjs/designs/atelier/ui/cart/cart-summary.tsx +106 -107
  55. package/templates/nextjs/designs/atelier/ui/cart/cart-view.tsx +229 -184
  56. package/templates/nextjs/designs/atelier/ui/cart/reservation-countdown.tsx +131 -131
  57. package/templates/nextjs/designs/atelier/ui/cart/tax-estimate-line.tsx +108 -0
  58. package/templates/nextjs/designs/atelier/ui/home/benefits-band.tsx +10 -1
  59. package/templates/nextjs/designs/atelier/ui/home/hero-section.tsx +178 -174
  60. package/templates/nextjs/designs/atelier/ui/home/home-client.tsx +4 -6
  61. package/templates/nextjs/designs/atelier/ui/home/newsletter-section.tsx +150 -78
  62. package/templates/nextjs/designs/atelier/ui/home/testimonials-band.tsx +79 -46
  63. package/templates/nextjs/designs/atelier/ui/layout/header-search.tsx +264 -0
  64. package/templates/nextjs/designs/atelier/ui/layout/region-switcher.tsx +44 -0
  65. package/templates/nextjs/designs/atelier/ui/layout/site-header.tsx.ejs +5 -0
  66. package/templates/nextjs/designs/atelier/ui/product/frequently-bought-together.tsx +202 -196
  67. package/templates/nextjs/designs/atelier/ui/product/product-card.tsx +27 -52
  68. package/templates/nextjs/designs/atelier/ui/product/product-client-section.tsx +12 -3
  69. package/templates/nextjs/designs/atelier/ui/product/product-listing.tsx +332 -260
  70. package/templates/nextjs/designs/atelier/ui/product/recommendation-section.tsx +101 -95
  71. package/templates/nextjs/designs/atelier/ui/product/review-form.tsx +30 -10
  72. package/templates/nextjs/designs/atelier/ui/product/stock-badge.tsx +17 -2
  73. package/templates/nextjs/designs/atelier/ui/shared/icons.tsx +9 -0
  74. package/templates/nextjs/ui-canvas/cart/cart-item.tsx +137 -137
  75. package/templates/nextjs/ui-canvas/cart/cart-summary.tsx +98 -99
  76. package/templates/nextjs/ui-canvas/cart/cart-view.tsx +140 -140
  77. package/templates/nextjs/ui-canvas/cart/gift-card-input.tsx +142 -0
  78. package/templates/nextjs/ui-canvas/cart/reservation-countdown.tsx +124 -124
  79. package/templates/nextjs/ui-canvas/cart/tax-estimate-line.tsx +104 -0
  80. package/templates/nextjs/ui-canvas/home/home-client.tsx +24 -26
  81. package/templates/nextjs/ui-canvas/layout/region-switcher.tsx +51 -0
  82. package/templates/nextjs/ui-canvas/layout/site-header.tsx.ejs +3 -0
  83. package/templates/nextjs/ui-canvas/product/frequently-bought-together.tsx +174 -168
  84. package/templates/nextjs/ui-canvas/product/product-card.tsx +9 -51
  85. package/templates/nextjs/ui-canvas/product/product-client-section.tsx +5 -3
  86. package/templates/nextjs/ui-canvas/product/recommendation-section.tsx +105 -99
  87. package/templates/nextjs/ui-canvas/product/review-form.tsx +9 -1
  88. package/templates/nextjs/ui-canvas/product/stock-badge.tsx +17 -2
@@ -1,260 +1,332 @@
1
- 'use client';
2
-
3
- import {
4
- useProductListing,
5
- sortOptions,
6
- type CategoryNode,
7
- } from '@/core/hooks/use-product-listing';
8
- import { ProductGrid } from '@/ui/product/product-grid';
9
- import { LoadingSpinner } from '@/ui/shared/loading-spinner';
10
- import { SelectMenu, type SelectMenuOption } from '@/ui/shared/select-menu';
11
- import { useTranslations } from '@/core/lib/translations';
12
-
13
- /**
14
- * Flatten the category tree into indented options so nested categories stay
15
- * selectable in the styled dropdown.
16
- */
17
- function flattenCategories(items: CategoryNode[], depth = 0): SelectMenuOption[] {
18
- return items.flatMap((node) => [
19
- { value: node.id, label: `${'— '.repeat(depth)}${node.name}` },
20
- ...flattenCategories(node.children, depth + 1),
21
- ]);
22
- }
23
-
24
- /** Shimmer skeleton card shown while the grid loads — no layout jump. */
25
- function SkeletonGrid() {
26
- return (
27
- <div
28
- className="grid grid-cols-2 gap-3 sm:gap-5 lg:grid-cols-4 lg:gap-6"
29
- role="status"
30
- aria-label="Loading"
31
- >
32
- {Array.from({ length: 8 }).map((_, i) => (
33
- <div key={i} className="card overflow-hidden">
34
- <div className="aspect-square animate-pulse bg-secondary" />
35
- <div className="space-y-2.5 p-4">
36
- <div className="h-4 w-3/4 animate-pulse rounded bg-secondary" />
37
- <div className="h-4 w-1/3 animate-pulse rounded bg-secondary" />
38
- <div className="mt-2 h-9 w-full animate-pulse rounded-full bg-secondary" />
39
- </div>
40
- </div>
41
- ))}
42
- </div>
43
- );
44
- }
45
-
46
- /**
47
- * Product listing page: page header band, filter/sort toolbar, grid,
48
- * load-more. All data and URL-state behavior comes from `useProductListing`;
49
- * this component is presentation only. Must be rendered inside `<Suspense>`
50
- * (URL params).
51
- */
52
- export function ProductListing() {
53
- const t = useTranslations('products');
54
- const tc = useTranslations('common');
55
-
56
- const {
57
- products,
58
- loading,
59
- loadingMore,
60
- page,
61
- totalPages,
62
- total,
63
- categories,
64
- brands,
65
- tags,
66
- metafieldDefs,
67
- searchQuery,
68
- categoryId,
69
- brandId,
70
- tagId,
71
- sortIndex,
72
- handleLoadMore,
73
- updateParam,
74
- handleCategorySelect,
75
- getSelectedMetafieldValues,
76
- setMetafieldValue,
77
- } = useProductListing();
78
-
79
- return (
80
- <section>
81
- {/* Page header band */}
82
- <header className="wash-hero relative overflow-hidden">
83
- <div className="container-page py-10 text-center lg:py-14">
84
- <h1 className="text-4xl sm:text-5xl">
85
- {searchQuery ? `${t('searchPrefix')} "${searchQuery}"` : t('allProducts')}
86
- </h1>
87
- <p className="mx-auto mt-3 max-w-xl text-muted-foreground">
88
- {searchQuery ? (
89
- !loading && (
90
- <>
91
- {total} {total === 1 ? tc('product') : tc('products')} {tc('found')}
92
- </>
93
- )
94
- ) : (
95
- t('listingSubtitle')
96
- )}
97
- </p>
98
- </div>
99
- </header>
100
-
101
- <div className="container-page pb-16 pt-8 lg:pb-20">
102
- {/* Filters + sort toolbar */}
103
- <div className="mb-8 flex flex-wrap items-center gap-3">
104
- {/* Category filter nested tree flattened into a select */}
105
- {categories.length > 0 && (
106
- <SelectMenu
107
- value={categoryId}
108
- options={[{ value: '', label: tc('all') }, ...flattenCategories(categories)]}
109
- onChange={(v) => (v ? handleCategorySelect(v) : updateParam('category', ''))}
110
- ariaLabel={t('filtersLabel')}
111
- />
112
- )}
113
-
114
- {/* Brand Filter */}
115
- {brands.length > 0 && (
116
- <SelectMenu
117
- value={brandId}
118
- options={[
119
- { value: '', label: t('allBrands') },
120
- ...brands.map((b) => ({ value: b.id, label: b.name })),
121
- ]}
122
- onChange={(v) => updateParam('brand', v)}
123
- ariaLabel={t('allBrands')}
124
- />
125
- )}
126
-
127
- {/* Tag Filter */}
128
- {tags.length > 0 && (
129
- <SelectMenu
130
- value={tagId}
131
- options={[
132
- { value: '', label: t('allTags') },
133
- ...tags.map((tg) => ({ value: tg.id, label: tg.name })),
134
- ]}
135
- onChange={(v) => updateParam('tag', v)}
136
- ariaLabel={t('allTags')}
137
- />
138
- )}
139
-
140
- {/* Custom-field (metafield) facets — rendered per definition type.
141
- Only definitions flagged `filterable: true` and published to
142
- this sales channel reach this list. */}
143
- {metafieldDefs.map((def) => {
144
- const selected = getSelectedMetafieldValues(def.key);
145
-
146
- if (def.type === 'BOOLEAN') {
147
- const isOn = selected.includes('true');
148
- return (
149
- <label
150
- key={def.id}
151
- className="inline-flex h-10 cursor-pointer items-center gap-2 rounded-full border bg-background px-4 text-sm font-medium"
152
- >
153
- <input
154
- type="checkbox"
155
- checked={isOn}
156
- onChange={(e) => setMetafieldValue(def.key, e.target.checked ? ['true'] : [])}
157
- className="h-4 w-4 accent-primary"
158
- />
159
- {def.name}
160
- </label>
161
- );
162
- }
163
-
164
- if (def.type === 'SELECT') {
165
- return (
166
- <SelectMenu
167
- key={def.id}
168
- value={selected[0] || ''}
169
- options={[
170
- { value: '', label: `${tc('all')} ${def.name}` },
171
- ...(def.enumValues || []).map((v) => ({
172
- value: v.value,
173
- label: v.label || v.value,
174
- })),
175
- ]}
176
- onChange={(v) => setMetafieldValue(def.key, v ? [v] : [])}
177
- ariaLabel={def.name}
178
- />
179
- );
180
- }
181
-
182
- // MULTI_SELECT — checkbox toggles. Each click adds/removes one value.
183
- return (
184
- <fieldset
185
- key={def.id}
186
- className="inline-flex flex-wrap items-center gap-2 rounded-full border bg-background px-4 py-2"
187
- >
188
- <legend className="sr-only">{def.name}</legend>
189
- <span className="text-sm font-medium text-muted-foreground">{def.name}:</span>
190
- {(def.enumValues || []).map((v) => {
191
- const active = selected.includes(v.value);
192
- return (
193
- <label
194
- key={v.value}
195
- className="inline-flex cursor-pointer items-center gap-1.5 text-sm"
196
- >
197
- <input
198
- type="checkbox"
199
- checked={active}
200
- onChange={() =>
201
- setMetafieldValue(
202
- def.key,
203
- active ? selected.filter((s) => s !== v.value) : [...selected, v.value]
204
- )
205
- }
206
- className="h-4 w-4 accent-primary"
207
- />
208
- {v.label || v.value}
209
- </label>
210
- );
211
- })}
212
- </fieldset>
213
- );
214
- })}
215
-
216
- {/* Result count + sort — pushed to the end of the toolbar */}
217
- <div className="ms-auto flex items-center gap-3">
218
- {!loading && (
219
- <p className="hidden text-sm text-muted-foreground sm:block">
220
- {total} {total === 1 ? tc('product') : tc('products')}
221
- </p>
222
- )}
223
- <SelectMenu
224
- value={String(sortIndex)}
225
- options={sortOptions.map((opt, idx) => ({
226
- value: String(idx),
227
- label: t(opt.labelKey),
228
- }))}
229
- onChange={(v) => updateParam('sort', v)}
230
- ariaLabel={tc('sortBy')}
231
- />
232
- </div>
233
- </div>
234
-
235
- {/* Products Grid */}
236
- {loading ? (
237
- <SkeletonGrid />
238
- ) : (
239
- <>
240
- <ProductGrid products={products} />
241
-
242
- {/* Load More */}
243
- {page < totalPages && (
244
- <div className="mt-10 flex justify-center">
245
- <button
246
- type="button"
247
- onClick={handleLoadMore}
248
- disabled={loadingMore}
249
- className="btn-outline btn-md min-w-44"
250
- >
251
- {loadingMore ? <LoadingSpinner size="sm" /> : t('loadMore')}
252
- </button>
253
- </div>
254
- )}
255
- </>
256
- )}
257
- </div>
258
- </section>
259
- );
260
- }
1
+ 'use client';
2
+
3
+ import {
4
+ useProductListing,
5
+ sortOptions,
6
+ type CategoryNode,
7
+ } from '@/core/hooks/use-product-listing';
8
+ import { ProductGrid } from '@/ui/product/product-grid';
9
+ import { LoadingSpinner } from '@/ui/shared/loading-spinner';
10
+ import { SelectMenu, type SelectMenuOption } from '@/ui/shared/select-menu';
11
+ import { useState } from 'react';
12
+ import { useTranslations } from '@/core/lib/translations';
13
+
14
+ /**
15
+ * Flatten the category tree into indented options so nested categories stay
16
+ * selectable in the styled dropdown.
17
+ */
18
+ function flattenCategories(items: CategoryNode[], depth = 0): SelectMenuOption[] {
19
+ return items.flatMap((node) => [
20
+ { value: node.id, label: `${'— '.repeat(depth)}${node.name}` },
21
+ ...flattenCategories(node.children, depth + 1),
22
+ ]);
23
+ }
24
+
25
+ /** Shimmer skeleton card shown while the grid loads — no layout jump. */
26
+ function SkeletonGrid() {
27
+ return (
28
+ <div
29
+ className="grid grid-cols-2 gap-3 sm:gap-5 lg:grid-cols-4 lg:gap-6"
30
+ role="status"
31
+ aria-label="Loading"
32
+ >
33
+ {Array.from({ length: 8 }).map((_, i) => (
34
+ <div key={i} className="card overflow-hidden">
35
+ <div className="aspect-square animate-pulse bg-secondary" />
36
+ <div className="space-y-2.5 p-4">
37
+ <div className="h-4 w-3/4 animate-pulse rounded bg-secondary" />
38
+ <div className="h-4 w-1/3 animate-pulse rounded bg-secondary" />
39
+ <div className="mt-2 h-9 w-full animate-pulse rounded-full bg-secondary" />
40
+ </div>
41
+ </div>
42
+ ))}
43
+ </div>
44
+ );
45
+ }
46
+
47
+ /**
48
+ * Append a product count to a facet value label when one is known.
49
+ *
50
+ * `metafieldCounts` comes from `getMetafieldFilters()`, which not every mode
51
+ * or store can answer — a missing entry means "no count available", NOT zero,
52
+ * so the bare label is returned unchanged rather than showing "(0)" on a facet
53
+ * that may well have products behind it.
54
+ */
55
+ function withCount(label: string, count: number | undefined): string {
56
+ return typeof count === 'number' ? `${label} (${count})` : label;
57
+ }
58
+
59
+ /**
60
+ * Product listing page: page header band, filter/sort toolbar, grid,
61
+ * load-more. All data and URL-state behavior comes from `useProductListing`;
62
+ * this component is presentation only. Must be rendered inside `<Suspense>`
63
+ * (URL params).
64
+ */
65
+ export function ProductListing() {
66
+ const t = useTranslations('products');
67
+ const tc = useTranslations('common');
68
+
69
+ const {
70
+ products,
71
+ loading,
72
+ loadingMore,
73
+ page,
74
+ totalPages,
75
+ total,
76
+ categories,
77
+ brands,
78
+ tags,
79
+ metafieldDefs,
80
+ metafieldCounts,
81
+ searchQuery,
82
+ categoryId,
83
+ brandId,
84
+ tagId,
85
+ minPrice,
86
+ maxPrice,
87
+ setPriceRange,
88
+ sortIndex,
89
+ handleLoadMore,
90
+ updateParam,
91
+ handleCategorySelect,
92
+ getSelectedMetafieldValues,
93
+ setMetafieldValue,
94
+ } = useProductListing();
95
+
96
+ // Draft bounds. Held locally so typing does not refetch on every keystroke;
97
+ // `setPriceRange` pushes both to the URL in one navigation on submit. Seeded
98
+ // from the URL and re-seeded whenever it changes (including a back button or
99
+ // a "clear filters" that wipes the params).
100
+ const [priceDraft, setPriceDraft] = useState({ min: minPrice, max: maxPrice });
101
+ const [priceDraftKey, setPriceDraftKey] = useState(`${minPrice}|${maxPrice}`);
102
+ if (priceDraftKey !== `${minPrice}|${maxPrice}`) {
103
+ setPriceDraftKey(`${minPrice}|${maxPrice}`);
104
+ setPriceDraft({ min: minPrice, max: maxPrice });
105
+ }
106
+
107
+ return (
108
+ <section>
109
+ {/* Page header band */}
110
+ <header className="wash-hero relative overflow-hidden">
111
+ <div className="container-page py-10 text-center lg:py-14">
112
+ <h1 className="text-4xl sm:text-5xl">
113
+ {searchQuery ? `${t('searchPrefix')} "${searchQuery}"` : t('allProducts')}
114
+ </h1>
115
+ <p className="mx-auto mt-3 max-w-xl text-muted-foreground">
116
+ {searchQuery ? (
117
+ !loading && (
118
+ <>
119
+ {total} {total === 1 ? tc('product') : tc('products')} {tc('found')}
120
+ </>
121
+ )
122
+ ) : (
123
+ t('listingSubtitle')
124
+ )}
125
+ </p>
126
+ </div>
127
+ </header>
128
+
129
+ <div className="container-page pb-16 pt-8 lg:pb-20">
130
+ {/* Filters + sort toolbar */}
131
+ <div className="mb-8 flex flex-wrap items-center gap-3">
132
+ {/* Category filter nested tree flattened into a select */}
133
+ {categories.length > 0 && (
134
+ <SelectMenu
135
+ value={categoryId}
136
+ options={[{ value: '', label: tc('all') }, ...flattenCategories(categories)]}
137
+ onChange={(v) => (v ? handleCategorySelect(v) : updateParam('category', ''))}
138
+ ariaLabel={t('filtersLabel')}
139
+ />
140
+ )}
141
+
142
+ {/* Price range. `minPrice` / `maxPrice` are discrete top-level keys
143
+ on getProducts — there is no `filters` object, and an unknown key
144
+ is dropped by the SDK's whitelist before the request goes out.
145
+ Always rendered: unlike brands/tags there is no list to be empty,
146
+ and an empty pair of bounds simply filters nothing. */}
147
+ <form
148
+ className="flex items-center gap-2 rounded-full border bg-background px-3 py-1.5"
149
+ onSubmit={(event) => {
150
+ event.preventDefault();
151
+ setPriceRange(priceDraft.min, priceDraft.max);
152
+ }}
153
+ >
154
+ <span className="text-muted-foreground text-sm font-medium">{t('priceLabel')}</span>
155
+ <input
156
+ type="number"
157
+ inputMode="decimal"
158
+ min={0}
159
+ step="any"
160
+ value={priceDraft.min}
161
+ onChange={(event) => setPriceDraft((d) => ({ ...d, min: event.target.value }))}
162
+ aria-label={t('priceMin')}
163
+ placeholder={t('priceMin')}
164
+ className="h-8 w-20 rounded-full border-0 bg-transparent px-2 text-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary"
165
+ />
166
+ <span aria-hidden="true" className="text-muted-foreground">
167
+ &ndash;
168
+ </span>
169
+ <input
170
+ type="number"
171
+ inputMode="decimal"
172
+ min={0}
173
+ step="any"
174
+ value={priceDraft.max}
175
+ onChange={(event) => setPriceDraft((d) => ({ ...d, max: event.target.value }))}
176
+ aria-label={t('priceMax')}
177
+ placeholder={t('priceMax')}
178
+ className="h-8 w-20 rounded-full border-0 bg-transparent px-2 text-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary"
179
+ />
180
+ <button type="submit" className="btn-outline btn-sm h-8 rounded-full px-3">
181
+ {tc('apply')}
182
+ </button>
183
+ </form>
184
+
185
+ {/* Brand Filter */}
186
+ {brands.length > 0 && (
187
+ <SelectMenu
188
+ value={brandId}
189
+ options={[
190
+ { value: '', label: t('allBrands') },
191
+ ...brands.map((b) => ({ value: b.id, label: b.name })),
192
+ ]}
193
+ onChange={(v) => updateParam('brand', v)}
194
+ ariaLabel={t('allBrands')}
195
+ />
196
+ )}
197
+
198
+ {/* Tag Filter */}
199
+ {tags.length > 0 && (
200
+ <SelectMenu
201
+ value={tagId}
202
+ options={[
203
+ { value: '', label: t('allTags') },
204
+ ...tags.map((tg) => ({ value: tg.id, label: tg.name })),
205
+ ]}
206
+ onChange={(v) => updateParam('tag', v)}
207
+ ariaLabel={t('allTags')}
208
+ />
209
+ )}
210
+
211
+ {/* Custom-field (metafield) facets — rendered per definition type.
212
+ Only definitions flagged `filterable: true` and published to
213
+ this sales channel reach this list. */}
214
+ {metafieldDefs.map((def) => {
215
+ const selected = getSelectedMetafieldValues(def.key);
216
+ const counts = metafieldCounts[def.key];
217
+
218
+ if (def.type === 'BOOLEAN') {
219
+ const isOn = selected.includes('true');
220
+ return (
221
+ <label
222
+ key={def.id}
223
+ className="inline-flex h-10 cursor-pointer items-center gap-2 rounded-full border bg-background px-4 text-sm font-medium"
224
+ >
225
+ <input
226
+ type="checkbox"
227
+ checked={isOn}
228
+ onChange={(e) => setMetafieldValue(def.key, e.target.checked ? ['true'] : [])}
229
+ className="h-4 w-4 accent-primary"
230
+ />
231
+ {def.name}
232
+ </label>
233
+ );
234
+ }
235
+
236
+ if (def.type === 'SELECT') {
237
+ return (
238
+ <SelectMenu
239
+ key={def.id}
240
+ value={selected[0] || ''}
241
+ options={[
242
+ { value: '', label: `${tc('all')} ${def.name}` },
243
+ ...(def.enumValues || []).map((v) => ({
244
+ value: v.value,
245
+ label: withCount(v.label || v.value, counts?.[v.value]),
246
+ })),
247
+ ]}
248
+ onChange={(v) => setMetafieldValue(def.key, v ? [v] : [])}
249
+ ariaLabel={def.name}
250
+ />
251
+ );
252
+ }
253
+
254
+ // MULTI_SELECT — checkbox toggles. Each click adds/removes one value.
255
+ return (
256
+ <fieldset
257
+ key={def.id}
258
+ className="inline-flex flex-wrap items-center gap-2 rounded-full border bg-background px-4 py-2"
259
+ >
260
+ <legend className="sr-only">{def.name}</legend>
261
+ <span className="text-sm font-medium text-muted-foreground">{def.name}:</span>
262
+ {(def.enumValues || []).map((v) => {
263
+ const active = selected.includes(v.value);
264
+ return (
265
+ <label
266
+ key={v.value}
267
+ className="inline-flex cursor-pointer items-center gap-1.5 text-sm"
268
+ >
269
+ <input
270
+ type="checkbox"
271
+ checked={active}
272
+ onChange={() =>
273
+ setMetafieldValue(
274
+ def.key,
275
+ active ? selected.filter((s) => s !== v.value) : [...selected, v.value]
276
+ )
277
+ }
278
+ className="h-4 w-4 accent-primary"
279
+ />
280
+ {withCount(v.label || v.value, counts?.[v.value])}
281
+ </label>
282
+ );
283
+ })}
284
+ </fieldset>
285
+ );
286
+ })}
287
+
288
+ {/* Result count + sort — pushed to the end of the toolbar */}
289
+ <div className="ms-auto flex items-center gap-3">
290
+ {!loading && (
291
+ <p className="hidden text-sm text-muted-foreground sm:block">
292
+ {total} {total === 1 ? tc('product') : tc('products')}
293
+ </p>
294
+ )}
295
+ <SelectMenu
296
+ value={String(sortIndex)}
297
+ options={sortOptions.map((opt, idx) => ({
298
+ value: String(idx),
299
+ label: t(opt.labelKey),
300
+ }))}
301
+ onChange={(v) => updateParam('sort', v)}
302
+ ariaLabel={tc('sortBy')}
303
+ />
304
+ </div>
305
+ </div>
306
+
307
+ {/* Products Grid */}
308
+ {loading ? (
309
+ <SkeletonGrid />
310
+ ) : (
311
+ <>
312
+ <ProductGrid products={products} />
313
+
314
+ {/* Load More */}
315
+ {page < totalPages && (
316
+ <div className="mt-10 flex justify-center">
317
+ <button
318
+ type="button"
319
+ onClick={handleLoadMore}
320
+ disabled={loadingMore}
321
+ className="btn-outline btn-md min-w-44"
322
+ >
323
+ {loadingMore ? <LoadingSpinner size="sm" /> : t('loadMore')}
324
+ </button>
325
+ </div>
326
+ )}
327
+ </>
328
+ )}
329
+ </div>
330
+ </section>
331
+ );
332
+ }