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