@schematichq/schematic-components 2.31.1 → 2.32.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.
@@ -159,10 +159,10 @@ function PaymentMethodForm({
159
159
  onSelectExisting,
160
160
  t
161
161
  }) {
162
- const { create } = (0, import_schematic_react4.useSetupIntent)();
163
- const [state, setState] = (0, import_react4.useState)({ status: "loading" });
164
- const hostRef = (0, import_react4.useRef)(null);
165
- (0, import_react4.useEffect)(() => {
162
+ const { create } = (0, import_schematic_react5.useSetupIntent)();
163
+ const [state, setState] = (0, import_react6.useState)({ status: "loading" });
164
+ const hostRef = (0, import_react6.useRef)(null);
165
+ (0, import_react6.useEffect)(() => {
166
166
  let cancelled = false;
167
167
  let setupFailed = false;
168
168
  Promise.all([
@@ -208,7 +208,7 @@ function PaymentMethodForm({
208
208
  };
209
209
  }, [create, locale]);
210
210
  if (state.status === "loading") {
211
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
211
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
212
212
  "div",
213
213
  {
214
214
  "aria-busy": "true",
@@ -216,15 +216,15 @@ function PaymentMethodForm({
216
216
  "data-state": "pending",
217
217
  ref: hostRef,
218
218
  children: [
219
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "schematic-hidden", children: t("paymentMethodsFormLoading") }),
220
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-skeleton", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
219
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "schematic-hidden", children: t("paymentMethodsFormLoading") }),
220
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
221
221
  ]
222
222
  }
223
223
  );
224
224
  }
225
225
  if (state.status === "failed") {
226
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-payment-methods__form", "data-state": "error", children: [
227
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
226
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-payment-methods__form", "data-state": "error", children: [
227
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
228
228
  "p",
229
229
  {
230
230
  className: "schematic-error schematic-small schematic-payment-methods__form-error",
@@ -232,11 +232,11 @@ function PaymentMethodForm({
232
232
  children: t(state.errorKey)
233
233
  }
234
234
  ),
235
- onSelectExisting !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SelectExisting, { t, onSelectExisting })
235
+ onSelectExisting !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SelectExisting, { t, onSelectExisting })
236
236
  ] });
237
237
  }
238
238
  const { Elements } = state.ui;
239
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
239
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
240
240
  Elements,
