@usethrottle/auth 0.11.0 → 0.12.1

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 (68) hide show
  1. package/README.md +52 -0
  2. package/dist/AccountDashboard-V63ghvjY.d.ts +90 -0
  3. package/dist/AccountModal-KA54WUFW.js +13 -0
  4. package/dist/AccountModal-KA54WUFW.js.map +1 -0
  5. package/dist/AccountModal-pIMgledL.d.ts +141 -0
  6. package/dist/AuthModal-T2GYI6ZF.js +13 -0
  7. package/dist/AuthModal-T2GYI6ZF.js.map +1 -0
  8. package/dist/SignUpPage-BJcMUb2V.d.ts +160 -0
  9. package/dist/chunk-3B4DNX5T.js +2 -0
  10. package/dist/chunk-3B4DNX5T.js.map +1 -0
  11. package/dist/chunk-5EUZYJJL.js +29 -0
  12. package/dist/chunk-5EUZYJJL.js.map +1 -0
  13. package/dist/chunk-6WN3J5MM.js +2075 -0
  14. package/dist/chunk-6WN3J5MM.js.map +1 -0
  15. package/dist/chunk-CUNMJ2PH.js +1320 -0
  16. package/dist/chunk-CUNMJ2PH.js.map +1 -0
  17. package/dist/chunk-ETYOOYYV.js +2 -0
  18. package/dist/chunk-ETYOOYYV.js.map +1 -0
  19. package/dist/chunk-JSDZMPCV.js +520 -0
  20. package/dist/chunk-JSDZMPCV.js.map +1 -0
  21. package/dist/chunk-QPVS6JXP.js +39 -0
  22. package/dist/chunk-QPVS6JXP.js.map +1 -0
  23. package/dist/chunk-RCNUWITB.js +747 -0
  24. package/dist/chunk-RCNUWITB.js.map +1 -0
  25. package/dist/{chunk-YY6YATXT.js → chunk-TDQC3LMQ.js} +17 -3
  26. package/dist/chunk-TDQC3LMQ.js.map +1 -0
  27. package/dist/{chunk-EFMKBOTL.js → chunk-UFGW76AZ.js} +2 -2
  28. package/dist/chunk-VDK23T6L.js +230 -0
  29. package/dist/chunk-VDK23T6L.js.map +1 -0
  30. package/dist/chunk-X6D35EAX.js +19 -0
  31. package/dist/chunk-X6D35EAX.js.map +1 -0
  32. package/dist/client-7LVKfuXO.d.ts +319 -0
  33. package/dist/hooks-DkpLrEiC.d.ts +148 -0
  34. package/dist/index.cjs +16 -2
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +34 -3
  37. package/dist/index.d.ts +34 -3
  38. package/dist/index.js +16 -2
  39. package/dist/index.js.map +1 -1
  40. package/dist/localization-SnIAZXJn.d.ts +389 -0
  41. package/dist/react/components/account/index.d.ts +37 -0
  42. package/dist/react/components/account/index.js +44 -0
  43. package/dist/react/components/account/index.js.map +1 -0
  44. package/dist/react/components/auth/index.d.ts +17 -0
  45. package/dist/react/components/auth/index.js +40 -0
  46. package/dist/react/components/auth/index.js.map +1 -0
  47. package/dist/react/components/guards.d.ts +21 -0
  48. package/dist/react/components/guards.js +13 -0
  49. package/dist/react/components/guards.js.map +1 -0
  50. package/dist/react/components/index.cjs +3561 -2805
  51. package/dist/react/components/index.cjs.map +1 -1
  52. package/dist/react/components/index.d.cts +14 -2
  53. package/dist/react/components/index.d.ts +14 -821
  54. package/dist/react/components/index.js +90 -4680
  55. package/dist/react/components/index.js.map +1 -1
  56. package/dist/react/components/provider.d.ts +79 -0
  57. package/dist/react/components/provider.js +18 -0
  58. package/dist/react/components/provider.js.map +1 -0
  59. package/dist/react/forms/index.js +1 -1
  60. package/dist/react/index.cjs +16 -2
  61. package/dist/react/index.cjs.map +1 -1
  62. package/dist/react/index.d.cts +34 -3
  63. package/dist/react/index.d.ts +5 -433
  64. package/dist/react/index.js +3 -2
  65. package/dist/styles.css +7 -4
  66. package/package.json +4 -1
  67. package/dist/chunk-YY6YATXT.js.map +0 -1
  68. /package/dist/{chunk-EFMKBOTL.js.map → chunk-UFGW76AZ.js.map} +0 -0
