create-brainerce-store 1.18.0 → 1.20.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 (67) hide show
  1. package/LICENSE +0 -0
  2. package/dist/index.js +31 -9
  3. package/messages/en.json +366 -362
  4. package/messages/he.json +366 -362
  5. package/package.json +8 -8
  6. package/templates/nextjs/base/next.config.ts +31 -31
  7. package/templates/nextjs/base/scripts/fetch-store-info.mjs +81 -81
  8. package/templates/nextjs/base/src/app/.well-known/apple-developer-merchantid-domain-association/route.ts +26 -26
  9. package/templates/nextjs/base/src/app/account/layout.tsx +9 -9
  10. package/templates/nextjs/base/src/app/account/page.tsx +122 -122
  11. package/templates/nextjs/base/src/app/api/auth/logout/route.ts +14 -14
  12. package/templates/nextjs/base/src/app/api/auth/me/route.ts +56 -56
  13. package/templates/nextjs/base/src/app/api/auth/oauth-callback/route.ts +59 -59
  14. package/templates/nextjs/base/src/app/api/auth/reset-callback/route.ts +41 -41
  15. package/templates/nextjs/base/src/app/api/auth/reset-password/route.ts +77 -77
  16. package/templates/nextjs/base/src/app/api/store/[...path]/route.ts +198 -198
  17. package/templates/nextjs/base/src/app/auth/callback/page.tsx +92 -92
  18. package/templates/nextjs/base/src/app/cart/layout.tsx +9 -9
  19. package/templates/nextjs/base/src/app/cart/page.tsx +204 -204
  20. package/templates/nextjs/base/src/app/checkout/layout.tsx +9 -9
  21. package/templates/nextjs/base/src/app/checkout/page.tsx +860 -860
  22. package/templates/nextjs/base/src/app/forgot-password/page.tsx +112 -112
  23. package/templates/nextjs/base/src/app/layout.tsx.ejs +75 -0
  24. package/templates/nextjs/base/src/app/login/layout.tsx +9 -9
  25. package/templates/nextjs/base/src/app/login/page.tsx +59 -59
  26. package/templates/nextjs/base/src/app/order-confirmation/layout.tsx +9 -9
  27. package/templates/nextjs/base/src/app/order-confirmation/page.tsx +17 -0
  28. package/templates/nextjs/base/src/app/payment-complete/page.tsx +59 -0
  29. package/templates/nextjs/base/src/app/products/[slug]/page.tsx +67 -67
  30. package/templates/nextjs/base/src/app/products/[slug]/product-client-section.tsx +486 -486
  31. package/templates/nextjs/base/src/app/products/layout.tsx +18 -18
  32. package/templates/nextjs/base/src/app/products/page.tsx +431 -431
  33. package/templates/nextjs/base/src/app/register/layout.tsx +9 -9
  34. package/templates/nextjs/base/src/app/register/page.tsx +65 -65
  35. package/templates/nextjs/base/src/app/reset-password/page.tsx +132 -132
  36. package/templates/nextjs/base/src/app/robots.ts +14 -14
  37. package/templates/nextjs/base/src/app/sitemap.ts +25 -25
  38. package/templates/nextjs/base/src/app/verify-email/page.tsx +258 -258
  39. package/templates/nextjs/base/src/components/account/address-book.tsx +432 -432
  40. package/templates/nextjs/base/src/components/account/order-history.tsx +350 -350
  41. package/templates/nextjs/base/src/components/auth/oauth-buttons.tsx +137 -137
  42. package/templates/nextjs/base/src/components/auth/register-form.tsx +232 -232
  43. package/templates/nextjs/base/src/components/cart/cart-bundle-offer.tsx +247 -111
  44. package/templates/nextjs/base/src/components/cart/cart-item.tsx +153 -153
  45. package/templates/nextjs/base/src/components/cart/cart-upgrade-banner.tsx +142 -142
  46. package/templates/nextjs/base/src/components/cart/free-shipping-bar.tsx +59 -59
  47. package/templates/nextjs/base/src/components/checkout/checkout-form.tsx +415 -415
  48. package/templates/nextjs/base/src/components/checkout/order-bump-card.tsx +243 -83
  49. package/templates/nextjs/base/src/components/checkout/payment-step.tsx +49 -3
  50. package/templates/nextjs/base/src/components/layout/footer.tsx +41 -41
  51. package/templates/nextjs/base/src/components/layout/header.tsx +336 -336
  52. package/templates/nextjs/base/src/components/layout/language-switcher.tsx.ejs +63 -0
  53. package/templates/nextjs/base/src/components/products/discount-badge.tsx +22 -22
  54. package/templates/nextjs/base/src/components/products/frequently-bought-together.tsx +202 -202
  55. package/templates/nextjs/base/src/components/products/product-card.tsx +218 -218
  56. package/templates/nextjs/base/src/components/products/recommendation-section.tsx +107 -107
  57. package/templates/nextjs/base/src/components/products/stock-badge.tsx +63 -63
  58. package/templates/nextjs/base/src/components/products/variant-selector.tsx +292 -292
  59. package/templates/nextjs/base/src/components/seo/product-json-ld.tsx +72 -72
  60. package/templates/nextjs/base/src/i18n.ts.ejs +21 -0
  61. package/templates/nextjs/base/src/lib/auth.ts +149 -149
  62. package/templates/nextjs/base/src/lib/brainerce.ts.ejs +9 -0
  63. package/templates/nextjs/base/src/lib/translations.ts.ejs +31 -0
  64. package/templates/nextjs/base/src/middleware.ts.ejs +81 -0
  65. package/templates/nextjs/base/src/providers/store-provider.tsx.ejs +41 -0
  66. package/templates/nextjs/base/src/lib/translations.ts +0 -11
  67. package/templates/nextjs/base/src/middleware.ts +0 -25