241
241
  {
242
242
  stripe: state.stripe,
@@ -244,7 +244,7 @@ function PaymentMethodForm({
244
244
  appearance: state.appearance,
245
245
  clientSecret: state.clientSecret
246
246
  },
247
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
247
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
248
248
  Fields,
249
249
  {
250
250
  checkoutPrefill,
@@ -273,19 +273,19 @@ function Fields({
273
273
  const showAddress = collectAddress || collectPhone;
274
274
  const prefill = checkoutPrefill?.billingDetails;
275
275
  const prefillName = orUndefined(prefill?.name);
276
- const emailId = (0, import_react4.useId)();
276
+ const emailId = (0, import_react6.useId)();
277
277
  const stripe = useStripe();
278
278
  const elements = useElements();
279
- const [saving, setSaving] = (0, import_react4.useState)(false);
280
- const [message, setMessage] = (0, import_react4.useState)(null);
281
- const [complete, setComplete] = (0, import_react4.useState)(false);
282
- const [ready, setReady] = (0, import_react4.useState)(false);
283
- const [loadFailed, setLoadFailed] = (0, import_react4.useState)(false);
284
- const [addressComplete, setAddressComplete] = (0, import_react4.useState)(!collectAddress);
285
- const [typedEmail, setTypedEmail] = (0, import_react4.useState)(null);
279
+ const [saving, setSaving] = (0, import_react6.useState)(false);
280
+ const [message, setMessage] = (0, import_react6.useState)(null);
281
+ const [complete, setComplete] = (0, import_react6.useState)(false);
282
+ const [ready, setReady] = (0, import_react6.useState)(false);
283
+ const [loadFailed, setLoadFailed] = (0, import_react6.useState)(false);
284
+ const [addressComplete, setAddressComplete] = (0, import_react6.useState)(!collectAddress);
285
+ const [typedEmail, setTypedEmail] = (0, import_react6.useState)(null);
286
286
  const email = typedEmail ?? orUndefined(prefill?.email) ?? "";
287
287
  const emailValid = !collectEmail || VALID_EMAIL.test(email);
288
- (0, import_react4.useEffect)(() => {
288
+ (0, import_react6.useEffect)(() => {
289
289
  if (ready) {
290
290
  return;
291
291
  }
@@ -337,14 +337,14 @@ function Fields({
337
337
  setSaving(false);
338
338
  }
339
339
  };
340
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
340
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
341
341
  "form",
342
342
  {
343
343
  className: "schematic-payment-methods__form",
344
344
  "data-state": "ready",
345
345
  onSubmit: (event) => void submit(event),
346
346
  children: [
347
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-payment-methods__fields", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
347
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-payment-methods__fields", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
348
348
  PaymentElement,
349
349
  {
350
350
  onChange: (event) => setComplete(event.complete),
@@ -355,8 +355,8 @@ function Fields({
355
355
  }
356
356
  }
357
357
  ) }),
358
- collectEmail && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-payment-methods__field", children: [
359
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
358
+ collectEmail && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-payment-methods__field", children: [
359
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
360
360
  "label",
361
361
  {
362
362
  className: "schematic-payment-methods__field-label",
@@ -364,7 +364,7 @@ function Fields({
364
364
  children: t("paymentMethodsEmail")
365
365
  }
366
366
  ),
367
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
367
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
368
368
  "input",
369
369
  {
370
370
  autoComplete: "email",
@@ -378,7 +378,7 @@ function Fields({
378
378
  }
379
379
  )
380
380
  ] }),
381
- showAddress && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-payment-methods__address", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
381
+ showAddress && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-payment-methods__address", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
382
382
  AddressElement,
383
383
  {
384
384
  options: {
@@ -392,7 +392,7 @@ function Fields({
392
392
  },
393
393
  prefillName ?? ""
394
394
  ) }),
395
- loadFailed && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
395
+ loadFailed && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
396
396
  "p",
397
397
  {
398
398
  className: "schematic-error schematic-small schematic-payment-methods__form-error",
@@ -400,7 +400,7 @@ function Fields({
400
400
  children: t("paymentMethodsFormError")
401
401
  }
402
402
  ),
403
- message !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
403
+ message !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
404
404
  "p",
405
405
  {
406
406
  className: "schematic-error schematic-small schematic-payment-methods__form-error",
@@ -408,7 +408,7 @@ function Fields({
408
408
  children: message
409
409
  }
410
410
  ),
411
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
411
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
412
412
  "button",
413
413
  {
414
414
  className: "schematic-cta schematic-payment-methods__save",
@@ -417,7 +417,7 @@ function Fields({
417
417
  children: saving ? t("paymentMethodsSaving") : t("paymentMethodsSave")
418
418
  }
419
419
  ),
420
- onSelectExisting !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
420
+ onSelectExisting !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
421
421
  SelectExisting,
422
422
  {
423
423
  disabled: saving,
@@ -434,7 +434,7 @@ function SelectExisting({
434
434
  onSelectExisting,
435
435
  t
436
436
  }) {
437
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
437
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
438
438
  "button",
439
439
  {
440
440
  className: "schematic-link-button schematic-payment-methods__select-existing",
@@ -445,14 +445,14 @@ function SelectExisting({
445
445
  }
446
446
  );
447
447
  }
448
- var import_schematic_react4, import_react4, import_jsx_runtime6, NO_CLIENT_SECRET, STRIPE_NOT_LOADED, PROBE_CSS, READY_TIMEOUT_MS, VALID_EMAIL, PaymentMethodForm_default;
448
+ var import_schematic_react5, import_react6, import_jsx_runtime7, NO_CLIENT_SECRET, STRIPE_NOT_LOADED, PROBE_CSS, READY_TIMEOUT_MS, VALID_EMAIL, PaymentMethodForm_default;
449
449
  var init_PaymentMethodForm = __esm({
450
450
  "src/elements/PaymentMethodForm.tsx"() {
451
451
  "use strict";
452
- import_schematic_react4 = require("@schematichq/schematic-react");
453
- import_react4 = require("react");
452
+ import_schematic_react5 = require("@schematichq/schematic-react");
453
+ import_react6 = require("react");
454
454
  init_tokens();
455
- import_jsx_runtime6 = require("react/jsx-runtime");
455
+ import_jsx_runtime7 = require("react/jsx-runtime");
456
456
  NO_CLIENT_SECRET = "The setup intent carries no client secret.";
457
457
  STRIPE_NOT_LOADED = "Stripe.js did not load.";
458
458
  PROBE_CSS = withTokenDefaults(
@@ -476,14 +476,15 @@ var init_PaymentMethodForm = __esm({
476
476
  // src/elements/index.ts
477
477
  var index_exports = {};
478
478
  __export(index_exports, {
479
- BillingDataProvider: () => import_schematic_react7.BillingDataProvider,
479
+ BillingDataProvider: () => import_schematic_react8.BillingDataProvider,
480
480
  DEFAULT_STRINGS: () => DEFAULT_STRINGS,
481
- FEATURE_USER_USAGE_LIMIT: () => import_schematic_react7.FEATURE_USER_USAGE_LIMIT,
481
+ FEATURE_USER_USAGE_LIMIT: () => import_schematic_react8.FEATURE_USER_USAGE_LIMIT,
482
482
  IncludedFeatures: () => IncludedFeatures,
483
483
  Invoices: () => Invoices,
484
+ MeteredFeatures: () => MeteredFeatures,
484
485
  PaymentMethods: () => PaymentMethods,
485
486
  SCHEMATIC_TOKENS: () => SCHEMATIC_TOKENS,
486
- SchematicI18nProvider: () => import_schematic_react7.SchematicI18nProvider,
487
+ SchematicI18nProvider: () => import_schematic_react8.SchematicI18nProvider,
487
488
  SchematicStyles: () => SchematicStyles,
488
489
  Tooltip: () => Tooltip,
489
490
  UpcomingBill: () => UpcomingBill,
@@ -491,6 +492,7 @@ __export(index_exports, {
491
492
  currentTier: () => currentTier,
492
493
  deriveIncludedFeatures: () => deriveIncludedFeatures,
493
494
  deriveInvoiceList: () => deriveInvoiceList,
495
+ deriveMeteredFeatures: () => deriveMeteredFeatures,
494
496
  derivePaymentMethods: () => derivePaymentMethods,
495
497
  deriveUpcomingInvoice: () => deriveUpcomingInvoice,
496
498
  featureName: () => featureName,
@@ -514,23 +516,23 @@ __export(index_exports, {
514
516
  tierRanges: () => tierRanges,
515
517
  unitPrice: () => unitPrice,
516
518
  usageLimit: () => usageLimit,
517
- useFeatureUsage: () => import_schematic_react7.useFeatureUsage,
518
- useFeatureUserUsage: () => import_schematic_react7.useFeatureUserUsage,
519
- useInvalidateBillingData: () => import_schematic_react7.useInvalidateBillingData,
520
- useInvoices: () => import_schematic_react7.useInvoices,
521
- usePaymentMethods: () => import_schematic_react7.usePaymentMethods,
519
+ useFeatureUsage: () => import_schematic_react8.useFeatureUsage,
520
+ useFeatureUserUsage: () => import_schematic_react8.useFeatureUserUsage,
521
+ useInvalidateBillingData: () => import_schematic_react8.useInvalidateBillingData,
522
+ useInvoices: () => import_schematic_react8.useInvoices,
523
+ usePaymentMethods: () => import_schematic_react8.usePaymentMethods,
522
524
  useResolvedLocale: () => useResolvedLocale,
523
- useSchematicI18n: () => import_schematic_react7.useSchematicI18n,
524
- useSchematicLocale: () => import_schematic_react7.useSchematicLocale,
525
- useSchematicStrings: () => import_schematic_react7.useSchematicStrings,
526
- useSchematicTranslate: () => import_schematic_react7.useSchematicTranslate,
527
- useSetupIntent: () => import_schematic_react7.useSetupIntent,
525
+ useSchematicI18n: () => import_schematic_react8.useSchematicI18n,
526
+ useSchematicLocale: () => import_schematic_react8.useSchematicLocale,
527
+ useSchematicStrings: () => import_schematic_react8.useSchematicStrings,
528
+ useSchematicTranslate: () => import_schematic_react8.useSchematicTranslate,
529
+ useSetupIntent: () => import_schematic_react8.useSetupIntent,
528
530
  useTranslator: () => useTranslator,
529
- useUpcomingInvoice: () => import_schematic_react7.useUpcomingInvoice,
531
+ useUpcomingInvoice: () => import_schematic_react8.useUpcomingInvoice,
530
532
  viewerLocale: () => viewerLocale
531
533
  });
532
534
  module.exports = __toCommonJS(index_exports);
533
- var import_schematic_react7 = require("@schematichq/schematic-react");
535
+ var import_schematic_react8 = require("@schematichq/schematic-react");
534
536
 
535
537
  // src/elements/model/errors.ts
536
538
  function httpStatus(error) {
@@ -1555,6 +1557,192 @@ function nonEmpty(value) {
1555
1557
  return value === void 0 || value === null || value === "" ? null : value;
1556
1558
  }
1557
1559
 
1560
+ // src/elements/model/meteredFeatures.ts
1561
+ var TONES = [
1562
+ "ok",
1563
+ "ok",
1564
+ "ok",
1565
+ "warning",
1566
+ "critical",
1567
+ "critical"
1568
+ ];
1569
+ function deriveMeteredFeatures(features, options) {
1570
+ const ordered = options.visibleFeatures === void 0 ? features : options.visibleFeatures.flatMap((id) => {
1571
+ const row = features.find((f) => f.featureId === id);
1572
+ return row === void 0 ? [] : [row];
1573
+ });
1574
+ return ordered.filter((row) => row.featureType === "event" || row.featureType === "trait").map((row) => meteredFeatureRow(row, options));
1575
+ }
1576
+ function meteredFeatureRow(row, options) {
1577
+ const { locale } = options;
1578
+ const unit = {
1579
+ name: row.featureName,
1580
+ singularName: row.featureSingularName ?? void 0,
1581
+ pluralName: row.featurePluralName ?? void 0
1582
+ };
1583
+ const limit = usageLimit(row, options);
1584
+ const resetsAt = usableDate(row.resetsAt);
1585
+ return {
1586
+ featureId: row.featureId,
1587
+ name: row.featureName,
1588
+ description: row.featureDescription === "" ? null : row.featureDescription ?? null,
1589
+ icon: row.featureIcon === "" ? null : row.featureIcon ?? null,
1590
+ headline: headline(row, limit, unit, locale),
1591
+ limit: limitLine(row, limit, unit, options),
1592
+ resetsAt: resetsAt === void 0 ? null : formatDate(resetsAt, locale, { month: "short", year: void 0 }),
1593
+ hardLimit: row.priceBehavior !== void 0 && row.priceBehavior !== null && row.priceBehavior !== "credit_burndown" && row.valueType === "numeric" && typeof row.allocation === "number" ? {
1594
+ amount: row.allocation,
1595
+ units: featureName(unit, row.allocation, locale)
1596
+ } : null,
1597
+ meter: meter(row, options),
1598
+ priceDetails: priceDetails(row, unit, locale),
1599
+ canAddMore: row.priceBehavior === "pay_in_advance",
1600
+ hasUsageByUser: row.featureType === "event",
1601
+ unit,
1602
+ source: row
1603
+ };
1604
+ }
1605
+ function headline(row, limit, unit, locale) {
1606
+ if (row.priceBehavior === "pay_in_advance") {
1607
+ return {
1608
+ kind: "quantity",
1609
+ amount: limit === null ? null : formatNumber(limit, locale),
1610
+ units: featureName(unit, limit ?? 0, locale)
1611
+ };
1612
+ }
1613
+ if (typeof row.usage !== "number") {
1614
+ return null;
1615
+ }
1616
+ return {
1617
+ kind: "used",
1618
+ amount: formatNumber(row.usage, locale),
1619
+ units: featureName(unit, row.usage, locale)
1620
+ };
1621
+ }
1622
+ function limitLine(row, limit, unit, options) {
1623
+ const { locale } = options;
1624
+ switch (row.priceBehavior) {
1625
+ case "tier": {
1626
+ const tier = currentTier(row);
1627
+ if (tier !== null) {
1628
+ return tier.to === null ? { kind: "tierUnlimited", feature: featureName(unit, 0, locale) } : {
1629
+ kind: "tierUpTo",
1630
+ amount: formatNumber(tier.to, locale),
1631
+ feature: featureName(unit, tier.to, locale)
1632
+ };
1633
+ }
1634
+ break;
1635
+ }
1636
+ case "overage":
1637
+ if (limit !== null) {
1638
+ return { kind: "included", amount: formatNumber(limit, locale) };
1639
+ }
1640
+ break;
1641
+ case "pay_in_advance":
1642
+ if (typeof row.usage === "number") {
1643
+ return { kind: "used", amount: formatNumber(row.usage, locale) };
1644
+ }
1645
+ break;
1646
+ case "pay_as_you_go":
1647
+ if (typeof row.currentCost === "number" && row.price !== void 0) {
1648
+ return {
1649
+ kind: "cost",
1650
+ cost: formatCurrency(row.currentCost, row.price.currency, locale)
1651
+ };
1652
+ }
1653
+ break;
1654
+ case "credit_burndown":
1655
+ if (options.showCredits === false || typeof row.consumptionRate !== "number" || row.creditName === void 0 || row.creditName === null) {
1656
+ return null;
1657
+ }
1658
+ return {
1659
+ kind: "perUse",
1660
+ amount: formatConsumptionRate(row.consumptionRate, locale),
1661
+ units: featureName(
1662
+ {
1663
+ name: row.creditName,
1664
+ singularName: row.creditSingularName,
1665
+ pluralName: row.creditPluralName
1666
+ },
1667
+ row.consumptionRate,
1668
+ locale
1669
+ )
1670
+ };
1671
+ default:
1672
+ break;
1673
+ }
1674
+ return limit === null ? { kind: "noLimit" } : { kind: "limitOf", amount: formatNumber(limit, locale) };
1675
+ }
1676
+ function meter(row, options) {
1677
+ if (row.priceBehavior === "pay_as_you_go" || row.priceBehavior === "credit_burndown" || typeof row.usage !== "number") {
1678
+ return null;
1679
+ }
1680
+ const total = options.showWarningThresholdAsLimit === true && typeof row.warningThreshold === "number" ? row.warningThreshold : row.softLimit ?? row.allocation ?? null;
1681
+ if (typeof total !== "number") {
1682
+ return null;
1683
+ }
1684
+ const usage = row.usage;
1685
+ const past = row.priceBehavior === "overage" && usage > total;
1686
+ const ratio = past ? Math.min(usage, total) / Math.max(usage, total) : total === 0 ? 1 : usage / total;
1687
+ const digits = { maximumFractionDigits: 10 };
1688
+ return {
1689
+ value: usage,
1690
+ total,
1691
+ percent: Math.min(ratio * 100, 100),
1692
+ tone: row.priceBehavior === "tier" ? "tier" : past ? "overage" : TONES[Math.floor(
1693
+ (total === 0 ? 1 : Math.min(usage, total) / total) * (TONES.length - 1)
1694
+ )],
1695
+ valueText: formatNumber(usage, options.locale, digits),
1696
+ totalText: formatNumber(total, options.locale, digits)
1697
+ };
1698
+ }
1699
+ function priceDetails(row, unit, locale) {
1700
+ const price = row.price;
1701
+ if (price === void 0) {
1702
+ return null;
1703
+ }
1704
+ const tier = currentTier(row);
1705
+ const period = row.featureType === "trait" ? pricePeriod(price) : null;
1706
+ const money = (amount) => formatCurrency(amount, price.currency, locale);
1707
+ if (row.priceBehavior === "overage") {
1708
+ if (tier === null || tier.perUnitPrice === null) {
1709
+ return null;
1710
+ }
1711
+ const size = price.packageSize;
1712
+ const over = typeof row.usage === "number" && typeof row.softLimit === "number" ? Math.max(0, row.usage - row.softLimit) : 0;
1713
+ return {
1714
+ kind: "overage",
1715
+ unitPrice: money(tier.perUnitPrice),
1716
+ packageSize: size,
1717
+ units: featureName(unit, size, locale),
1718
+ period,
1719
+ overage: {
1720
+ amount: formatNumber(over, locale),
1721
+ units: featureName(unit, over, locale),
1722
+ cost: money(tier.perUnitPrice * over)
1723
+ }
1724
+ };
1725
+ }
1726
+ if (row.priceBehavior === "tier") {
1727
+ if (tier === null || tier.perUnitPrice === null) {
1728
+ return null;
1729
+ }
1730
+ return {
1731
+ kind: "tier",
1732
+ from: tier.from === 0 ? 1 : tier.from,
1733
+ to: tier.to,
1734
+ cost: typeof row.currentCost === "number" ? money(row.currentCost) : null,
1735
+ period,
1736
+ tiers: {
1737
+ ranges: tierRanges(price),
1738
+ currency: price.currency,
1739
+ mode: price.tiersMode ?? null
1740
+ }
1741
+ };
1742
+ }
1743
+ return null;
1744
+ }
1745
+
1558
1746
  // src/elements/strings.ts
1559
1747
  var DEFAULT_STRINGS_LOCALE = "en";
1560
1748
  var DEFAULT_STRINGS = {
@@ -1630,6 +1818,32 @@ var DEFAULT_STRINGS = {
1630
1818
  includedFeaturesHideAll: "Hide all",
1631
1819
  includedFeaturesExpires: "Expires {{date}}",
1632
1820
  includedFeaturesPerLicense: "Includes {{amount}} {{creditName}} per {{licenseName}}",
1821
+ meteredFeaturesLoading: "Loading usage",
1822
+ meteredFeaturesHeader: "Usage",
1823
+ meteredFeaturesError: "There was a problem retrieving your usage.",
1824
+ meteredFeaturesUnavailable: "Usage is not available for this account.",
1825
+ meteredFeaturesUsed: "{{amount}} {{units}} used",
1826
+ meteredFeaturesIncluded: "{{amount}} included",
1827
+ meteredFeaturesInUse: "{{amount}} used",
1828
+ meteredFeaturesLimitOf: "Limit of {{amount}}",
1829
+ meteredFeaturesNoLimit: "No limit",
1830
+ meteredFeaturesAddMore: "Add More",
1831
+ meteredFeaturesAdditional: "Additional",
1832
+ meteredFeaturesTier: "Tier",
1833
+ usageByUserHeader: "Usage by user",
1834
+ usageByUserTotal: "{{amount}} used by your team this period",
1835
+ usageByUserError: "There was a problem retrieving usage by user.",
1836
+ usageByUserUnattributed: "Unattributed",
1837
+ // Looked up by the bare key with `{ count }`; `shown` is the count formatted.
1838
+ usageByUserMore: "plus {{shown}} more",
1839
+ usageByUserShowTop: "Show top {{shown}} users",
1840
+ usageByUserShowTop_one: "Show top {{shown}} user",
1841
+ usageByUserShowTop_other: "Show top {{shown}} users",
1842
+ usageByUserShowAllCount: "Show all {{shown}} users",
1843
+ usageByUserShowAllCount_one: "Show all {{shown}} user",
1844
+ usageByUserShowAllCount_other: "Show all {{shown}} users",
1845
+ usageByUserShowAll: "Show all",
1846
+ usageByUserShowFewer: "Show fewer",
1633
1847
  // Shared by the usage elements.
1634
1848
  usageUnits: "{{amount}} {{units}}",
1635
1849
  usagePerUnit: "{{cost}} per {{unit}}",
@@ -2368,6 +2582,238 @@ var invoicesCss = `
2368
2582
  }
2369
2583
  `;
2370
2584
 
2585
+ // src/elements/styles/metered-features.ts
2586
+ var meteredFeaturesCss = `
2587
+ .schematic-metered-features__list {
2588
+ display: flex;
2589
+ flex-direction: column;
2590
+ gap: var(--schematic-space);
2591
+ list-style: none;
2592
+ margin: 0;
2593
+ padding: 0;
2594
+ }
2595
+
2596
+ /* Each feature is a card; while pending or failed, the root is the card. */
2597
+ .schematic-metered-features[data-state="pending"],
2598
+ .schematic-metered-features[data-state="error"] {
2599
+ background: var(--schematic-background);
2600
+ border-radius: var(--schematic-radius);
2601
+ box-shadow: var(--schematic-shadow);
2602
+ padding: calc(var(--schematic-card-padding) * 0.75)
2603
+ var(--schematic-card-padding);
2604
+ }
2605
+
2606
+ .schematic-metered-features__feature {
2607
+ container-type: inline-size;
2608
+ display: flex;
2609
+ flex-direction: column;
2610
+ gap: calc(var(--schematic-space) * 1.5);
2611
+ overflow: hidden;
2612
+ }
2613
+
2614
+ .schematic-metered-features__main {
2615
+ display: flex;
2616
+ gap: calc(var(--schematic-space) * 1.5);
2617
+ }
2618
+
2619
+ /* Kept without a glyph, as in the embed, so names line up. */
2620
+ .schematic-metered-features__icon {
2621
+ align-items: center;
2622
+ background: var(--schematic-surface);
2623
+ border-radius: 9999px;
2624
+ color: var(--schematic-accent);
2625
+ display: inline-flex;
2626
+ flex-shrink: 0;
2627
+ font-size: 1.5rem;
2628
+ height: 2.75rem;
2629
+ justify-content: center;
2630
+ width: 2.75rem;
2631
+ }
2632
+
2633
+ /* The glyph takes the base text colour rather than inheriting, so the accent
2634
+ is set on it too. */
2635
+ .schematic-metered-features__icon .schematic-icon {
2636
+ color: var(--schematic-accent);
2637
+ }
2638
+
2639
+ .schematic-metered-features__body {
2640
+ display: flex;
2641
+ flex-direction: column;
2642
+ flex-grow: 1;
2643
+ gap: calc(var(--schematic-space) * 2);
2644
+ min-width: 0;
2645
+ }
2646
+
2647
+ .schematic-metered-features__top {
2648
+ display: flex;
2649
+ flex-wrap: wrap;
2650
+ gap: var(--schematic-space);
2651
+ }
2652
+
2653
+ .schematic-metered-features__title {
2654
+ display: flex;
2655
+ flex: 1 1 min-content;
2656
+ flex-direction: column;
2657
+ gap: 0.5rem;
2658
+ }
2659
+
2660
+ .schematic-metered-features__name {
2661
+ font-family: var(--schematic-font-heading);
2662
+ font-size: 1.8125rem;
2663
+ font-weight: 800;
2664
+ line-height: var(--schematic-line-height-heading);
2665
+ margin: 0;
2666
+ }
2667
+
2668
+ /* Beside the title when both fit, otherwise beneath it as in the embed,
2669
+ rather than wrapping in a narrow column. */
2670
+ .schematic-metered-features__figures {
2671
+ display: flex;
2672
+ flex: 0 0 auto;
2673
+ flex-direction: column;
2674
+ gap: 0.25rem;
2675
+ max-width: 100%;
2676
+ text-align: end;
2677
+ }
2678
+
2679
+ .schematic-metered-features__headline {
2680
+ font-size: 1.0625rem;
2681
+ font-variant-numeric: tabular-nums;
2682
+ font-weight: 500;
2683
+ white-space: nowrap;
2684
+ }
2685
+
2686
+ @container (max-width: 30rem) {
2687
+ .schematic-metered-features__figures {
2688
+ min-width: 0;
2689
+ text-align: start;
2690
+ }
2691
+
2692
+ /* Too narrow to keep "1,300 GB of storage used" on one line. */
2693
+ .schematic-metered-features__headline {
2694
+ white-space: normal;
2695
+ }
2696
+ }
2697
+
2698
+ .schematic-metered-features__limit {
2699
+ font-variant-numeric: tabular-nums;
2700
+ }
2701
+
2702
+ .schematic-metered-features__add-more {
2703
+ align-self: flex-start;
2704
+ white-space: nowrap;
2705
+ }
2706
+
2707
+ /* Negative margins undo the card's padding so the footer bleeds to its edges. */
2708
+ .schematic-metered-features__price-details {
2709
+ align-items: center;
2710
+ background: var(--schematic-surface);
2711
+ display: flex;
2712
+ gap: var(--schematic-space);
2713
+ justify-content: space-between;
2714
+ margin: 0 calc(var(--schematic-card-padding) * -1)
2715
+ calc(var(--schematic-card-padding) * -0.75);
2716
+ padding: calc(var(--schematic-card-padding) * 0.4375)
2717
+ var(--schematic-card-padding);
2718
+ }
2719
+
2720
+ .schematic-metered-features .schematic-skeleton__cell[data-column="name"] {
2721
+ width: 10rem;
2722
+ }
2723
+
2724
+ .schematic-metered-features .schematic-skeleton__cell[data-column="usage"] {
2725
+ width: 6rem;
2726
+ }
2727
+
2728
+ .schematic-metered-features__meter {
2729
+ align-items: center;
2730
+ display: flex;
2731
+ gap: var(--schematic-space);
2732
+ }
2733
+
2734
+ .schematic-metered-features__meter .schematic-meter {
2735
+ flex-grow: 1;
2736
+ min-width: 6rem;
2737
+ }
2738
+
2739
+ .schematic-meter--tier {
2740
+ background: color-mix(in srgb, var(--schematic-accent) 50%, transparent);
2741
+ }
2742
+
2743
+ /* Past the soft limit, the fill is the included share over a warning track. */
2744
+ .schematic-meter--overage {
2745
+ background: var(--schematic-warning);
2746
+ }
2747
+
2748
+ .schematic-metered-features__meter-label {
2749
+ font-size: 0.875rem;
2750
+ font-variant-numeric: tabular-nums;
2751
+ font-weight: 500;
2752
+ white-space: nowrap;
2753
+ }
2754
+
2755
+ .schematic-usage-by-user {
2756
+ align-items: flex-start;
2757
+ display: flex;
2758
+ flex-direction: column;
2759
+ gap: 0.25rem;
2760
+ }
2761
+
2762
+ .schematic-usage-by-user__title {
2763
+ font-family: var(--schematic-font-heading);
2764
+ font-size: 1.125rem;
2765
+ font-weight: 800;
2766
+ }
2767
+
2768
+ .schematic-usage-by-user__list {
2769
+ align-self: stretch;
2770
+ list-style: none;
2771
+ margin: 0.5rem 0 0;
2772
+ padding: 0;
2773
+ }
2774
+
2775
+ .schematic-usage-by-user__user {
2776
+ align-items: center;
2777
+ display: flex;
2778
+ gap: 0.75rem;
2779
+ padding: 0.5rem 0;
2780
+ }
2781
+
2782
+ .schematic-usage-by-user__avatar {
2783
+ align-items: center;
2784
+ background: var(--schematic-surface);
2785
+ border-radius: 9999px;
2786
+ display: inline-flex;
2787
+ flex-shrink: 0;
2788
+ font-size: 0.6875rem;
2789
+ font-weight: 500;
2790
+ height: 1.75rem;
2791
+ justify-content: center;
2792
+ width: 1.75rem;
2793
+ }
2794
+
2795
+ .schematic-usage-by-user__name {
2796
+ flex-grow: 1;
2797
+ overflow: hidden;
2798
+ text-overflow: ellipsis;
2799
+ white-space: nowrap;
2800
+ }
2801
+
2802
+ .schematic-usage-by-user__amount {
2803
+ text-align: end;
2804
+ }
2805
+
2806
+ .schematic-usage-by-user__toggle {
2807
+ align-items: center;
2808
+ display: inline-flex;
2809
+ gap: 0.25rem;
2810
+ }
2811
+
2812
+ .schematic-usage-by-user__toggle .schematic-chevron {
2813
+ margin-inline-start: -0.333rem;
2814
+ }
2815
+ `;
2816
+
2371
2817
  // src/elements/styles/payment-methods.ts
2372
2818
  var paymentMethodsCss = `
2373
2819
  .schematic-payment-methods {
@@ -3335,13 +3781,14 @@ ${upcomingBillCss}
3335
3781
  ${paymentMethodsCss}
3336
3782
  ${tooltipCss}
3337
3783
  ${includedFeaturesCss}
3784
+ ${meteredFeaturesCss}
3338
3785
  `;
3339
3786
  var schematicStylesCss = withTokenDefaults(rulesCss) + iconsCss;
3340
3787
  var SchematicStyles = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { "data-schematic-styles": "", children: schematicStylesCss });
3341
3788
 
3342
3789
  // src/elements/IncludedFeatures.tsx
3343
3790
  var import_schematic_react2 = require("@schematichq/schematic-react");
3344
- var import_react2 = require("react");
3791
+ var import_react3 = require("react");
3345
3792
 
3346
3793
  // src/elements/common.tsx
3347
3794
  var import_schematic_react = require("@schematichq/schematic-react");
@@ -3523,7 +3970,10 @@ var Dialog = ({ children, className, closeLabel, onClose, open, title, titleId }
3523
3970
  };
3524
3971
 
3525
3972
  // src/elements/usage.tsx
3973
+ var import_react2 = require("react");
3526
3974
  var import_jsx_runtime3 = require("react/jsx-runtime");
3975
+ var COLLAPSED_USER_COUNT = 3;
3976
+ var EXPANDED_USER_COUNT = 20;
3527
3977
  function shortPeriod(period, t) {
3528
3978
  switch (period) {
3529
3979
  case "month":
@@ -3585,6 +4035,106 @@ function PriceTiers({
3585
4035
  mode !== null && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "schematic-tiers__mode", children: mode === "volume" ? t("usageTiersVolume") : t("usageTiersGraduated") })
3586
4036
  ] });
3587
4037
  }
4038
+ function UserBreakdown({
4039
+ breakdown,
4040
+ error,
4041
+ locale,
4042
+ onRetry,
4043
+ t,
4044
+ unit
4045
+ }) {
4046
+ const [expanded, setExpanded] = (0, import_react2.useState)(false);
4047
+ const users = (0, import_react2.useMemo)(
4048
+ () => [...breakdown?.users ?? []].sort((a, b) => b.amount - a.amount),
4049
+ [breakdown?.users]
4050
+ );
4051
+ const amount = (value) => `${formatNumber(value, locale)} ${featureName(unit, value, locale)}`;
4052
+ if (breakdown === void 0 && error !== void 0) {
4053
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "schematic-usage-by-user", role: "alert", children: [
4054
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "schematic-usage-by-user__title", children: t("usageByUserHeader") }),
4055
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "schematic-error", children: t("usageByUserError") }),
4056
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4057
+ "button",
4058
+ {
4059
+ className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-status__retry",
4060
+ type: "button",
4061
+ onClick: onRetry,
4062
+ children: t("retry")
4063
+ }
4064
+ )
4065
+ ] });
4066
+ }
4067
+ const unattributed = breakdown?.unattributed ?? null;
4068
+ if (breakdown === void 0 || users.length === 0 && unattributed === null) {
4069
+ return null;
4070
+ }
4071
+ const visible = users.slice(
4072
+ 0,
4073
+ expanded ? EXPANDED_USER_COUNT : COLLAPSED_USER_COUNT
4074
+ );
4075
+ const remaining = Math.max(breakdown.count - visible.length, 0);
4076
+ const hidden = Math.max(
4077
+ Math.min(breakdown.count, EXPANDED_USER_COUNT) - Math.min(users.length, COLLAPSED_USER_COUNT),
4078
+ 0
4079
+ );
4080
+ const expandLabel = breakdown.count > EXPANDED_USER_COUNT ? t("usageByUserShowTop", {
4081
+ count: EXPANDED_USER_COUNT,
4082
+ shown: formatNumber(EXPANDED_USER_COUNT, locale)
4083
+ }) : hidden > 0 ? t("usageByUserShowAllCount", {
4084
+ count: breakdown.count,
4085
+ shown: formatNumber(breakdown.count, locale)
4086
+ }) : t("usageByUserShowAll");
4087
+ const user = (key, label, value, muted = false) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("li", { className: "schematic-usage-by-user__user", children: [
4088
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "aria-hidden": "true", className: "schematic-usage-by-user__avatar", children: muted ? "?" : (label.trim()[0] ?? "?").toUpperCase() }),
4089
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4090
+ "span",
4091
+ {
4092
+ className: cx(
4093
+ "schematic-usage-by-user__name",
4094
+ muted && "schematic-muted"
4095
+ ),
4096
+ children: label
4097
+ }
4098
+ ),
4099
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "schematic-muted schematic-usage-by-user__amount", children: amount(value) })
4100
+ ] }, key);
4101
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "schematic-usage-by-user", children: [
4102
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "schematic-usage-by-user__title", children: t("usageByUserHeader") }),
4103
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "schematic-muted", children: t("usageByUserTotal", { amount: amount(breakdown.total) }) }),
4104
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("ul", { className: "schematic-usage-by-user__list", children: [
4105
+ visible.map((entry) => user(entry.id, entry.label, entry.amount)),
4106
+ expanded && unattributed !== null && user(
4107
+ "unattributed",
4108
+ t("usageByUserUnattributed"),
4109
+ unattributed,
4110
+ true
4111
+ )
4112
+ ] }),
4113
+ expanded && remaining > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "schematic-muted", children: t("usageByUserMore", {
4114
+ count: remaining,
4115
+ shown: formatNumber(remaining, locale)
4116
+ }) }),
4117
+ (hidden > 0 || unattributed !== null) && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
4118
+ "button",
4119
+ {
4120
+ "aria-expanded": expanded,
4121
+ className: "schematic-link-button schematic-usage-by-user__toggle",
4122
+ type: "button",
4123
+ onClick: () => setExpanded((value) => !value),
4124
+ children: [
4125
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
4126
+ "i",
4127
+ {
4128
+ "aria-hidden": "true",
4129
+ className: `schematic-icon schematic-icon--${expanded ? "chevron-up" : "chevron-down"} schematic-chevron`
4130
+ }
4131
+ ),
4132
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "schematic-link-button__label", children: expanded ? t("usageByUserShowFewer") : expandLabel })
4133
+ ]
4134
+ }
4135
+ )
4136
+ ] });
4137
+ }
3588
4138
 
