@schematichq/schematic-components 2.25.2 → 2.27.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.
@@ -0,0 +1,1859 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/elements/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ BillingDataProvider: () => import_schematic_react4.BillingDataProvider,
24
+ DEFAULT_STRINGS: () => DEFAULT_STRINGS,
25
+ Invoices: () => Invoices,
26
+ SCHEMATIC_TOKENS: () => SCHEMATIC_TOKENS,
27
+ SchematicI18nProvider: () => import_schematic_react4.SchematicI18nProvider,
28
+ SchematicStyles: () => SchematicStyles,
29
+ UpcomingBill: () => UpcomingBill,
30
+ billingResources: () => billingResources,
31
+ deriveInvoiceList: () => deriveInvoiceList,
32
+ deriveUpcomingInvoice: () => deriveUpcomingInvoice,
33
+ featureName: () => featureName,
34
+ formatConsumptionRate: () => formatConsumptionRate,
35
+ formatCurrency: () => formatCurrency,
36
+ formatDate: () => formatDate,
37
+ formatNumber: () => formatNumber,
38
+ formatPercent: () => formatPercent,
39
+ formatShortDate: () => formatShortDate,
40
+ httpStatus: () => httpStatus,
41
+ interpolate: () => interpolate,
42
+ lookup: () => lookup,
43
+ plural: () => plural,
44
+ resolveLocale: () => resolveLocale,
45
+ schematicStylesCss: () => schematicStylesCss,
46
+ schematicTokensCss: () => schematicTokensCss,
47
+ useInvalidateBillingData: () => import_schematic_react4.useInvalidateBillingData,
48
+ useInvoices: () => import_schematic_react4.useInvoices,
49
+ useResolvedLocale: () => useResolvedLocale,
50
+ useSchematicI18n: () => import_schematic_react4.useSchematicI18n,
51
+ useSchematicLocale: () => import_schematic_react4.useSchematicLocale,
52
+ useSchematicStrings: () => import_schematic_react4.useSchematicStrings,
53
+ useSchematicTranslate: () => import_schematic_react4.useSchematicTranslate,
54
+ useTranslator: () => useTranslator,
55
+ useUpcomingInvoice: () => import_schematic_react4.useUpcomingInvoice,
56
+ viewerLocale: () => viewerLocale
57
+ });
58
+ module.exports = __toCommonJS(index_exports);
59
+ var import_schematic_react4 = require("@schematichq/schematic-react");
60
+
61
+ // src/elements/model/errors.ts
62
+ function httpStatus(error) {
63
+ if (error === void 0 || error.name !== "SchematicApiError") {
64
+ return void 0;
65
+ }
66
+ const { status } = error;
67
+ return typeof status === "number" ? status : void 0;
68
+ }
69
+
70
+ // src/utils/pluralize.ts
71
+ var pluralRules = [];
72
+ var singularRules = [];
73
+ var uncountables = {};
74
+ var irregularPlurals = {};
75
+ var irregularSingles = {};
76
+ function sanitizeRule(rule) {
77
+ return typeof rule === "string" ? new RegExp("^" + rule + "$", "i") : rule;
78
+ }
79
+ function restoreCase(word, token) {
80
+ if (word === token) {
81
+ return token;
82
+ }
83
+ if (word === word.toLowerCase()) {
84
+ return token.toLowerCase();
85
+ }
86
+ if (word === word.toUpperCase()) {
87
+ return token.toUpperCase();
88
+ }
89
+ if (word[0] === word[0].toUpperCase()) {
90
+ return token.charAt(0).toUpperCase() + token.slice(1).toLowerCase();
91
+ }
92
+ return token.toLowerCase();
93
+ }
94
+ function replace(word, rule) {
95
+ return word.replace(rule[0], function(...args) {
96
+ const [match, index] = args;
97
+ const result = rule[1].replace(
98
+ /\$(\d{1,2})/g,
99
+ (match2, index2) => args[index2] || ""
100
+ );
101
+ if (match === "") {
102
+ return restoreCase(word[index - 1], result);
103
+ }
104
+ return restoreCase(match, result);
105
+ });
106
+ }
107
+ function sanitizeWord(token, word, rules) {
108
+ if (!token.length || token in uncountables) {
109
+ return word;
110
+ }
111
+ let len = rules.length;
112
+ while (len--) {
113
+ const rule = rules[len];
114
+ if (rule[0].test(word)) {
115
+ return replace(word, rule);
116
+ }
117
+ }
118
+ return word;
119
+ }
120
+ function replaceWord(replaceMap, keepMap, rules) {
121
+ return function(word) {
122
+ const token = word.toLowerCase();
123
+ if (token in keepMap) {
124
+ return restoreCase(word, token);
125
+ }
126
+ if (token in replaceMap) {
127
+ return restoreCase(word, replaceMap[token]);
128
+ }
129
+ return sanitizeWord(token, word, rules);
130
+ };
131
+ }
132
+ function checkWord(replaceMap, keepMap, rules) {
133
+ return function(word) {
134
+ const token = word.toLowerCase();
135
+ if (token in keepMap) {
136
+ return true;
137
+ }
138
+ if (token in replaceMap) {
139
+ return false;
140
+ }
141
+ return sanitizeWord(token, token, rules) === token;
142
+ };
143
+ }
144
+ function pluralize(word, count, inclusive) {
145
+ const pluralized = count === 1 ? pluralize.singular(word) : pluralize.plural(word);
146
+ return (inclusive ? count + " " : "") + pluralized;
147
+ }
148
+ pluralize.plural = replaceWord(irregularSingles, irregularPlurals, pluralRules);
149
+ pluralize.isPlural = checkWord(irregularSingles, irregularPlurals, pluralRules);
150
+ pluralize.singular = replaceWord(
151
+ irregularPlurals,
152
+ irregularSingles,
153
+ singularRules
154
+ );
155
+ pluralize.isSingular = checkWord(
156
+ irregularPlurals,
157
+ irregularSingles,
158
+ singularRules
159
+ );
160
+ pluralize.addPluralRule = function(rule, replacement) {
161
+ pluralRules.push([sanitizeRule(rule), replacement]);
162
+ };
163
+ pluralize.addSingularRule = function(rule, replacement) {
164
+ singularRules.push([sanitizeRule(rule), replacement]);
165
+ };
166
+ pluralize.addUncountableRule = function(word) {
167
+ if (typeof word === "string") {
168
+ uncountables[word.toLowerCase()] = true;
169
+ return;
170
+ }
171
+ pluralize.addPluralRule(word, "$0");
172
+ pluralize.addSingularRule(word, "$0");
173
+ };
174
+ pluralize.addIrregularRule = function(single, plural2) {
175
+ plural2 = plural2.toLowerCase();
176
+ single = single.toLowerCase();
177
+ irregularSingles[single] = plural2;
178
+ irregularPlurals[plural2] = single;
179
+ };
180
+ [
181
+ // Pronouns.
182
+ ["I", "we"],
183
+ ["me", "us"],
184
+ ["he", "they"],
185
+ ["she", "they"],
186
+ ["them", "them"],
187
+ ["myself", "ourselves"],
188
+ ["yourself", "yourselves"],
189
+ ["itself", "themselves"],
190
+ ["herself", "themselves"],
191
+ ["himself", "themselves"],
192
+ ["themself", "themselves"],
193
+ ["is", "are"],
194
+ ["was", "were"],
195
+ ["has", "have"],
196
+ ["this", "these"],
197
+ ["that", "those"],
198
+ ["my", "our"],
199
+ ["its", "their"],
200
+ ["his", "their"],
201
+ ["her", "their"],
202
+ // Words ending in with a consonant and `o`.
203
+ ["echo", "echoes"],
204
+ ["dingo", "dingoes"],
205
+ ["volcano", "volcanoes"],
206
+ ["tornado", "tornadoes"],
207
+ ["torpedo", "torpedoes"],
208
+ // Ends with `us`.
209
+ ["genus", "genera"],
210
+ ["viscus", "viscera"],
211
+ // Ends with `ma`.
212
+ ["stigma", "stigmata"],
213
+ ["stoma", "stomata"],
214
+ ["dogma", "dogmata"],
215
+ ["lemma", "lemmata"],
216
+ ["schema", "schemata"],
217
+ ["anathema", "anathemata"],
218
+ // Other irregular rules.
219
+ ["ox", "oxen"],
220
+ ["axe", "axes"],
221
+ ["die", "dice"],
222
+ ["yes", "yeses"],
223
+ ["foot", "feet"],
224
+ ["eave", "eaves"],
225
+ ["goose", "geese"],
226
+ ["tooth", "teeth"],
227
+ ["quiz", "quizzes"],
228
+ ["human", "humans"],
229
+ ["proof", "proofs"],
230
+ ["carve", "carves"],
231
+ ["valve", "valves"],
232
+ ["looey", "looies"],
233
+ ["thief", "thieves"],
234
+ ["groove", "grooves"],
235
+ ["pickaxe", "pickaxes"],
236
+ ["passerby", "passersby"],
237
+ ["canvas", "canvases"]
238
+ ].forEach(function(rule) {
239
+ return pluralize.addIrregularRule(rule[0], rule[1]);
240
+ });
241
+ [
242
+ [/s?$/i, "s"],
243
+ [/[\u0080-\uFFFF]$/i, "$0"],
244
+ [/([^aeiou]ese)$/i, "$1"],
245
+ [/(ax|test)is$/i, "$1es"],
246
+ [/(alias|[^aou]us|t[lm]as|gas|ris)$/i, "$1es"],
247
+ [/(e[mn]u)s?$/i, "$1s"],
248
+ [/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, "$1"],
249
+ [
250
+ /(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,
251
+ "$1i"
252
+ ],
253
+ [/(alumn|alg|vertebr)(?:a|ae)$/i, "$1ae"],
254
+ [/(seraph|cherub)(?:im)?$/i, "$1im"],
255
+ [/(her|at|gr)o$/i, "$1oes"],
256
+ [
257
+ /(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i,
258
+ "$1a"
259
+ ],
260
+ [
261
+ /(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i,
262
+ "$1a"
263
+ ],
264
+ [/sis$/i, "ses"],
265
+ [/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, "$1$2ves"],
266
+ [/([^aeiouy]|qu)y$/i, "$1ies"],
267
+ [/([^ch][ieo][ln])ey$/i, "$1ies"],
268
+ [/(x|ch|ss|sh|zz)$/i, "$1es"],
269
+ [/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, "$1ices"],
270
+ [/\b((?:tit)?m|l)(?:ice|ouse)$/i, "$1ice"],
271
+ [/(pe)(?:rson|ople)$/i, "$1ople"],
272
+ [/(child)(?:ren)?$/i, "$1ren"],
273
+ [/eaux$/i, "$0"],
274
+ [/m[ae]n$/i, "men"],
275
+ ["thou", "you"]
276
+ ].forEach((rule) => {
277
+ pluralize.addPluralRule(rule[0], rule[1]);
278
+ });
279
+ [
280
+ [/s$/i, ""],
281
+ [/(ss)$/i, "$1"],
282
+ [/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, "$1fe"],
283
+ [/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, "$1f"],
284
+ [/ies$/i, "y"],
285
+ [/(dg|ss|ois|lk|ok|wn|mb|th|ch|ec|oal|is|ck|ix|sser|ts|wb)ies$/i, "$1ie"],
286
+ [
287
+ /\b(l|(?:neck|cross|hog|aun)?t|coll|faer|food|gen|goon|group|hipp|junk|vegg|(?:pork)?p|charl|calor|cut)ies$/i,
288
+ "$1ie"
289
+ ],
290
+ [/\b(mon|smil)ies$/i, "$1ey"],
291
+ [/\b((?:tit)?m|l)ice$/i, "$1ouse"],
292
+ [/(seraph|cherub)im$/i, "$1"],
293
+ [
294
+ /(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i,
295
+ "$1"
296
+ ],
297
+ [
298
+ /(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i,
299
+ "$1sis"
300
+ ],
301
+ [/(movie|twelve|abuse|e[mn]u)s$/i, "$1"],
302
+ [/(test)(?:is|es)$/i, "$1is"],
303
+ [
304
+ /(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,
305
+ "$1us"
306
+ ],
307
+ [
308
+ /(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i,
309
+ "$1um"
310
+ ],
311
+ [
312
+ /(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i,
313
+ "$1on"
314
+ ],
315
+ [/(alumn|alg|vertebr)ae$/i, "$1a"],
316
+ [/(cod|mur|sil|vert|ind)ices$/i, "$1ex"],
317
+ [/(matr|append)ices$/i, "$1ix"],
318
+ [/(pe)(rson|ople)$/i, "$1rson"],
319
+ [/(child)ren$/i, "$1"],
320
+ [/(eau)x?$/i, "$1"],
321
+ [/men$/i, "man"]
322
+ ].forEach((rule) => {
323
+ pluralize.addSingularRule(rule[0], rule[1]);
324
+ });
325
+ [
326
+ // Singular words with no plurals.
327
+ "adulthood",
328
+ "advice",
329
+ "agenda",
330
+ "aid",
331
+ "aircraft",
332
+ "alcohol",
333
+ "ammo",
334
+ "analytics",
335
+ "anime",
336
+ "athletics",
337
+ "audio",
338
+ "bison",
339
+ "blood",
340
+ "bream",
341
+ "buffalo",
342
+ "butter",
343
+ "carp",
344
+ "cash",
345
+ "chassis",
346
+ "chess",
347
+ "clothing",
348
+ "cod",
349
+ "commerce",
350
+ "cooperation",
351
+ "corps",
352
+ "debris",
353
+ "diabetes",
354
+ "digestion",
355
+ "elk",
356
+ "energy",
357
+ "equipment",
358
+ "excretion",
359
+ "expertise",
360
+ "firmware",
361
+ "flounder",
362
+ "fun",
363
+ "gallows",
364
+ "garbage",
365
+ "graffiti",
366
+ "hardware",
367
+ "headquarters",
368
+ "health",
369
+ "herpes",
370
+ "highjinks",
371
+ "homework",
372
+ "housework",
373
+ "information",
374
+ "jeans",
375
+ "justice",
376
+ "kudos",
377
+ "labour",
378
+ "literature",
379
+ "machinery",
380
+ "mackerel",
381
+ "mail",
382
+ "media",
383
+ "mews",
384
+ "moose",
385
+ "music",
386
+ "mud",
387
+ "manga",
388
+ "news",
389
+ "only",
390
+ "personnel",
391
+ "pike",
392
+ "plankton",
393
+ "pliers",
394
+ "police",
395
+ "pollution",
396
+ "premises",
397
+ "rain",
398
+ "research",
399
+ "rice",
400
+ "salmon",
401
+ "scissors",
402
+ "series",
403
+ "sewage",
404
+ "shambles",
405
+ "shrimp",
406
+ "software",
407
+ "staff",
408
+ "swine",
409
+ "tennis",
410
+ "traffic",
411
+ "transportation",
412
+ "trout",
413
+ "tuna",
414
+ "wealth",
415
+ "welfare",
416
+ "whiting",
417
+ "wildebeest",
418
+ "wildlife",
419
+ "you",
420
+ /pok[eé]mon$/i,
421
+ // Regexes.
422
+ /[^aeiou]ese$/i,
423
+ // "chinese", "japanese"
424
+ /deer$/i,
425
+ // "deer", "reindeer"
426
+ /fish$/i,
427
+ // "fish", "blowfish", "angelfish"
428
+ /measles$/i,
429
+ /o[iu]s$/i,
430
+ // "carnivorous"
431
+ /pox$/i,
432
+ // "chickpox", "smallpox"
433
+ /sheep$/i
434
+ ].forEach(pluralize.addUncountableRule);
435
+
436
+ // src/elements/model/format.ts
437
+ var DEFAULT_LOCALE = "en-US";
438
+ var usableLocales = /* @__PURE__ */ new Map();
439
+ var MAX_CACHED_LOCALES = 64;
440
+ function isUsableLocale(locale) {
441
+ const cached = usableLocales.get(locale);
442
+ if (cached !== void 0) {
443
+ return cached;
444
+ }
445
+ let usable = true;
446
+ try {
447
+ Intl.getCanonicalLocales(locale);
448
+ } catch {
449
+ usable = false;
450
+ }
451
+ if (usableLocales.size >= MAX_CACHED_LOCALES) {
452
+ usableLocales.clear();
453
+ }
454
+ usableLocales.set(locale, usable);
455
+ return usable;
456
+ }
457
+ function usableLocale(locale) {
458
+ return isUsableLocale(locale) ? locale : DEFAULT_LOCALE;
459
+ }
460
+ function resolveLocale(locale) {
461
+ return locale !== void 0 && locale !== "" && isUsableLocale(locale) ? locale : DEFAULT_LOCALE;
462
+ }
463
+ function viewerLocale() {
464
+ if (typeof navigator === "undefined" || navigator.language === "") {
465
+ return void 0;
466
+ }
467
+ return isUsableLocale(navigator.language) ? navigator.language : void 0;
468
+ }
469
+ var ZERO_DECIMAL_CURRENCIES = /* @__PURE__ */ new Set([
470
+ "BIF",
471
+ "CLP",
472
+ "DJF",
473
+ "GNF",
474
+ "JPY",
475
+ "KMF",
476
+ "KRW",
477
+ "MGA",
478
+ "PYG",
479
+ "RWF",
480
+ "UGX",
481
+ "VND",
482
+ "VUV",
483
+ "XAF",
484
+ "XOF",
485
+ "XPF"
486
+ ]);
487
+ var MAXIMUM_FRACTION_DIGITS = 10;
488
+ var MAXIMUM_SIGNIFICANT_DIGITS = 6;
489
+ function toMajorUnits(amountMinor, currency) {
490
+ return ZERO_DECIMAL_CURRENCIES.has(currency.toUpperCase()) ? amountMinor : amountMinor / 100;
491
+ }
492
+ function formatCurrency(amountMinor, currency, locale, options = {}) {
493
+ const resolvedCurrency = currency.toUpperCase();
494
+ const resolvedLocale = usableLocale(locale);
495
+ const { preserveSubUnitPrecision = true } = options;
496
+ const major = toMajorUnits(amountMinor, resolvedCurrency);
497
+ const hasSubUnitPrecision = preserveSubUnitPrecision && /[1-9]/.test((amountMinor % 1).toFixed(MAXIMUM_SIGNIFICANT_DIGITS));
498
+ try {
499
+ return new Intl.NumberFormat(resolvedLocale, {
500
+ style: "currency",
501
+ currency: resolvedCurrency,
502
+ ...hasSubUnitPrecision && {
503
+ minimumSignificantDigits: 1,
504
+ maximumSignificantDigits: 12
505
+ }
506
+ }).format(major);
507
+ } catch {
508
+ return `${formatNumber(major, resolvedLocale, { minimumFractionDigits: 2 })} ${resolvedCurrency}`;
509
+ }
510
+ }
511
+ function formatNumber(value, locale, options) {
512
+ return new Intl.NumberFormat(usableLocale(locale), options).format(value);
513
+ }
514
+ function formatConsumptionRate(rate, locale) {
515
+ return formatNumber(rate, locale, {
516
+ maximumFractionDigits: MAXIMUM_FRACTION_DIGITS
517
+ });
518
+ }
519
+ function formatPercent(fraction, locale) {
520
+ return new Intl.NumberFormat(usableLocale(locale), {
521
+ style: "percent",
522
+ maximumFractionDigits: 2
523
+ }).format(fraction);
524
+ }
525
+ function usableDate(date) {
526
+ if (date === null || date === void 0) {
527
+ return void 0;
528
+ }
529
+ return Number.isNaN(date.getTime()) ? void 0 : date;
530
+ }
531
+ function formatDate(date, locale, options) {
532
+ if (usableDate(date) === void 0) {
533
+ return "";
534
+ }
535
+ return new Intl.DateTimeFormat(usableLocale(locale), {
536
+ month: "long",
537
+ day: "numeric",
538
+ year: "numeric",
539
+ ...options
540
+ }).format(date);
541
+ }
542
+ function formatShortDate(date, locale) {
543
+ if (usableDate(date) === void 0) {
544
+ return "";
545
+ }
546
+ return new Intl.DateTimeFormat(usableLocale(locale), {
547
+ month: "numeric",
548
+ day: "numeric"
549
+ }).format(date);
550
+ }
551
+ function featureName(named, count = 0, locale = DEFAULT_LOCALE) {
552
+ const isOne = pluralCategory(count, locale) === "one";
553
+ const singularName = orNull(named.singularName) ?? named.name;
554
+ const pluralName = orNull(named.pluralName);
555
+ if (isOne) {
556
+ return singularName;
557
+ }
558
+ if (pluralName !== null) {
559
+ return pluralName;
560
+ }
561
+ return isEnglish(locale) ? pluralize(singularName, 2) : singularName;
562
+ }
563
+ function plural(locale, count, forms) {
564
+ return forms[pluralCategory(count, locale)] ?? forms.other;
565
+ }
566
+ function pluralCategory(count, locale) {
567
+ return new Intl.PluralRules(usableLocale(locale)).select(count);
568
+ }
569
+ function isEnglish(locale) {
570
+ return new Intl.Locale(usableLocale(locale)).language === "en";
571
+ }
572
+ function orNull(value) {
573
+ return value === void 0 || value === null || value === "" ? null : value;
574
+ }
575
+
576
+ // src/elements/model/invoices.ts
577
+ function linkableURL(url) {
578
+ if (url === void 0 || url === null || url === "") {
579
+ return null;
580
+ }
581
+ try {
582
+ const { protocol } = new URL(url);
583
+ return protocol === "http:" || protocol === "https:" ? url : null;
584
+ } catch {
585
+ return null;
586
+ }
587
+ }
588
+ function deriveInvoiceList(page, options) {
589
+ const { format, locale } = options;
590
+ return {
591
+ rows: page.invoices.map((invoice) => {
592
+ const date = usableDate(invoice.dueDate) ?? usableDate(invoice.createdAt) ?? null;
593
+ const currency = invoice.currency.toUpperCase();
594
+ return {
595
+ id: invoice.id,
596
+ date,
597
+ dateText: date === null ? "" : format?.date?.(date, locale) ?? formatDate(date, locale),
598
+ amountMinor: invoice.amountDue,
599
+ currency,
600
+ // Absolute: credit notes render in parentheses, not with a minus sign.
601
+ amountText: format?.amount?.(invoice.amountDue, currency, locale) ?? formatCurrency(Math.abs(invoice.amountDue), currency, locale, {
602
+ preserveSubUnitPrecision: false
603
+ }),
604
+ isCredit: invoice.amountDue < 0,
605
+ status: invoice.status ?? null,
606
+ url: linkableURL(invoice.url)
607
+ };
608
+ }),
609
+ count: page.count,
610
+ hasMore: page.hasMore
611
+ };
612
+ }
613
+
614
+ // src/elements/model/upcomingBill.ts
615
+ function deriveUpcomingInvoice(invoice, options) {
616
+ const { format, locale } = options;
617
+ const currency = invoice.currency.toUpperCase();
618
+ const money = (amountMinor) => format?.amount?.(amountMinor, currency, locale) ?? formatCurrency(amountMinor, currency, locale, {
619
+ preserveSubUnitPrecision: false
620
+ });
621
+ const line = (amountMinor) => ({
622
+ amountMinor,
623
+ amountText: money(amountMinor)
624
+ });
625
+ const applied = invoice.customerBalanceApplied;
626
+ const remaining = invoice.customerBalanceRemaining;
627
+ const dueDate = usableDate(invoice.dueDate) ?? null;
628
+ return {
629
+ amountDueMinor: invoice.amountDue,
630
+ amountDueText: money(invoice.amountDue),
631
+ subtotalMinor: invoice.subtotal,
632
+ subtotalText: money(invoice.subtotal),
633
+ currency,
634
+ dueAt: dueDate === null ? null : {
635
+ date: dueDate,
636
+ text: format?.date?.(dueDate, locale) ?? formatDate(dueDate, locale)
637
+ },
638
+ // A deduction: the sign is the locale's, so a host never assembles one.
639
+ balanceApplied: applied > 0 ? line(-applied) : null,
640
+ // Zero remaining is worth saying when a balance was spent; no balance at
641
+ // all is not.
642
+ balanceRemaining: applied > 0 || remaining > 0 ? line(remaining) : null,
643
+ discounts: invoice.discounts.flatMap(
644
+ (discount) => discountLine(discount, currency, locale, money)
645
+ )
646
+ };
647
+ }
648
+ function discountLine(discount, invoiceCurrency, locale, money) {
649
+ const percentOff = discount.percentOff ?? null;
650
+ const amountOff = discount.amountOff ?? null;
651
+ const isPercent = percentOff !== null && percentOff > 0;
652
+ if (!isPercent && (amountOff === null || amountOff <= 0)) {
653
+ return [];
654
+ }
655
+ const currency = discount.currency?.toUpperCase() ?? invoiceCurrency;
656
+ return [
657
+ {
658
+ couponName: discount.couponName,
659
+ code: discount.customerFacingCode ?? null,
660
+ kind: isPercent ? "percent" : "amount",
661
+ valueText: isPercent ? formatPercent(percentOff / 100, locale) : currency === invoiceCurrency ? money(amountOff ?? 0) : formatCurrency(amountOff ?? 0, currency, locale, {
662
+ preserveSubUnitPrecision: false
663
+ }),
664
+ percentOff: isPercent ? percentOff : null,
665
+ amountOffMinor: isPercent ? null : amountOff,
666
+ months: discount.duration === "repeating" ? discount.durationInMonths ?? null : null,
667
+ duration: discount.duration
668
+ }
669
+ ];
670
+ }
671
+
672
+ // src/elements/strings.ts
673
+ var DEFAULT_STRINGS_LOCALE = "en";
674
+ var DEFAULT_STRINGS = {
675
+ retry: "Try again",
676
+ invoicesLoading: "Loading invoices",
677
+ invoicesHeader: "Invoices",
678
+ invoicesError: "There was a problem retrieving your invoices.",
679
+ invoicesUnavailable: "Invoices are not available for this account.",
680
+ invoicesEmpty: "No invoices created yet",
681
+ invoicesSeeMore: "See more",
682
+ invoicesSeeLess: "See less",
683
+ invoicesLoadMore: "Load more",
684
+ invoicesChargeTooltip: "Charge \u2014 you were billed this amount",
685
+ invoicesCreditTooltip: "Credit \u2014 this amount was returned to your account, typically due to a plan change or proration",
686
+ invoicesUndated: "View invoice",
687
+ upcomingBillLoading: "Loading your next bill",
688
+ upcomingBillHeader: "Next bill due {{date}}",
689
+ upcomingBillError: "There was a problem retrieving your upcoming invoice.",
690
+ upcomingBillUnavailable: "Your upcoming invoice is not available for this account.",
691
+ upcomingBillEmpty: "No upcoming invoice",
692
+ upcomingBillEstimate: "Estimated bill",
693
+ upcomingBillBalanceApplied: "Applied balance towards next invoice",
694
+ upcomingBillBalanceRemaining: "Remaining balance after next invoice",
695
+ upcomingBillDiscount: "Discount",
696
+ upcomingBillDiscountValue: "{{value}} off",
697
+ // Looked up by the bare key with `{ count }`; English has two forms.
698
+ upcomingBillDiscountRepeating: "{{value}} off for next {{count}} months",
699
+ upcomingBillDiscountRepeating_one: "{{value}} off for next month",
700
+ upcomingBillDiscountRepeating_other: "{{value}} off for next {{count}} months"
701
+ };
702
+ var MISSING_STRING = "\0schematic:missing";
703
+ function interpolate(template, vars) {
704
+ if (vars === void 0 || !template.includes("{{")) {
705
+ return template;
706
+ }
707
+ return template.replace(/\{\{(\w+)\}\}/g, (whole, name) => {
708
+ const value = vars[name];
709
+ return value === void 0 || value === null ? whole : String(value);
710
+ });
711
+ }
712
+ function pluralCategory2(count, locale) {
713
+ try {
714
+ return new Intl.PluralRules(locale).select(count);
715
+ } catch {
716
+ return "other";
717
+ }
718
+ }
719
+ function lookup(catalog, key, vars, locale = DEFAULT_STRINGS_LOCALE) {
720
+ if (catalog === void 0) {
721
+ return void 0;
722
+ }
723
+ const count = vars?.count;
724
+ const template = typeof count === "number" ? catalog[`${key}_${pluralCategory2(count, locale)}`] ?? catalog[`${key}_other`] ?? catalog[key] : catalog[key];
725
+ return template === void 0 ? void 0 : interpolate(template, vars);
726
+ }
727
+ function defaultString(key, vars) {
728
+ return lookup(DEFAULT_STRINGS, key, vars) ?? DEFAULT_STRINGS[key] ?? key;
729
+ }
730
+
731
+ // src/elements/styles/invoices.ts
732
+ var invoicesCss = `
733
+ .schematic-invoices {
734
+ display: flex;
735
+ flex-direction: column;
736
+ }
737
+
738
+ .schematic-invoices__list {
739
+ display: flex;
740
+ flex-direction: column;
741
+ gap: calc(var(--schematic-space) / 2);
742
+ list-style: none;
743
+ margin: 0;
744
+ padding: 0;
745
+ }
746
+
747
+ .schematic-invoices__row {
748
+ align-items: center;
749
+ display: flex;
750
+ gap: var(--schematic-space);
751
+ justify-content: space-between;
752
+ }
753
+
754
+ .schematic-invoices__date {
755
+ text-align: start;
756
+ }
757
+
758
+ .schematic-invoices__link {
759
+ color: var(--schematic-accent);
760
+ text-decoration: none;
761
+ }
762
+
763
+ .schematic-invoices__link:hover {
764
+ text-decoration: underline;
765
+ }
766
+
767
+ .schematic-invoices__amount {
768
+ cursor: help;
769
+ font-variant-numeric: tabular-nums;
770
+ /* Keeps a lone amount at the end when the date is hidden. */
771
+ margin-inline-start: auto;
772
+ text-align: end;
773
+ }
774
+
775
+ .schematic-invoices__credit {
776
+ color: var(--schematic-muted);
777
+ }
778
+
779
+ .schematic-invoices__actions {
780
+ align-items: center;
781
+ display: flex;
782
+ gap: var(--schematic-space);
783
+ margin-top: var(--schematic-space);
784
+ }
785
+
786
+ .schematic-invoices__see-more {
787
+ align-items: center;
788
+ display: inline-flex;
789
+ gap: 0.375rem;
790
+ }
791
+
792
+ /* A chevron drawn from two borders. The vertical nudge lives in the
793
+ transform with the rotation so one transition carries both. */
794
+ .schematic-invoices__chevron {
795
+ border-block-end: 2px solid var(--schematic-muted);
796
+ border-inline-end: 2px solid var(--schematic-muted);
797
+ display: inline-block;
798
+ height: 0.5em;
799
+ transform: translateY(-0.125em) rotate(45deg);
800
+ transition: transform 0.15s;
801
+ width: 0.5em;
802
+ }
803
+
804
+ .schematic-invoices__see-more[aria-expanded="true"] .schematic-invoices__chevron {
805
+ transform: translateY(0.125em) rotate(-135deg);
806
+ }
807
+
808
+ .schematic-invoices__empty {
809
+ padding: calc(var(--schematic-space) / 2) 0;
810
+ }
811
+
812
+ .schematic-invoices .schematic-skeleton__cell[data-column="date"] {
813
+ width: 7rem;
814
+ }
815
+
816
+ .schematic-invoices .schematic-skeleton__cell[data-column="amount"] {
817
+ width: 4rem;
818
+ }
819
+ `;
820
+
821
+ // src/elements/styles/tokens.ts
822
+ var ld = (light, dark) => `light-dark(${light}, ${dark})`;
823
+ var SCHEMATIC_TOKENS = {
824
+ "--schematic-accent": ld("#194bfb", "#6f92ff"),
825
+ "--schematic-accent-contrast": ld("#ffffff", "#0a0a0a"),
826
+ "--schematic-background": ld("#ffffff", "#0e0e0e"),
827
+ "--schematic-border": ld(
828
+ "hsla(0, 0%, 0%, 0.125)",
829
+ "hsla(0, 0%, 100%, 0.145)"
830
+ ),
831
+ "--schematic-card-divider": ld(
832
+ "hsla(0, 0%, 0%, 0.175)",
833
+ "hsla(0, 0%, 100%, 0.2)"
834
+ ),
835
+ "--schematic-card-padding": "2.8125rem",
836
+ "--schematic-danger": ld("#d75a5c", "#ff6b6e"),
837
+ "--schematic-font-body": '"Public Sans", system-ui, sans-serif',
838
+ "--schematic-font-heading": '"Manrope", system-ui, sans-serif',
839
+ "--schematic-line-height": "1.5",
840
+ "--schematic-line-height-heading": "1.2",
841
+ "--schematic-meter-track": ld("#f2f4f7", "#26282d"),
842
+ "--schematic-muted": ld("#8a8a8a", "#a1a1a1"),
843
+ "--schematic-primary": ld("#000000", "#ffffff"),
844
+ "--schematic-primary-contrast": ld("#ffffff", "#000000"),
845
+ "--schematic-radius": "0.625rem",
846
+ // `light-dark()` takes colours only, so it is applied per shadow layer.
847
+ "--schematic-shadow": `0px 1px 20px 0px ${ld("#1018280f", "#00000099")}, 0px 1px 3px 0px ${ld("#1018281a", "#0000007a")}`,
848
+ "--schematic-space": "1rem",
849
+ "--schematic-text": ld("#000000", "#ffffff"),
850
+ "--schematic-warning": ld("#ffaa06", "#ffbb3d")
851
+ };
852
+ var BARE_TOKEN = /var\((--schematic-[a-z-]+)\)/g;
853
+ function withTokenDefaults(css) {
854
+ return css.replace(BARE_TOKEN, (_match, name) => {
855
+ const fallback = SCHEMATIC_TOKENS[name];
856
+ if (fallback === void 0) {
857
+ throw new Error(`Unknown Schematic token: ${name}`);
858
+ }
859
+ return `var(${name}, ${fallback})`;
860
+ });
861
+ }
862
+ var schematicTokensCss = `:root {
863
+ ${Object.entries(SCHEMATIC_TOKENS).map(([name, value]) => ` ${name}: ${value};`).join("\n")}
864
+ }
865
+ `;
866
+
867
+ // src/elements/styles/upcoming-bill.ts
868
+ var upcomingBillCss = `
869
+ .schematic-upcoming-bill {
870
+ display: flex;
871
+ flex-direction: column;
872
+ gap: var(--schematic-space);
873
+ }
874
+
875
+ .schematic-upcoming-bill .schematic-header {
876
+ margin-bottom: 0;
877
+ }
878
+
879
+ .schematic-upcoming-bill .schematic-header__title {
880
+ margin-bottom: 0;
881
+ }
882
+
883
+ .schematic-upcoming-bill__amount {
884
+ align-items: flex-start;
885
+ display: flex;
886
+ gap: var(--schematic-space);
887
+ justify-content: space-between;
888
+ }
889
+
890
+ .schematic-upcoming-bill__total {
891
+ font-family: var(--schematic-font-heading);
892
+ font-size: 1.8125rem;
893
+ font-variant-numeric: tabular-nums;
894
+ font-weight: 800;
895
+ line-height: 1;
896
+ }
897
+
898
+ .schematic-upcoming-bill__estimate {
899
+ font-weight: 600;
900
+ max-width: 10rem;
901
+ text-align: end;
902
+ }
903
+
904
+ .schematic-upcoming-bill__rows {
905
+ display: flex;
906
+ flex-direction: column;
907
+ gap: var(--schematic-space);
908
+ }
909
+
910
+ .schematic-upcoming-bill .schematic-row__value {
911
+ font-variant-numeric: tabular-nums;
912
+ }
913
+
914
+ .schematic-upcoming-bill__discounts {
915
+ align-items: flex-end;
916
+ display: flex;
917
+ flex-direction: column;
918
+ gap: calc(var(--schematic-space) / 2);
919
+ list-style: none;
920
+ margin: 0;
921
+ padding: 0;
922
+ }
923
+
924
+ .schematic-upcoming-bill__discount {
925
+ align-items: center;
926
+ display: inline-flex;
927
+ gap: calc(var(--schematic-space) / 2);
928
+ }
929
+
930
+ .schematic-upcoming-bill__empty {
931
+ padding: calc(var(--schematic-space) / 2) 0;
932
+ }
933
+
934
+ .schematic-upcoming-bill .schematic-skeleton__cell[data-column="amount"] {
935
+ height: 1.8125rem;
936
+ width: 7rem;
937
+ }
938
+
939
+ .schematic-upcoming-bill .schematic-skeleton__cell[data-column="row"] {
940
+ width: 12rem;
941
+ }
942
+ `;
943
+
944
+ // src/elements/styles/index.tsx
945
+ var import_jsx_runtime = require("react/jsx-runtime");
946
+ var rulesCss = `
947
+ :where([class^="schematic-"]) {
948
+ box-sizing: border-box;
949
+ color: var(--schematic-text);
950
+ font-family: var(--schematic-font-body);
951
+ line-height: var(--schematic-line-height);
952
+ }
953
+
954
+ :where([class^="schematic-"]) *,
955
+ :where([class^="schematic-"]) *::before,
956
+ :where([class^="schematic-"]) *::after {
957
+ box-sizing: inherit;
958
+ }
959
+
960
+ :where([class^="schematic-"]) p {
961
+ margin: 0;
962
+ }
963
+
964
+ .schematic-card {
965
+ background: var(--schematic-background);
966
+ border-radius: var(--schematic-radius);
967
+ box-shadow: var(--schematic-shadow);
968
+ color: var(--schematic-text);
969
+ padding: calc(var(--schematic-card-padding) * 0.75)
970
+ var(--schematic-card-padding);
971
+ }
972
+
973
+ .schematic-muted {
974
+ color: var(--schematic-muted);
975
+ }
976
+
977
+ .schematic-small {
978
+ font-size: 0.875rem;
979
+ }
980
+
981
+ .schematic-status {
982
+ align-items: center;
983
+ display: flex;
984
+ gap: var(--schematic-space);
985
+ }
986
+
987
+ /* The message may run long; the action beside it stays one line. */
988
+ .schematic-status__retry {
989
+ flex-shrink: 0;
990
+ white-space: nowrap;
991
+ }
992
+
993
+ /* Visually hidden, still read by assistive technology. */
994
+ .schematic-hidden {
995
+ border: 0;
996
+ clip-path: inset(50%);
997
+ height: 1px;
998
+ overflow: hidden;
999
+ padding: 0;
1000
+ position: absolute;
1001
+ white-space: nowrap;
1002
+ width: 1px;
1003
+ }
1004
+
1005
+ .schematic-skeleton {
1006
+ animation: schematic-pulse 1.2s ease-in-out infinite;
1007
+ display: flex;
1008
+ flex-direction: column;
1009
+ gap: calc(var(--schematic-space) * 0.75);
1010
+ }
1011
+
1012
+ .schematic-skeleton:empty {
1013
+ background: var(--schematic-meter-track);
1014
+ border-radius: var(--schematic-radius);
1015
+ min-height: 6rem;
1016
+ }
1017
+
1018
+ .schematic-skeleton__heading,
1019
+ .schematic-skeleton__cell {
1020
+ background: var(--schematic-meter-track);
1021
+ border-radius: calc(var(--schematic-radius) / 2);
1022
+ }
1023
+
1024
+ .schematic-skeleton__heading {
1025
+ height: 1.25rem;
1026
+ margin-bottom: calc(var(--schematic-space) * 0.75);
1027
+ width: 8rem;
1028
+ }
1029
+
1030
+ .schematic-skeleton__row {
1031
+ align-items: center;
1032
+ display: flex;
1033
+ gap: var(--schematic-space);
1034
+ justify-content: space-between;
1035
+ }
1036
+
1037
+ .schematic-skeleton__cell {
1038
+ height: 1rem;
1039
+ }
1040
+
1041
+ @keyframes schematic-pulse {
1042
+ 0%,
1043
+ 100% {
1044
+ opacity: 1;
1045
+ }
1046
+ 50% {
1047
+ opacity: 0.5;
1048
+ }
1049
+ }
1050
+
1051
+ @media (prefers-reduced-motion: reduce) {
1052
+ .schematic-skeleton {
1053
+ animation: none;
1054
+ }
1055
+ }
1056
+
1057
+ .schematic-error {
1058
+ color: var(--schematic-danger);
1059
+ }
1060
+
1061
+ .schematic-status-note {
1062
+ font-size: 0.875rem;
1063
+ margin-top: var(--schematic-space);
1064
+ }
1065
+
1066
+ .schematic-cta {
1067
+ align-items: center;
1068
+ background: var(--schematic-primary);
1069
+ border: 1px solid var(--schematic-primary);
1070
+ border-radius: 0.5rem;
1071
+ color: var(--schematic-primary-contrast);
1072
+ cursor: pointer;
1073
+ display: inline-flex;
1074
+ font-family: var(--schematic-font-body);
1075
+ font-size: 1.0625rem;
1076
+ font-weight: 500;
1077
+ justify-content: center;
1078
+ line-height: 1;
1079
+ min-height: 3.25rem;
1080
+ padding: 0.5rem 1.5rem;
1081
+ text-decoration: none;
1082
+ transition: background-color 0.1s, border-color 0.1s;
1083
+ }
1084
+
1085
+ .schematic-cta:hover:not(:disabled) {
1086
+ background: color-mix(
1087
+ in srgb,
1088
+ var(--schematic-primary) 85%,
1089
+ var(--schematic-primary-contrast)
1090
+ );
1091
+ border-color: color-mix(
1092
+ in srgb,
1093
+ var(--schematic-primary) 85%,
1094
+ var(--schematic-primary-contrast)
1095
+ );
1096
+ }
1097
+
1098
+ .schematic-cta:focus-visible,
1099
+ .schematic-link-button:focus-visible {
1100
+ outline: 2px solid var(--schematic-accent);
1101
+ outline-offset: 2px;
1102
+ }
1103
+
1104
+ .schematic-cta:disabled {
1105
+ background: var(--schematic-meter-track);
1106
+ border-color: var(--schematic-meter-track);
1107
+ color: var(--schematic-muted);
1108
+ cursor: not-allowed;
1109
+ }
1110
+
1111
+ .schematic-cta--outline {
1112
+ background: transparent;
1113
+ color: var(--schematic-text);
1114
+ }
1115
+
1116
+ .schematic-cta--outline:hover:not(:disabled) {
1117
+ background: color-mix(in srgb, var(--schematic-primary) 10%, transparent);
1118
+ border-color: var(--schematic-primary);
1119
+ }
1120
+
1121
+ .schematic-cta--small {
1122
+ font-size: 0.9375rem;
1123
+ min-height: 2.5rem;
1124
+ padding: 0.375rem 1rem;
1125
+ }
1126
+
1127
+ .schematic-link-button {
1128
+ background: none;
1129
+ border: none;
1130
+ color: var(--schematic-accent);
1131
+ cursor: pointer;
1132
+ font-family: var(--schematic-font-body);
1133
+ font-size: 1rem;
1134
+ padding: 0;
1135
+ }
1136
+
1137
+ .schematic-link-button:hover {
1138
+ text-decoration: underline;
1139
+ }
1140
+
1141
+ .schematic-icon {
1142
+ align-items: center;
1143
+ background: color-mix(
1144
+ in oklch,
1145
+ var(--schematic-background) 87.5%,
1146
+ var(--schematic-text)
1147
+ );
1148
+ border-radius: 9999px;
1149
+ color: var(--schematic-primary);
1150
+ display: inline-flex;
1151
+ flex-shrink: 0;
1152
+ font-size: 1.5rem;
1153
+ font-style: normal;
1154
+ height: 2.75rem;
1155
+ justify-content: center;
1156
+ line-height: 1;
1157
+ width: 2.75rem;
1158
+ }
1159
+
1160
+ .schematic-icon--bare {
1161
+ background: none;
1162
+ font-size: 1.25rem;
1163
+ height: auto;
1164
+ width: auto;
1165
+ }
1166
+
1167
+ .schematic-meter {
1168
+ background: var(--schematic-meter-track);
1169
+ border-radius: 9999px;
1170
+ height: 0.5rem;
1171
+ overflow: hidden;
1172
+ width: 100%;
1173
+ }
1174
+
1175
+ .schematic-meter__fill {
1176
+ background: var(--schematic-accent);
1177
+ border-radius: 9999px;
1178
+ height: 100%;
1179
+ }
1180
+
1181
+ .schematic-meter--warning .schematic-meter__fill {
1182
+ background: var(--schematic-warning);
1183
+ }
1184
+
1185
+ .schematic-meter--over .schematic-meter__fill {
1186
+ background: var(--schematic-danger);
1187
+ }
1188
+
1189
+ .schematic-notice {
1190
+ border: 1px solid var(--schematic-border);
1191
+ border-inline-start: 4px solid var(--schematic-accent);
1192
+ border-radius: var(--schematic-radius);
1193
+ padding: calc(var(--schematic-space) / 2) var(--schematic-space);
1194
+ }
1195
+
1196
+ .schematic-notice--warning {
1197
+ border-inline-start-color: var(--schematic-warning);
1198
+ }
1199
+
1200
+ .schematic-notice--danger {
1201
+ border-inline-start-color: var(--schematic-danger);
1202
+ }
1203
+
1204
+ .schematic-notice a {
1205
+ color: var(--schematic-accent);
1206
+ }
1207
+
1208
+ .schematic-toggle {
1209
+ border: 1px solid var(--schematic-border);
1210
+ border-radius: 2.5rem;
1211
+ display: inline-flex;
1212
+ }
1213
+
1214
+ .schematic-toggle button {
1215
+ background: none;
1216
+ border: none;
1217
+ border-radius: 2.5rem;
1218
+ color: var(--schematic-text);
1219
+ cursor: pointer;
1220
+ font-family: var(--schematic-font-body);
1221
+ font-size: 0.9375rem;
1222
+ font-weight: 400;
1223
+ line-height: var(--schematic-line-height);
1224
+ margin: -1px;
1225
+ padding: 0.4375rem 1.25rem;
1226
+ white-space: nowrap;
1227
+ }
1228
+
1229
+ .schematic-toggle button[aria-pressed="true"] {
1230
+ background: var(--schematic-border);
1231
+ font-weight: 600;
1232
+ }
1233
+
1234
+ .schematic-select {
1235
+ background: var(--schematic-background);
1236
+ border: 1px solid var(--schematic-border);
1237
+ border-radius: 0.5rem;
1238
+ color: var(--schematic-text);
1239
+ font-family: var(--schematic-font-body);
1240
+ padding: 0.375rem 0.625rem;
1241
+ }
1242
+
1243
+ .schematic-header {
1244
+ align-items: baseline;
1245
+ display: flex;
1246
+ gap: var(--schematic-space);
1247
+ justify-content: space-between;
1248
+ margin-bottom: var(--schematic-space);
1249
+ }
1250
+
1251
+ .schematic-header__title {
1252
+ font-family: var(--schematic-font-heading);
1253
+ font-size: 1.25rem;
1254
+ font-weight: 600;
1255
+ line-height: var(--schematic-line-height-heading);
1256
+ margin: 0 0 calc(var(--schematic-space) / 2);
1257
+ }
1258
+
1259
+ /* A label on the left, its value on the right. */
1260
+ .schematic-row {
1261
+ align-items: flex-start;
1262
+ display: flex;
1263
+ gap: var(--schematic-space);
1264
+ justify-content: space-between;
1265
+ }
1266
+
1267
+ .schematic-row__label {
1268
+ font-weight: 600;
1269
+ }
1270
+
1271
+ .schematic-row__value {
1272
+ text-align: end;
1273
+ }
1274
+
1275
+ .schematic-feature-list {
1276
+ display: flex;
1277
+ flex-direction: column;
1278
+ gap: var(--schematic-space);
1279
+ list-style: none;
1280
+ margin: 0;
1281
+ padding: 0;
1282
+ }
1283
+
1284
+ .schematic-feature {
1285
+ display: flex;
1286
+ flex-direction: column;
1287
+ gap: calc(var(--schematic-space) / 2);
1288
+ }
1289
+
1290
+ .schematic-feature__row {
1291
+ align-items: center;
1292
+ display: flex;
1293
+ gap: var(--schematic-space);
1294
+ }
1295
+
1296
+ .schematic-feature__name {
1297
+ flex-grow: 1;
1298
+ font-weight: 500;
1299
+ }
1300
+
1301
+ .schematic-feature__detail {
1302
+ text-align: end;
1303
+ }
1304
+
1305
+ .schematic-feature__description {
1306
+ color: var(--schematic-muted);
1307
+ font-size: 0.875rem;
1308
+ }
1309
+
1310
+ .schematic-feature__actions {
1311
+ display: flex;
1312
+ justify-content: flex-end;
1313
+ }
1314
+
1315
+ .schematic-badge {
1316
+ background: var(--schematic-primary);
1317
+ border-radius: 9999px;
1318
+ color: var(--schematic-primary-contrast);
1319
+ display: inline-block;
1320
+ font-size: 0.75rem;
1321
+ padding: 0.125rem 0.85rem;
1322
+ }
1323
+
1324
+ .schematic-chip {
1325
+ border: 1px solid var(--schematic-border);
1326
+ border-radius: 0.3125rem;
1327
+ font-size: 0.75rem;
1328
+ padding: 0.1875rem 0.375rem;
1329
+ text-transform: uppercase;
1330
+ }
1331
+
1332
+ .schematic-pricing-table {
1333
+ display: flex;
1334
+ flex-direction: column;
1335
+ gap: calc(var(--schematic-space) * 2);
1336
+ }
1337
+
1338
+ .schematic-pricing-table__controls {
1339
+ align-items: center;
1340
+ display: flex;
1341
+ gap: 0.75rem;
1342
+ margin-inline-start: auto;
1343
+ }
1344
+
1345
+ .schematic-pricing-table__plans {
1346
+ display: grid;
1347
+ gap: var(--schematic-space);
1348
+ grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
1349
+ }
1350
+
1351
+ .schematic-plan-card {
1352
+ display: flex;
1353
+ flex-direction: column;
1354
+ padding: var(--schematic-card-padding) 0;
1355
+ position: relative;
1356
+ }
1357
+
1358
+ .schematic-plan-card--active {
1359
+ outline: 2px solid var(--schematic-primary);
1360
+ }
1361
+
1362
+ .schematic-plan-card__header {
1363
+ border-bottom: 1px solid var(--schematic-card-divider);
1364
+ display: flex;
1365
+ flex-direction: column;
1366
+ gap: 0.75rem;
1367
+ padding: 0 var(--schematic-card-padding)
1368
+ calc(var(--schematic-card-padding) * 0.75);
1369
+ }
1370
+
1371
+ .schematic-plan-card__header h3 {
1372
+ align-items: center;
1373
+ display: flex;
1374
+ font-size: 1.8125rem;
1375
+ font-weight: 800;
1376
+ gap: 0.5rem;
1377
+ margin: 0;
1378
+ }
1379
+
1380
+ .schematic-plan-card__description {
1381
+ min-height: 1.5em;
1382
+ }
1383
+
1384
+ .schematic-plan-card__price {
1385
+ font-family: var(--schematic-font-heading);
1386
+ font-size: 1.8125rem;
1387
+ font-weight: 800;
1388
+ line-height: var(--schematic-line-height-heading);
1389
+ }
1390
+
1391
+ .schematic-plan-card__price sub {
1392
+ font-family: var(--schematic-font-body);
1393
+ font-size: 0.875rem;
1394
+ font-weight: 400;
1395
+ vertical-align: baseline;
1396
+ }
1397
+
1398
+ .schematic-plan-card__badge {
1399
+ position: absolute;
1400
+ inset-inline-end: var(--schematic-space);
1401
+ top: var(--schematic-space);
1402
+ }
1403
+
1404
+ .schematic-plan-card__body {
1405
+ display: flex;
1406
+ flex-direction: column;
1407
+ flex-grow: 1;
1408
+ gap: var(--schematic-card-padding);
1409
+ justify-content: end;
1410
+ padding: calc(var(--schematic-card-padding) * 0.75)
1411
+ var(--schematic-card-padding) 0;
1412
+ }
1413
+
1414
+ .schematic-plan-card__entitlements {
1415
+ display: flex;
1416
+ flex-direction: column;
1417
+ gap: var(--schematic-space);
1418
+ list-style: none;
1419
+ margin: 0;
1420
+ padding: 0;
1421
+ }
1422
+
1423
+ .schematic-plan-card__entitlements li {
1424
+ align-items: center;
1425
+ display: flex;
1426
+ gap: var(--schematic-space);
1427
+ }
1428
+
1429
+ .schematic-plan-card__inclusion {
1430
+ margin-bottom: calc(var(--schematic-space) / 2);
1431
+ }
1432
+
1433
+ .schematic-plan-card__detail {
1434
+ display: block;
1435
+ font-size: 0.875rem;
1436
+ }
1437
+
1438
+ .schematic-plan-card__show-all {
1439
+ margin-top: var(--schematic-space);
1440
+ }
1441
+
1442
+ .schematic-plan-card__current {
1443
+ align-items: center;
1444
+ display: flex;
1445
+ gap: 0.25rem;
1446
+ justify-content: center;
1447
+ padding: 0.625rem 0;
1448
+ }
1449
+
1450
+ .schematic-plan-card__action {
1451
+ display: flex;
1452
+ flex-direction: column;
1453
+ gap: calc(var(--schematic-space) / 2);
1454
+ }
1455
+
1456
+ .schematic-plan-card .schematic-cta {
1457
+ width: 100%;
1458
+ }
1459
+
1460
+ ${invoicesCss}
1461
+ ${upcomingBillCss}
1462
+ `;
1463
+ var schematicStylesCss = withTokenDefaults(rulesCss);
1464
+ var SchematicStyles = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { "data-schematic-styles": "", children: schematicStylesCss });
1465
+
1466
+ // src/elements/Invoices.tsx
1467
+ var import_schematic_react2 = require("@schematichq/schematic-react");
1468
+ var import_react2 = require("react");
1469
+
1470
+ // src/elements/common.tsx
1471
+ var import_schematic_react = require("@schematichq/schematic-react");
1472
+ var import_react = require("react");
1473
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1474
+ var cx = (...names) => names.filter((name) => typeof name === "string" && name !== "").join(" ");
1475
+ function billingResources(...elements) {
1476
+ const names = [];
1477
+ for (const element of elements) {
1478
+ for (const name of element.resources) {
1479
+ if (!names.includes(name)) {
1480
+ names.push(name);
1481
+ }
1482
+ }
1483
+ }
1484
+ return names;
1485
+ }
1486
+ function useResolvedLocale(locale) {
1487
+ const configured = (0, import_schematic_react.useSchematicLocale)();
1488
+ const viewer = (0, import_react.useSyncExternalStore)(
1489
+ subscribeToNothing,
1490
+ viewerLocale,
1491
+ noViewerLocale
1492
+ );
1493
+ return resolveLocale(locale ?? configured ?? viewer);
1494
+ }
1495
+ var subscribeToNothing = () => () => {
1496
+ };
1497
+ var noViewerLocale = () => void 0;
1498
+ function useTranslator(overrides, locale) {
1499
+ const resolved = useResolvedLocale(locale);
1500
+ const { onMissingString, strings, translate } = (0, import_schematic_react.useSchematicI18n)();
1501
+ return (0, import_react.useCallback)(
1502
+ (key, vars) => {
1503
+ const override = lookup(overrides, key, vars, resolved) ?? lookup(strings, key, vars, resolved);
1504
+ if (override !== void 0) {
1505
+ return override;
1506
+ }
1507
+ const fallback = defaultString(key, vars);
1508
+ if (translate === void 0) {
1509
+ return fallback;
1510
+ }
1511
+ const translated = translate(key, {
1512
+ ...vars,
1513
+ defaultValue: MISSING_STRING
1514
+ });
1515
+ if (translated === void 0 || translated === MISSING_STRING || translated === key) {
1516
+ onMissingString?.(key);
1517
+ return fallback;
1518
+ }
1519
+ return translated;
1520
+ },
1521
+ [onMissingString, overrides, resolved, strings, translate]
1522
+ );
1523
+ }
1524
+ var isDevelopment = (() => {
1525
+ try {
1526
+ return process.env.NODE_ENV !== "production";
1527
+ } catch {
1528
+ return false;
1529
+ }
1530
+ })();
1531
+ function useReportHiddenError(error, errorMessage) {
1532
+ (0, import_react.useEffect)(() => {
1533
+ if (isDevelopment && error !== void 0 && errorMessage !== void 0) {
1534
+ console.error(`Schematic: ${errorMessage}`, error);
1535
+ }
1536
+ }, [error, errorMessage]);
1537
+ }
1538
+ var StatusFrame = ({
1539
+ children,
1540
+ className,
1541
+ error,
1542
+ errorMessage,
1543
+ hasData,
1544
+ isPending,
1545
+ loadingLabel,
1546
+ onRetry,
1547
+ retryText,
1548
+ skeleton = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "schematic-skeleton" })
1549
+ }) => {
1550
+ useReportHiddenError(error, errorMessage);
1551
+ if (error !== void 0 && !hasData) {
1552
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className, "data-state": "error", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "schematic-status", role: "alert", children: [
1553
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "schematic-error schematic-status__message", children: errorMessage ?? error.message }),
1554
+ onRetry !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1555
+ "button",
1556
+ {
1557
+ className: "schematic-link-button schematic-status__retry",
1558
+ type: "button",
1559
+ onClick: onRetry,
1560
+ children: retryText
1561
+ }
1562
+ )
1563
+ ] }) });
1564
+ }
1565
+ if (isPending && !hasData) {
1566
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "aria-busy": "true", className, "data-state": "pending", children: [
1567
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "schematic-hidden", children: loadingLabel }),
1568
+ skeleton
1569
+ ] });
1570
+ }
1571
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className, "data-state": "ready", children: [
1572
+ children,
1573
+ error !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "schematic-status-note schematic-error", role: "alert", children: errorMessage ?? error.message })
1574
+ ] });
1575
+ };
1576
+
1577
+ // src/elements/Invoices.tsx
1578
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1579
+ var SKELETON_ROWS = 4;
1580
+ function Invoices({
1581
+ className,
1582
+ collapsible = true,
1583
+ headingLevel = 2,
1584
+ limit = 10,
1585
+ locale: localeProp,
1586
+ query,
1587
+ showAmount = true,
1588
+ showDate = true,
1589
+ showHeader = true,
1590
+ strings
1591
+ }) {
1592
+ const {
1593
+ data: page,
1594
+ error,
1595
+ isPending,
1596
+ loadMore,
1597
+ refetch
1598
+ } = (0, import_schematic_react2.useInvoices)(query);
1599
+ const locale = useResolvedLocale(localeProp);
1600
+ const t = useTranslator(strings, localeProp);
1601
+ const [expanded, setExpanded] = (0, import_react2.useState)(false);
1602
+ const list = (0, import_react2.useMemo)(
1603
+ () => page === void 0 ? void 0 : deriveInvoiceList(page, { locale }),
1604
+ [locale, page]
1605
+ );
1606
+ const headingId = (0, import_react2.useId)();
1607
+ const rows = list?.rows ?? [];
1608
+ const canCollapse = collapsible && rows.length > limit;
1609
+ const showingAll = !canCollapse || expanded;
1610
+ const visible = showingAll ? rows : rows.slice(0, limit);
1611
+ const Heading = `h${headingLevel}`;
1612
+ const columns = [].concat(
1613
+ showDate ? "date" : [],
1614
+ showAmount ? "amount" : []
1615
+ );
1616
+ const unavailable = list === void 0 && httpStatus(error) === 404;
1617
+ const errorMessage = error === void 0 ? void 0 : unavailable ? t("invoicesUnavailable") : t("invoicesError");
1618
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1619
+ StatusFrame,
1620
+ {
1621
+ className: cx("schematic-card", "schematic-invoices", className),
1622
+ error,
1623
+ errorMessage,
1624
+ hasData: list !== void 0,
1625
+ isPending,
1626
+ loadingLabel: t("invoicesLoading"),
1627
+ onRetry: refetch,
1628
+ retryText: t("retry"),
1629
+ skeleton: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1630
+ InvoicesSkeleton,
1631
+ {
1632
+ columns,
1633
+ rows: Math.max(1, Math.min(limit, SKELETON_ROWS)),
1634
+ showHeader
1635
+ }
1636
+ ),
1637
+ children: list !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1638
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Heading, { className: "schematic-header__title", id: headingId, children: t("invoicesHeader") }) }),
1639
+ rows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "schematic-muted schematic-invoices__empty", children: t("invoicesEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1640
+ "ul",
1641
+ {
1642
+ className: "schematic-invoices__list",
1643
+ "aria-label": showHeader ? void 0 : t("invoicesHeader"),
1644
+ "aria-labelledby": showHeader ? headingId : void 0,
1645
+ children: visible.map((row) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1646
+ "li",
1647
+ {
1648
+ className: "schematic-invoices__row",
1649
+ "data-testid": "schematic-invoice",
1650
+ children: [
1651
+ showDate && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "schematic-invoices__date", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(InvoiceDate, { row, t }) }),
1652
+ showAmount && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1653
+ "span",
1654
+ {
1655
+ className: cx(
1656
+ "schematic-invoices__amount",
1657
+ row.isCredit && "schematic-invoices__credit"
1658
+ ),
1659
+ title: row.isCredit ? t("invoicesCreditTooltip") : t("invoicesChargeTooltip"),
1660
+ children: row.isCredit ? `(${row.amountText})` : row.amountText
1661
+ }
1662
+ )
1663
+ ]
1664
+ },
1665
+ row.id
1666
+ ))
1667
+ }
1668
+ ),
1669
+ (canCollapse || showingAll && list.hasMore) && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "schematic-invoices__actions", children: [
1670
+ canCollapse && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1671
+ "button",
1672
+ {
1673
+ "aria-expanded": expanded,
1674
+ className: "schematic-link-button schematic-invoices__see-more",
1675
+ type: "button",
1676
+ onClick: () => setExpanded((value) => !value),
1677
+ children: [
1678
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1679
+ "span",
1680
+ {
1681
+ "aria-hidden": "true",
1682
+ className: "schematic-invoices__chevron"
1683
+ }
1684
+ ),
1685
+ expanded ? t("invoicesSeeLess") : t("invoicesSeeMore")
1686
+ ]
1687
+ }
1688
+ ),
1689
+ showingAll && list.hasMore && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1690
+ "button",
1691
+ {
1692
+ className: "schematic-link-button schematic-invoices__load-more",
1693
+ disabled: isPending,
1694
+ type: "button",
1695
+ onClick: () => {
1696
+ setExpanded(true);
1697
+ void loadMore();
1698
+ },
1699
+ children: t("invoicesLoadMore")
1700
+ }
1701
+ )
1702
+ ] })
1703
+ ] })
1704
+ }
1705
+ );
1706
+ }
1707
+ function InvoicesSkeleton({
1708
+ columns,
1709
+ rows,
1710
+ showHeader
1711
+ }) {
1712
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "schematic-skeleton", children: [
1713
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "schematic-skeleton__heading" }),
1714
+ Array.from({ length: rows }, (_, row) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "schematic-skeleton__row", children: columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1715
+ "div",
1716
+ {
1717
+ className: "schematic-skeleton__cell",
1718
+ "data-column": column
1719
+ },
1720
+ column
1721
+ )) }, row))
1722
+ ] });
1723
+ }
1724
+ function InvoiceDate({ row, t }) {
1725
+ if (row.url === null) {
1726
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "schematic-invoices__date-text", children: row.dateText });
1727
+ }
1728
+ const label = row.dateText === "" ? t("invoicesUndated") : row.dateText;
1729
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1730
+ "a",
1731
+ {
1732
+ className: "schematic-invoices__link",
1733
+ href: row.url,
1734
+ rel: "noreferrer",
1735
+ target: "_blank",
1736
+ children: label
1737
+ }
1738
+ );
1739
+ }
1740
+ Invoices.resources = ["invoices"];
1741
+
1742
+ // src/elements/UpcomingBill.tsx
1743
+ var import_schematic_react3 = require("@schematichq/schematic-react");
1744
+ var import_react3 = require("react");
1745
+ var import_jsx_runtime4 = require("react/jsx-runtime");
1746
+ function UpcomingBill({
1747
+ className,
1748
+ headingLevel = 2,
1749
+ locale: localeProp,
1750
+ showAmount = true,
1751
+ showBalance = true,
1752
+ showDiscounts = true,
1753
+ showHeader = true,
1754
+ strings
1755
+ }) {
1756
+ const { data: invoice, error, isPending, refetch } = (0, import_schematic_react3.useUpcomingInvoice)();
1757
+ const locale = useResolvedLocale(localeProp);
1758
+ const t = useTranslator(strings, localeProp);
1759
+ const bill = (0, import_react3.useMemo)(
1760
+ () => invoice === void 0 || invoice === null ? null : deriveUpcomingInvoice(invoice, { locale }),
1761
+ [invoice, locale]
1762
+ );
1763
+ const Heading = `h${headingLevel}`;
1764
+ const balanceRows = showBalance && bill !== null && (bill.balanceApplied !== null || bill.balanceRemaining !== null);
1765
+ const discountRow = showDiscounts && bill !== null && bill.discounts.length > 0;
1766
+ const unavailable = invoice === void 0 && httpStatus(error) === 404;
1767
+ const errorMessage = error === void 0 ? void 0 : unavailable ? t("upcomingBillUnavailable") : t("upcomingBillError");
1768
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1769
+ StatusFrame,
1770
+ {
1771
+ className: cx("schematic-card", "schematic-upcoming-bill", className),
1772
+ error,
1773
+ errorMessage,
1774
+ hasData: invoice !== void 0,
1775
+ isPending,
1776
+ loadingLabel: t("upcomingBillLoading"),
1777
+ onRetry: refetch,
1778
+ retryText: t("retry"),
1779
+ skeleton: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(UpcomingBillSkeleton, { showHeader }),
1780
+ children: bill === null ? invoice !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
1781
+ showHeader && bill.dueAt !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Heading, { className: "schematic-header__title", children: t("upcomingBillHeader", { date: bill.dueAt.text }) }) }),
1782
+ showAmount && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-upcoming-bill__amount", children: [
1783
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1784
+ "span",
1785
+ {
1786
+ className: "schematic-upcoming-bill__total",
1787
+ "data-testid": "schematic-upcoming-total",
1788
+ children: bill.amountDueText
1789
+ }
1790
+ ),
1791
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
1792
+ ] }),
1793
+ (balanceRows || discountRow) && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-upcoming-bill__rows", children: [
1794
+ balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1795
+ "div",
1796
+ {
1797
+ className: "schematic-row schematic-upcoming-bill__balance-applied",
1798
+ "data-testid": "schematic-balance-applied",
1799
+ children: [
1800
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
1801
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
1802
+ ]
1803
+ }
1804
+ ),
1805
+ balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1806
+ "div",
1807
+ {
1808
+ className: "schematic-row schematic-upcoming-bill__balance-remaining",
1809
+ "data-testid": "schematic-balance-remaining",
1810
+ children: [
1811
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
1812
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
1813
+ ]
1814
+ }
1815
+ ),
1816
+ discountRow && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1817
+ "div",
1818
+ {
1819
+ className: "schematic-row schematic-upcoming-bill__discount-row",
1820
+ "data-testid": "schematic-discounts",
1821
+ children: [
1822
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
1823
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1824
+ "li",
1825
+ {
1826
+ className: "schematic-upcoming-bill__discount",
1827
+ "data-testid": "schematic-discount",
1828
+ children: [
1829
+ discount.code !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
1830
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
1831
+ ]
1832
+ },
1833
+ `${discount.couponName}-${index}`
1834
+ )) })
1835
+ ]
1836
+ }
1837
+ )
1838
+ ] })
1839
+ ] })
1840
+ }
1841
+ );
1842
+ }
1843
+ function UpcomingBillSkeleton({ showHeader }) {
1844
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-skeleton", children: [
1845
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__heading" }),
1846
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
1847
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
1848
+ ] });
1849
+ }
1850
+ function discountText(discount, t) {
1851
+ if (discount.months === null) {
1852
+ return t("upcomingBillDiscountValue", { value: discount.valueText });
1853
+ }
1854
+ return t("upcomingBillDiscountRepeating", {
1855
+ count: discount.months,
1856
+ value: discount.valueText
1857
+ });
1858
+ }
1859
+ UpcomingBill.resources = ["upcomingInvoice"];