@@ -0,0 +1,2075 @@
1
+ "use client";
2
+ import {
3
+ useAddresses,
4
+ useCustomer,
5
+ useInvoice,
6
+ useInvoices,
7
+ useOrder,
8
+ useOrders,
9
+ useSavedCards,
10
+ useSubscriptions
11
+ } from "./chunk-UFGW76AZ.js";
12
+ import {
13
+ useAction
14
+ } from "./chunk-QPVS6JXP.js";
15
+ import {
16
+ Alert,
17
+ AppearanceProvider,
18
+ Badge,
19
+ Button,
20
+ DataTable,
21
+ EmptyState,
22
+ Field,
23
+ FieldRow,
24
+ Modal,
25
+ Skeleton,
26
+ Spinner,
27
+ Tabs,
28
+ useAppearance,
29
+ useAppearanceProviderValue,
30
+ useConfirm,
31
+ useCopy
32
+ } from "./chunk-CUNMJ2PH.js";
33
+ import {
34
+ messageForError
35
+ } from "./chunk-K7RCWADI.js";
36
+ import {
37
+ useAuth
38
+ } from "./chunk-TDQC3LMQ.js";
39
+
40
+ // src/react/components/account/AccountModal.tsx
41
+ import { useId as useId3 } from "react";
42
+
43
+ // src/react/components/account/AccountDashboard.tsx
44
+ import { useEffect as useEffect6, useId as useId2, useState as useState11 } from "react";
45
+
46
+ // src/react/components/account/VerifyEmailBanner.tsx
47
+ import { useState } from "react";
48
+ import { jsx, jsxs } from "react/jsx-runtime";
49
+ var DISMISS_KEY = "throttle-auth:verify-banner-dismissed";
50
+ function readDismissed() {
51
+ try {
52
+ return sessionStorage.getItem(DISMISS_KEY) === "1";
53
+ } catch {
54
+ return false;
55
+ }
56
+ }
57
+ function writeDismissed() {
58
+ try {
59
+ sessionStorage.setItem(DISMISS_KEY, "1");
60
+ } catch {
61
+ }
62
+ }
63
+ function VerifyEmailBanner(props) {
64
+ const a = useAppearance(props.appearance);
65
+ const scoped = useAppearanceProviderValue(props.appearance);
66
+ const { t } = useCopy(props.localization);
67
+ const { auth, status, emailVerified } = useAuth();
68
+ const { submitting, notice, error, run } = useAction();
69
+ const [dismissed, setDismissed] = useState(readDismissed);
70
+ if (status !== "authenticated" || emailVerified || dismissed) return null;
71
+ return /* @__PURE__ */ jsx(AppearanceProvider, { value: scoped, children: /* @__PURE__ */ jsx("div", { ...a.rootProps, children: /* @__PURE__ */ jsxs("div", { ...a.el("verifyBanner.root", "throttle-banner"), children: [
72
+ /* @__PURE__ */ jsx("span", { ...a.el("verifyBanner.message"), children: t.verifyBanner.message }),
73
+ notice ? /* @__PURE__ */ jsx(Alert, { tone: "success", children: notice }) : null,
74
+ error ? /* @__PURE__ */ jsx(Alert, { tone: "error", children: error }) : null,
75
+ /* @__PURE__ */ jsxs("span", { className: "throttle-actions", children: [
76
+ /* @__PURE__ */ jsx(
77
+ Button,
78
+ {
79
+ variant: "secondary",
80
+ loading: submitting,
81
+ elementKey: "verifyBanner.resendButton",
82
+ onClick: () => void run(async () => {
83
+ await auth.resendVerification();
84
+ return t.verifyEmail.resentNotice;
85
+ }),
86
+ children: t.verifyBanner.resendButton
87
+ }
88
+ ),
89
+ /* @__PURE__ */ jsx(
90
+ Button,
91
+ {
92
+ variant: "link",
93
+ elementKey: "verifyBanner.dismissButton",
94
+ onClick: () => {
95
+ writeDismissed();
96
+ setDismissed(true);
97
+ },
98
+ children: t.verifyBanner.dismissButton
99
+ }
100
+ )
101
+ ] })
102
+ ] }) }) });
103
+ }
104
+
105
+ // src/react/components/account/icons.tsx
106
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
107
+ function Glyph(props) {
108
+ return /* @__PURE__ */ jsx2(
109
+ "svg",
110
+ {
111
+ className: "throttle-tabs__railicon",
112
+ width: "18",
113
+ height: "18",
114
+ viewBox: "0 0 24 24",
115
+ fill: "none",
116
+ stroke: "currentColor",
117
+ strokeWidth: "1.6",
118
+ strokeLinecap: "round",
119
+ strokeLinejoin: "round",
120
+ "aria-hidden": "true",
121
+ focusable: "false",
122
+ children: props.children
123
+ }
124
+ );
125
+ }
126
+ var ACCOUNT_ICONS = {
127
+ profile: /* @__PURE__ */ jsxs2(Glyph, { children: [
128
+ /* @__PURE__ */ jsx2("circle", { cx: "12", cy: "8", r: "4" }),
129
+ /* @__PURE__ */ jsx2("path", { d: "M4 21c0-4 3.6-6 8-6s8 2 8 6" })
130
+ ] }),
131
+ addresses: /* @__PURE__ */ jsxs2(Glyph, { children: [
132
+ /* @__PURE__ */ jsx2("path", { d: "M12 21s7-5.3 7-11a7 7 0 1 0-14 0c0 5.7 7 11 7 11Z" }),
133
+ /* @__PURE__ */ jsx2("circle", { cx: "12", cy: "10", r: "2.5" })
134
+ ] }),
135
+ paymentMethods: /* @__PURE__ */ jsxs2(Glyph, { children: [
136
+ /* @__PURE__ */ jsx2("rect", { x: "2.5", y: "5.5", width: "19", height: "13", rx: "2.5" }),
137
+ /* @__PURE__ */ jsx2("path", { d: "M2.5 10h19" })
138
+ ] }),
139
+ orders: /* @__PURE__ */ jsxs2(Glyph, { children: [
140
+ /* @__PURE__ */ jsx2("path", { d: "M4 7h16v13H4z" }),
141
+ /* @__PURE__ */ jsx2("path", { d: "M8 7V4h8v3" }),
142
+ /* @__PURE__ */ jsx2("path", { d: "M8 12h8" })
143
+ ] }),
144
+ invoices: /* @__PURE__ */ jsxs2(Glyph, { children: [
145
+ /* @__PURE__ */ jsx2("path", { d: "M6 3h12v18l-3-2-3 2-3-2-3 2Z" }),
146
+ /* @__PURE__ */ jsx2("path", { d: "M9 8h6M9 12h6" })
147
+ ] }),
148
+ subscriptions: /* @__PURE__ */ jsxs2(Glyph, { children: [
149
+ /* @__PURE__ */ jsx2("path", { d: "M3 12a9 9 0 0 1 15.5-6.2" }),
150
+ /* @__PURE__ */ jsx2("path", { d: "M21 12a9 9 0 0 1-15.5 6.2" }),
151
+ /* @__PURE__ */ jsx2("path", { d: "M18 3v4h-4M6 21v-4h4" })
152
+ ] }),
153
+ security: /* @__PURE__ */ jsxs2(Glyph, { children: [
154
+ /* @__PURE__ */ jsx2("path", { d: "M12 3 4 6.5V12c0 5 3.4 8.3 8 9 4.6-.7 8-4 8-9V6.5Z" }),
155
+ /* @__PURE__ */ jsx2("path", { d: "m9 12 2 2 4-4" })
156
+ ] })
157
+ };
158
+
159
+ // src/react/components/account/ProfilePanel.tsx
160
+ import { useEffect, useState as useState2, useRef } from "react";
161
+
162
+ // src/react/components/account/PanelState.tsx
163
+ import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
164
+ function PanelState(props) {
165
+ const { t, errorMessage } = useCopy();
166
+ const { data, isLoading, error, refetch } = props.resource;
167
+ const empty = props.isEmpty(data);
168
+ if (isLoading && empty) return /* @__PURE__ */ jsx3(Skeleton, { count: props.skeletonRows ?? 3 });
169
+ const errorBanner = error ? /* @__PURE__ */ jsxs3("div", { className: "throttle-stack", children: [
170
+ /* @__PURE__ */ jsx3(Alert, { tone: "error", children: errorMessage(error) }),
171
+ /* @__PURE__ */ jsx3(Button, { variant: "secondary", onClick: () => void refetch(), children: t.common.retry })
172
+ ] }) : null;
173
+ const gatedByVerification = error?.code === "verification_required";
174
+ if (gatedByVerification && empty) {
175
+ return /* @__PURE__ */ jsx3(EmptyState, { title: props.emptyTitle, description: props.gatedDescription ?? props.emptyDescription });
176
+ }
177
+ if (error && empty) return errorBanner;
178
+ if (empty) {
179
+ return props.gated ? /* @__PURE__ */ jsx3(EmptyState, { title: props.emptyTitle, description: props.gatedDescription }) : /* @__PURE__ */ jsx3(EmptyState, { title: props.emptyTitle, description: props.emptyDescription });
180
+ }
181
+ return /* @__PURE__ */ jsxs3(Fragment, { children: [
182
+ errorBanner,
183
+ props.children(data)
184
+ ] });
185
+ }
186
+
187
+ // src/react/components/account/ProfilePanel.tsx
188
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
189
+ function ProfilePanel(props) {
190
+ const a = useAppearance(props.appearance);
191
+ const scoped = useAppearanceProviderValue(props.appearance);
192
+ const { t } = useCopy(props.localization);
193
+ const { status } = useAuth();
194
+ const resource = useCustomer();
195
+ const { submitting, error, notice, run } = useAction();
196
+ const [form, setForm] = useState2({ firstName: "", lastName: "", phone: "", company: "" });
197
+ const edited = useRef(false);
198
+ useEffect(() => {
199
+ const c = resource.data;
200
+ if (!c || edited.current) return;
201
+ setForm({
202
+ firstName: c.firstName ?? "",
203
+ lastName: c.lastName ?? "",
204
+ phone: c.phone ?? "",
205
+ company: c.company ?? ""
206
+ });
207
+ }, [resource.data]);
208
+ if (status === "unauthenticated") return null;
209
+ return /* @__PURE__ */ jsx4(AppearanceProvider, { value: scoped, children: /* @__PURE__ */ jsx4("div", { ...a.rootProps, children: /* @__PURE__ */ jsx4("div", { ...a.el("profilePanel.root", "throttle-panel"), children: /* @__PURE__ */ jsx4(
210
+ PanelState,
211
+ {
212
+ resource,
213
+ isEmpty: (c) => c === null,
214
+ emptyTitle: t.common.somethingWentWrong,
215
+ skeletonRows: 4,
216
+ children: (customer) => /* @__PURE__ */ jsxs4(
217
+ "form",
218
+ {
219
+ ...a.el("profilePanel.form", "throttle-stack"),
220
+ onSubmit: (e) => {
221
+ e.preventDefault();
222
+ void run(async () => {
223
+ edited.current = false;
224
+ await resource.update({
225
+ firstName: form.firstName,
226
+ lastName: form.lastName,
227
+ phone: form.phone,
228
+ company: form.company || null
229
+ });
230
+ return t.profile.savedNotice;
231
+ });
232
+ },
233
+ children: [
234
+ /* @__PURE__ */ jsx4(
235
+ Field,
236
+ {
237
+ label: t.profile.email,
238
+ type: "email",
239
+ value: customer.email,
240
+ onChange: () => {
241
+ },
242
+ disabled: true,
243
+ hint: t.profile.emailReadOnly
244
+ }
245
+ ),
246
+ /* @__PURE__ */ jsxs4(FieldRow, { children: [
247
+ /* @__PURE__ */ jsx4(
248
+ Field,
249
+ {
250
+ label: t.profile.firstName,
251
+ value: form.firstName,
252
+ autoComplete: "given-name",
253
+ onChange: (v) => {
254
+ edited.current = true;
255
+ setForm((f) => ({ ...f, firstName: v }));
256
+ }
257
+ }
258
+ ),
259
+ /* @__PURE__ */ jsx4(
260
+ Field,
261
+ {
262
+ label: t.profile.lastName,
263
+ value: form.lastName,
264
+ autoComplete: "family-name",
265
+ onChange: (v) => {
266
+ edited.current = true;
267
+ setForm((f) => ({ ...f, lastName: v }));
268
+ }
269
+ }
270
+ )
271
+ ] }),
272
+ /* @__PURE__ */ jsxs4(FieldRow, { children: [
273
+ /* @__PURE__ */ jsx4(
274
+ Field,
275
+ {
276
+ label: t.profile.phone,
277
+ type: "tel",
278
+ value: form.phone,
279
+ autoComplete: "tel",
280
+ onChange: (v) => {
281
+ edited.current = true;
282
+ setForm((f) => ({ ...f, phone: v }));
283
+ }
284
+ }
285
+ ),
286
+ /* @__PURE__ */ jsx4(
287
+ Field,
288
+ {
289
+ label: t.profile.company,
290
+ value: form.company,
291
+ autoComplete: "organization",
292
+ onChange: (v) => {
293
+ edited.current = true;
294
+ setForm((f) => ({ ...f, company: v }));
295
+ }
296
+ }
297
+ )
298
+ ] }),
299
+ error ? /* @__PURE__ */ jsx4(Alert, { tone: "error", children: error }) : null,
300
+ notice ? /* @__PURE__ */ jsx4(Alert, { tone: "success", children: notice }) : null,
301
+ /* @__PURE__ */ jsx4(Button, { type: "submit", loading: submitting, elementKey: "profilePanel.submitButton", children: t.profile.saveButton })
302
+ ]
303
+ }
304
+ )
305
+ }
306
+ ) }) }) });
307
+ }
308
+
309
+ // src/react/components/account/AddressesPanel.tsx
310
+ import { useState as useState4 } from "react";
311
+
312
+ // src/react/components/account/AddressForm.tsx
313
+ import { useState as useState3 } from "react";
314
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
315
+ function AddressForm(props) {
316
+ const a = useAppearance();
317
+ const { t } = useCopy();
318
+ const i = props.initial;
319
+ const [form, setForm] = useState3({
320
+ label: i?.label ?? "",
321
+ firstName: i?.firstName ?? "",
322
+ lastName: i?.lastName ?? "",
323
+ company: i?.company ?? "",
324
+ addressLine1: i?.addressLine1 ?? "",
325
+ addressLine2: i?.addressLine2 ?? "",
326
+ city: i?.city ?? "",
327
+ stateProvince: i?.stateProvince ?? "",
328
+ postalCode: i?.postalCode ?? "",
329
+ countryCode: i?.countryCode ?? "",
330
+ phone: i?.phone ?? ""
331
+ });
332
+ const set = (key) => (value) => setForm((f) => ({ ...f, [key]: value }));
333
+ return /* @__PURE__ */ jsxs5(
334
+ "form",
335
+ {
336
+ ...a.el(props.elementKey ?? "addressesPanel.form", "throttle-stack"),
337
+ onSubmit: (e) => {
338
+ e.preventDefault();
339
+ props.onSubmit({
340
+ label: form.label || void 0,
341
+ firstName: form.firstName || void 0,
342
+ lastName: form.lastName || void 0,
343
+ company: form.company || void 0,
344
+ addressLine1: form.addressLine1,
345
+ addressLine2: form.addressLine2 || void 0,
346
+ city: form.city,
347
+ stateProvince: form.stateProvince || void 0,
348
+ postalCode: form.postalCode || void 0,
349
+ // The API wants ISO-3166 alpha-2; uppercase so "gb" is not rejected.
350
+ countryCode: form.countryCode.toUpperCase(),
351
+ phone: form.phone || void 0
352
+ });
353
+ },
354
+ children: [
355
+ /* @__PURE__ */ jsxs5(FieldRow, { children: [
356
+ props.hideLabel ? null : /* @__PURE__ */ jsx5(Field, { label: t.addresses.label, value: form.label, onChange: set("label") }),
357
+ /* @__PURE__ */ jsx5(Field, { label: t.addresses.company, value: form.company, onChange: set("company"), autoComplete: "organization" })
358
+ ] }),
359
+ /* @__PURE__ */ jsxs5(FieldRow, { children: [
360
+ /* @__PURE__ */ jsx5(Field, { label: t.addresses.firstName, value: form.firstName, onChange: set("firstName"), autoComplete: "given-name" }),
361
+ /* @__PURE__ */ jsx5(Field, { label: t.addresses.lastName, value: form.lastName, onChange: set("lastName"), autoComplete: "family-name" })
362
+ ] }),
363
+ /* @__PURE__ */ jsx5(
364
+ Field,
365
+ {
366
+ label: t.addresses.addressLine1,
367
+ value: form.addressLine1,
368
+ onChange: set("addressLine1"),
369
+ required: true,
370
+ autoComplete: "address-line1"
371
+ }
372
+ ),
373
+ /* @__PURE__ */ jsx5(
374
+ Field,
375
+ {
376
+ label: t.addresses.addressLine2,
377
+ value: form.addressLine2,
378
+ onChange: set("addressLine2"),
379
+ autoComplete: "address-line2"
380
+ }
381
+ ),
382
+ /* @__PURE__ */ jsxs5(FieldRow, { children: [
383
+ /* @__PURE__ */ jsx5(Field, { label: t.addresses.city, value: form.city, onChange: set("city"), required: true, autoComplete: "address-level2" }),
384
+ /* @__PURE__ */ jsx5(
385
+ Field,
386
+ {
387
+ label: t.addresses.stateProvince,
388
+ value: form.stateProvince,
389
+ onChange: set("stateProvince"),
390
+ autoComplete: "address-level1"
391
+ }
392
+ )
393
+ ] }),
394
+ /* @__PURE__ */ jsxs5(FieldRow, { children: [
395
+ /* @__PURE__ */ jsx5(
396
+ Field,
397
+ {
398
+ label: t.addresses.postalCode,
399
+ value: form.postalCode,
400
+ onChange: set("postalCode"),
401
+ autoComplete: "postal-code"
402
+ }
403
+ ),
404
+ /* @__PURE__ */ jsx5(
405
+ Field,
406
+ {
407
+ label: t.addresses.countryCode,
408
+ value: form.countryCode,
409
+ onChange: set("countryCode"),
410
+ required: true,
411
+ autoComplete: "country",
412
+ hint: "ISO 3166-1 alpha-2, e.g. GB"
413
+ }
414
+ )
415
+ ] }),
416
+ /* @__PURE__ */ jsx5(Field, { label: t.addresses.phone, type: "tel", value: form.phone, onChange: set("phone"), autoComplete: "tel" }),
417
+ props.error ? /* @__PURE__ */ jsx5(Alert, { tone: "error", children: props.error }) : null,
418
+ /* @__PURE__ */ jsxs5("div", { className: "throttle-actions", children: [
419
+ /* @__PURE__ */ jsx5(Button, { type: "submit", loading: props.submitting, children: t.common.save }),
420
+ /* @__PURE__ */ jsx5(Button, { variant: "link", onClick: props.onCancel, children: t.common.cancel })
421
+ ] })
422
+ ]
423
+ }
424
+ );
425
+ }
426
+
427
+ // src/react/components/account/AddressesPanel.tsx
428
+ import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
429
+ function AddressesPanel(props) {
430
+ const a = useAppearance(props.appearance);
431
+ const scoped = useAppearanceProviderValue(props.appearance);
432
+ const { t } = useCopy(props.localization);
433
+ const resource = useAddresses();
434
+ const { submitting, error, run } = useAction();
435
+ const confirm = useConfirm();
436
+ const [editing, setEditing] = useState4(null);
437
+ const variant = props.variant ?? "rows";
438
+ const rowsVariant = variant === "rows";
439
+ const listBase = rowsVariant ? "throttle-rows" : "throttle-stack";
440
+ const itemBase = rowsVariant ? "throttle-rowitem" : "throttle-listitem";
441
+ const actionVariant = (base) => rowsVariant ? base === "danger" ? "linkDanger" : "link" : base;
442
+ const close = () => setEditing(null);
443
+ const formatAddress = (address) => [address.addressLine2, address.city, address.stateProvince, address.postalCode, address.countryCode].filter(Boolean).join(", ");
444
+ return /* @__PURE__ */ jsx6(AppearanceProvider, { value: scoped, children: /* @__PURE__ */ jsx6("div", { ...a.rootProps, children: /* @__PURE__ */ jsxs6("div", { ...a.el("addressesPanel.root", "throttle-panel"), children: [
445
+ !editing && error ? /* @__PURE__ */ jsx6(Alert, { tone: "error", children: error }) : null,
446
+ editing ? /* @__PURE__ */ jsx6(
447
+ AddressForm,
448
+ {
449
+ initial: editing === "new" ? void 0 : editing,
450
+ submitting,
451
+ error,
452
+ onCancel: close,
453
+ onSubmit: (input) => void run(async () => {
454
+ if (editing === "new") await resource.create(input);
455
+ else await resource.update(editing.id, input);
456
+ close();
457
+ })
458
+ }
459
+ ) : /* @__PURE__ */ jsxs6(Fragment2, { children: [
460
+ /* @__PURE__ */ jsx6("div", { children: /* @__PURE__ */ jsx6(Button, { elementKey: "addressesPanel.addButton", variant: "secondary", onClick: () => setEditing("new"), children: t.addresses.addButton }) }),
461
+ /* @__PURE__ */ jsx6(
462
+ PanelState,
463
+ {
464
+ resource,
465
+ isEmpty: (rows) => rows.length === 0,
466
+ emptyTitle: t.addresses.empty,
467
+ emptyDescription: t.addresses.emptyDescription,
468
+ children: (rows) => variant === "table" ? /* @__PURE__ */ jsx6(
469
+ DataTable,
470
+ {
471
+ tableKey: "addressesPanel.table",
472
+ rowElementKey: "addressesPanel.row",
473
+ rowKey: (address) => address.id,
474
+ rows,
475
+ columns: [
476
+ { key: "label", label: t.addresses.label, render: (address) => address.label || address.addressLine1 },
477
+ { key: "address", label: t.addresses.columnAddress, render: (address) => /* @__PURE__ */ jsxs6(Fragment2, { children: [
478
+ address.addressLine1,
479
+ formatAddress(address) ? `, ${formatAddress(address)}` : ""
480
+ ] }) },
481
+ { key: "default", label: t.addresses.defaultBadge, render: (address) => address.isDefault ? /* @__PURE__ */ jsx6(Badge, { tone: "success", children: t.addresses.defaultBadge }) : null },
482
+ { key: "actions", label: t.common.actions, render: (address) => /* @__PURE__ */ jsxs6("div", { className: "throttle-actions", children: [
483
+ !address.isDefault ? /* @__PURE__ */ jsx6(
484
+ Button,
485
+ {
486
+ variant: "secondary",
487
+ elementKey: "addressesPanel.defaultButton",
488
+ onClick: () => void run(() => resource.update(address.id, { isDefault: true })),
489
+ children: t.addresses.makeDefault
490
+ }
491
+ ) : null,
492
+ /* @__PURE__ */ jsx6(
493
+ Button,
494
+ {
495
+ variant: "secondary",
496
+ elementKey: "addressesPanel.editButton",
497
+ onClick: () => setEditing(address),
498
+ children: t.common.edit
499
+ }
500
+ ),
501
+ /* @__PURE__ */ jsx6(
502
+ Button,
503
+ {
504
+ variant: "danger",
505
+ elementKey: "addressesPanel.deleteButton",
506
+ disabled: submitting,
507
+ onClick: async () => {
508
+ if (!await confirm({ title: t.addresses.deleteConfirm, confirmLabel: t.addresses.deleteConfirmAction, tone: "danger" })) return;
509
+ void run(() => resource.remove(address.id));
510
+ },
511
+ children: t.common.delete
512
+ }
513
+ )
514
+ ] }) }
515
+ ]
516
+ }
517
+ ) : /* @__PURE__ */ jsx6("div", { ...a.el("addressesPanel.list", listBase), children: rows.map((address) => /* @__PURE__ */ jsxs6("div", { ...a.el("addressesPanel.item", itemBase), children: [
518
+ /* @__PURE__ */ jsxs6("div", { children: [
519
+ /* @__PURE__ */ jsxs6("div", { className: "throttle-row", children: [
520
+ /* @__PURE__ */ jsx6("strong", { children: address.label || address.addressLine1 }),
521
+ address.isDefault ? /* @__PURE__ */ jsx6(Badge, { tone: "success", children: t.addresses.defaultBadge }) : null
522
+ ] }),
523
+ /* @__PURE__ */ jsx6("p", { className: "throttle-muted", children: address.addressLine1 }),
524
+ /* @__PURE__ */ jsx6("p", { className: "throttle-muted", children: formatAddress(address) })
525
+ ] }),
526
+ /* @__PURE__ */ jsxs6("div", { className: "throttle-actions", children: [
527
+ !address.isDefault ? /* @__PURE__ */ jsx6(
528
+ Button,
529
+ {
530
+ variant: actionVariant("secondary"),
531
+ elementKey: "addressesPanel.defaultButton",
532
+ onClick: () => void run(() => resource.update(address.id, { isDefault: true })),
533
+ children: t.addresses.makeDefault
534
+ }
535
+ ) : null,
536
+ /* @__PURE__ */ jsx6(
537
+ Button,
538
+ {
539
+ variant: actionVariant("secondary"),
540
+ elementKey: "addressesPanel.editButton",
541
+ onClick: () => setEditing(address),
542
+ children: t.common.edit
543
+ }
544
+ ),
545
+ /* @__PURE__ */ jsx6(
546
+ Button,
547
+ {
548
+ variant: actionVariant("danger"),
549
+ elementKey: "addressesPanel.deleteButton",
550
+ disabled: submitting,
551
+ onClick: async () => {
552
+ if (!await confirm({ title: t.addresses.deleteConfirm, confirmLabel: t.addresses.deleteConfirmAction, tone: "danger" })) return;
553
+ void run(() => resource.remove(address.id));
554
+ },
555
+ children: t.common.delete
556
+ }
557
+ )
558
+ ] })
559
+ ] }, address.id)) })
560
+ }
561
+ )
562
+ ] })
563
+ ] }) }) });
564
+ }
565
+
566
+ // src/react/components/account/PaymentMethodsPanel.tsx
567
+ import { useState as useState6 } from "react";
568
+
569
+ // src/react/components/account/AddCardDialog.tsx
570
+ import { useEffect as useEffect2, useId, useRef as useRef2, useState as useState5 } from "react";
571
+ import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
572
+ function AddCardDialog(props) {
573
+ const { account } = useAuth();
574
+ const titleId = useId();
575
+ const { t } = useCopy(props.localization);
576
+ const [src, setSrc] = useState5(null);
577
+ const [error, setError] = useState5(null);
578
+ const [busy, setBusy] = useState5(false);
579
+ const onAdded = useRef2(props.onAdded);
580
+ const onClose = useRef2(props.onClose);
581
+ onAdded.current = props.onAdded;
582
+ onClose.current = props.onClose;
583
+ useEffect2(() => {
584
+ if (!props.open) {
585
+ setSrc(null);
586
+ setError(null);
587
+ return;
588
+ }
589
+ let live = true;
590
+ setError(null);
591
+ account.startCardSetup().then(
592
+ (session) => {
593
+ if (!live) return;
594
+ let url = session.embedUrl;
595
+ try {
596
+ const u = new URL(session.embedUrl, window.location.origin);
597
+ u.searchParams.set("parentOrigin", window.location.origin);
598
+ url = u.toString();
599
+ } catch {
600
+ }
601
+ setSrc(url);
602
+ },
603
+ (err) => {
604
+ if (live) setError(messageForError(err));
605
+ }
606
+ );
607
+ return () => {
608
+ live = false;
609
+ };
610
+ }, [props.open, account]);
611
+ useEffect2(() => {
612
+ if (!src) return;
613
+ const frameOrigin = (() => {
614
+ try {
615
+ return new URL(src).origin;
616
+ } catch {
617
+ return null;
618
+ }
619
+ })();
620
+ if (!frameOrigin) return;
621
+ async function onMessage(event) {
622
+ if (event.origin !== frameOrigin) return;
623
+ const data = event.data;
624
+ if (!data || typeof data.type !== "string") return;
625
+ if (data.type === "throttle.completed" && data.paymentId) {
626
+ setBusy(true);
627
+ try {
628
+ await account.confirmCardSetup(data.paymentId);
629
+ onAdded.current();
630
+ onClose.current();
631
+ } catch (err) {
632
+ setError(messageForError(err));
633
+ } finally {
634
+ setBusy(false);
635
+ }
636
+ } else if (data.type === "throttle.error") {
637
+ setError(data.message || t.common.somethingWentWrong);
638
+ } else if (data.type === "throttle.cancelled") {
639
+ onClose.current();
640
+ }
641
+ }
642
+ window.addEventListener("message", onMessage);
643
+ return () => window.removeEventListener("message", onMessage);
644
+ }, [src, account, t]);
645
+ if (!props.open) return null;
646
+ return /* @__PURE__ */ jsxs7(Modal, { open: true, onClose: props.onClose, labelledBy: titleId, children: [
647
+ /* @__PURE__ */ jsx7("div", { className: "throttle-modal__header", children: /* @__PURE__ */ jsx7("h2", { id: titleId, className: "throttle-modal__title", children: t.paymentMethods.addTitle }) }),
648
+ /* @__PURE__ */ jsxs7("div", { className: "throttle-modal__body", children: [
649
+ error ? /* @__PURE__ */ jsx7(Alert, { tone: "error", children: error }) : null,
650
+ busy ? /* @__PURE__ */ jsx7("div", { className: "throttle-centre", children: /* @__PURE__ */ jsx7(Spinner, {}) }) : src ? /* @__PURE__ */ jsx7(
651
+ "iframe",
652
+ {
653
+ className: "throttle-cardframe",
654
+ src,
655
+ title: t.paymentMethods.addTitle,
656
+ sandbox: "allow-scripts allow-forms allow-same-origin"
657
+ }
658
+ ) : !error ? /* @__PURE__ */ jsx7("div", { className: "throttle-centre", children: /* @__PURE__ */ jsx7(Spinner, {}) }) : null
659
+ ] })
660
+ ] });
661
+ }
662
+
663
+ // src/react/components/account/PaymentMethodsPanel.tsx
664
+ import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
665
+ function PaymentMethodsPanel(props) {
666
+ const a = useAppearance(props.appearance);
667
+ const scoped = useAppearanceProviderValue(props.appearance);
668
+ const { t } = useCopy(props.localization);
669
+ const { emailVerified } = useAuth();
670
+ const resource = useSavedCards();
671
+ const { submitting, error, run } = useAction();
672
+ const confirm = useConfirm();
673
+ const [adding, setAdding] = useState6(false);
674
+ const variant = props.variant ?? "rows";
675
+ const rowsVariant = variant === "rows";
676
+ const listBase = rowsVariant ? "throttle-rows" : "throttle-stack";
677
+ const itemBase = rowsVariant ? "throttle-rowitem" : "throttle-listitem";
678
+ const actionVariant = (base) => rowsVariant ? base === "danger" ? "linkDanger" : "link" : base;
679
+ const cardLabel = (card) => `${(card.cardBrand ?? card.methodType).toUpperCase()} \u2022\u2022\u2022\u2022 ${card.cardLastFour ?? "____"}`;
680
+ const expiryLabel = (card) => card.cardExpMonth && card.cardExpYear ? `${String(card.cardExpMonth).padStart(2, "0")}/${card.cardExpYear}` : "";
681
+ return /* @__PURE__ */ jsx8(AppearanceProvider, { value: scoped, children: /* @__PURE__ */ jsx8("div", { ...a.rootProps, children: /* @__PURE__ */ jsxs8("div", { ...a.el("paymentMethodsPanel.root", "throttle-panel"), children: [
682
+ error ? /* @__PURE__ */ jsx8(Alert, { tone: "error", children: error }) : null,
683
+ emailVerified ? /* @__PURE__ */ jsx8("div", { children: /* @__PURE__ */ jsx8(Button, { elementKey: "paymentMethodsPanel.addButton", variant: "secondary", onClick: () => setAdding(true), children: t.paymentMethods.addButton }) }) : null,
684
+ /* @__PURE__ */ jsx8(
685
+ AddCardDialog,
686
+ {
687
+ open: adding,
688
+ onClose: () => setAdding(false),
689
+ onAdded: () => {
690
+ void resource.refetch();
691
+ },
692
+ localization: props.localization
693
+ }
694
+ ),
695
+ /* @__PURE__ */ jsx8(
696
+ PanelState,
697
+ {
698
+ resource,
699
+ gated: !emailVerified,
700
+ gatedDescription: t.paymentMethods.gatedDescription,
701
+ isEmpty: (rows) => rows.length === 0,
702
+ emptyTitle: t.paymentMethods.empty,
703
+ emptyDescription: t.paymentMethods.emptyDescription,
704
+ children: (rows) => variant === "table" ? /* @__PURE__ */ jsx8(
705
+ DataTable,
706
+ {
707
+ tableKey: "paymentMethodsPanel.table",
708
+ rowElementKey: "paymentMethodsPanel.row",
709
+ rowKey: (card) => card.id,
710
+ rows,
711
+ columns: [
712
+ { key: "card", label: t.paymentMethods.columnCard, render: (card) => cardLabel(card) },
713
+ { key: "expires", label: t.paymentMethods.expires, render: (card) => expiryLabel(card) },
714
+ { key: "default", label: t.paymentMethods.defaultBadge, render: (card) => card.isDefault ? /* @__PURE__ */ jsx8(Badge, { tone: "success", children: t.paymentMethods.defaultBadge }) : null },
715
+ { key: "actions", label: t.common.actions, render: (card) => /* @__PURE__ */ jsxs8("div", { className: "throttle-actions", children: [
716
+ !card.isDefault ? /* @__PURE__ */ jsx8(
717
+ Button,
718
+ {
719
+ variant: "secondary",
720
+ loading: submitting,
721
+ elementKey: "paymentMethodsPanel.defaultButton",
722
+ onClick: () => void run(() => resource.setDefault(card.id)),
723
+ children: t.paymentMethods.makeDefault
724
+ }
725
+ ) : null,
726
+ /* @__PURE__ */ jsx8(
727
+ Button,
728
+ {
729
+ variant: "danger",
730
+ elementKey: "paymentMethodsPanel.deleteButton",
731
+ disabled: submitting,
732
+ onClick: async () => {
733
+ if (!await confirm({ title: t.paymentMethods.deleteConfirm, confirmLabel: t.paymentMethods.deleteConfirmAction, tone: "danger" })) return;
734
+ void run(() => resource.remove(card.id));
735
+ },
736
+ children: t.common.delete
737
+ }
738
+ )
739
+ ] }) }
740
+ ]
741
+ }
742
+ ) : /* @__PURE__ */ jsx8("div", { ...a.el("paymentMethodsPanel.list", listBase), children: rows.map((card) => /* @__PURE__ */ jsxs8("div", { ...a.el("paymentMethodsPanel.item", itemBase), children: [
743
+ /* @__PURE__ */ jsxs8("div", { children: [
744
+ /* @__PURE__ */ jsxs8("div", { className: "throttle-row", children: [
745
+ /* @__PURE__ */ jsx8("strong", { children: cardLabel(card) }),
746
+ card.isDefault ? /* @__PURE__ */ jsx8(Badge, { tone: "success", children: t.paymentMethods.defaultBadge }) : null
747
+ ] }),
748
+ card.cardExpMonth && card.cardExpYear ? /* @__PURE__ */ jsxs8("p", { className: "throttle-muted", children: [
749
+ t.paymentMethods.expires,
750
+ " ",
751
+ String(card.cardExpMonth).padStart(2, "0"),
752
+ "/",
753
+ card.cardExpYear
754
+ ] }) : null
755
+ ] }),
756
+ /* @__PURE__ */ jsxs8("div", { className: "throttle-actions", children: [
757
+ !card.isDefault ? /* @__PURE__ */ jsx8(
758
+ Button,
759
+ {
760
+ variant: actionVariant("secondary"),
761
+ loading: submitting,
762
+ elementKey: "paymentMethodsPanel.defaultButton",
763
+ onClick: () => void run(() => resource.setDefault(card.id)),
764
+ children: t.paymentMethods.makeDefault
765
+ }
766
+ ) : null,
767
+ /* @__PURE__ */ jsx8(
768
+ Button,
769
+ {
770
+ variant: actionVariant("danger"),
771
+ elementKey: "paymentMethodsPanel.deleteButton",
772
+ disabled: submitting,
773
+ onClick: async () => {
774
+ if (!await confirm({ title: t.paymentMethods.deleteConfirm, confirmLabel: t.paymentMethods.deleteConfirmAction, tone: "danger" })) return;
775
+ void run(() => resource.remove(card.id));
776
+ },
777
+ children: t.common.delete
778
+ }
779
+ )
780
+ ] })
781
+ ] }, card.id)) })
782
+ }
783
+ )
784
+ ] }) }) });
785
+ }
786
+
787
+ // src/react/components/account/OrdersPanel.tsx
788
+ import { useEffect as useEffect3, useState as useState7 } from "react";
789
+
790
+ // src/react/components/format.ts
791
+ function formatMoney(minorUnits, currency, locale) {
792
+ const code = (currency || "USD").toUpperCase();
793
+ let digits = 2;
794
+ try {
795
+ digits = new Intl.NumberFormat("en-US", { style: "currency", currency: code }).resolvedOptions().maximumFractionDigits ?? 2;
796
+ } catch {
797
+ }
798
+ const major = minorUnits / 10 ** digits;
799
+ try {
800
+ return new Intl.NumberFormat(locale, { style: "currency", currency: code }).format(major);
801
+ } catch {
802
+ try {
803
+ return new Intl.NumberFormat("en-US", { style: "currency", currency: code }).format(major);
804
+ } catch {
805
+ return `${code} ${major.toFixed(digits)}`;
806
+ }
807
+ }
808
+ }
809
+ function formatDate(value, locale) {
810
+ const date = value instanceof Date ? value : new Date(value);
811
+ if (Number.isNaN(date.getTime())) return "";
812
+ try {
813
+ return new Intl.DateTimeFormat(locale, { dateStyle: "medium" }).format(date);
814
+ } catch {
815
+ return date.toISOString().slice(0, 10);
816
+ }
817
+ }
818
+ function scheduleDueLabel(row, locale) {
819
+ if (row.intervalUnit !== "hour") return formatDate(row.dueAt, locale);
820
+ const date = new Date(row.dueAt);
821
+ if (Number.isNaN(date.getTime())) return "";
822
+ const opts = {
823
+ dateStyle: "medium",
824
+ timeStyle: "short",
825
+ timeZone: "UTC"
826
+ };
827
+ try {
828
+ return `${new Intl.DateTimeFormat(locale, opts).format(date)} UTC`;
829
+ } catch {
830
+ return `${new Intl.DateTimeFormat("en-US", opts).format(date)} UTC`;
831
+ }
832
+ }
833
+
834
+ // src/react/components/account/OrderStatus.tsx
835
+ import { Fragment as Fragment3, jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
836
+ function copyKey(wire) {
837
+ return wire.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
838
+ }
839
+ var ATTENTION_PAYMENT_STATES = /* @__PURE__ */ new Set(["pending", "failed", "disputed", "expired"]);
840
+ var TERMINAL_STATUSES = /* @__PURE__ */ new Set(["cancelled", "closed", "void", "expired", "voided"]);
841
+ function StatusBadge(props) {
842
+ const label = props.labels[copyKey(props.status)] ?? props.status.replace(/_/g, " ");
843
+ return /* @__PURE__ */ jsx9(Badge, { tone: TERMINAL_STATUSES.has(props.status) ? "muted" : "neutral", children: label });
844
+ }
845
+ function OrderStatus(props) {
846
+ const labels = props.t.orders.statusLabels;
847
+ const payLabels = props.t.orders.paymentLabels;
848
+ const lifecycle = labels[copyKey(props.status)] ?? props.status.replace(/_/g, " ");
849
+ const money = props.paymentStatus ? payLabels[copyKey(props.paymentStatus)] : void 0;
850
+ return /* @__PURE__ */ jsxs9(Fragment3, { children: [
851
+ /* @__PURE__ */ jsx9(Badge, { tone: TERMINAL_STATUSES.has(props.status) ? "muted" : "neutral", children: lifecycle }),
852
+ money ? /* @__PURE__ */ jsx9(Badge, { tone: ATTENTION_PAYMENT_STATES.has(props.paymentStatus) ? "warning" : "neutral", children: money }) : null
853
+ ] });
854
+ }
855
+
856
+ // src/react/components/account/AddressBlock.tsx
857
+ import { jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
858
+ function addressLines(address) {
859
+ if (!address || typeof address !== "object") return [];
860
+ const a = address;
861
+ const str = (k) => typeof a[k] === "string" && a[k].trim() ? a[k].trim() : null;
862
+ const name = [str("firstName"), str("lastName")].filter(Boolean).join(" ");
863
+ const cityLine = [str("city"), str("stateProvince"), str("postalCode")].filter(Boolean).join(", ");
864
+ return [
865
+ name || null,
866
+ str("company"),
867
+ str("addressLine1") ?? str("line1"),
868
+ str("addressLine2") ?? str("line2"),
869
+ cityLine || null,
870
+ str("countryCode") ?? str("country")
871
+ ].filter((l) => Boolean(l));
872
+ }
873
+ function AddressBlock(props) {
874
+ const a = useAppearance();
875
+ const lines = addressLines(props.address);
876
+ if (lines.length === 0) return null;
877
+ return /* @__PURE__ */ jsxs10("div", { ...a.el(props.elementKey ?? "orderDetail.address", "throttle-addressblock"), children: [
878
+ /* @__PURE__ */ jsx10("h4", { className: "throttle-section__title", children: props.heading }),
879
+ lines.map((l) => /* @__PURE__ */ jsx10("p", { className: "throttle-addressblock__line throttle-muted", children: l }, l))
880
+ ] });
881
+ }
882
+
883
+ // src/react/components/account/OrderTimeline.tsx
884
+ import { jsx as jsx11, jsxs as jsxs11 } from "react/jsx-runtime";
885
+ function orderTimeline(order, labels) {
886
+ const entries = [{ label: labels.placed, at: order.createdAt }];
887
+ if (order.completedAt) entries.push({ label: labels.completed, at: order.completedAt });
888
+ if (order.cancelledAt) entries.push({ label: labels.cancelled, at: order.cancelledAt });
889
+ if (order.closedAt) entries.push({ label: labels.closed, at: order.closedAt });
890
+ return entries.sort((x, y) => new Date(x.at).getTime() - new Date(y.at).getTime());
891
+ }
892
+ function OrderTimeline(props) {
893
+ const a = useAppearance();
894
+ if (props.entries.length <= 1) return null;
895
+ return /* @__PURE__ */ jsxs11("div", { ...a.el("orderDetail.timeline", "throttle-timeline"), children: [
896
+ /* @__PURE__ */ jsx11("h4", { className: "throttle-section__title", children: props.heading }),
897
+ props.entries.map((e) => /* @__PURE__ */ jsxs11("div", { className: "throttle-timeline__row", children: [
898
+ /* @__PURE__ */ jsx11("span", { className: "throttle-timeline__dot", "aria-hidden": "true" }),
899
+ /* @__PURE__ */ jsx11("span", { className: "throttle-timeline__label", children: e.label }),
900
+ /* @__PURE__ */ jsx11("span", { className: "throttle-muted", children: formatDate(e.at, props.locale) })
901
+ ] }, `${e.label}-${e.at}`))
902
+ ] });
903
+ }
904
+
905
+ // src/react/components/account/order-subscription-links.ts
906
+ function orderSubscriptionLinks(order, labels) {
907
+ const ids = order.subscriptionIds?.length ? order.subscriptionIds : order.subscriptionId ? [order.subscriptionId] : [];
908
+ if (ids.length === 1) return [{ id: ids[0], label: labels.single }];
909
+ return ids.map((id, index) => {
910
+ const name = order.lineItems.find((li) => li.subscriptionId === id)?.name;
911
+ return { id, label: name ? `${labels.named} ${name}` : `${labels.single} ${index + 1}` };
912
+ });
913
+ }
914
+
915
+ // src/react/components/account/OrderDetail.tsx
916
+ import { jsx as jsx12, jsxs as jsxs12 } from "react/jsx-runtime";
917
+ var CAN_PAY = /* @__PURE__ */ new Set(["draft", "pending"]);
918
+ var CAN_REORDER = /* @__PURE__ */ new Set(["fulfilled", "cancelled", "closed"]);
919
+ var CAN_CANCEL = /* @__PURE__ */ new Set(["draft", "pending", "processing"]);
920
+ var REORDER_PAID_PAYMENT = /* @__PURE__ */ new Set(["captured", "paid"]);
921
+ var SETTLED_PAYMENT = /* @__PURE__ */ new Set(["captured", "paid", "partially_refunded", "refunded"]);
922
+ var CAN_RETURN = /* @__PURE__ */ new Set(["fulfilled", "partially_fulfilled", "closed"]);
923
+ function Line(props) {
924
+ return /* @__PURE__ */ jsxs12("div", { className: "throttle-row", children: [
925
+ /* @__PURE__ */ jsx12("span", { className: "throttle-muted", children: props.label }),
926
+ /* @__PURE__ */ jsx12("span", { children: props.strong ? /* @__PURE__ */ jsx12("strong", { children: props.value }) : props.value })
927
+ ] });
928
+ }
929
+ function OrderDetail(props) {
930
+ const a = useAppearance(props.appearance);
931
+ const scoped = useAppearanceProviderValue(props.appearance);
932
+ const { t, locale } = useCopy(props.localization);
933
+ const { account } = useAuth();
934
+ const resource = useOrder(props.orderId);
935
+ const { submitting, error, run } = useAction();
936
+ const confirm = useConfirm();
937
+ const allowCancel = props.allowCancel ?? true;
938
+ const allowReturn = props.allowReturn ?? true;
939
+ return /* @__PURE__ */ jsx12(AppearanceProvider, { value: scoped, children: /* @__PURE__ */ jsx12("div", { ...a.rootProps, children: /* @__PURE__ */ jsxs12("div", { ...a.el("orderDetail.root", "throttle-panel"), children: [
940
+ props.onBack ? (
941
+ // Wrapped on purpose. The panel is a column flex container, so a
942
+ // direct child stretches to its full width however `width: auto`
943
+ // the link variant is — the control rendered 748px wide with a
944
+ // centred label. The wrapper takes the stretch; the button keeps
945
+ // its own width. A CSS fix would need a compound selector, and
946
+ // those outrank the merchant overrides in `appearance.elements`.
947
+ /* @__PURE__ */ jsx12("div", { children: /* @__PURE__ */ jsx12(Button, { variant: "link", elementKey: "orderDetail.backButton", onClick: props.onBack, children: t.common.back }) })
948
+ ) : null,
949
+ error ? /* @__PURE__ */ jsx12(Alert, { tone: "error", children: error }) : null,
950
+ /* @__PURE__ */ jsx12(
951
+ PanelState,
952
+ {
953
+ resource,
954
+ isEmpty: (o) => o === null,
955
+ emptyTitle: t.orders.empty,
956
+ skeletonRows: 5,
957
+ children: (order) => {
958
+ const target = {
959
+ id: order.id,
960
+ orderNumber: order.orderNumber,
961
+ currency: order.currency,
962
+ lineItems: order.lineItems.map((li) => ({
963
+ name: li.name,
964
+ unitPrice: li.unitPrice,
965
+ quantity: li.quantity,
966
+ sku: li.referenceId ?? null,
967
+ subscriptionId: li.subscriptionId ?? null
968
+ }))
969
+ };
970
+ const money = (v) => formatMoney(v, order.currency, locale);
971
+ const paid = SETTLED_PAYMENT.has(order.paymentStatus);
972
+ const showCancel = allowCancel && CAN_CANCEL.has(order.status) && !paid;
973
+ const showReorder = !!props.onReorder && (CAN_REORDER.has(order.status) || !!props.reorderOnPaid && REORDER_PAID_PAYMENT.has(order.paymentStatus));
974
+ const showReturn = allowReturn && CAN_RETURN.has(order.status);
975
+ return /* @__PURE__ */ jsxs12("div", { ...a.el("orderDetail.layout", "throttle-detail"), children: [
976
+ /* @__PURE__ */ jsxs12("div", { ...a.el("orderDetail.main", "throttle-detail__main"), children: [
977
+ /* @__PURE__ */ jsxs12("div", { className: "throttle-detail__section", children: [
978
+ /* @__PURE__ */ jsxs12("div", { className: "throttle-row", children: [
979
+ /* @__PURE__ */ jsx12("h3", { children: order.orderNumber }),
980
+ /* @__PURE__ */ jsx12(OrderStatus, { status: order.status, paymentStatus: order.paymentStatus, t })
981
+ ] }),
982
+ /* @__PURE__ */ jsx12("p", { className: "throttle-muted", children: formatDate(order.createdAt, locale) })
983
+ ] }),
984
+ /* @__PURE__ */ jsxs12("div", { className: "throttle-detail__section", children: [
985
+ /* @__PURE__ */ jsx12("span", { className: "throttle-detail__label", children: t.orders.items }),
986
+ /* @__PURE__ */ jsx12("div", { ...a.el("orderDetail.lineItems", "throttle-stack"), children: order.lineItems.map((item) => /* @__PURE__ */ jsxs12("div", { ...a.el("orderDetail.lineItem", "throttle-lineitem"), children: [
987
+ item.imageUrl ? /* @__PURE__ */ jsx12("img", { className: "throttle-lineitem__image", src: item.imageUrl, alt: "" }) : null,
988
+ /* @__PURE__ */ jsxs12("div", { style: { flex: 1 }, children: [
989
+ /* @__PURE__ */ jsx12("strong", { children: item.name }),
990
+ item.description ? /* @__PURE__ */ jsx12("p", { className: "throttle-lineitem__desc", children: item.description }) : null,
991
+ /* @__PURE__ */ jsxs12("p", { className: "throttle-lineitem__meta", children: [
992
+ t.orders.quantity,
993
+ " ",
994
+ item.quantity,
995
+ " \xD7 ",
996
+ money(item.unitPrice)
997
+ ] })
998
+ ] }),
999
+ /* @__PURE__ */ jsx12("span", { children: money(item.total) })
1000
+ ] }, item.id)) })
1001
+ ] }),
1002
+ /* @__PURE__ */ jsx12(
1003
+ OrderTimeline,
1004
+ {
1005
+ heading: t.orders.history,
1006
+ locale,
1007
+ entries: orderTimeline(order, {
1008
+ placed: t.orders.placed,
1009
+ completed: t.orders.completed,
1010
+ cancelled: t.orders.cancelledAt,
1011
+ closed: t.orders.closedAt
1012
+ })
1013
+ }
1014
+ ),
1015
+ /* @__PURE__ */ jsxs12("div", { ...a.el("orderDetail.addresses", "throttle-addresses"), children: [
1016
+ /* @__PURE__ */ jsx12(
1017
+ AddressBlock,
1018
+ {
1019
+ heading: t.orders.shipTo,
1020
+ address: order.shippingAddress,
1021
+ elementKey: "orderDetail.shippingAddress"
1022
+ }
1023
+ ),
1024
+ /* @__PURE__ */ jsx12(
1025
+ AddressBlock,
1026
+ {
1027
+ heading: t.orders.billTo,
1028
+ address: order.billingAddress,
1029
+ elementKey: "orderDetail.billingAddress"
1030
+ }
1031
+ )
1032
+ ] })
1033
+ ] }),
1034
+ /* @__PURE__ */ jsxs12("aside", { ...a.el("orderDetail.rail", "throttle-detail__rail"), children: [
1035
+ /* @__PURE__ */ jsxs12("div", { className: "throttle-detail__section", children: [
1036
+ /* @__PURE__ */ jsx12("span", { className: "throttle-detail__label", children: t.orders.total }),
1037
+ /* @__PURE__ */ jsx12("span", { className: "throttle-detail__headline", children: money(order.total) })
1038
+ ] }),
1039
+ /* @__PURE__ */ jsxs12("div", { ...a.el("orderDetail.totals", "throttle-totals"), children: [
1040
+ /* @__PURE__ */ jsx12(Line, { label: t.orders.subtotal, value: money(order.subtotal) }),
1041
+ order.discountTotal ? /* @__PURE__ */ jsx12(Line, { label: t.orders.discount, value: money(-order.discountTotal) }) : null,
1042
+ /* @__PURE__ */ jsx12(Line, { label: t.orders.shipping, value: money(order.shippingTotal) }),
1043
+ /* @__PURE__ */ jsx12(Line, { label: t.orders.tax, value: money(order.taxTotal) })
1044
+ ] }),
1045
+ /* @__PURE__ */ jsxs12("div", { ...a.el("orderDetail.actions", "throttle-detail__actions"), children: [
1046
+ props.onPayNow && CAN_PAY.has(order.status) ? /* @__PURE__ */ jsx12(Button, { elementKey: "orderDetail.payButton", onClick: () => props.onPayNow(target), children: t.orders.payNow }) : null,
1047
+ order.invoiceId ? /* @__PURE__ */ jsx12(
1048
+ Button,
1049
+ {
1050
+ variant: "secondary",
1051
+ loading: submitting,
1052
+ elementKey: "orderDetail.invoiceButton",
1053
+ onClick: () => void run(async () => {
1054
+ const { url } = await account.getInvoicePdfUrl(order.invoiceId);
1055
+ const opened = window.open(url, "_blank", "noopener,noreferrer");
1056
+ if (!opened) window.location.assign(url);
1057
+ }),
1058
+ children: t.orders.downloadInvoice
1059
+ }
1060
+ ) : null,
1061
+ props.onTrackShipment && order.status === "partially_fulfilled" ? /* @__PURE__ */ jsx12(
1062
+ Button,
1063
+ {
1064
+ variant: "secondary",
1065
+ elementKey: "orderDetail.trackButton",
1066
+ onClick: () => props.onTrackShipment(target),
1067
+ children: t.orders.track
1068
+ }
1069
+ ) : null,
1070
+ showReorder ? /* @__PURE__ */ jsx12(
1071
+ Button,
1072
+ {
1073
+ variant: "secondary",
1074
+ elementKey: "orderDetail.reorderButton",
1075
+ onClick: () => props.onReorder(target),
1076
+ children: t.orders.reorder
1077
+ }
1078
+ ) : null,
1079
+ props.onViewSubscription ? orderSubscriptionLinks(order, {
1080
+ single: t.orders.viewSubscription,
1081
+ named: t.orders.viewSubscriptionFor
1082
+ }).map((link) => /* @__PURE__ */ jsx12(
1083
+ Button,
1084
+ {
1085
+ variant: "secondary",
1086
+ elementKey: "orderDetail.subscriptionButton",
1087
+ onClick: () => props.onViewSubscription(link.id),
1088
+ children: link.label
1089
+ },
1090
+ link.id
1091
+ )) : null,
1092
+ showReturn ? /* @__PURE__ */ jsx12(
1093
+ Button,
1094
+ {
1095
+ variant: "secondary",
1096
+ disabled: submitting,
1097
+ elementKey: "orderDetail.returnButton",
1098
+ onClick: () => void (async () => {
1099
+ if (!await confirm({
1100
+ title: t.orders.requestReturnConfirm,
1101
+ body: t.orders.requestReturnBody,
1102
+ confirmLabel: t.orders.requestReturnAction
1103
+ })) return;
1104
+ await run(async () => {
1105
+ await account.requestOrderReturn(order.id, {
1106
+ items: order.lineItems.map((li) => ({
1107
+ lineItemId: li.id,
1108
+ quantity: li.quantity
1109
+ }))
1110
+ });
1111
+ await resource.refetch();
1112
+ });
1113
+ })(),
1114
+ children: t.orders.requestReturn
1115
+ }
1116
+ ) : null,
1117
+ showCancel ? /* @__PURE__ */ jsx12(
1118
+ Button,
1119
+ {
1120
+ variant: "danger",
1121
+ disabled: submitting,
1122
+ elementKey: "orderDetail.cancelButton",
1123
+ onClick: () => void (async () => {
1124
+ if (!await confirm({
1125
+ title: t.orders.cancelOrderConfirm,
1126
+ body: t.orders.cancelOrderBody,
1127
+ confirmLabel: t.orders.cancelOrderAction,
1128
+ tone: "danger"
1129
+ })) return;
1130
+ await run(async () => {
1131
+ await account.cancelOrder(order.id);
1132
+ await resource.refetch();
1133
+ });
1134
+ })(),
1135
+ children: t.orders.cancelOrder
1136
+ }
1137
+ ) : null
1138
+ ] })
1139
+ ] })
1140
+ ] });
1141
+ }
1142
+ }
1143
+ )
1144
+ ] }) }) });
1145
+ }
1146
+
1147
+ // src/react/components/account/OrdersPanel.tsx
1148
+ import { jsx as jsx13, jsxs as jsxs13 } from "react/jsx-runtime";
1149
+ function OrdersPanel(props) {
1150
+ const a = useAppearance(props.appearance);
1151
+ const scoped = useAppearanceProviderValue(props.appearance);
1152
+ const { t, locale } = useCopy(props.localization);
1153
+ const { emailVerified } = useAuth();
1154
+ const resource = useOrders();
1155
+ const [openId, setOpenId] = useState7(props.initialOpenId ?? null);
1156
+ useEffect3(() => {
1157
+ if (props.initialOpenId) setOpenId(props.initialOpenId);
1158
+ }, [props.initialOpenId]);
1159
+ const variant = props.variant ?? "table";
1160
+ const rowsVariant = variant === "rows";
1161
+ const listBase = rowsVariant ? "throttle-rows" : "throttle-stack";
1162
+ const itemBase = rowsVariant ? "throttle-rowitem" : "throttle-listitem";
1163
+ if (openId) {
1164
+ return /* @__PURE__ */ jsx13(
1165
+ OrderDetail,
1166
+ {
1167
+ orderId: openId,
1168
+ onBack: () => setOpenId(null),
1169
+ onPayNow: props.onPayNow,
1170
+ onReorder: props.onReorder,
1171
+ onTrackShipment: props.onTrackShipment,
1172
+ onViewSubscription: props.onViewSubscription,
1173
+ allowCancel: props.allowCancel,
1174
+ allowReturn: props.allowReturn,
1175
+ reorderOnPaid: props.reorderOnPaid,
1176
+ appearance: props.appearance,
1177
+ localization: props.localization
1178
+ }
1179
+ );
1180
+ }
1181
+ return /* @__PURE__ */ jsx13(AppearanceProvider, { value: scoped, children: /* @__PURE__ */ jsx13("div", { ...a.rootProps, children: /* @__PURE__ */ jsx13("div", { ...a.el("ordersPanel.root", "throttle-panel"), children: /* @__PURE__ */ jsx13(
1182
+ PanelState,
1183
+ {
1184
+ resource,
1185
+ gated: !emailVerified,
1186
+ gatedDescription: t.orders.gatedDescription,
1187
+ isEmpty: (rows) => rows.length === 0,
1188
+ emptyTitle: t.orders.empty,
1189
+ emptyDescription: t.orders.emptyDescription,
1190
+ children: (rows) => variant === "table" ? /* @__PURE__ */ jsx13(
1191
+ DataTable,
1192
+ {
1193
+ tableKey: "ordersPanel.table",
1194
+ rowElementKey: "ordersPanel.row",
1195
+ rowKey: (o) => o.id,
1196
+ onRowClick: (o) => setOpenId(o.id),
1197
+ rows,
1198
+ columns: [
1199
+ { key: "orderNumber", label: t.orders.number },
1200
+ { key: "createdAt", label: t.orders.date, render: (o) => formatDate(o.createdAt, locale) },
1201
+ {
1202
+ key: "status",
1203
+ label: t.orders.status,
1204
+ render: (o) => /* @__PURE__ */ jsx13(OrderStatus, { status: o.status, paymentStatus: o.paymentStatus, t })
1205
+ },
1206
+ {
1207
+ key: "total",
1208
+ label: t.orders.total,
1209
+ render: (o) => /* @__PURE__ */ jsx13("span", { className: "throttle-table__money", children: formatMoney(o.total, o.currency, locale) })
1210
+ }
1211
+ ]
1212
+ }
1213
+ ) : /* @__PURE__ */ jsx13("div", { ...a.el("ordersPanel.list", listBase), children: rows.map((o) => /* @__PURE__ */ jsxs13("div", { ...a.el("ordersPanel.item", itemBase), children: [
1214
+ /* @__PURE__ */ jsxs13("div", { children: [
1215
+ /* @__PURE__ */ jsxs13("div", { className: "throttle-row", children: [
1216
+ /* @__PURE__ */ jsx13("strong", { children: o.orderNumber }),
1217
+ /* @__PURE__ */ jsx13(OrderStatus, { status: o.status, paymentStatus: o.paymentStatus, t })
1218
+ ] }),
1219
+ /* @__PURE__ */ jsx13("p", { className: "throttle-muted", children: formatDate(o.createdAt, locale) }),
1220
+ /* @__PURE__ */ jsx13("p", { className: "throttle-muted", children: formatMoney(o.total, o.currency, locale) })
1221
+ ] }),
1222
+ /* @__PURE__ */ jsx13("div", { className: "throttle-actions", children: /* @__PURE__ */ jsx13(
1223
+ Button,
1224
+ {
1225
+ variant: rowsVariant ? "link" : "secondary",
1226
+ elementKey: "ordersPanel.viewButton",
1227
+ onClick: () => setOpenId(o.id),
1228
+ children: t.common.view
1229
+ }
1230
+ ) })
1231
+ ] }, o.id)) })
1232
+ }
1233
+ ) }) }) });
1234
+ }
1235
+
1236
+ // src/react/components/account/InvoicesPanel.tsx
1237
+ import { useEffect as useEffect4, useState as useState8 } from "react";
1238
+
1239
+ // src/react/components/account/InvoiceDetail.tsx
1240
+ import { jsx as jsx14, jsxs as jsxs14 } from "react/jsx-runtime";
1241
+ var PAYABLE = /* @__PURE__ */ new Set(["open"]);
1242
+ function Line2(props) {
1243
+ return /* @__PURE__ */ jsxs14("div", { className: "throttle-row", children: [
1244
+ /* @__PURE__ */ jsx14("span", { className: "throttle-muted", children: props.label }),
1245
+ /* @__PURE__ */ jsx14("span", { children: props.value })
1246
+ ] });
1247
+ }
1248
+ function InvoiceDetail(props) {
1249
+ const a = useAppearance(props.appearance);
1250
+ const scoped = useAppearanceProviderValue(props.appearance);
1251
+ const { t, locale } = useCopy(props.localization);
1252
+ const { account } = useAuth();
1253
+ const resource = useInvoice(props.invoiceId);
1254
+ const { submitting, error, run } = useAction();
1255
+ return /* @__PURE__ */ jsx14(AppearanceProvider, { value: scoped, children: /* @__PURE__ */ jsx14("div", { ...a.rootProps, children: /* @__PURE__ */ jsxs14("div", { ...a.el("invoiceDetail.root", "throttle-panel"), children: [
1256
+ props.onBack ? (
1257
+ // Wrapped on purpose — see OrderDetail's back button for why a
1258
+ // direct flex child stretched to 748px.
1259
+ /* @__PURE__ */ jsx14("div", { children: /* @__PURE__ */ jsx14(Button, { variant: "link", elementKey: "invoiceDetail.backButton", onClick: props.onBack, children: t.common.back }) })
1260
+ ) : null,
1261
+ error ? /* @__PURE__ */ jsx14(Alert, { tone: "error", children: error }) : null,
1262
+ /* @__PURE__ */ jsx14(PanelState, { resource, isEmpty: (i) => i === null, emptyTitle: t.invoices.empty, skeletonRows: 4, children: (invoice) => {
1263
+ const money = (v) => formatMoney(v, invoice.currency, locale);
1264
+ const lines = invoice.lineItems ?? [];
1265
+ const partOfOrder = invoice.orderTotal != null;
1266
+ const isDepositReceipt = partOfOrder && invoice.balanceDue != null;
1267
+ const headlineLabel = !partOfOrder ? t.invoices.total : isDepositReceipt ? t.invoices.amountPaid : t.invoices.amountDue;
1268
+ return /* @__PURE__ */ jsxs14("div", { ...a.el("invoiceDetail.layout", "throttle-detail"), children: [
1269
+ /* @__PURE__ */ jsxs14("div", { ...a.el("invoiceDetail.main", "throttle-detail__main"), children: [
1270
+ /* @__PURE__ */ jsxs14("div", { className: "throttle-detail__section", children: [
1271
+ /* @__PURE__ */ jsxs14("div", { className: "throttle-row", children: [
1272
+ /* @__PURE__ */ jsx14("h3", { children: invoice.number }),
1273
+ /* @__PURE__ */ jsx14(StatusBadge, { status: invoice.status, labels: t.invoices.statusLabels })
1274
+ ] }),
1275
+ /* @__PURE__ */ jsxs14("p", { className: "throttle-muted", children: [
1276
+ t.invoices.issued,
1277
+ " ",
1278
+ formatDate(invoice.issuedAt, locale)
1279
+ ] })
1280
+ ] }),
1281
+ lines.length > 0 ? /* @__PURE__ */ jsxs14("div", { className: "throttle-detail__section", children: [
1282
+ /* @__PURE__ */ jsx14("span", { className: "throttle-detail__label", children: t.invoices.items }),
1283
+ /* @__PURE__ */ jsx14("div", { ...a.el("invoiceDetail.lineItems", "throttle-stack"), children: lines.map((item, i) => /* @__PURE__ */ jsxs14("div", { ...a.el("invoiceDetail.lineItem", "throttle-lineitem"), children: [
1284
+ /* @__PURE__ */ jsxs14("div", { style: { flex: 1 }, children: [
1285
+ /* @__PURE__ */ jsx14("strong", { children: item.name }),
1286
+ item.description ? /* @__PURE__ */ jsx14("p", { className: "throttle-lineitem__desc", children: item.description }) : null,
1287
+ /* @__PURE__ */ jsxs14("p", { className: "throttle-lineitem__meta", children: [
1288
+ t.orders.quantity,
1289
+ " ",
1290
+ item.quantity,
1291
+ " \xD7 ",
1292
+ money(item.unitPrice)
1293
+ ] })
1294
+ ] }),
1295
+ /* @__PURE__ */ jsx14("span", { children: money(item.total) })
1296
+ ] }, i)) })
1297
+ ] }) : null
1298
+ ] }),
1299
+ /* @__PURE__ */ jsxs14("aside", { ...a.el("invoiceDetail.rail", "throttle-detail__rail"), children: [
1300
+ /* @__PURE__ */ jsxs14("div", { className: "throttle-detail__section", children: [
1301
+ /* @__PURE__ */ jsx14("span", { className: "throttle-detail__label", children: headlineLabel }),
1302
+ /* @__PURE__ */ jsx14("span", { className: "throttle-detail__headline", children: money(invoice.total) })
1303
+ ] }),
1304
+ /* @__PURE__ */ jsxs14("div", { ...a.el("invoiceDetail.totals", "throttle-totals"), children: [
1305
+ partOfOrder ? /* @__PURE__ */ jsx14(Line2, { label: t.invoices.orderTotal, value: money(invoice.orderTotal) }) : null,
1306
+ partOfOrder && invoice.amountPaid ? /* @__PURE__ */ jsx14(Line2, { label: t.invoices.amountPaid, value: `-${money(invoice.amountPaid)}` }) : null,
1307
+ partOfOrder && invoice.compWaived ? /* @__PURE__ */ jsx14(Line2, { label: t.invoices.waived, value: `-${money(invoice.compWaived)}` }) : null,
1308
+ isDepositReceipt && invoice.balanceDue ? /* @__PURE__ */ jsx14(Line2, { label: t.invoices.balanceDue, value: money(invoice.balanceDue) }) : null,
1309
+ invoice.dueAt ? /* @__PURE__ */ jsx14(Line2, { label: t.invoices.due, value: formatDate(invoice.dueAt, locale) }) : null,
1310
+ invoice.periodStart && invoice.periodEnd ? /* @__PURE__ */ jsx14(
1311
+ Line2,
1312
+ {
1313
+ label: t.invoices.period,
1314
+ value: `${formatDate(invoice.periodStart, locale)} \u2013 ${formatDate(invoice.periodEnd, locale)}`
1315
+ }
1316
+ ) : null,
1317
+ invoice.amountRefunded ? /* @__PURE__ */ jsx14(Line2, { label: t.invoices.refunded, value: money(invoice.amountRefunded) }) : null
1318
+ ] }),
1319
+ /* @__PURE__ */ jsxs14("div", { ...a.el("invoiceDetail.actions", "throttle-detail__actions"), children: [
1320
+ props.onPay && PAYABLE.has(invoice.status) ? /* @__PURE__ */ jsx14(
1321
+ Button,
1322
+ {
1323
+ elementKey: "invoiceDetail.payButton",
1324
+ onClick: () => props.onPay({
1325
+ id: invoice.id,
1326
+ number: invoice.number,
1327
+ total: invoice.total,
1328
+ currency: invoice.currency
1329
+ }),
1330
+ children: t.invoices.payButton
1331
+ }
1332
+ ) : null,
1333
+ /* @__PURE__ */ jsx14(
1334
+ Button,
1335
+ {
1336
+ variant: "secondary",
1337
+ loading: submitting,
1338
+ elementKey: "invoiceDetail.downloadButton",
1339
+ onClick: () => void run(async () => {
1340
+ const { url } = await account.getInvoicePdfUrl(invoice.id);
1341
+ const opened = window.open(url, "_blank", "noopener,noreferrer");
1342
+ if (!opened) window.location.assign(url);
1343
+ }),
1344
+ children: t.invoices.downloadButton
1345
+ }
1346
+ ),
1347
+ invoice.orderId && props.onViewOrder ? /* @__PURE__ */ jsx14(
1348
+ Button,
1349
+ {
1350
+ variant: "secondary",
1351
+ elementKey: "invoiceDetail.orderLink",
1352
+ onClick: () => props.onViewOrder(invoice.orderId),
1353
+ children: invoice.orderNumber ? `${t.invoices.viewOrder} ${invoice.orderNumber}` : t.invoices.viewOrder
1354
+ }
1355
+ ) : null,
1356
+ invoice.subscriptionId && props.onViewSubscription ? /* @__PURE__ */ jsx14(
1357
+ Button,
1358
+ {
1359
+ variant: "secondary",
1360
+ elementKey: "invoiceDetail.subscriptionLink",
1361
+ onClick: () => props.onViewSubscription(invoice.subscriptionId),
1362
+ children: t.invoices.viewSubscription
1363
+ }
1364
+ ) : null
1365
+ ] })
1366
+ ] })
1367
+ ] });
1368
+ } })
1369
+ ] }) }) });
1370
+ }
1371
+
1372
+ // src/react/components/account/InvoicesPanel.tsx
1373
+ import { jsx as jsx15, jsxs as jsxs15 } from "react/jsx-runtime";
1374
+ function InvoicesPanel(props) {
1375
+ const a = useAppearance(props.appearance);
1376
+ const scoped = useAppearanceProviderValue(props.appearance);
1377
+ const { t, locale } = useCopy(props.localization);
1378
+ const { emailVerified } = useAuth();
1379
+ const resource = useInvoices();
1380
+ const [openId, setOpenId] = useState8(props.initialOpenId ?? null);
1381
+ useEffect4(() => {
1382
+ if (props.initialOpenId) setOpenId(props.initialOpenId);
1383
+ }, [props.initialOpenId]);
1384
+ const variant = props.variant ?? "table";
1385
+ const rowsVariant = variant === "rows";
1386
+ const listBase = rowsVariant ? "throttle-rows" : "throttle-stack";
1387
+ const itemBase = rowsVariant ? "throttle-rowitem" : "throttle-listitem";
1388
+ if (openId) {
1389
+ return /* @__PURE__ */ jsx15(
1390
+ InvoiceDetail,
1391
+ {
1392
+ invoiceId: openId,
1393
+ onBack: () => setOpenId(null),
1394
+ onViewOrder: props.onViewOrder,
1395
+ onViewSubscription: props.onViewSubscription,
1396
+ onPay: props.onPay,
1397
+ appearance: props.appearance,
1398
+ localization: props.localization
1399
+ }
1400
+ );
1401
+ }
1402
+ return /* @__PURE__ */ jsx15(AppearanceProvider, { value: scoped, children: /* @__PURE__ */ jsx15("div", { ...a.rootProps, children: /* @__PURE__ */ jsx15("div", { ...a.el("invoicesPanel.root", "throttle-panel"), children: /* @__PURE__ */ jsx15(
1403
+ PanelState,
1404
+ {
1405
+ resource,
1406
+ gated: !emailVerified,
1407
+ gatedDescription: t.invoices.gatedDescription,
1408
+ isEmpty: (rows) => rows.length === 0,
1409
+ emptyTitle: t.invoices.empty,
1410
+ emptyDescription: t.invoices.emptyDescription,
1411
+ children: (rows) => variant === "table" ? /* @__PURE__ */ jsx15(
1412
+ DataTable,
1413
+ {
1414
+ tableKey: "invoicesPanel.table",
1415
+ rowElementKey: "invoicesPanel.row",
1416
+ rowKey: (i) => i.id,
1417
+ onRowClick: (i) => setOpenId(i.id),
1418
+ rows,
1419
+ columns: [
1420
+ { key: "number", label: t.invoices.number },
1421
+ { key: "issuedAt", label: t.invoices.issued, render: (i) => formatDate(i.issuedAt, locale) },
1422
+ { key: "status", label: t.invoices.status, render: (i) => /* @__PURE__ */ jsx15(StatusBadge, { status: i.status, labels: t.invoices.statusLabels }) },
1423
+ {
1424
+ key: "total",
1425
+ label: t.invoices.total,
1426
+ render: (i) => /* @__PURE__ */ jsx15("span", { className: "throttle-table__money", children: formatMoney(i.total, i.currency, locale) })
1427
+ }
1428
+ ]
1429
+ }
1430
+ ) : /* @__PURE__ */ jsx15("div", { ...a.el("invoicesPanel.list", listBase), children: rows.map((i) => /* @__PURE__ */ jsxs15("div", { ...a.el("invoicesPanel.item", itemBase), children: [
1431
+ /* @__PURE__ */ jsxs15("div", { children: [
1432
+ /* @__PURE__ */ jsxs15("div", { className: "throttle-row", children: [
1433
+ /* @__PURE__ */ jsx15("strong", { children: i.number }),
1434
+ /* @__PURE__ */ jsx15(StatusBadge, { status: i.status, labels: t.invoices.statusLabels })
1435
+ ] }),
1436
+ /* @__PURE__ */ jsx15("p", { className: "throttle-muted", children: formatDate(i.issuedAt, locale) }),
1437
+ /* @__PURE__ */ jsx15("p", { className: "throttle-muted", children: formatMoney(i.total, i.currency, locale) })
1438
+ ] }),
1439
+ /* @__PURE__ */ jsx15("div", { className: "throttle-actions", children: /* @__PURE__ */ jsx15(
1440
+ Button,
1441
+ {
1442
+ variant: rowsVariant ? "link" : "secondary",
1443
+ elementKey: "invoicesPanel.viewButton",
1444
+ onClick: () => setOpenId(i.id),
1445
+ children: t.common.view
1446
+ }
1447
+ ) })
1448
+ ] }, i.id)) })
1449
+ }
1450
+ ) }) }) });
1451
+ }
1452
+
1453
+ // src/react/components/account/SubscriptionsPanel.tsx
1454
+ import { useState as useState9 } from "react";
1455
+
1456
+ // ../core-cadence/src/cadence.ts
1457
+ var INTERVAL_UNITS = ["hour", "day", "week", "month"];
1458
+ var NAMED_INTERVALS = ["weekly", "biweekly", "monthly", "quarterly", "yearly"];
1459
+ var INTERVAL_VALUES = [...NAMED_INTERVALS, "custom"];
1460
+ var HOUR_MS = 36e5;
1461
+ var DAY_MS = 24 * HOUR_MS;
1462
+ var WEEK_MS = 7 * DAY_MS;
1463
+ function isNamedInterval(value) {
1464
+ return typeof value === "string" && NAMED_INTERVALS.includes(value);
1465
+ }
1466
+ function isIntervalUnit(value) {
1467
+ return typeof value === "string" && INTERVAL_UNITS.includes(value);
1468
+ }
1469
+
1470
+ // ../core-cadence/src/schedule.ts
1471
+ function isVariedSchedule(rows) {
1472
+ if (!rows || rows.length === 0) return false;
1473
+ return rows.some(
1474
+ (r, i) => r.discount !== 0 || r.amount !== rows[0].amount || i > 1 && (r.intervalUnit !== rows[1].intervalUnit || r.intervalCount !== rows[1].intervalCount)
1475
+ );
1476
+ }
1477
+ function upcomingSchedulePayments(rows) {
1478
+ if (!rows || !isVariedSchedule(rows)) return [];
1479
+ return rows.filter((r) => r.status !== "paid" && r.dueAt != null);
1480
+ }
1481
+
1482
+ // ../core-cadence/src/labels.ts
1483
+ var NAMED_NOUN = {
1484
+ weekly: "week",
1485
+ biweekly: "2 weeks",
1486
+ monthly: "month",
1487
+ quarterly: "quarter",
1488
+ yearly: "year"
1489
+ };
1490
+ function cadenceNoun(cadence) {
1491
+ if (isNamedInterval(cadence.interval)) return NAMED_NOUN[cadence.interval];
1492
+ if (isIntervalUnit(cadence.intervalUnit) && cadence.intervalCount != null) {
1493
+ return cadence.intervalCount === 1 ? cadence.intervalUnit : `${cadence.intervalCount} ${cadence.intervalUnit}s`;
1494
+ }
1495
+ return cadence.interval;
1496
+ }
1497
+ function scheduleDeal(sub) {
1498
+ if (!sub.paymentSchedule || sub.scheduleTotal == null || !isVariedSchedule(sub.paymentSchedule)) return null;
1499
+ return { total: sub.scheduleTotal, payments: sub.paymentSchedule.length };
1500
+ }
1501
+
1502
+ // src/react/components/account/SubscriptionsPanel.tsx
1503
+ import { Fragment as Fragment4, jsx as jsx16, jsxs as jsxs16 } from "react/jsx-runtime";
1504
+ var CAN_PAUSE = /* @__PURE__ */ new Set(["active"]);
1505
+ var CAN_RESUME = /* @__PURE__ */ new Set(["paused"]);
1506
+ var CAN_CANCEL2 = /* @__PURE__ */ new Set(["active", "trialing", "paused", "past_due", "unpaid"]);
1507
+ var isInstallment = (sub) => sub.totalPayments != null;
1508
+ var canChangeAddress = (sub) => sub.deliveryMethod === "shipment" && sub.status !== "cancelled" && sub.status !== "completed";
1509
+ function oneLine(address) {
1510
+ if (!address) return null;
1511
+ const parts = [address.addressLine1, address.addressLine2, address.city, address.stateProvince, address.postalCode, address.countryCode];
1512
+ return parts.filter(Boolean).join(", ") || null;
1513
+ }
1514
+ function SubscriptionsPanel(props) {
1515
+ const a = useAppearance(props.appearance);
1516
+ const scoped = useAppearanceProviderValue(props.appearance);
1517
+ const { t, locale } = useCopy(props.localization);
1518
+ const { emailVerified } = useAuth();
1519
+ const resource = useSubscriptions();
1520
+ const { submitting, error, run } = useAction();
1521
+ const confirm = useConfirm();
1522
+ const [editingAddress, setEditingAddress] = useState9(null);
1523
+ const variant = props.variant ?? "rows";
1524
+ const rowsVariant = variant === "rows";
1525
+ const listBase = rowsVariant ? "throttle-rows" : "throttle-stack";
1526
+ const itemBase = rowsVariant ? "throttle-rowitem" : "throttle-listitem";
1527
+ const actionVariant = (base) => base;
1528
+ const confirmThen = (fn, ask) => () => {
1529
+ void (async () => {
1530
+ if (!await confirm({ ...ask, tone: ask.tone ?? "neutral" })) return;
1531
+ await run(fn);
1532
+ })();
1533
+ };
1534
+ const priceLabel = (sub) => {
1535
+ const deal = scheduleDeal(sub);
1536
+ return deal ? t.subscriptions.installmentTotal.replace("{amount}", formatMoney(deal.total, sub.currency, locale)) : `${formatMoney(sub.amount, sub.currency, locale)} / ${cadenceNoun(sub)}${sub.quantity > 1 ? ` \xD7 ${sub.quantity}` : ""}`;
1537
+ };
1538
+ const nextPaymentLabel = (sub) => {
1539
+ if (!isVariedSchedule(sub.paymentSchedule) || !sub.paymentSchedule || sub.nextPaymentAmount == null) return null;
1540
+ const upcoming = sub.paymentSchedule.find((r) => r.status !== "paid");
1541
+ return t.subscriptions.installmentNext.replace("{amount}", formatMoney(sub.nextPaymentAmount, sub.currency, locale)).replace(
1542
+ "{date}",
1543
+ upcoming?.dueAt ? scheduleDueLabel({ dueAt: upcoming.dueAt, intervalUnit: upcoming.intervalUnit }, locale) : formatDate(sub.currentPeriodEnd, locale)
1544
+ );
1545
+ };
1546
+ const upcomingList = (sub) => {
1547
+ const upcoming = upcomingSchedulePayments(sub.paymentSchedule);
1548
+ if (upcoming.length === 0) return null;
1549
+ return /* @__PURE__ */ jsx16("ul", { className: "throttle-muted", "aria-label": t.subscriptions.upcomingPayments, children: upcoming.map((r) => /* @__PURE__ */ jsx16("li", { children: t.subscriptions.upcomingPayment.replace("{amount}", formatMoney(r.net, sub.currency, locale)).replace("{date}", scheduleDueLabel(r, locale)) }, r.dueAt)) });
1550
+ };
1551
+ const shipsTo = (sub) => sub.deliveryMethod === "shipment" && oneLine(sub.shippingAddress) ? /* @__PURE__ */ jsxs16("p", { className: "throttle-muted", children: [
1552
+ t.subscriptions.shipsTo,
1553
+ " ",
1554
+ oneLine(sub.shippingAddress)
1555
+ ] }) : null;
1556
+ const addressAction = (sub, variantFor) => canChangeAddress(sub) ? /* @__PURE__ */ jsx16(
1557
+ Button,
1558
+ {
1559
+ variant: variantFor("secondary"),
1560
+ elementKey: "subscriptionsPanel.changeAddressButton",
1561
+ disabled: submitting,
1562
+ onClick: () => setEditingAddress(sub.id),
1563
+ children: t.subscriptions.changeAddress
1564
+ }
1565
+ ) : null;
1566
+ const renewsLabel = (sub) => formatDate(
1567
+ sub.status === "completed" ? sub.completedAt ?? sub.currentPeriodEnd : sub.status === "cancelled" ? sub.cancelledAt ?? sub.currentPeriodEnd : sub.currentPeriodEnd,
1568
+ locale
1569
+ );
1570
+ const lifecycleActions = (sub, variantFor) => isInstallment(sub) ? null : /* @__PURE__ */ jsxs16("div", { className: "throttle-actions", children: [
1571
+ CAN_PAUSE.has(sub.status) ? /* @__PURE__ */ jsx16(
1572
+ Button,
1573
+ {
1574
+ variant: variantFor("secondary"),
1575
+ loading: submitting,
1576
+ elementKey: "subscriptionsPanel.pauseButton",
1577
+ onClick: confirmThen(() => resource.pause(sub.id), {
1578
+ title: t.subscriptions.pauseConfirm,
1579
+ confirmLabel: t.subscriptions.pauseButton
1580
+ }),
1581
+ children: t.subscriptions.pauseButton
1582
+ }
1583
+ ) : null,
1584
+ CAN_RESUME.has(sub.status) ? /* @__PURE__ */ jsx16(
1585
+ Button,
1586
+ {
1587
+ variant: variantFor("secondary"),
1588
+ loading: submitting,
1589
+ elementKey: "subscriptionsPanel.resumeButton",
1590
+ onClick: confirmThen(() => resource.resume(sub.id), {
1591
+ title: t.subscriptions.resumeConfirm,
1592
+ confirmLabel: t.subscriptions.resumeButton
1593
+ }),
1594
+ children: t.subscriptions.resumeButton
1595
+ }
1596
+ ) : null,
1597
+ CAN_CANCEL2.has(sub.status) && !sub.cancelAtPeriodEnd ? /* @__PURE__ */ jsx16(
1598
+ Button,
1599
+ {
1600
+ variant: variantFor("secondary"),
1601
+ elementKey: "subscriptionsPanel.cancelButton",
1602
+ disabled: submitting,
1603
+ onClick: confirmThen(() => resource.cancel(sub.id, { atPeriodEnd: true }), {
1604
+ title: t.subscriptions.cancelConfirm,
1605
+ confirmLabel: t.subscriptions.cancelConfirmAction,
1606
+ tone: "danger"
1607
+ }),
1608
+ children: t.subscriptions.cancelAtPeriodEnd
1609
+ }
1610
+ ) : null,
1611
+ CAN_CANCEL2.has(sub.status) ? /* @__PURE__ */ jsx16(
1612
+ Button,
1613
+ {
1614
+ variant: variantFor("danger"),
1615
+ elementKey: "subscriptionsPanel.cancelNowButton",
1616
+ disabled: submitting,
1617
+ onClick: confirmThen(() => resource.cancel(sub.id, { atPeriodEnd: false }), {
1618
+ title: t.subscriptions.cancelNowConfirm,
1619
+ confirmLabel: t.subscriptions.cancelConfirmAction,
1620
+ tone: "danger"
1621
+ }),
1622
+ children: t.subscriptions.cancelNow
1623
+ }
1624
+ ) : null
1625
+ ] });
1626
+ return /* @__PURE__ */ jsx16(AppearanceProvider, { value: scoped, children: /* @__PURE__ */ jsx16("div", { ...a.rootProps, children: /* @__PURE__ */ jsxs16("div", { ...a.el("subscriptionsPanel.root", "throttle-panel"), children: [
1627
+ error && !editingAddress ? /* @__PURE__ */ jsx16(Alert, { tone: "error", children: error }) : null,
1628
+ editingAddress ? (() => {
1629
+ const sub = resource.data.find((row) => row.id === editingAddress);
1630
+ const current = sub?.shippingAddress;
1631
+ return /* @__PURE__ */ jsxs16("div", { className: "throttle-stack", children: [
1632
+ /* @__PURE__ */ jsx16("strong", { children: t.subscriptions.changeAddressTitle }),
1633
+ /* @__PURE__ */ jsx16("p", { className: "throttle-muted", children: t.subscriptions.changeAddressHint }),
1634
+ /* @__PURE__ */ jsx16(
1635
+ AddressForm,
1636
+ {
1637
+ elementKey: "subscriptionsPanel.addressForm",
1638
+ hideLabel: true,
1639
+ initial: current ? { ...current, label: null } : void 0,
1640
+ submitting,
1641
+ error,
1642
+ onCancel: () => setEditingAddress(null),
1643
+ onSubmit: ({ label: _label, isDefault: _isDefault, ...address }) => {
1644
+ void run(async () => {
1645
+ await resource.updateShippingAddress(editingAddress, address);
1646
+ setEditingAddress(null);
1647
+ });
1648
+ }
1649
+ }
1650
+ )
1651
+ ] });
1652
+ })() : null,
1653
+ /* @__PURE__ */ jsx16(
1654
+ PanelState,
1655
+ {
1656
+ resource,
1657
+ gated: !emailVerified,
1658
+ gatedDescription: t.subscriptions.gatedDescription,
1659
+ isEmpty: (rows) => rows.length === 0,
1660
+ emptyTitle: t.subscriptions.empty,
1661
+ emptyDescription: t.subscriptions.emptyDescription,
1662
+ children: (rows) => variant === "table" ? /* @__PURE__ */ jsx16(
1663
+ DataTable,
1664
+ {
1665
+ tableKey: "subscriptionsPanel.table",
1666
+ rowElementKey: "subscriptionsPanel.row",
1667
+ rowKey: (sub) => sub.id,
1668
+ rows,
1669
+ columns: [
1670
+ { key: "plan", label: t.subscriptions.columnPlan, render: (sub) => /* @__PURE__ */ jsxs16(Fragment4, { children: [
1671
+ sub.planName ?? sub.planReference,
1672
+ sub.totalPayments != null ? /* @__PURE__ */ jsx16("div", { className: "throttle-muted", children: t.subscriptions.installmentProgress.replace("{paid}", String(Math.min(sub.paymentsMade ?? 0, sub.totalPayments))).replace("{total}", String(sub.totalPayments)) }) : null,
1673
+ nextPaymentLabel(sub) ? /* @__PURE__ */ jsx16("div", { className: "throttle-muted", children: nextPaymentLabel(sub) }) : null,
1674
+ upcomingList(sub),
1675
+ shipsTo(sub)
1676
+ ] }) },
1677
+ { key: "price", label: t.subscriptions.columnPrice, render: (sub) => /* @__PURE__ */ jsx16("span", { className: "throttle-table__money", children: priceLabel(sub) }) },
1678
+ { key: "renews", label: t.subscriptions.columnRenews, render: (sub) => renewsLabel(sub) },
1679
+ { key: "status", label: t.subscriptions.columnStatus, render: (sub) => /* @__PURE__ */ jsxs16("div", { className: "throttle-row", children: [
1680
+ /* @__PURE__ */ jsx16(StatusBadge, { status: sub.status, labels: t.subscriptions.statusLabels }),
1681
+ sub.cancelAtPeriodEnd ? /* @__PURE__ */ jsx16(Badge, { tone: "warning", children: t.subscriptions.cancelScheduled }) : null
1682
+ ] }) },
1683
+ { key: "actions", label: t.common.actions, render: (sub) => /* @__PURE__ */ jsxs16(Fragment4, { children: [
1684
+ lifecycleActions(sub, (base) => base),
1685
+ addressAction(sub, (base) => base)
1686
+ ] }) }
1687
+ ]
1688
+ }
1689
+ ) : /* @__PURE__ */ jsx16("div", { ...a.el("subscriptionsPanel.list", listBase), children: rows.map((sub) => /* @__PURE__ */ jsxs16("div", { ...a.el("subscriptionsPanel.item", itemBase), children: [
1690
+ /* @__PURE__ */ jsxs16("div", { children: [
1691
+ /* @__PURE__ */ jsxs16("div", { className: "throttle-row", children: [
1692
+ /* @__PURE__ */ jsx16("strong", { children: sub.planName ?? sub.planReference }),
1693
+ /* @__PURE__ */ jsx16(StatusBadge, { status: sub.status, labels: t.subscriptions.statusLabels })
1694
+ ] }),
1695
+ sub.totalPayments != null ? /* @__PURE__ */ jsx16("div", { className: "throttle-muted", children: t.subscriptions.installmentProgress.replace("{paid}", String(Math.min(sub.paymentsMade ?? 0, sub.totalPayments))).replace("{total}", String(sub.totalPayments)) }) : null,
1696
+ nextPaymentLabel(sub) ? /* @__PURE__ */ jsx16("div", { className: "throttle-muted", children: nextPaymentLabel(sub) }) : null,
1697
+ upcomingList(sub),
1698
+ /* @__PURE__ */ jsx16("p", { className: "throttle-muted", children: priceLabel(sub) }),
1699
+ shipsTo(sub),
1700
+ sub.status === "completed" ? /* @__PURE__ */ jsxs16("p", { className: "throttle-muted", children: [
1701
+ t.subscriptions.statusLabels.completed,
1702
+ " ",
1703
+ formatDate(sub.completedAt ?? sub.currentPeriodEnd, locale)
1704
+ ] }) : sub.status === "cancelled" ? /* @__PURE__ */ jsxs16("p", { className: "throttle-muted", children: [
1705
+ t.subscriptions.cancelledOn,
1706
+ " ",
1707
+ formatDate(sub.cancelledAt ?? sub.currentPeriodEnd, locale)
1708
+ ] }) : /* @__PURE__ */ jsxs16("p", { className: "throttle-muted", children: [
1709
+ sub.cancelAtPeriodEnd ? t.subscriptions.endsOn : t.subscriptions.renewsOn,
1710
+ " ",
1711
+ formatDate(sub.currentPeriodEnd, locale)
1712
+ ] }),
1713
+ sub.trialEnd ? /* @__PURE__ */ jsxs16("p", { className: "throttle-muted", children: [
1714
+ t.subscriptions.trialEnds,
1715
+ " ",
1716
+ formatDate(sub.trialEnd, locale)
1717
+ ] }) : null,
1718
+ sub.cancelAtPeriodEnd ? /* @__PURE__ */ jsx16(Badge, { tone: "warning", children: t.subscriptions.cancelScheduled }) : null
1719
+ ] }),
1720
+ lifecycleActions(sub, actionVariant),
1721
+ addressAction(sub, actionVariant)
1722
+ ] }, sub.id)) })
1723
+ }
1724
+ )
1725
+ ] }) }) });
1726
+ }
1727
+
1728
+ // src/react/components/account/SecurityPanel.tsx
1729
+ import { useCallback, useEffect as useEffect5, useRef as useRef3, useState as useState10 } from "react";
1730
+
1731
+ // src/react/components/account/device.ts
1732
+ var BROWSERS = [
1733
+ [/\bEdg(?:e|A|iOS)?\//, "Edge"],
1734
+ [/\bOPR\/|\bOpera\b/, "Opera"],
1735
+ // No leading \b: real agents ship prefixed builds (HeadlessChrome), and a
1736
+ // word boundary there sends them to the Safari rule instead.
1737
+ [/Chrome\/|CriOS\//, "Chrome"],
1738
+ [/\bFirefox\/|\bFxiOS\//, "Firefox"],
1739
+ [/\bSafari\//, "Safari"]
1740
+ ];
1741
+ var PLATFORMS = [
1742
+ [/\biPhone\b|\biPad\b|\biPod\b/, "iOS"],
1743
+ [/\bAndroid\b/, "Android"],
1744
+ [/\bMac OS X\b|\bMacintosh\b/, "macOS"],
1745
+ [/\bWindows\b/, "Windows"],
1746
+ [/\bLinux\b|\bX11\b/, "Linux"]
1747
+ ];
1748
+ function first(ua, table) {
1749
+ for (const [pattern, label] of table) if (pattern.test(ua)) return label;
1750
+ return null;
1751
+ }
1752
+ function describeDevice(userAgent) {
1753
+ const ua = (userAgent ?? "").trim();
1754
+ if (!ua) return "";
1755
+ const browser = first(ua, BROWSERS);
1756
+ if (!browser) return ua;
1757
+ const platform = first(ua, PLATFORMS);
1758
+ return platform ? `${browser} on ${platform}` : browser;
1759
+ }
1760
+
1761
+ // src/react/components/account/SecurityPanel.tsx
1762
+ import { Fragment as Fragment5, jsx as jsx17, jsxs as jsxs17 } from "react/jsx-runtime";
1763
+ function SecurityPanel(props) {
1764
+ const a = useAppearance(props.appearance);
1765
+ const scoped = useAppearanceProviderValue(props.appearance);
1766
+ const { t, locale, errorMessage } = useCopy(props.localization);
1767
+ const { auth } = useAuth();
1768
+ const variant = props.variant ?? "rows";
1769
+ const rowsVariant = variant === "rows";
1770
+ const itemBase = rowsVariant ? "throttle-rowitem" : "throttle-listitem";
1771
+ const revokeVariant = rowsVariant ? "linkDanger" : "danger";
1772
+ const [password, setPassword] = useState10("");
1773
+ const passwordAction = useAction();
1774
+ const sessionAction = useAction();
1775
+ const [sessions, setSessions] = useState10(null);
1776
+ const [listError, setListError] = useState10(null);
1777
+ const errorMessageRef = useRef3(errorMessage);
1778
+ useEffect5(() => {
1779
+ errorMessageRef.current = errorMessage;
1780
+ });
1781
+ const load = useCallback(async () => {
1782
+ try {
1783
+ setSessions(await auth.listSessions());
1784
+ setListError(null);
1785
+ } catch (err) {
1786
+ setListError(errorMessageRef.current(err));
1787
+ }
1788
+ }, [auth]);
1789
+ useEffect5(() => {
1790
+ void load();
1791
+ }, [load]);
1792
+ const others = (sessions ?? []).filter((s) => !s.current);
1793
+ return /* @__PURE__ */ jsx17(AppearanceProvider, { value: scoped, children: /* @__PURE__ */ jsx17("div", { ...a.rootProps, children: /* @__PURE__ */ jsxs17("div", { ...a.el("securityPanel.root", "throttle-panel"), children: [
1794
+ /* @__PURE__ */ jsxs17(
1795
+ "form",
1796
+ {
1797
+ ...a.el("securityPanel.passwordForm", "throttle-stack"),
1798
+ onSubmit: (e) => {
1799
+ e.preventDefault();
1800
+ void passwordAction.run(async () => {
1801
+ await auth.changePassword(password);
1802
+ setPassword("");
1803
+ return t.security.changedNotice;
1804
+ });
1805
+ },
1806
+ children: [
1807
+ /* @__PURE__ */ jsx17("h3", { children: t.security.passwordTitle }),
1808
+ /* @__PURE__ */ jsx17(
1809
+ Field,
1810
+ {
1811
+ label: t.security.newPassword,
1812
+ type: "password",
1813
+ autoComplete: "new-password",
1814
+ required: true,
1815
+ value: password,
1816
+ onChange: setPassword
1817
+ }
1818
+ ),
1819
+ passwordAction.error ? /* @__PURE__ */ jsx17(Alert, { tone: "error", children: passwordAction.error }) : null,
1820
+ passwordAction.notice ? /* @__PURE__ */ jsx17(Alert, { tone: "success", children: passwordAction.notice }) : null,
1821
+ /* @__PURE__ */ jsx17(Button, { type: "submit", loading: passwordAction.submitting, elementKey: "securityPanel.passwordButton", children: t.security.changeButton })
1822
+ ]
1823
+ }
1824
+ ),
1825
+ /* @__PURE__ */ jsxs17("div", { ...a.el("securityPanel.sessionList", "throttle-stack"), children: [
1826
+ /* @__PURE__ */ jsx17("h3", { children: t.security.sessionsTitle }),
1827
+ listError ? /* @__PURE__ */ jsxs17(Fragment5, { children: [
1828
+ /* @__PURE__ */ jsx17(Alert, { tone: "error", children: listError }),
1829
+ /* @__PURE__ */ jsx17(Button, { variant: "secondary", onClick: () => void load(), children: t.common.retry })
1830
+ ] }) : null,
1831
+ sessionAction.error ? /* @__PURE__ */ jsx17(Alert, { tone: "error", children: sessionAction.error }) : null,
1832
+ sessions === null && !listError ? /* @__PURE__ */ jsx17(Skeleton, { count: 2 }) : null,
1833
+ sessions !== null && !listError && variant === "table" ? /* @__PURE__ */ jsx17(
1834
+ DataTable,
1835
+ {
1836
+ tableKey: "securityPanel.table",
1837
+ rowElementKey: "securityPanel.row",
1838
+ rowKey: (session) => session.id,
1839
+ rows: sessions,
1840
+ columns: [
1841
+ { key: "device", label: t.security.columnDevice, render: (session) => /* @__PURE__ */ jsxs17("div", { className: "throttle-row", children: [
1842
+ /* @__PURE__ */ jsx17("span", { children: describeDevice(session.userAgent) || session.ipPrefix || session.id }),
1843
+ session.current ? /* @__PURE__ */ jsx17(Badge, { tone: "success", children: t.security.thisDevice }) : null
1844
+ ] }) },
1845
+ { key: "lastActive", label: t.security.lastActive, render: (session) => formatDate(session.lastUsedAt, locale) },
1846
+ { key: "actions", label: t.common.actions, render: (session) => !session.current ? /* @__PURE__ */ jsx17(
1847
+ Button,
1848
+ {
1849
+ variant: "danger",
1850
+ loading: sessionAction.submitting,
1851
+ elementKey: "securityPanel.revokeButton",
1852
+ onClick: () => void sessionAction.run(async () => {
1853
+ await auth.revokeSession(session.id);
1854
+ await load();
1855
+ }),
1856
+ children: t.security.revokeButton
1857
+ }
1858
+ ) : null }
1859
+ ]
1860
+ }
1861
+ ) : (sessions ?? []).map((session) => /* @__PURE__ */ jsxs17("div", { ...a.el("securityPanel.sessionItem", itemBase), children: [
1862
+ /* @__PURE__ */ jsxs17("div", { children: [
1863
+ /* @__PURE__ */ jsxs17("div", { className: "throttle-row", children: [
1864
+ /* @__PURE__ */ jsx17("strong", { children: describeDevice(session.userAgent) || session.ipPrefix || session.id }),
1865
+ session.current ? /* @__PURE__ */ jsx17(Badge, { tone: "success", children: t.security.thisDevice }) : null
1866
+ ] }),
1867
+ /* @__PURE__ */ jsxs17("p", { className: "throttle-muted", children: [
1868
+ t.security.lastActive,
1869
+ " ",
1870
+ formatDate(session.lastUsedAt, locale)
1871
+ ] })
1872
+ ] }),
1873
+ !session.current ? /* @__PURE__ */ jsx17(
1874
+ Button,
1875
+ {
1876
+ variant: revokeVariant,
1877
+ loading: sessionAction.submitting,
1878
+ elementKey: "securityPanel.revokeButton",
1879
+ onClick: () => void sessionAction.run(async () => {
1880
+ await auth.revokeSession(session.id);
1881
+ await load();
1882
+ }),
1883
+ children: t.security.revokeButton
1884
+ }
1885
+ ) : null
1886
+ ] }, session.id)),
1887
+ sessions !== null && others.length === 0 ? /* @__PURE__ */ jsx17("p", { className: "throttle-muted", children: t.security.sessionsEmpty }) : null,
1888
+ others.length > 0 ? /* @__PURE__ */ jsx17(
1889
+ Button,
1890
+ {
1891
+ variant: "danger",
1892
+ loading: sessionAction.submitting,
1893
+ elementKey: "securityPanel.revokeAllButton",
1894
+ onClick: () => void sessionAction.run(async () => {
1895
+ for (const session of others) {
1896
+ await auth.revokeSession(session.id);
1897
+ }
1898
+ await load();
1899
+ }),
1900
+ children: t.security.revokeAllButton
1901
+ }
1902
+ ) : null
1903
+ ] })
1904
+ ] }) }) });
1905
+ }
1906
+
1907
+ // src/react/components/account/AccountDashboard.tsx
1908
+ import { Fragment as Fragment6, jsx as jsx18, jsxs as jsxs18 } from "react/jsx-runtime";
1909
+ var ACCOUNT_TABS = [
1910
+ "profile",
1911
+ "addresses",
1912
+ "paymentMethods",
1913
+ "orders",
1914
+ "invoices",
1915
+ "subscriptions",
1916
+ "security"
1917
+ ];
1918
+ var HASH_FOR = {
1919
+ profile: "#/profile",
1920
+ addresses: "#/addresses",
1921
+ paymentMethods: "#/payment-methods",
1922
+ orders: "#/orders",
1923
+ invoices: "#/invoices",
1924
+ subscriptions: "#/subscriptions",
1925
+ security: "#/security"
1926
+ };
1927
+ var TAB_FOR_HASH = Object.fromEntries(
1928
+ Object.entries(HASH_FOR).map(([tab, hash]) => [hash, tab])
1929
+ );
1930
+ function AccountDashboard(props) {
1931
+ const a = useAppearance(props.appearance);
1932
+ const scoped = useAppearanceProviderValue(props.appearance);
1933
+ const { t } = useCopy(props.localization);
1934
+ const { status } = useAuth();
1935
+ const shown = props.tabs ?? [...ACCOUNT_TABS];
1936
+ const controlled = props.tab !== void 0;
1937
+ const [internal, setInternal] = useState11(shown[0] ?? "profile");
1938
+ const [openOrderId, setOpenOrderId] = useState11(null);
1939
+ const idBase = useId2();
1940
+ useEffect6(() => {
1941
+ if (props.routing !== "hash" || typeof window === "undefined") return;
1942
+ const apply = () => {
1943
+ const next = TAB_FOR_HASH[window.location.hash] ?? shown[0];
1944
+ if (!next || !shown.includes(next)) return;
1945
+ if (controlled) props.onTabChange?.(next);
1946
+ else setInternal(next);
1947
+ };
1948
+ apply();
1949
+ window.addEventListener("hashchange", apply);
1950
+ return () => window.removeEventListener("hashchange", apply);
1951
+ }, [props.routing, controlled, shown.join(",")]);
1952
+ if (status !== "authenticated") return null;
1953
+ const active = controlled ? props.tab : internal;
1954
+ const go = (next) => {
1955
+ props.onTabChange?.(next);
1956
+ if (!controlled) setInternal(next);
1957
+ if (props.routing === "hash" && typeof window !== "undefined") window.location.hash = HASH_FOR[next];
1958
+ };
1959
+ const shared = { appearance: props.appearance, localization: props.localization };
1960
+ const sidebar = (props.layout ?? "sidebar") === "sidebar";
1961
+ const nav = /* @__PURE__ */ jsx18(
1962
+ Tabs,
1963
+ {
1964
+ idBase,
1965
+ orientation: sidebar ? "vertical" : "horizontal",
1966
+ active,
1967
+ onChange: (id) => go(id),
1968
+ tabs: shown.map((id) => ({
1969
+ id,
1970
+ label: t.account.tabs[id],
1971
+ // Icons ride the rail only. In the horizontal strip they cost
1972
+ // horizontal room, which is the scarce axis there.
1973
+ icon: sidebar ? ACCOUNT_ICONS[id] : void 0
1974
+ }))
1975
+ }
1976
+ );
1977
+ const panel = /* @__PURE__ */ jsxs18(
1978
+ "div",
1979
+ {
1980
+ ...a.el("accountDashboard.panel", sidebar ? "throttle-account__content" : "throttle-tabs__panel"),
1981
+ role: "tabpanel",
1982
+ id: `${idBase}-panel-${active}`,
1983
+ "aria-labelledby": `${idBase}-tab-${active}`,
1984
+ tabIndex: 0,
1985
+ children: [
1986
+ active === "profile" ? /* @__PURE__ */ jsx18(ProfilePanel, { ...shared }) : null,
1987
+ active === "addresses" ? /* @__PURE__ */ jsx18(AddressesPanel, { ...shared, variant: props.panelVariant }) : null,
1988
+ active === "paymentMethods" ? /* @__PURE__ */ jsx18(PaymentMethodsPanel, { ...shared, variant: props.panelVariant }) : null,
1989
+ active === "orders" ? /* @__PURE__ */ jsx18(
1990
+ OrdersPanel,
1991
+ {
1992
+ ...shared,
1993
+ variant: props.panelVariant,
1994
+ initialOpenId: openOrderId,
1995
+ onViewSubscription: () => go("subscriptions"),
1996
+ onPayNow: props.onPayNow,
1997
+ onReorder: props.onReorder,
1998
+ onTrackShipment: props.onTrackShipment,
1999
+ reorderOnPaid: props.reorderOnPaid
2000
+ }
2001
+ ) : null,
2002
+ active === "invoices" ? /* @__PURE__ */ jsx18(
2003
+ InvoicesPanel,
2004
+ {
2005
+ ...shared,
2006
+ variant: props.panelVariant,
2007
+ onViewOrder: (orderId) => {
2008
+ setOpenOrderId(orderId);
2009
+ go("orders");
2010
+ },
2011
+ onViewSubscription: () => go("subscriptions")
2012
+ }
2013
+ ) : null,
2014
+ active === "subscriptions" ? /* @__PURE__ */ jsx18(SubscriptionsPanel, { ...shared, variant: props.panelVariant }) : null,
2015
+ active === "security" ? /* @__PURE__ */ jsx18(SecurityPanel, { ...shared, variant: props.panelVariant }) : null
2016
+ ]
2017
+ }
2018
+ );
2019
+ return /* @__PURE__ */ jsx18(AppearanceProvider, { value: scoped, children: /* @__PURE__ */ jsx18("div", { ...a.rootProps, children: /* @__PURE__ */ jsxs18("div", { ...a.el("accountDashboard.root", "throttle-panel throttle-account-root"), children: [
2020
+ /* @__PURE__ */ jsx18(VerifyEmailBanner, { ...shared }),
2021
+ sidebar ? /* @__PURE__ */ jsxs18("div", { className: "throttle-account", children: [
2022
+ /* @__PURE__ */ jsx18("div", { ...a.el("accountDashboard.sidebar"), children: nav }),
2023
+ panel
2024
+ ] }) : /* @__PURE__ */ jsxs18(Fragment6, { children: [
2025
+ /* @__PURE__ */ jsx18("div", { ...a.el("accountDashboard.tabs"), children: nav }),
2026
+ panel
2027
+ ] })
2028
+ ] }) }) });
2029
+ }
2030
+
2031
+ // src/react/components/account/AccountModal.tsx
2032
+ import { jsx as jsx19, jsxs as jsxs19 } from "react/jsx-runtime";
2033
+ function AccountModal(props) {
2034
+ const a = useAppearance(props.appearance);
2035
+ const scoped = useAppearanceProviderValue(props.appearance);
2036
+ const { t } = useCopy(props.localization);
2037
+ const titleId = useId3();
2038
+ return /* @__PURE__ */ jsx19(AppearanceProvider, { value: scoped, children: /* @__PURE__ */ jsxs19(
2039
+ Modal,
2040
+ {
2041
+ open: props.open,
2042
+ onClose: props.onClose,
2043
+ labelledBy: titleId,
2044
+ restoreFocusTo: props.restoreFocusTo,
2045
+ overlayKey: "accountModal.overlay",
2046
+ containerKey: "accountModal.container",
2047
+ children: [
2048
+ /* @__PURE__ */ jsx19("div", { ...a.el("accountModal.header", "throttle-modal__header"), children: /* @__PURE__ */ jsx19("h2", { id: titleId, ...a.el("accountModal.title", "throttle-modal__title"), children: t.account.title }) }),
2049
+ /* @__PURE__ */ jsx19("div", { ...a.el("accountModal.body", "throttle-modal__body"), children: /* @__PURE__ */ jsx19(AccountDashboard, { tabs: props.tabs, appearance: props.appearance, localization: props.localization }) })
2050
+ ]
2051
+ }
2052
+ ) });
2053
+ }
2054
+
2055
+ export {
2056
+ VerifyEmailBanner,
2057
+ PanelState,
2058
+ ProfilePanel,
2059
+ AddressForm,
2060
+ AddressesPanel,
2061
+ AddCardDialog,
2062
+ PaymentMethodsPanel,
2063
+ formatMoney,
2064
+ formatDate,
2065
+ OrderDetail,
2066
+ OrdersPanel,
2067
+ InvoiceDetail,
2068
+ InvoicesPanel,
2069
+ SubscriptionsPanel,
2070
+ SecurityPanel,
2071
+ ACCOUNT_TABS,
2072
+ AccountDashboard,
2073
+ AccountModal
2074
+ };
2075
+ //# sourceMappingURL=chunk-6WN3J5MM.js.map