3589
4139
  // src/elements/IncludedFeatures.tsx
3590
4140
  var import_jsx_runtime4 = require("react/jsx-runtime");
@@ -3608,8 +4158,8 @@ function IncludedFeatures({
3608
4158
  const { data: features, error, isPending, refetch } = (0, import_schematic_react2.useFeatureUsage)();
3609
4159
  const locale = useResolvedLocale(localeProp);
3610
4160
  const t = useTranslator(strings, localeProp);
3611
- const [expanded, setExpanded] = (0, import_react2.useState)(false);
3612
- const rows = (0, import_react2.useMemo)(
4161
+ const [expanded, setExpanded] = (0, import_react3.useState)(false);
4162
+ const rows = (0, import_react3.useMemo)(
3613
4163
  () => features === void 0 ? [] : deriveIncludedFeatures(features, {
3614
4164
  locale,
3615
4165
  showCredits,
@@ -3820,7 +4370,7 @@ IncludedFeatures.resources = ["featureUsage"];
3820
4370
 
3821
4371
  // src/elements/Invoices.tsx
3822
4372
  var import_schematic_react3 = require("@schematichq/schematic-react");
3823
- var import_react3 = require("react");
4373
+ var import_react4 = require("react");
3824
4374
  var import_jsx_runtime5 = require("react/jsx-runtime");
3825
4375
  var SKELETON_ROWS = 4;
3826
4376
  function Invoices({
@@ -3844,12 +4394,12 @@ function Invoices({
3844
4394
  } = (0, import_schematic_react3.useInvoices)(query);
3845
4395
  const locale = useResolvedLocale(localeProp);
3846
4396
  const t = useTranslator(strings, localeProp);
3847
- const [expanded, setExpanded] = (0, import_react3.useState)(false);
3848
- const list = (0, import_react3.useMemo)(
4397
+ const [expanded, setExpanded] = (0, import_react4.useState)(false);
4398
+ const list = (0, import_react4.useMemo)(
3849
4399
  () => page === void 0 ? void 0 : deriveInvoiceList(page, { locale }),
3850
4400
  [locale, page]
3851
4401
  );
3852
- const headingId = (0, import_react3.useId)();
4402
+ const headingId = (0, import_react4.useId)();
3853
4403
  const rows = list?.rows ?? [];
3854
4404
  const canCollapse = collapsible && rows.length > limit;
3855
4405
  const showingAll = !canCollapse || expanded;
@@ -3990,11 +4540,354 @@ function InvoiceDate({ row, t }) {
3990
4540
  }
3991
4541
  Invoices.resources = ["invoices"];
3992
4542
 
3993
- // src/elements/PaymentMethods.tsx
3994
- var import_schematic_react5 = require("@schematichq/schematic-react");
4543
+ // src/elements/MeteredFeatures.tsx
4544
+ var import_schematic_react4 = require("@schematichq/schematic-react");
3995
4545
  var import_react5 = require("react");
3996
- var import_jsx_runtime7 = require("react/jsx-runtime");
3997
- var PaymentMethodForm2 = (0, import_react5.lazy)(() => Promise.resolve().then(() => (init_PaymentMethodForm(), PaymentMethodForm_exports)));
4546
+ var import_jsx_runtime6 = require("react/jsx-runtime");
4547
+ function MeteredFeatures({
4548
+ addMoreTarget,
4549
+ addMoreUrl,
4550
+ className,
4551
+ headingLevel = 2,
4552
+ locale: localeProp,
4553
+ onAddMore,
4554
+ showAllocation = true,
4555
+ showCredits = true,
4556
+ showDescription = true,
4557
+ showHardLimit = false,
4558
+ showHeader = false,
4559
+ showIcon = true,
4560
+ showMeter = true,
4561
+ showUsage = true,
4562
+ showUsageByUser = true,
4563
+ showWarningThresholdAsLimit = false,
4564
+ strings,
4565
+ visibleFeatures
4566
+ }) {
4567
+ const { data: features, error, isPending, refetch } = (0, import_schematic_react4.useFeatureUsage)();
4568
+ const locale = useResolvedLocale(localeProp);
4569
+ const t = useTranslator(strings, localeProp);
4570
+ const rows = (0, import_react5.useMemo)(
4571
+ () => features === void 0 ? [] : deriveMeteredFeatures(features, {
4572
+ locale,
4573
+ showCredits,
4574
+ showWarningThresholdAsLimit,
4575
+ visibleFeatures
4576
+ }),
4577
+ [
4578
+ features,
4579
+ locale,
4580
+ showCredits,
4581
+ showWarningThresholdAsLimit,
4582
+ visibleFeatures
4583
+ ]
4584
+ );
4585
+ const unavailable = features === void 0 && httpStatus(error) === 404;
4586
+ const errorMessage = error === void 0 ? void 0 : unavailable ? t("meteredFeaturesUnavailable") : t("meteredFeaturesError");
4587
+ if (features !== void 0 && error === void 0 && rows.length === 0) {
4588
+ return null;
4589
+ }
4590
+ const Heading = `h${headingLevel}`;
4591
+ const NameHeading = showHeader ? `h${Math.min(6, headingLevel + 1)}` : Heading;
4592
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
4593
+ StatusFrame,
4594
+ {
4595
+ className: cx("schematic-metered-features", className),
4596
+ error,
4597
+ errorMessage,
4598
+ hasData: features !== void 0,
4599
+ isPending,
4600
+ loadingLabel: t("meteredFeaturesLoading"),
4601
+ onRetry: refetch,
4602
+ retryText: t("retry"),
4603
+ skeleton: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MeteredFeaturesSkeleton, { showHeader }),
4604
+ children: [
4605
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Heading, { className: "schematic-header__title", children: t("meteredFeaturesHeader") }) }),
4606
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: "schematic-metered-features__list", children: rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
4607
+ "li",
4608
+ {
4609
+ className: "schematic-card schematic-metered-features__feature",
4610
+ "data-testid": "schematic-metered-feature",
4611
+ children: [
4612
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__main", children: [
4613
+ showIcon && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "schematic-metered-features__icon", children: row.icon !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4614
+ "i",
4615
+ {
4616
+ "aria-hidden": "true",
4617
+ className: `schematic-icon schematic-icon--${row.icon}`
4618
+ }
4619
+ ) }),
4620
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__body", children: [
4621
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__top", children: [
4622
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__title", children: [
4623
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(NameHeading, { className: "schematic-metered-features__name", children: row.name }),
4624
+ showDescription && row.description !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "schematic-muted", children: row.description })
4625
+ ] }),
4626
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__figures", children: [
4627
+ showUsage && row.headline !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "schematic-metered-features__headline", children: headlineText(row.headline, t) }),
4628
+ showAllocation && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4629
+ LimitLine,
4630
+ {
4631
+ row,
4632
+ showHardLimit,
4633
+ t
4634
+ }
4635
+ )
4636
+ ] })
4637
+ ] }),
4638
+ showMeter && row.meter !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Meter, { meter: row.meter }),
4639
+ row.canAddMore && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4640
+ AddMore,
4641
+ {
4642
+ label: t("meteredFeaturesAddMore"),
4643
+ onAddMore: onAddMore === void 0 ? void 0 : () => onAddMore(row.source),
4644
+ target: addMoreTarget,
4645
+ url: addMoreUrl
4646
+ }
4647
+ )
4648
+ ] })
4649
+ ] }),
4650
+ showUsageByUser && row.hasUsageByUser && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(UsageByUser, { locale, row, t }),
4651
+ row.priceDetails !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4652
+ PriceDetails,
4653
+ {
4654
+ details: row.priceDetails,
4655
+ locale,
4656
+ row,
4657
+ t
4658
+ }
4659
+ )
4660
+ ]
4661
+ },
4662
+ row.featureId
4663
+ )) })
4664
+ ]
4665
+ }
4666
+ );
4667
+ }
4668
+ function headlineText(headline2, t) {
4669
+ if (headline2.kind === "used") {
4670
+ return t("meteredFeaturesUsed", {
4671
+ amount: headline2.amount,
4672
+ units: headline2.units
4673
+ });
4674
+ }
4675
+ return headline2.amount === null ? headline2.units : t("usageUnits", { amount: headline2.amount, units: headline2.units });
4676
+ }
4677
+ function limitText(limit, t) {
4678
+ switch (limit.kind) {
4679
+ case "tierUpTo":
4680
+ return t("usageTierUpTo", {
4681
+ amount: limit.amount,
4682
+ feature: limit.feature
4683
+ });
4684
+ case "tierUnlimited":
4685
+ return t("usageTierUnlimited", { feature: limit.feature });
4686
+ case "included":
4687
+ return t("meteredFeaturesIncluded", { amount: limit.amount });
4688
+ case "used":
4689
+ return t("meteredFeaturesInUse", { amount: limit.amount });
4690
+ case "cost":
4691
+ return limit.cost;
4692
+ case "perUse":
4693
+ return t("usagePerUse", { amount: limit.amount, units: limit.units });
4694
+ case "limitOf":
4695
+ return t("meteredFeaturesLimitOf", { amount: limit.amount });
4696
+ case "noLimit":
4697
+ return t("meteredFeaturesNoLimit");
4698
+ }
4699
+ }
4700
+ function LimitLine({
4701
+ row,
4702
+ showHardLimit,
4703
+ t
4704
+ }) {
4705
+ const parts = [];
4706
+ if (row.limit !== null) {
4707
+ parts.push(limitText(row.limit, t));
4708
+ }
4709
+ if (row.resetsAt !== null) {
4710
+ parts.push(t("usageResets", { date: row.resetsAt }));
4711
+ }
4712
+ if (parts.length === 0) {
4713
+ return null;
4714
+ }
4715
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "schematic-muted schematic-metered-features__limit", children: [
4716
+ parts.join(" \u2022 "),
4717
+ showHardLimit && row.hardLimit !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
4718
+ amount: row.hardLimit.amount,
4719
+ units: row.hardLimit.units
4720
+ }) })
4721
+ ] });
4722
+ }
4723
+ var METER_TONE_CLASS = {
4724
+ ok: void 0,
4725
+ warning: "schematic-meter--warning",
4726
+ critical: "schematic-meter--over",
4727
+ tier: "schematic-meter--tier",
4728
+ overage: "schematic-meter--overage"
4729
+ };
4730
+ function Meter({ meter: meter2 }) {
4731
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__meter", children: [
4732
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4733
+ "div",
4734
+ {
4735
+ "aria-valuemax": meter2.total,
4736
+ "aria-valuemin": 0,
4737
+ "aria-valuenow": meter2.value,
4738
+ className: cx("schematic-meter", METER_TONE_CLASS[meter2.tone]),
4739
+ "data-tone": meter2.tone,
4740
+ role: "meter",
4741
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4742
+ "div",
4743
+ {
4744
+ className: "schematic-meter__fill",
4745
+ style: { width: `${meter2.percent}%` }
4746
+ }
4747
+ )
4748
+ }
4749
+ ),
4750
+ meter2.total > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "schematic-metered-features__meter-label", children: [
4751
+ meter2.valueText,
4752
+ "/",
4753
+ meter2.totalText
4754
+ ] })
4755
+ ] });
4756
+ }
4757
+ function AddMore({
4758
+ label,
4759
+ onAddMore,
4760
+ target,
4761
+ url
4762
+ }) {
4763
+ if (onAddMore !== void 0) {
4764
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4765
+ "button",
4766
+ {
4767
+ className: "schematic-cta schematic-metered-features__add-more",
4768
+ type: "button",
4769
+ onClick: onAddMore,
4770
+ children: label
4771
+ }
4772
+ );
4773
+ }
4774
+ if (url !== void 0) {
4775
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4776
+ "a",
4777
+ {
4778
+ className: "schematic-cta schematic-metered-features__add-more",
4779
+ href: url,
4780
+ target,
4781
+ children: label
4782
+ }
4783
+ );
4784
+ }
4785
+ return null;
4786
+ }
4787
+ function PriceDetails({
4788
+ details,
4789
+ locale,
4790
+ row,
4791
+ t
4792
+ }) {
4793
+ const period = details.period === null ? void 0 : shortPeriod(details.period, t);
4794
+ if (details.kind === "overage") {
4795
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__price-details", children: [
4796
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
4797
+ t("meteredFeaturesAdditional"),
4798
+ ": ",
4799
+ details.unitPrice,
4800
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("sub", { children: [
4801
+ "/",
4802
+ details.packageSize > 1 && `${details.packageSize} `,
4803
+ details.units,
4804
+ period !== void 0 && `/${period}`
4805
+ ] })
4806
+ ] }),
4807
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
4808
+ details.overage.amount,
4809
+ " ",
4810
+ details.overage.units,
4811
+ " \xB7 ",
4812
+ details.overage.cost,
4813
+ period !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("sub", { children: [
4814
+ "/",
4815
+ period
4816
+ ] })
4817
+ ] })
4818
+ ] });
4819
+ }
4820
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__price-details", children: [
4821
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
4822
+ t("meteredFeaturesTier"),
4823
+ ": ",
4824
+ details.from,
4825
+ details.to === null ? "+" : details.to !== details.from ? `\u2013${details.to}` : "",
4826
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4827
+ PriceTiers,
4828
+ {
4829
+ currency: details.tiers.currency,
4830
+ locale,
4831
+ mode: details.tiers.mode,
4832
+ period: details.period,
4833
+ ranges: details.tiers.ranges,
4834
+ t,
4835
+ unit: featureName(row.unit, 1, locale)
4836
+ }
4837
+ ) })
4838
+ ] }),
4839
+ details.cost !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
4840
+ details.cost,
4841
+ period !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("sub", { children: [
4842
+ "/",
4843
+ period
4844
+ ] })
4845
+ ] })
4846
+ ] });
4847
+ }
4848
+ function UsageByUser({
4849
+ locale,
4850
+ row,
4851
+ t
4852
+ }) {
4853
+ const { data, error, refetch } = (0, import_schematic_react4.useFeatureUserUsage)(row.featureId);
4854
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4855
+ UserBreakdown,
4856
+ {
4857
+ breakdown: data === void 0 ? void 0 : {
4858
+ count: data.count,
4859
+ total: data.total,
4860
+ unattributed: data.unattributed ?? null,
4861
+ users: data.users.map((user) => ({
4862
+ amount: user.usage,
4863
+ id: user.userId,
4864
+ label: user.name ?? user.userId
4865
+ }))
4866
+ },
4867
+ error,
4868
+ locale,
4869
+ onRetry: refetch,
4870
+ t,
4871
+ unit: row.unit
4872
+ }
4873
+ );
4874
+ }
4875
+ function MeteredFeaturesSkeleton({ showHeader }) {
4876
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-skeleton", children: [
4877
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-skeleton__heading" }),
4878
+ [0, 1].map((index) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-skeleton__row", children: [
4879
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
4880
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "usage" })
4881
+ ] }, index))
4882
+ ] });
4883
+ }
4884
+ MeteredFeatures.resources = ["featureUsage"];
4885
+
4886
+ // src/elements/PaymentMethods.tsx
4887
+ var import_schematic_react6 = require("@schematichq/schematic-react");
4888
+ var import_react7 = require("react");
4889
+ var import_jsx_runtime8 = require("react/jsx-runtime");
4890
+ var PaymentMethodForm2 = (0, import_react7.lazy)(() => Promise.resolve().then(() => (init_PaymentMethodForm(), PaymentMethodForm_exports)));
3998
4891
  function PaymentMethods({
3999
4892
  allowEdit = true,
4000
4893
  checkoutPrefill,
@@ -4015,24 +4908,24 @@ function PaymentMethods({
4015
4908
  refetch,
4016
4909
  remove,
4017
4910
  setDefault
4018
- } = (0, import_schematic_react5.usePaymentMethods)();
4911
+ } = (0, import_schematic_react6.usePaymentMethods)();
4019
4912
  const locale = useResolvedLocale(localeProp);
4020
4913
  const t = useTranslator(strings, localeProp);
4021
- const [dialog, setDialog] = (0, import_react5.useState)(null);
4022
- const [choosing, setChoosing] = (0, import_react5.useState)(false);
4023
- const [lastWrite, setLastWrite] = (0, import_react5.useState)(null);
4024
- const derived = (0, import_react5.useMemo)(
4914
+ const [dialog, setDialog] = (0, import_react7.useState)(null);
4915
+ const [choosing, setChoosing] = (0, import_react7.useState)(false);
4916
+ const [lastWrite, setLastWrite] = (0, import_react7.useState)(null);
4917
+ const derived = (0, import_react7.useMemo)(
4025
4918
  () => methods === void 0 ? void 0 : derivePaymentMethods(methods, { locale }),
4026
4919
  [locale, methods]
4027
4920
  );
4028
- const write = (0, import_react5.useCallback)(async (next) => {
4921
+ const write = (0, import_react7.useCallback)(async (next) => {
4029
4922
  setLastWrite(next);
4030
4923
  try {
4031
4924
  await next.action();
4032
4925
  } catch {
4033
4926
  }
4034
4927
  }, []);
4035
- const saved = (0, import_react5.useCallback)(
4928
+ const saved = (0, import_react7.useCallback)(
4036
4929
  async (paymentMethodId) => {
4037
4930
  await write({
4038
4931
  action: () => setDefault(paymentMethodId),
@@ -4043,16 +4936,16 @@ function PaymentMethods({
4043
4936
  },
4044
4937
  [setDefault, write]
4045
4938
  );
4046
- const open = (0, import_react5.useCallback)(() => {
4939
+ const open = (0, import_react7.useCallback)(() => {
4047
4940
  setLastWrite(null);
4048
4941
  setChoosing(false);
4049
4942
  setDialog("current");
4050
4943
  }, []);
4051
- const close = (0, import_react5.useCallback)(() => setDialog(null), []);
4944
+ const close = (0, import_react7.useCallback)(() => setDialog(null), []);
4052
4945
  const Heading = `h${headingLevel}`;
4053
4946
  const unavailable = derived === void 0 && httpStatus(error) === 404;
4054
4947
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("paymentMethodsUnavailable") : t("paymentMethodsError");
4055
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4948
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4056
4949
  StatusFrame,
4057
4950
  {
4058
4951
  className: cx("schematic-card", "schematic-payment-methods", className),
@@ -4063,9 +4956,9 @@ function PaymentMethods({
4063
4956
  loadingLabel: t("paymentMethodsLoading"),
4064
4957
  onRetry: refetch,
4065
4958
  retryText: t("retry"),
4066
- skeleton: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PaymentMethodsSkeleton, { showHeader }),
4067
- children: derived !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
4068
- showHeader && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4959
+ skeleton: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PaymentMethodsSkeleton, { showHeader }),
4960
+ children: derived !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
4961
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4069
4962
  PaymentMethodsHeader,
4070
4963
  {
4071
4964
  derived,
@@ -4074,7 +4967,7 @@ function PaymentMethods({
4074
4967
  t
4075
4968
  }
4076
4969
  ),
4077
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MethodPill, { row: derived.current, t, children: allowEdit && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4970
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MethodPill, { row: derived.current, t, children: allowEdit && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4078
4971
  "button",
4079
4972
  {
4080
4973
  className: "schematic-link-button schematic-payment-methods__edit",
@@ -4083,7 +4976,7 @@ function PaymentMethods({
4083
4976
  children: derived.current === null ? t("paymentMethodsAdd") : t("paymentMethodsEdit")
4084
4977
  }
4085
4978
  ) }),
4086
- dialog !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4979
+ dialog !== null && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4087
4980
  PaymentMethodsDialog,
4088
4981
  {
4089
4982
  checkoutPrefill,
@@ -4135,7 +5028,7 @@ function PaymentMethodsDialog({
4135
5028
  const { current, others, rows } = derived;
4136
5029
  const hasMethods = rows.length > 0;
4137
5030
  const showForm = view === "add" || !hasMethods;
4138
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
5031
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4139
5032
  Dialog,
4140
5033
  {
4141
5034
  className: "schematic-payment-methods__dialog",
@@ -4144,11 +5037,11 @@ function PaymentMethodsDialog({
4144
5037
  title: t("paymentMethodsDialogTitle"),
4145
5038
  onClose,
4146
5039
  children: [
4147
- showForm ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4148
- import_react5.Suspense,
5040
+ showForm ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
5041
+ import_react7.Suspense,
4149
5042
  {
4150
- fallback: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(FormSkeleton, { label: t("paymentMethodsFormLoading") }),
4151
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
5043
+ fallback: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(FormSkeleton, { label: t("paymentMethodsFormLoading") }),
5044
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4152
5045
  PaymentMethodForm2,
4153
5046
  {
4154
5047
  checkoutPrefill,
@@ -4160,8 +5053,8 @@ function PaymentMethodsDialog({
4160
5053
  }
4161
5054
  )
4162
5055
  }
4163
- ) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
4164
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
5056
+ ) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
5057
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4165
5058
  PaymentMethodsHeader,
4166
5059
  {
4167
5060
  derived,
@@ -4170,7 +5063,7 @@ function PaymentMethodsDialog({
4170
5063
  t
4171
5064
  }
4172
5065
  ),
4173
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MethodPill, { row: current, t, children: current?.canRemove === true && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
5066
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MethodPill, { row: current, t, children: current?.canRemove === true && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4174
5067
  "button",
4175
5068
  {
4176
5069
  className: "schematic-link-button schematic-payment-methods__remove-current",
@@ -4180,7 +5073,7 @@ function PaymentMethodsDialog({
4180
5073
  children: t("paymentMethodsRemove")
4181
5074
  }
4182
5075
  ) }),
4183
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
5076
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4184
5077
  "button",
4185
5078
  {
4186
5079
  "aria-expanded": choosing,
@@ -4188,8 +5081,8 @@ function PaymentMethodsDialog({
4188
5081
  type: "button",
4189
5082
  onClick: onChoose,
4190
5083
  children: [
4191
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "schematic-payment-methods__choose-label", children: t("paymentMethodsChooseDifferent") }),
4192
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
5084
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-payment-methods__choose-label", children: t("paymentMethodsChooseDifferent") }),
5085
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4193
5086
  "i",
4194
5087
  {
4195
5088
  "aria-hidden": "true",
@@ -4204,13 +5097,13 @@ function PaymentMethodsDialog({
4204
5097
  ]
4205
5098
  }
4206
5099
  ),
4207
- choosing && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
4208
- others.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
5100
+ choosing && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
5101
+ others.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4209
5102
  "ul",
4210
5103
  {
4211
5104
  "aria-label": t("paymentMethodsChooseDifferent"),
4212
5105
  className: "schematic-payment-methods__list",
4213
- children: others.map((row) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
5106
+ children: others.map((row) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4214
5107
  "li",
4215
5108
  {
4216
5109
  className: "schematic-payment-methods__row",
@@ -4218,11 +5111,11 @@ function PaymentMethodsDialog({
4218
5111
  "data-kind": row.kind,
4219
5112
  "data-testid": "schematic-payment-method",
4220
5113
  children: [
4221
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Method, { row, t }),
4222
- row.expiresShort !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "schematic-payment-methods__expires", children: t("paymentMethodsExpires", {
5114
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Method, { row, t }),
5115
+ row.expiresShort !== null && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-payment-methods__expires", children: t("paymentMethodsExpires", {
4223
5116
  date: row.expiresShort
4224
5117
  }) }),
4225
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
5118
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4226
5119
  "button",
4227
5120
  {
4228
5121
  className: "schematic-link-button schematic-payment-methods__set-default",
@@ -4232,7 +5125,7 @@ function PaymentMethodsDialog({
4232
5125
  children: t("paymentMethodsSetDefault")
4233
5126
  }
4234
5127
  ),
4235
- row.canRemove && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
5128
+ row.canRemove && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4236
5129
  "button",
4237
5130
  {
4238
5131
  "aria-label": t("paymentMethodsRemove"),
@@ -4240,7 +5133,7 @@ function PaymentMethodsDialog({
4240
5133
  disabled: isMutating,
4241
5134
  type: "button",
4242
5135
  onClick: () => onRemove(row),
4243
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
5136
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4244
5137
  "i",
4245
5138
  {
4246
5139
  "aria-hidden": "true",
@@ -4255,7 +5148,7 @@ function PaymentMethodsDialog({
4255
5148
  ))
4256
5149
  }
4257
5150
  ),
4258
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
5151
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4259
5152
  "button",
4260
5153
  {
4261
5154
  className: "schematic-cta schematic-payment-methods__add-new",
@@ -4267,14 +5160,14 @@ function PaymentMethodsDialog({
4267
5160
  )
4268
5161
  ] })
4269
5162
  ] }),
4270
- mutationError !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
5163
+ mutationError !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4271
5164
  "p",
4272
5165
  {
4273
5166
  className: "schematic-status-note schematic-error schematic-payment-methods__error",
4274
5167
  role: "alert",
4275
5168
  children: [
4276
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "schematic-payment-methods__error-message", children: mutationError }),
4277
- onRetry !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
5169
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-payment-methods__error-message", children: mutationError }),
5170
+ onRetry !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4278
5171
  "button",
4279
5172
  {
4280
5173
  className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-payment-methods__error-retry",
@@ -4297,9 +5190,9 @@ function PaymentMethodsHeader({
4297
5190
  showExpiration,
4298
5191
  t
4299
5192
  }) {
4300
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-header", children: [
4301
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Heading, { className: "schematic-header__title", children: t("paymentMethodsHeader") }),
4302
- showExpiration && derived.expiryWarning !== "none" && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
5193
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "schematic-header", children: [
5194
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Heading, { className: "schematic-header__title", children: t("paymentMethodsHeader") }),
5195
+ showExpiration && derived.expiryWarning !== "none" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4303
5196
  "span",
4304
5197
  {
4305
5198
  className: "schematic-small schematic-payment-methods__expiry-warning",
@@ -4314,37 +5207,37 @@ function MethodPill({
4314
5207
  row,
4315
5208
  t
4316
5209
  }) {
4317
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
5210
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4318
5211
  "div",
4319
5212
  {
4320
5213
  className: "schematic-payment-methods__current",
4321
5214
  "data-testid": "schematic-payment-method-current",
4322
5215
  children: [
4323
- row === null ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "schematic-payment-methods__empty", children: t("paymentMethodsEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Method, { row, t }),
5216
+ row === null ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-payment-methods__empty", children: t("paymentMethodsEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Method, { row, t }),
4324
5217
  children
4325
5218
  ]
4326
5219
  }
4327
5220
  );
4328
5221
  }
4329
5222
  function Method({ row, t }) {
4330
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
5223
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4331
5224
  "span",
4332
5225
  {
4333
5226
  className: "schematic-payment-methods__method",
4334
5227
  "data-brand": row.brand,
4335
5228
  "data-kind": row.kind,
4336
5229
  children: [
4337
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
5230
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
4338
5231
  "i",
4339
5232
  {
4340
5233
  "aria-hidden": "true",
4341
5234
  className: `schematic-icon schematic-icon--${row.icon} schematic-payment-methods__icon`
4342
5235
  }
4343
5236
  ),
4344
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "schematic-payment-methods__label", children: labelText(row.label, t) }),
4345
- row.last4 !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
5237
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-payment-methods__label", children: labelText(row.label, t) }),
5238
+ row.last4 !== null && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
4346
5239
  " ",
4347
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "schematic-payment-methods__last4", children: row.last4 })
5240
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-payment-methods__last4", children: row.last4 })
4348
5241
  ] })
4349
5242
  ]
4350
5243
  }
@@ -4358,24 +5251,24 @@ function expiryWarningText(derived, t) {
4358
5251
  return derived.expiryWarning === "expired" ? t("paymentMethodsExpired") : t("paymentMethodsExpiresInMonths", { months });
4359
5252
  }
4360
5253
  function PaymentMethodsSkeleton({ showHeader }) {
4361
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-skeleton", children: [
4362
- showHeader && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__heading" }),
4363
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-skeleton__row", children: [
4364
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "method" }),
4365
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "action" })
5254
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "schematic-skeleton", children: [
5255
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__heading" }),
5256
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "schematic-skeleton__row", children: [
5257
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "method" }),
5258
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "action" })
4366
5259
  ] })
4367
5260
  ] });
4368
5261
  }
4369
5262
  function FormSkeleton({ label }) {
4370
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
5263
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
4371
5264
  "div",
4372
5265
  {
4373
5266
  "aria-busy": "true",
4374
5267
  className: "schematic-payment-methods__form",
4375
5268
  "data-state": "pending",
4376
5269
  children: [
4377
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "schematic-hidden", children: label }),
4378
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
5270
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-hidden", children: label }),
5271
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
4379
5272
  ]
4380
5273
  }
4381
5274
  );
@@ -4383,9 +5276,9 @@ function FormSkeleton({ label }) {
4383
5276
  PaymentMethods.resources = ["paymentMethods"];
4384
5277
 
4385
5278
  // src/elements/UpcomingBill.tsx
4386
- var import_schematic_react6 = require("@schematichq/schematic-react");
4387
- var import_react6 = require("react");
4388
- var import_jsx_runtime8 = require("react/jsx-runtime");
5279
+ var import_schematic_react7 = require("@schematichq/schematic-react");
5280
+ var import_react8 = require("react");
5281
+ var import_jsx_runtime9 = require("react/jsx-runtime");
4389
5282
  function UpcomingBill({
4390
5283
  className,
4391
5284
  headingLevel = 2,
@@ -4396,10 +5289,10 @@ function UpcomingBill({
4396
5289
  showHeader = true,
4397
5290
  strings
4398
5291
  }) {
4399
- const { data: invoice, error, isPending, refetch } = (0, import_schematic_react6.useUpcomingInvoice)();
5292
+ const { data: invoice, error, isPending, refetch } = (0, import_schematic_react7.useUpcomingInvoice)();
4400
5293
  const locale = useResolvedLocale(localeProp);
4401
5294
  const t = useTranslator(strings, localeProp);
4402
- const bill = (0, import_react6.useMemo)(
5295
+ const bill = (0, import_react8.useMemo)(
4403
5296
  () => invoice === void 0 || invoice === null ? null : deriveUpcomingInvoice(invoice, { locale }),
4404
5297
  [invoice, locale]
4405
5298
  );
@@ -4408,7 +5301,7 @@ function UpcomingBill({
4408
5301
  const discountRow = showDiscounts && bill !== null && bill.discounts.length > 0;
4409
5302
  const unavailable = invoice === void 0 && httpStatus(error) === 404;
4410
5303
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("upcomingBillUnavailable") : t("upcomingBillError");
4411
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
5304
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4412
5305
  StatusFrame,
4413
5306
  {
4414
5307
  className: cx("schematic-card", "schematic-upcoming-bill", className),
@@ -4419,11 +5312,11 @@ function UpcomingBill({
4419
5312
  loadingLabel: t("upcomingBillLoading"),
4420
5313
  onRetry: refetch,
4421
5314
  retryText: t("retry"),
4422
- skeleton: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(UpcomingBillSkeleton, { showHeader }),
4423
- children: bill === null ? invoice !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
4424
- showHeader && bill.dueAt !== null && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Heading, { className: "schematic-header__title", children: t("upcomingBillHeader", { date: bill.dueAt.text }) }) }),
4425
- showAmount && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "schematic-upcoming-bill__amount", children: [
4426
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
5315
+ skeleton: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(UpcomingBillSkeleton, { showHeader }),
5316
+ children: bill === null ? invoice !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
5317
+ showHeader && bill.dueAt !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Heading, { className: "schematic-header__title", children: t("upcomingBillHeader", { date: bill.dueAt.text }) }) }),
5318
+ showAmount && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "schematic-upcoming-bill__amount", children: [
5319
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4427
5320
  "span",
4428
5321
  {
4429
5322
  className: "schematic-upcoming-bill__total",
@@ -4431,46 +5324,46 @@ function UpcomingBill({
4431
5324
  children: bill.amountDueText
4432
5325
  }
4433
5326
  ),
4434
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
5327
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
4435
5328
  ] }),
4436
- (balanceRows || discountRow) && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "schematic-upcoming-bill__rows", children: [
4437
- balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
5329
+ (balanceRows || discountRow) && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "schematic-upcoming-bill__rows", children: [
5330
+ balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
4438
5331
  "div",
4439
5332
  {
4440
5333
  className: "schematic-row schematic-upcoming-bill__balance-applied",
4441
5334
  "data-testid": "schematic-balance-applied",
4442
5335
  children: [
4443
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
4444
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
5336
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
5337
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
4445
5338
  ]
4446
5339
  }
4447
5340
  ),
4448
- balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
5341
+ balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
4449
5342
  "div",
4450
5343
  {
4451
5344
  className: "schematic-row schematic-upcoming-bill__balance-remaining",
4452
5345
  "data-testid": "schematic-balance-remaining",
4453
5346
  children: [
4454
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
4455
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
5347
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
5348
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
4456
5349
  ]
4457
5350
  }
4458
5351
  ),
4459
- discountRow && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
5352
+ discountRow && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
4460
5353
  "div",
4461
5354
  {
4462
5355
  className: "schematic-row schematic-upcoming-bill__discount-row",
4463
5356
  "data-testid": "schematic-discounts",
4464
5357
  children: [
4465
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
4466
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
5358
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
5359
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
4467
5360
  "li",
4468
5361
  {
4469
5362
  className: "schematic-upcoming-bill__discount",
4470
5363
  "data-testid": "schematic-discount",
4471
5364
  children: [
4472
- discount.code !== null && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
4473
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
5365
+ discount.code !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
5366
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
4474
5367
  ]
4475
5368
  },
4476
5369
  `${discount.couponName}-${index}`
@@ -4484,10 +5377,10 @@ function UpcomingBill({
4484
5377
  );
4485
5378
  }
4486
5379
  function UpcomingBillSkeleton({ showHeader }) {
4487
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "schematic-skeleton", children: [
4488
- showHeader && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__heading" }),
4489
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
4490
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
5380
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "schematic-skeleton", children: [
5381
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__heading" }),
5382
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
5383
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
4491
5384
  ] });
4492
5385
  }
4493
5386
  function discountText(discount, t) {