@@ -1,350 +1,350 @@
1
- 'use client';
2
-
3
- import { useState, useEffect } from 'react';
4
- import Image from 'next/image';
5
- import type { Order, OrderStatus, OrderDownloadLink } from 'brainerce';
6
- import { formatPrice } from 'brainerce';
7
- import { getClient } from '@/lib/brainerce';
8
- import { useTranslations } from '@/lib/translations';
9
- import { cn } from '@/lib/utils';
10
-
11
- const STATUS_CONFIG: Record<OrderStatus, { labelKey: string; className: string }> = {
12
- pending: {
13
- labelKey: 'statusPending',
14
- className: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-950/30 dark:text-yellow-400',
15
- },
16
- processing: {
17
- labelKey: 'statusProcessing',
18
- className: 'bg-blue-100 text-blue-800 dark:bg-blue-950/30 dark:text-blue-400',
19
- },
20
- shipped: {
21
- labelKey: 'statusShipped',
22
- className: 'bg-purple-100 text-purple-800 dark:bg-purple-950/30 dark:text-purple-400',
23
- },
24
- delivered: {
25
- labelKey: 'statusDelivered',
26
- className: 'bg-green-100 text-green-800 dark:bg-green-950/30 dark:text-green-400',
27
- },
28
- cancelled: {
29
- labelKey: 'statusCancelled',
30
- className: 'bg-red-100 text-red-800 dark:bg-red-950/30 dark:text-red-400',
31
- },
32
- refunded: {
33
- labelKey: 'statusRefunded',
34
- className: 'bg-orange-100 text-orange-800 dark:bg-orange-950/30 dark:text-orange-400',
35
- },
36
- };
37
-
38
- interface OrderHistoryProps {
39
- orders: Order[];
40
- className?: string;
41
- }
42
-
43
- export function OrderHistory({ orders, className }: OrderHistoryProps) {
44
- const t = useTranslations('account');
45
- if (orders.length === 0) {
46
- return (
47
- <div className={cn('py-12 text-center', className)}>
48
- <svg
49
- className="text-muted-foreground mx-auto mb-3 h-12 w-12"
50
- fill="none"
51
- viewBox="0 0 24 24"
52
- stroke="currentColor"
53
- >
54
- <path
55
- strokeLinecap="round"
56
- strokeLinejoin="round"
57
- strokeWidth={1.5}
58
- d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"
59
- />
60
- </svg>
61
- <h3 className="text-foreground text-lg font-semibold">{t('noOrders')}</h3>
62
- <p className="text-muted-foreground mt-1 text-sm">{t('noOrdersDesc')}</p>
63
- </div>
64
- );
65
- }
66
-
67
- return (
68
- <div className={cn('space-y-4', className)}>
69
- {orders.map((order) => (
70
- <OrderCard key={order.id} order={order} />
71
- ))}
72
- </div>
73
- );
74
- }
75
-
76
- function OrderCard({ order }: { order: Order }) {
77
- const t = useTranslations('account');
78
- const tc = useTranslations('common');
79
- const [expanded, setExpanded] = useState(false);
80
- const statusConfig =
81
- STATUS_CONFIG[order.status?.toLowerCase() as OrderStatus] || STATUS_CONFIG.pending;
82
- const currency = order.currency || 'USD';
83
- const totalAmount = order.totalAmount || order.total || '0';
84
-
85
- return (
86
- <div className="border-border overflow-hidden rounded-lg border">
87
- {/* Order header */}
88
- <button
89
- type="button"
90
- onClick={() => setExpanded(!expanded)}
91
- className="hover:bg-muted/50 flex w-full items-center justify-between p-4 text-start transition-colors"
92
- >
93
- <div className="min-w-0 flex-1">
94
- <div className="flex flex-wrap items-center gap-3">
95
- <span className="text-foreground text-sm font-semibold">
96
- {order.orderNumber || `${t('orderPrefix')} ${order.id.slice(0, 8)}`}
97
- </span>
98
- <span
99
- className={cn(
100
- 'inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium',
101
- statusConfig.className
102
- )}
103
- >
104
- {t(
105
- statusConfig.labelKey as
106
- | 'statusPending'
107
- | 'statusProcessing'
108
- | 'statusShipped'
109
- | 'statusDelivered'
110
- | 'statusCancelled'
111
- | 'statusRefunded'
112
- )}
113
- </span>
114
- </div>
115
- <div className="text-muted-foreground mt-1 flex items-center gap-4 text-xs">
116
- <span>
117
- {order.createdAt && !isNaN(new Date(order.createdAt).getTime())
118
- ? new Date(order.createdAt).toLocaleDateString(undefined, {
119
- year: 'numeric',
120
- month: 'short',
121
- day: 'numeric',
122
- })
123
- : '—'}
124
- </span>
125
- <span>
126
- {order.items.length} {order.items.length === 1 ? tc('item') : tc('items')}
127
- </span>
128
- </div>
129
- </div>
130
-
131
- <div className="flex flex-shrink-0 items-center gap-3">
132
- <span className="text-foreground text-sm font-semibold">
133
- {formatPrice(parseFloat(totalAmount), { currency }) as string}
134
- </span>
135
- <svg
136
- className={cn(
137
- 'text-muted-foreground h-4 w-4 transition-transform',
138
- expanded && 'rotate-180'
139
- )}
140
- fill="none"
141
- viewBox="0 0 24 24"
142
- stroke="currentColor"
143
- >
144
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
145
- </svg>
146
- </div>
147
- </button>
148
-
149
- {/* Expanded order items */}
150
- {expanded && (
151
- <div className="border-border bg-muted/30 space-y-3 border-t px-4 py-3">
152
- {order.items.map((item, index) => (
153
- <div key={`${item.productId}-${index}`} className="flex items-center gap-3">
154
- <div className="bg-muted relative h-10 w-10 flex-shrink-0 overflow-hidden rounded">
155
- {item.image ? (
156
- <Image
157
- src={item.image}
158
- alt={item.name || t('productFallback')}
159
- fill
160
- sizes="40px"
161
- className="object-cover"
162
- />
163
- ) : (
164
- <div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
165
- <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
166
- <path
167
- strokeLinecap="round"
168
- strokeLinejoin="round"
169
- strokeWidth={1.5}
170
- d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"
171
- />
172
- </svg>
173
- </div>
174
- )}
175
- </div>
176
-
177
- <div className="min-w-0 flex-1">
178
- <p className="text-foreground truncate text-sm">
179
- {item.name || t('productFallback')}
180
- </p>
181
- <p className="text-muted-foreground text-xs">
182
- {tc('qty')} {item.quantity}
183
- </p>
184
- </div>
185
-
186
- <span className="text-foreground flex-shrink-0 text-sm">
187
- {formatPrice(parseFloat(item.price), { currency }) as string}
188
- </span>
189
- </div>
190
- ))}
191
-
192
- {/* Downloads section */}
193
- {order.hasDownloads && <OrderDownloads orderId={order.id} />}
194
-
195
- <OrderFinancialSummary order={order} currency={currency} />
196
- </div>
197
- )}
198
- </div>
199
- );
200
- }
201
-
202
- function OrderDownloads({ orderId }: { orderId: string }) {
203
- const t = useTranslations('account');
204
- const [downloads, setDownloads] = useState<OrderDownloadLink[] | null>(null);
205
- const [loading, setLoading] = useState(true);
206
-
207
- useEffect(() => {
208
- let cancelled = false;
209
- async function fetch() {
210
- try {
211
- const client = getClient();
212
- const links = await client.getOrderDownloads(orderId);
213
- if (!cancelled) setDownloads(links);
214
- } catch {
215
- if (!cancelled) setDownloads([]);
216
- } finally {
217
- if (!cancelled) setLoading(false);
218
- }
219
- }
220
- fetch();
221
- return () => {
222
- cancelled = true;
223
- };
224
- }, [orderId]);
225
-
226
- if (loading) {
227
- return (
228
- <div className="border-border border-t pt-2">
229
- <p className="text-muted-foreground animate-pulse text-xs">{t('downloads')}...</p>
230
- </div>
231
- );
232
- }
233
-
234
- if (!downloads || downloads.length === 0) return null;
235
-
236
- return (
237
- <div className="border-border space-y-2 border-t pt-2">
238
- <p className="text-foreground text-sm font-medium">{t('downloads')}</p>
239
- {downloads.map((link, idx) => (
240
- <div key={idx} className="flex items-center gap-3">
241
- <div className="min-w-0 flex-1">
242
- <p className="text-foreground truncate text-sm">{link.fileName}</p>
243
- <p className="text-muted-foreground text-xs">
244
- {link.productName}
245
- {' · '}
246
- {link.downloadLimit != null
247
- ? `${link.downloadsUsed}/${link.downloadLimit} ${t('downloadsRemaining')}`
248
- : t('unlimitedDownloads')}
249
- {' · '}
250
- {link.expiresAt
251
- ? `${t('expiresAt')} ${new Date(link.expiresAt).toLocaleDateString()}`
252
- : t('noExpiry')}
253
- </p>
254
- </div>
255
- <a
256
- href={link.downloadUrl}
257
- target="_blank"
258
- rel="noopener noreferrer"
259
- className="bg-primary text-primary-foreground flex-shrink-0 rounded px-3 py-1 text-xs font-medium hover:opacity-90"
260
- >
261
- {t('downloadFile')}
262
- </a>
263
- </div>
264
- ))}
265
- </div>
266
- );
267
- }
268
-
269
- function OrderFinancialSummary({ order, currency }: { order: Order; currency: string }) {
270
- const tc = useTranslations('common');
271
- const totalAmount = order.totalAmount || order.total || '0';
272
- const subtotal = order.subtotal ? parseFloat(order.subtotal) : null;
273
- const ruleAmt = order.ruleDiscountAmount ? parseFloat(order.ruleDiscountAmount) : 0;
274
- const couponAmt = order.couponDiscount ? parseFloat(order.couponDiscount) : 0;
275
- const shipping = order.shippingAmount ? parseFloat(order.shippingAmount) : 0;
276
- const tax = order.taxAmount ? parseFloat(order.taxAmount) : 0;
277
- const rules = order.appliedDiscounts;
278
-
279
- const hasBreakdown = subtotal !== null && subtotal > 0;
280
-
281
- if (!hasBreakdown) {
282
- return (
283
- <div className="border-border flex items-center justify-between border-t pt-2">
284
- <span className="text-muted-foreground text-sm font-medium">{tc('total')}</span>
285
- <span className="text-foreground text-sm font-semibold">
286
- {formatPrice(parseFloat(totalAmount), { currency }) as string}
287
- </span>
288
- </div>
289
- );
290
- }
291
-
292
- return (
293
- <div className="border-border space-y-1 border-t pt-2 text-sm">
294
- <div className="flex items-center justify-between">
295
- <span className="text-muted-foreground">{tc('subtotal')}</span>
296
- <span className="text-foreground">{formatPrice(subtotal, { currency }) as string}</span>
297
- </div>
298
-
299
- {rules && rules.length > 0
300
- ? rules.map((rule) => (
301
- <div key={rule.ruleId} className="flex items-center justify-between">
302
- <span className="text-muted-foreground">{rule.ruleName}</span>
303
- <span className="text-destructive">
304
- -{formatPrice(parseFloat(rule.discountAmount || '0'), { currency }) as string}
305
- </span>
306
- </div>
307
- ))
308
- : ruleAmt > 0 && (
309
- <div className="flex items-center justify-between">
310
- <span className="text-muted-foreground">{tc('generalDiscount')}</span>
311
- <span className="text-destructive">
312
- -{formatPrice(ruleAmt, { currency }) as string}
313
- </span>
314
- </div>
315
- )}
316
-
317
- {order.couponCode && couponAmt > 0 && (
318
- <div className="flex items-center justify-between">
319
- <span className="text-muted-foreground">
320
- {tc('couponDiscount')} ({order.couponCode})
321
- </span>
322
- <span className="text-destructive">
323
- -{formatPrice(couponAmt, { currency }) as string}
324
- </span>
325
- </div>
326
- )}
327
-
328
- {shipping > 0 && (
329
- <div className="flex items-center justify-between">
330
- <span className="text-muted-foreground">{tc('shipping')}</span>
331
- <span className="text-foreground">{formatPrice(shipping, { currency }) as string}</span>
332
- </div>
333
- )}
334
-
335
- {tax > 0 && (
336
- <div className="flex items-center justify-between">
337
- <span className="text-muted-foreground">{tc('tax')}</span>
338
- <span className="text-foreground">{formatPrice(tax, { currency }) as string}</span>
339
- </div>
340
- )}
341
-
342
- <div className="border-border flex items-center justify-between border-t pt-1">
343
- <span className="text-foreground font-medium">{tc('total')}</span>
344
- <span className="text-foreground font-semibold">
345
- {formatPrice(parseFloat(totalAmount), { currency }) as string}
346
- </span>
347
- </div>
348
- </div>
349
- );
350
- }
1
+ 'use client';
2
+
3
+ import { useState, useEffect } from 'react';
4
+ import Image from 'next/image';
5
+ import type { Order, OrderStatus, OrderDownloadLink } from 'brainerce';
6
+ import { formatPrice } from 'brainerce';
7
+ import { getClient } from '@/lib/brainerce';
8
+ import { useTranslations } from '@/lib/translations';
9
+ import { cn } from '@/lib/utils';
10
+
11
+ const STATUS_CONFIG: Record<OrderStatus, { labelKey: string; className: string }> = {
12
+ pending: {
13
+ labelKey: 'statusPending',
14
+ className: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-950/30 dark:text-yellow-400',
15
+ },
16
+ processing: {
17
+ labelKey: 'statusProcessing',
18
+ className: 'bg-blue-100 text-blue-800 dark:bg-blue-950/30 dark:text-blue-400',
19
+ },
20
+ shipped: {
21
+ labelKey: 'statusShipped',
22
+ className: 'bg-purple-100 text-purple-800 dark:bg-purple-950/30 dark:text-purple-400',
23
+ },
24
+ delivered: {
25
+ labelKey: 'statusDelivered',
26
+ className: 'bg-green-100 text-green-800 dark:bg-green-950/30 dark:text-green-400',
27
+ },
28
+ cancelled: {
29
+ labelKey: 'statusCancelled',
30
+ className: 'bg-red-100 text-red-800 dark:bg-red-950/30 dark:text-red-400',
31
+ },
32
+ refunded: {
33
+ labelKey: 'statusRefunded',
34
+ className: 'bg-orange-100 text-orange-800 dark:bg-orange-950/30 dark:text-orange-400',
35
+ },
36
+ };
37
+
38
+ interface OrderHistoryProps {
39
+ orders: Order[];
40
+ className?: string;
41
+ }
42
+
43
+ export function OrderHistory({ orders, className }: OrderHistoryProps) {
44
+ const t = useTranslations('account');
45
+ if (orders.length === 0) {
46
+ return (
47
+ <div className={cn('py-12 text-center', className)}>
48
+ <svg
49
+ className="text-muted-foreground mx-auto mb-3 h-12 w-12"
50
+ fill="none"
51
+ viewBox="0 0 24 24"
52
+ stroke="currentColor"
53
+ >
54
+ <path
55
+ strokeLinecap="round"
56
+ strokeLinejoin="round"
57
+ strokeWidth={1.5}
58
+ d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4"
59
+ />
60
+ </svg>
61
+ <h3 className="text-foreground text-lg font-semibold">{t('noOrders')}</h3>
62
+ <p className="text-muted-foreground mt-1 text-sm">{t('noOrdersDesc')}</p>
63
+ </div>
64
+ );
65
+ }
66
+
67
+ return (
68
+ <div className={cn('space-y-4', className)}>
69
+ {orders.map((order) => (
70
+ <OrderCard key={order.id} order={order} />
71
+ ))}
72
+ </div>
73
+ );
74
+ }
75
+
76
+ function OrderCard({ order }: { order: Order }) {
77
+ const t = useTranslations('account');
78
+ const tc = useTranslations('common');
79
+ const [expanded, setExpanded] = useState(false);
80
+ const statusConfig =
81
+ STATUS_CONFIG[order.status?.toLowerCase() as OrderStatus] || STATUS_CONFIG.pending;
82
+ const currency = order.currency || 'USD';
83
+ const totalAmount = order.totalAmount || order.total || '0';
84
+
85
+ return (
86
+ <div className="border-border overflow-hidden rounded-lg border">
87
+ {/* Order header */}
88
+ <button
89
+ type="button"
90
+ onClick={() => setExpanded(!expanded)}
91
+ className="hover:bg-muted/50 flex w-full items-center justify-between p-4 text-start transition-colors"
92
+ >
93
+ <div className="min-w-0 flex-1">
94
+ <div className="flex flex-wrap items-center gap-3">
95
+ <span className="text-foreground text-sm font-semibold">
96
+ {order.orderNumber || `${t('orderPrefix')} ${order.id.slice(0, 8)}`}
97
+ </span>
98
+ <span
99
+ className={cn(
100
+ 'inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium',
101
+ statusConfig.className
102
+ )}
103
+ >
104
+ {t(
105
+ statusConfig.labelKey as
106
+ | 'statusPending'
107
+ | 'statusProcessing'
108
+ | 'statusShipped'
109
+ | 'statusDelivered'
110
+ | 'statusCancelled'
111
+ | 'statusRefunded'
112
+ )}
113
+ </span>
114
+ </div>
115
+ <div className="text-muted-foreground mt-1 flex items-center gap-4 text-xs">
116
+ <span>
117
+ {order.createdAt && !isNaN(new Date(order.createdAt).getTime())
118
+ ? new Date(order.createdAt).toLocaleDateString(undefined, {
119
+ year: 'numeric',
120
+ month: 'short',
121
+ day: 'numeric',
122
+ })
123
+ : '—'}
124
+ </span>
125
+ <span>
126
+ {order.items.length} {order.items.length === 1 ? tc('item') : tc('items')}
127
+ </span>
128
+ </div>
129
+ </div>
130
+
131
+ <div className="flex flex-shrink-0 items-center gap-3">
132
+ <span className="text-foreground text-sm font-semibold">
133
+ {formatPrice(parseFloat(totalAmount), { currency }) as string}
134
+ </span>
135
+ <svg
136
+ className={cn(
137
+ 'text-muted-foreground h-4 w-4 transition-transform',
138
+ expanded && 'rotate-180'
139
+ )}
140
+ fill="none"
141
+ viewBox="0 0 24 24"
142
+ stroke="currentColor"
143
+ >
144
+ <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
145
+ </svg>
146
+ </div>
147
+ </button>
148
+
149
+ {/* Expanded order items */}
150
+ {expanded && (
151
+ <div className="border-border bg-muted/30 space-y-3 border-t px-4 py-3">
152
+ {order.items.map((item, index) => (
153
+ <div key={`${item.productId}-${index}`} className="flex items-center gap-3">
154
+ <div className="bg-muted relative h-10 w-10 flex-shrink-0 overflow-hidden rounded">
155
+ {item.image ? (
156
+ <Image
157
+ src={item.image}
158
+ alt={item.name || t('productFallback')}
159
+ fill
160
+ sizes="40px"
161
+ className="object-cover"
162
+ />
163
+ ) : (
164
+ <div className="text-muted-foreground absolute inset-0 flex items-center justify-center">
165
+ <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
166
+ <path
167
+ strokeLinecap="round"
168
+ strokeLinejoin="round"
169
+ strokeWidth={1.5}
170
+ d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"
171
+ />
172
+ </svg>
173
+ </div>
174
+ )}
175
+ </div>
176
+
177
+ <div className="min-w-0 flex-1">
178
+ <p className="text-foreground truncate text-sm">
179
+ {item.name || t('productFallback')}
180
+ </p>
181
+ <p className="text-muted-foreground text-xs">
182
+ {tc('qty')} {item.quantity}
183
+ </p>
184
+ </div>
185
+
186
+ <span className="text-foreground flex-shrink-0 text-sm">
187
+ {formatPrice(parseFloat(item.price), { currency }) as string}
188
+ </span>
189
+ </div>
190
+ ))}
191
+
192
+ {/* Downloads section */}
193
+ {order.hasDownloads && <OrderDownloads orderId={order.id} />}
194
+
195
+ <OrderFinancialSummary order={order} currency={currency} />
196
+ </div>
197
+ )}
198
+ </div>
199
+ );
200
+ }
201
+
202
+ function OrderDownloads({ orderId }: { orderId: string }) {
203
+ const t = useTranslations('account');
204
+ const [downloads, setDownloads] = useState<OrderDownloadLink[] | null>(null);
205
+ const [loading, setLoading] = useState(true);
206
+
207
+ useEffect(() => {
208
+ let cancelled = false;
209
+ async function fetch() {
210
+ try {
211
+ const client = getClient();
212
+ const links = await client.getOrderDownloads(orderId);
213
+ if (!cancelled) setDownloads(links);
214
+ } catch {
215
+ if (!cancelled) setDownloads([]);
216
+ } finally {
217
+ if (!cancelled) setLoading(false);
218
+ }
219
+ }
220
+ fetch();
221
+ return () => {
222
+ cancelled = true;
223
+ };
224
+ }, [orderId]);
225
+
226
+ if (loading) {
227
+ return (
228
+ <div className="border-border border-t pt-2">
229
+ <p className="text-muted-foreground animate-pulse text-xs">{t('downloads')}...</p>
230
+ </div>
231
+ );
232
+ }
233
+
234
+ if (!downloads || downloads.length === 0) return null;
235
+
236
+ return (
237
+ <div className="border-border space-y-2 border-t pt-2">
238
+ <p className="text-foreground text-sm font-medium">{t('downloads')}</p>
239
+ {downloads.map((link, idx) => (
240
+ <div key={idx} className="flex items-center gap-3">
241
+ <div className="min-w-0 flex-1">
242
+ <p className="text-foreground truncate text-sm">{link.fileName}</p>
243
+ <p className="text-muted-foreground text-xs">
244
+ {link.productName}
245
+ {' · '}
246
+ {link.downloadLimit != null
247
+ ? `${link.downloadsUsed}/${link.downloadLimit} ${t('downloadsRemaining')}`
248
+ : t('unlimitedDownloads')}
249
+ {' · '}
250
+ {link.expiresAt
251
+ ? `${t('expiresAt')} ${new Date(link.expiresAt).toLocaleDateString()}`
252
+ : t('noExpiry')}
253
+ </p>
254
+ </div>
255
+ <a
256
+ href={link.downloadUrl}
257
+ target="_blank"
258
+ rel="noopener noreferrer"
259
+ className="bg-primary text-primary-foreground flex-shrink-0 rounded px-3 py-1 text-xs font-medium hover:opacity-90"
260
+ >
261
+ {t('downloadFile')}
262
+ </a>
263
+ </div>
264
+ ))}
265
+ </div>
266
+ );
267
+ }
268
+
269
+ function OrderFinancialSummary({ order, currency }: { order: Order; currency: string }) {
270
+ const tc = useTranslations('common');
271
+ const totalAmount = order.totalAmount || order.total || '0';
272
+ const subtotal = order.subtotal ? parseFloat(order.subtotal) : null;
273
+ const ruleAmt = order.ruleDiscountAmount ? parseFloat(order.ruleDiscountAmount) : 0;
274
+ const couponAmt = order.couponDiscount ? parseFloat(order.couponDiscount) : 0;
275
+ const shipping = order.shippingAmount ? parseFloat(order.shippingAmount) : 0;
276
+ const tax = order.taxAmount ? parseFloat(order.taxAmount) : 0;
277
+ const rules = order.appliedDiscounts;
278
+
279
+ const hasBreakdown = subtotal !== null && subtotal > 0;
280
+
281
+ if (!hasBreakdown) {
282
+ return (
283
+ <div className="border-border flex items-center justify-between border-t pt-2">
284
+ <span className="text-muted-foreground text-sm font-medium">{tc('total')}</span>
285
+ <span className="text-foreground text-sm font-semibold">
286
+ {formatPrice(parseFloat(totalAmount), { currency }) as string}
287
+ </span>
288
+ </div>
289
+ );
290
+ }
291
+
292
+ return (
293
+ <div className="border-border space-y-1 border-t pt-2 text-sm">
294
+ <div className="flex items-center justify-between">
295
+ <span className="text-muted-foreground">{tc('subtotal')}</span>
296
+ <span className="text-foreground">{formatPrice(subtotal, { currency }) as string}</span>
297
+ </div>
298
+
299
+ {rules && rules.length > 0
300
+ ? rules.map((rule) => (
301
+ <div key={rule.ruleId} className="flex items-center justify-between">
302
+ <span className="text-muted-foreground">{rule.ruleName}</span>
303
+ <span className="text-destructive">
304
+ -{formatPrice(parseFloat(rule.discountAmount || '0'), { currency }) as string}
305
+ </span>
306
+ </div>
307
+ ))
308
+ : ruleAmt > 0 && (
309
+ <div className="flex items-center justify-between">
310
+ <span className="text-muted-foreground">{tc('generalDiscount')}</span>
311
+ <span className="text-destructive">
312
+ -{formatPrice(ruleAmt, { currency }) as string}
313
+ </span>
314
+ </div>
315
+ )}
316
+
317
+ {order.couponCode && couponAmt > 0 && (
318
+ <div className="flex items-center justify-between">
319
+ <span className="text-muted-foreground">
320
+ {tc('couponDiscount')} ({order.couponCode})
321
+ </span>
322
+ <span className="text-destructive">
323
+ -{formatPrice(couponAmt, { currency }) as string}
324
+ </span>
325
+ </div>
326
+ )}
327
+
328
+ {shipping > 0 && (
329
+ <div className="flex items-center justify-between">
330
+ <span className="text-muted-foreground">{tc('shipping')}</span>
331
+ <span className="text-foreground">{formatPrice(shipping, { currency }) as string}</span>
332
+ </div>
333
+ )}
334
+
335
+ {tax > 0 && (
336
+ <div className="flex items-center justify-between">
337
+ <span className="text-muted-foreground">{tc('tax')}</span>
338
+ <span className="text-foreground">{formatPrice(tax, { currency }) as string}</span>
339
+ </div>
340
+ )}
341
+
342
+ <div className="border-border flex items-center justify-between border-t pt-1">
343
+ <span className="text-foreground font-medium">{tc('total')}</span>
344
+ <span className="text-foreground font-semibold">
345
+ {formatPrice(parseFloat(totalAmount), { currency }) as string}
346
+ </span>
347
+ </div>
348
+ </div>
349
+ );
350
+ }