@schematichq/schematic-components 2.25.2 → 3.0.0

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