@schematichq/schematic-components 2.31.1 → 2.33.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.
@@ -53,6 +53,9 @@ var init_tokens = __esm({
53
53
  "--schematic-font-heading": '"Manrope", system-ui, sans-serif',
54
54
  // Link buttons' face: Edit, Set default, Try again, and the rest.
55
55
  "--schematic-font-link": '"Inter", system-ui, sans-serif',
56
+ // A lighter tint than the surface, for panels set into a card: a credit's
57
+ // grants, a plan's auto top-up.
58
+ "--schematic-inset": ld("hsla(0, 0%, 0%, 0.04)", "hsla(0, 0%, 100%, 0.06)"),
56
59
  "--schematic-line-height": "1.375",
57
60
  "--schematic-line-height-heading": "1.2",
58
61
  "--schematic-meter-track": ld("#f2f4f7", "#26282d"),
@@ -87,8 +90,8 @@ __export(PaymentMethodForm_exports, {
87
90
  resolveAppearance: () => resolveAppearance
88
91
  });
89
92
  import { useSetupIntent } from "@schematichq/schematic-react";
90
- import { useEffect as useEffect2, useId as useId3, useRef as useRef2, useState as useState3 } from "react";
91
- import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
93
+ import { useEffect as useEffect2, useId as useId3, useRef as useRef2, useState as useState5 } from "react";
94
+ import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
92
95
  function orUndefined(value) {
93
96
  return value === void 0 || value === "" ? void 0 : value;
94
97
  }
@@ -141,7 +144,7 @@ function PaymentMethodForm({
141
144
  t
142
145
  }) {
143
146
  const { create } = useSetupIntent();
144
- const [state, setState] = useState3({ status: "loading" });
147
+ const [state, setState] = useState5({ status: "loading" });
145
148
  const hostRef = useRef2(null);
146
149
  useEffect2(() => {
147
150
  let cancelled = false;
@@ -189,7 +192,7 @@ function PaymentMethodForm({
189
192
  };
190
193
  }, [create, locale]);
191
194
  if (state.status === "loading") {
192
- return /* @__PURE__ */ jsxs5(
195
+ return /* @__PURE__ */ jsxs7(
193
196
  "div",
194
197
  {
195
198
  "aria-busy": "true",
@@ -197,15 +200,15 @@ function PaymentMethodForm({
197
200
  "data-state": "pending",
198
201
  ref: hostRef,
199
202
  children: [
200
- /* @__PURE__ */ jsx6("span", { className: "schematic-hidden", children: t("paymentMethodsFormLoading") }),
201
- /* @__PURE__ */ jsx6("div", { className: "schematic-skeleton", children: /* @__PURE__ */ jsx6("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx6("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
203
+ /* @__PURE__ */ jsx8("span", { className: "schematic-hidden", children: t("paymentMethodsFormLoading") }),
204
+ /* @__PURE__ */ jsx8("div", { className: "schematic-skeleton", children: /* @__PURE__ */ jsx8("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx8("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
202
205
  ]
203
206
  }
204
207
  );
205
208
  }
206
209
  if (state.status === "failed") {
207
- return /* @__PURE__ */ jsxs5("div", { className: "schematic-payment-methods__form", "data-state": "error", children: [
208
- /* @__PURE__ */ jsx6(
210
+ return /* @__PURE__ */ jsxs7("div", { className: "schematic-payment-methods__form", "data-state": "error", children: [
211
+ /* @__PURE__ */ jsx8(
209
212
  "p",
210
213
  {
211
214
  className: "schematic-error schematic-small schematic-payment-methods__form-error",
@@ -213,11 +216,11 @@ function PaymentMethodForm({
213
216
  children: t(state.errorKey)
214
217
  }
215
218
  ),
216
- onSelectExisting !== void 0 && /* @__PURE__ */ jsx6(SelectExisting, { t, onSelectExisting })
219
+ onSelectExisting !== void 0 && /* @__PURE__ */ jsx8(SelectExisting, { t, onSelectExisting })
217
220
  ] });
218
221
  }
219
222
  const { Elements } = state.ui;
220
- return /* @__PURE__ */ jsx6(
223
+ return /* @__PURE__ */ jsx8(
221
224
  Elements,
222
225
  {
223
226
  stripe: state.stripe,
@@ -225,7 +228,7 @@ function PaymentMethodForm({
225
228
  appearance: state.appearance,
226
229
  clientSecret: state.clientSecret
227
230
  },
228
- children: /* @__PURE__ */ jsx6(
231
+ children: /* @__PURE__ */ jsx8(
229
232
  Fields,
230
233
  {
231
234
  checkoutPrefill,
@@ -257,13 +260,13 @@ function Fields({
257
260
  const emailId = useId3();
258
261
  const stripe = useStripe();
259
262
  const elements = useElements();
260
- const [saving, setSaving] = useState3(false);
261
- const [message, setMessage] = useState3(null);
262
- const [complete, setComplete] = useState3(false);
263
- const [ready, setReady] = useState3(false);
264
- const [loadFailed, setLoadFailed] = useState3(false);
265
- const [addressComplete, setAddressComplete] = useState3(!collectAddress);
266
- const [typedEmail, setTypedEmail] = useState3(null);
263
+ const [saving, setSaving] = useState5(false);
264
+ const [message, setMessage] = useState5(null);
265
+ const [complete, setComplete] = useState5(false);
266
+ const [ready, setReady] = useState5(false);
267
+ const [loadFailed, setLoadFailed] = useState5(false);
268
+ const [addressComplete, setAddressComplete] = useState5(!collectAddress);
269
+ const [typedEmail, setTypedEmail] = useState5(null);
267
270
  const email = typedEmail ?? orUndefined(prefill?.email) ?? "";
268
271
  const emailValid = !collectEmail || VALID_EMAIL.test(email);
269
272
  useEffect2(() => {
@@ -318,14 +321,14 @@ function Fields({
318
321
  setSaving(false);
319
322
  }
320
323
  };
321
- return /* @__PURE__ */ jsxs5(
324
+ return /* @__PURE__ */ jsxs7(
322
325
  "form",
323
326
  {
324
327
  className: "schematic-payment-methods__form",
325
328
  "data-state": "ready",
326
329
  onSubmit: (event) => void submit(event),
327
330
  children: [
328
- /* @__PURE__ */ jsx6("div", { className: "schematic-payment-methods__fields", children: /* @__PURE__ */ jsx6(
331
+ /* @__PURE__ */ jsx8("div", { className: "schematic-payment-methods__fields", children: /* @__PURE__ */ jsx8(
329
332
  PaymentElement,
330
333
  {
331
334
  onChange: (event) => setComplete(event.complete),
@@ -336,8 +339,8 @@ function Fields({
336
339
  }
337
340
  }
338
341
  ) }),
339
- collectEmail && /* @__PURE__ */ jsxs5("div", { className: "schematic-payment-methods__field", children: [
340
- /* @__PURE__ */ jsx6(
342
+ collectEmail && /* @__PURE__ */ jsxs7("div", { className: "schematic-payment-methods__field", children: [
343
+ /* @__PURE__ */ jsx8(
341
344
  "label",
342
345
  {
343
346
  className: "schematic-payment-methods__field-label",
@@ -345,7 +348,7 @@ function Fields({
345
348
  children: t("paymentMethodsEmail")
346
349
  }
347
350
  ),
348
- /* @__PURE__ */ jsx6(
351
+ /* @__PURE__ */ jsx8(
349
352
  "input",
350
353
  {
351
354
  autoComplete: "email",
@@ -359,7 +362,7 @@ function Fields({
359
362
  }
360
363
  )
361
364
  ] }),
362
- showAddress && /* @__PURE__ */ jsx6("div", { className: "schematic-payment-methods__address", children: /* @__PURE__ */ jsx6(
365
+ showAddress && /* @__PURE__ */ jsx8("div", { className: "schematic-payment-methods__address", children: /* @__PURE__ */ jsx8(
363
366
  AddressElement,
364
367
  {
365
368
  options: {
@@ -373,7 +376,7 @@ function Fields({
373
376
  },
374
377
  prefillName ?? ""
375
378
  ) }),
376
- loadFailed && /* @__PURE__ */ jsx6(
379
+ loadFailed && /* @__PURE__ */ jsx8(
377
380
  "p",
378
381
  {
379
382
  className: "schematic-error schematic-small schematic-payment-methods__form-error",
@@ -381,7 +384,7 @@ function Fields({
381
384
  children: t("paymentMethodsFormError")
382
385
  }
383
386
  ),
384
- message !== null && /* @__PURE__ */ jsx6(
387
+ message !== null && /* @__PURE__ */ jsx8(
385
388
  "p",
386
389
  {
387
390
  className: "schematic-error schematic-small schematic-payment-methods__form-error",
@@ -389,7 +392,7 @@ function Fields({
389
392
  children: message
390
393
  }
391
394
  ),
392
- /* @__PURE__ */ jsx6(
395
+ /* @__PURE__ */ jsx8(
393
396
  "button",
394
397
  {
395
398
  className: "schematic-cta schematic-payment-methods__save",
@@ -398,7 +401,7 @@ function Fields({
398
401
  children: saving ? t("paymentMethodsSaving") : t("paymentMethodsSave")
399
402
  }
400
403
  ),
401
- onSelectExisting !== void 0 && /* @__PURE__ */ jsx6(
404
+ onSelectExisting !== void 0 && /* @__PURE__ */ jsx8(
402
405
  SelectExisting,
403
406
  {
404
407
  disabled: saving,
@@ -415,7 +418,7 @@ function SelectExisting({
415
418
  onSelectExisting,
416
419
  t
417
420
  }) {
418
- return /* @__PURE__ */ jsx6(
421
+ return /* @__PURE__ */ jsx8(
419
422
  "button",
420
423
  {
421
424
  className: "schematic-link-button schematic-payment-methods__select-existing",
@@ -456,8 +459,10 @@ import {
456
459
  BillingDataProvider,
457
460
  FEATURE_USER_USAGE_LIMIT,
458
461
  SchematicI18nProvider,
459
- useFeatureUsage as useFeatureUsage2,
460
- useFeatureUserUsage,
462
+ useCreditBalances as useCreditBalances2,
463
+ useCreditUserUsage as useCreditUserUsage2,
464
+ useFeatureUsage as useFeatureUsage3,
465
+ useFeatureUserUsage as useFeatureUserUsage2,
461
466
  useInvalidateBillingData,
462
467
  useInvoices as useInvoices2,
463
468
  usePaymentMethods as usePaymentMethods2,
@@ -922,6 +927,9 @@ function formatCurrency(amountMinor, currency, locale, options = {}) {
922
927
  function formatNumber(value, locale, options) {
923
928
  return new Intl.NumberFormat(usableLocale(locale), options).format(value);
924
929
  }
930
+ function formatCredits(value, locale) {
931
+ return formatNumber(value, locale, { maximumFractionDigits: 10 });
932
+ }
925
933
  function formatConsumptionRate(rate, locale) {
926
934
  return formatNumber(rate, locale, {
927
935
  maximumFractionDigits: MAXIMUM_FRACTION_DIGITS
@@ -1318,7 +1326,10 @@ function includedFeatureRow(row, options) {
1318
1326
  description: nonEmpty(row.featureDescription),
1319
1327
  icon: nonEmpty(row.featureIcon),
1320
1328
  perLicenseCredits: row.perLicenseCreditGrants.filter((grant) => grant.scaling === "per_license").map((grant) => ({
1321
- amount: grant.creditAmount,
1329
+ // Credits come in fractions as small as 1e-10.
1330
+ amount: formatNumber(grant.creditAmount, locale, {
1331
+ maximumFractionDigits: 10
1332
+ }),
1322
1333
  creditName: featureName(
1323
1334
  {
1324
1335
  name: grant.creditName,
@@ -1338,7 +1349,7 @@ function includedFeatureRow(row, options) {
1338
1349
  usage: usageSegments(row, locale, tiered, period),
1339
1350
  usageSummary: usageSummary(row, options),
1340
1351
  hardLimit: row.priceBehavior !== void 0 && row.priceBehavior !== null && row.priceBehavior !== "credit_burndown" && row.valueType === "numeric" && typeof row.allocation === "number" ? {
1341
- amount: row.allocation,
1352
+ amount: formatNumber(row.allocation, locale),
1342
1353
  units: featureName(feature, row.allocation, locale)
1343
1354
  } : null,
1344
1355
  tiers: (row.priceBehavior === "tier" || tiered) && row.price !== void 0 ? {
@@ -1383,7 +1394,7 @@ function entitlementText(row, options) {
1383
1394
  return size > 1 ? {
1384
1395
  kind: "perPackage",
1385
1396
  cost,
1386
- size,
1397
+ size: formatNumber(size, locale),
1387
1398
  units: featureName(feature, size, locale)
1388
1399
  } : { kind: "perUnit", cost, unit: featureName(feature, 1, locale) };
1389
1400
  }
@@ -1444,14 +1455,14 @@ function usageSegments(row, locale, tiered, period) {
1444
1455
  segments.push({
1445
1456
  kind: "unitPricePerPeriod",
1446
1457
  cost: formatCurrency(unitPrice(row.price), row.price.currency, locale),
1447
- size,
1458
+ size: size > 1 ? formatNumber(size, locale) : null,
1448
1459
  units: featureName(feature, size, locale),
1449
1460
  period
1450
1461
  });
1451
1462
  } else if ((row.priceBehavior === "pay_as_you_go" || row.priceBehavior === "overage" || row.priceBehavior === "tier" || row.priceBehavior === "credit_burndown" || tiered) && typeof row.usage === "number") {
1452
1463
  segments.push({
1453
1464
  kind: "used",
1454
- amount: String(row.usage),
1465
+ amount: formatNumber(row.usage, locale),
1455
1466
  units: featureName(feature, row.usage, locale)
1456
1467
  });
1457
1468
  }
@@ -1492,6 +1503,284 @@ function nonEmpty(value) {
1492
1503
  return value === void 0 || value === null || value === "" ? null : value;
1493
1504
  }
1494
1505
 
1506
+ // src/elements/model/meteredFeatures.ts
1507
+ var TONES = [
1508
+ "ok",
1509
+ "ok",
1510
+ "ok",
1511
+ "warning",
1512
+ "critical",
1513
+ "critical"
1514
+ ];
1515
+ function deriveMeteredFeatures(features, options) {
1516
+ const ordered = options.visibleFeatures === void 0 ? features : options.visibleFeatures.flatMap((id) => {
1517
+ const row = features.find((f) => f.featureId === id);
1518
+ return row === void 0 ? [] : [row];
1519
+ });
1520
+ return ordered.filter((row) => row.featureType === "event" || row.featureType === "trait").map((row) => meteredFeatureRow(row, options));
1521
+ }
1522
+ function meteredFeatureRow(row, options) {
1523
+ const { locale } = options;
1524
+ const unit = {
1525
+ name: row.featureName,
1526
+ singularName: row.featureSingularName ?? void 0,
1527
+ pluralName: row.featurePluralName ?? void 0
1528
+ };
1529
+ const limit = usageLimit(row, options);
1530
+ const resetsAt = usableDate(row.resetsAt);
1531
+ return {
1532
+ featureId: row.featureId,
1533
+ name: row.featureName,
1534
+ description: row.featureDescription === "" ? null : row.featureDescription ?? null,
1535
+ icon: row.featureIcon === "" ? null : row.featureIcon ?? null,
1536
+ headline: headline(row, limit, unit, locale),
1537
+ limit: limitLine(row, limit, unit, options),
1538
+ resetsAt: resetsAt === void 0 ? null : formatDate(resetsAt, locale, { month: "short", year: void 0 }),
1539
+ hardLimit: row.priceBehavior !== void 0 && row.priceBehavior !== null && row.priceBehavior !== "credit_burndown" && row.valueType === "numeric" && typeof row.allocation === "number" ? {
1540
+ amount: formatNumber(row.allocation, locale),
1541
+ units: featureName(unit, row.allocation, locale)
1542
+ } : null,
1543
+ meter: meter(row, options),
1544
+ priceDetails: priceDetails(row, unit, locale),
1545
+ canAddMore: row.priceBehavior === "pay_in_advance",
1546
+ hasUsageByUser: row.featureType === "event",
1547
+ unit,
1548
+ source: row
1549
+ };
1550
+ }
1551
+ function headline(row, limit, unit, locale) {
1552
+ if (row.priceBehavior === "pay_in_advance") {
1553
+ return {
1554
+ kind: "quantity",
1555
+ amount: limit === null ? null : formatNumber(limit, locale),
1556
+ units: featureName(unit, limit ?? 0, locale)
1557
+ };
1558
+ }
1559
+ if (typeof row.usage !== "number") {
1560
+ return null;
1561
+ }
1562
+ return {
1563
+ kind: "used",
1564
+ amount: formatNumber(row.usage, locale),
1565
+ units: featureName(unit, row.usage, locale)
1566
+ };
1567
+ }
1568
+ function limitLine(row, limit, unit, options) {
1569
+ const { locale } = options;
1570
+ switch (row.priceBehavior) {
1571
+ case "tier": {
1572
+ const tier = currentTier(row);
1573
+ if (tier !== null) {
1574
+ return tier.to === null ? { kind: "tierUnlimited", feature: featureName(unit, 0, locale) } : {
1575
+ kind: "tierUpTo",
1576
+ amount: formatNumber(tier.to, locale),
1577
+ feature: featureName(unit, tier.to, locale)
1578
+ };
1579
+ }
1580
+ break;
1581
+ }
1582
+ case "overage":
1583
+ if (limit !== null) {
1584
+ return { kind: "included", amount: formatNumber(limit, locale) };
1585
+ }
1586
+ break;
1587
+ case "pay_in_advance":
1588
+ if (typeof row.usage === "number") {
1589
+ return { kind: "used", amount: formatNumber(row.usage, locale) };
1590
+ }
1591
+ break;
1592
+ case "pay_as_you_go":
1593
+ if (typeof row.currentCost === "number" && row.price !== void 0) {
1594
+ return {
1595
+ kind: "cost",
1596
+ cost: formatCurrency(row.currentCost, row.price.currency, locale)
1597
+ };
1598
+ }
1599
+ break;
1600
+ case "credit_burndown":
1601
+ if (options.showCredits === false || typeof row.consumptionRate !== "number" || row.creditName === void 0 || row.creditName === null) {
1602
+ return null;
1603
+ }
1604
+ return {
1605
+ kind: "perUse",
1606
+ amount: formatConsumptionRate(row.consumptionRate, locale),
1607
+ units: featureName(
1608
+ {
1609
+ name: row.creditName,
1610
+ singularName: row.creditSingularName,
1611
+ pluralName: row.creditPluralName
1612
+ },
1613
+ row.consumptionRate,
1614
+ locale
1615
+ )
1616
+ };
1617
+ default:
1618
+ break;
1619
+ }
1620
+ return limit === null ? { kind: "noLimit" } : { kind: "limitOf", amount: formatNumber(limit, locale) };
1621
+ }
1622
+ function meter(row, options) {
1623
+ if (row.priceBehavior === "pay_as_you_go" || row.priceBehavior === "credit_burndown" || typeof row.usage !== "number") {
1624
+ return null;
1625
+ }
1626
+ const total = options.showWarningThresholdAsLimit === true && typeof row.warningThreshold === "number" ? row.warningThreshold : row.softLimit ?? row.allocation ?? null;
1627
+ if (typeof total !== "number") {
1628
+ return null;
1629
+ }
1630
+ const usage = row.usage;
1631
+ const past = row.priceBehavior === "overage" && usage > total;
1632
+ const ratio = past ? Math.min(usage, total) / Math.max(usage, total) : total === 0 ? 1 : usage / total;
1633
+ const digits = { maximumFractionDigits: 10 };
1634
+ return {
1635
+ value: usage,
1636
+ total,
1637
+ percent: Math.min(ratio * 100, 100),
1638
+ tone: row.priceBehavior === "tier" ? "tier" : past ? "overage" : TONES[Math.floor(
1639
+ (total === 0 ? 1 : Math.min(usage, total) / total) * (TONES.length - 1)
1640
+ )],
1641
+ valueText: formatNumber(usage, options.locale, digits),
1642
+ totalText: formatNumber(total, options.locale, digits)
1643
+ };
1644
+ }
1645
+ function priceDetails(row, unit, locale) {
1646
+ const price = row.price;
1647
+ if (price === void 0) {
1648
+ return null;
1649
+ }
1650
+ const tier = currentTier(row);
1651
+ const period = row.featureType === "trait" ? pricePeriod(price) : null;
1652
+ const money = (amount) => formatCurrency(amount, price.currency, locale);
1653
+ if (row.priceBehavior === "overage") {
1654
+ if (tier === null || tier.perUnitPrice === null) {
1655
+ return null;
1656
+ }
1657
+ const size = price.packageSize;
1658
+ const over = typeof row.usage === "number" && typeof row.softLimit === "number" ? Math.max(0, row.usage - row.softLimit) : 0;
1659
+ return {
1660
+ kind: "overage",
1661
+ unitPrice: money(tier.perUnitPrice),
1662
+ packageSize: size > 1 ? formatNumber(size, locale) : null,
1663
+ units: featureName(unit, size, locale),
1664
+ period,
1665
+ overage: {
1666
+ amount: formatNumber(over, locale),
1667
+ units: featureName(unit, over, locale),
1668
+ cost: money(tier.perUnitPrice * over)
1669
+ }
1670
+ };
1671
+ }
1672
+ if (row.priceBehavior === "tier") {
1673
+ if (tier === null || tier.perUnitPrice === null) {
1674
+ return null;
1675
+ }
1676
+ return {
1677
+ kind: "tier",
1678
+ from: formatNumber(tier.from === 0 ? 1 : tier.from, locale),
1679
+ to: tier.to === null ? null : formatNumber(tier.to, locale),
1680
+ cost: typeof row.currentCost === "number" ? money(row.currentCost) : null,
1681
+ period,
1682
+ tiers: {
1683
+ ranges: tierRanges(price),
1684
+ currency: price.currency,
1685
+ mode: price.tiersMode ?? null
1686
+ }
1687
+ };
1688
+ }
1689
+ return null;
1690
+ }
1691
+
1692
+ // src/elements/model/creditUsage.ts
1693
+ function deriveCreditUsage(balances, options) {
1694
+ const ordered = options.visibleCredits === void 0 ? balances : options.visibleCredits.flatMap((id) => {
1695
+ const balance = balances.find((b) => b.creditId === id);
1696
+ return balance === void 0 ? [] : [balance];
1697
+ });
1698
+ return ordered.map((balance) => creditUsageRow(balance, options.locale));
1699
+ }
1700
+ function creditUsageRow(balance, locale) {
1701
+ const unit = {
1702
+ name: balance.creditName,
1703
+ singularName: balance.creditSingularName ?? void 0,
1704
+ pluralName: balance.creditPluralName ?? void 0
1705
+ };
1706
+ const composition = balance.composition;
1707
+ return {
1708
+ creditId: balance.creditId,
1709
+ name: balance.creditName,
1710
+ description: balance.creditDescription === "" ? null : balance.creditDescription,
1711
+ icon: balance.creditIcon === void 0 || balance.creditIcon === null || balance.creditIcon === "" ? null : balance.creditIcon,
1712
+ remaining: {
1713
+ amount: formatCredits(balance.remaining, locale),
1714
+ units: featureName(unit, balance.remaining, locale)
1715
+ },
1716
+ purchasable: balance.purchasable,
1717
+ ledger: balance.grants.map((grant) => ledgerRow(grant, unit, locale)),
1718
+ composition: composition === void 0 || composition === null ? null : {
1719
+ total: formatCredits(composition.total, locale),
1720
+ creditName: featureName(unit, composition.total, locale),
1721
+ period: composition.period,
1722
+ perLicense: {
1723
+ quantity: formatNumber(composition.licenseQuantity, locale),
1724
+ licenseName: featureName(
1725
+ {
1726
+ name: composition.licenseName,
1727
+ singularName: composition.licenseSingularName,
1728
+ pluralName: composition.licensePluralName
1729
+ },
1730
+ composition.licenseQuantity,
1731
+ locale
1732
+ ),
1733
+ perUnit: formatCredits(composition.perLicenseAmount, locale)
1734
+ },
1735
+ companyGrant: composition.fixedQuantity > 0 ? formatCredits(composition.fixedQuantity, locale) : null,
1736
+ renewsOn: renewsOn(composition.renewsAt, locale)
1737
+ },
1738
+ unit,
1739
+ source: balance
1740
+ };
1741
+ }
1742
+ function ledgerRow(grant, unit, locale) {
1743
+ const kind = grant.grantReason === "plan" ? "plan" : grant.grantReason === "purchased" ? "bundle" : grant.grantReason === "billing_credit_auto_topup" ? "autoTopup" : "promotional";
1744
+ const short = (date) => formatDate(date, locale, { month: "short" });
1745
+ const resetsAt = usableDate(grant.resetsAt);
1746
+ const expiresAt = usableDate(grant.expiresAt);
1747
+ return {
1748
+ id: grant.id,
1749
+ kind,
1750
+ amount: formatCredits(grant.quantity, locale),
1751
+ item: featureName(unit, kind === "bundle" ? 1 : grant.quantity, locale),
1752
+ createdAt: short(grant.createdAt),
1753
+ date: resetsAt !== void 0 ? { kind: "resets", text: short(resetsAt) } : expiresAt !== void 0 ? { kind: "expires", text: short(expiresAt) } : null,
1754
+ source: grant
1755
+ };
1756
+ }
1757
+ function renewsOn(date, locale) {
1758
+ const due = usableDate(date);
1759
+ if (due === void 0) {
1760
+ return null;
1761
+ }
1762
+ const day = due.getDate();
1763
+ if (!isEnglish2(locale)) {
1764
+ return formatNumber(day, locale);
1765
+ }
1766
+ const suffix = {
1767
+ few: "rd",
1768
+ many: "th",
1769
+ one: "st",
1770
+ other: "th",
1771
+ two: "nd",
1772
+ zero: "th"
1773
+ };
1774
+ return `${day}${suffix[new Intl.PluralRules("en", { type: "ordinal" }).select(day)]}`;
1775
+ }
1776
+ function isEnglish2(locale) {
1777
+ try {
1778
+ return new Intl.Locale(locale).language === "en";
1779
+ } catch {
1780
+ return false;
1781
+ }
1782
+ }
1783
+
1495
1784
  // src/elements/strings.ts
1496
1785
  var DEFAULT_STRINGS_LOCALE = "en";
1497
1786
  var DEFAULT_STRINGS = {
@@ -1567,6 +1856,53 @@ var DEFAULT_STRINGS = {
1567
1856
  includedFeaturesHideAll: "Hide all",
1568
1857
  includedFeaturesExpires: "Expires {{date}}",
1569
1858
  includedFeaturesPerLicense: "Includes {{amount}} {{creditName}} per {{licenseName}}",
1859
+ meteredFeaturesLoading: "Loading usage",
1860
+ meteredFeaturesHeader: "Usage",
1861
+ meteredFeaturesError: "There was a problem retrieving your usage.",
1862
+ meteredFeaturesUnavailable: "Usage is not available for this account.",
1863
+ meteredFeaturesUsed: "{{amount}} {{units}} used",
1864
+ meteredFeaturesIncluded: "{{amount}} included",
1865
+ meteredFeaturesInUse: "{{amount}} used",
1866
+ meteredFeaturesLimitOf: "Limit of {{amount}}",
1867
+ meteredFeaturesNoLimit: "No limit",
1868
+ meteredFeaturesAddMore: "Add More",
1869
+ meteredFeaturesAdditional: "Additional",
1870
+ meteredFeaturesTier: "Tier",
1871
+ creditUsageLoading: "Loading credits",
1872
+ creditUsageHeader: "Credits",
1873
+ creditUsageError: "There was a problem retrieving your credits.",
1874
+ creditUsageUnavailable: "Credits are not available for this account.",
1875
+ creditUsageRemaining: "{{amount}} {{units}} remaining",
1876
+ creditUsageBuyMore: "Buy More",
1877
+ creditUsageSeeDetails: "See balance details",
1878
+ creditUsageHideDetails: "Hide balance details",
1879
+ creditUsageSeeAll: "See all ({{total}})",
1880
+ creditUsageHideAll: "Hide all",
1881
+ creditUsageGrantPlan: "{{amount}} {{item}} included in plan",
1882
+ creditUsageGrantBundle: "{{amount}} {{item}} bundle purchased {{createdAt}}",
1883
+ creditUsageGrantAutoTopup: "{{amount}} {{item}} auto-topup purchased {{createdAt}}",
1884
+ creditUsageGrantPromotional: "{{amount}} promotional {{item}} granted {{createdAt}}",
1885
+ creditUsageResets: "Resets {{date}}",
1886
+ creditUsageExpires: "Expires {{date}}",
1887
+ creditUsageComposition: "Your plan includes {{total}} {{creditName}}/{{period}} \u2014 {{perLicense}}.",
1888
+ creditUsageCompositionWithGrant: "Your plan includes {{total}} {{creditName}}/{{period}} \u2014 {{perLicense}} + {{companyGrant}}.",
1889
+ creditUsagePerLicense: "{{quantity}} {{licenseName}} \xD7 {{perUnit}}",
1890
+ creditUsageCompanyGrant: "{{amount}} company grant",
1891
+ creditUsageRenewsOn: "Renews on the {{day}}.",
1892
+ usageByUserHeader: "Usage by user",
1893
+ usageByUserTotal: "{{amount}} used by your team this period",
1894
+ usageByUserError: "There was a problem retrieving usage by user.",
1895
+ usageByUserUnattributed: "Unattributed",
1896
+ // Looked up by the bare key with `{ count }`; `shown` is the count formatted.
1897
+ usageByUserMore: "plus {{shown}} more",
1898
+ usageByUserShowTop: "Show top {{shown}} users",
1899
+ usageByUserShowTop_one: "Show top {{shown}} user",
1900
+ usageByUserShowTop_other: "Show top {{shown}} users",
1901
+ usageByUserShowAllCount: "Show all {{shown}} users",
1902
+ usageByUserShowAllCount_one: "Show all {{shown}} user",
1903
+ usageByUserShowAllCount_other: "Show all {{shown}} users",
1904
+ usageByUserShowAll: "Show all",
1905
+ usageByUserShowFewer: "Show fewer",
1570
1906
  // Shared by the usage elements.
1571
1907
  usageUnits: "{{amount}} {{units}}",
1572
1908
  usagePerUnit: "{{cost}} per {{unit}}",
@@ -1619,6 +1955,160 @@ function defaultString(key, vars) {
1619
1955
  return lookup(DEFAULT_STRINGS, key, vars) ?? DEFAULT_STRINGS[key] ?? key;
1620
1956
  }
1621
1957
 
1958
+ // src/elements/styles/credit-usage.ts
1959
+ var creditUsageCss = `
1960
+ .schematic-credit-usage__credits {
1961
+ display: flex;
1962
+ flex-direction: column;
1963
+ gap: var(--schematic-space);
1964
+ }
1965
+
1966
+ /* Each credit draws its own card, so the root draws one only while pending
1967
+ or failed. */
1968
+ .schematic-credit-usage[data-state="pending"],
1969
+ .schematic-credit-usage[data-state="error"] {
1970
+ background: var(--schematic-background);
1971
+ border-radius: var(--schematic-radius);
1972
+ box-shadow: var(--schematic-shadow);
1973
+ padding: calc(var(--schematic-card-padding) * 0.75)
1974
+ var(--schematic-card-padding);
1975
+ }
1976
+
1977
+ .schematic-credit-usage__credit {
1978
+ display: flex;
1979
+ flex-direction: column;
1980
+ gap: var(--schematic-space);
1981
+ }
1982
+
1983
+ .schematic-credit-usage__main {
1984
+ display: flex;
1985
+ gap: calc(var(--schematic-space) * 1.5);
1986
+ }
1987
+
1988
+ /* Held even without a glyph, as the embed does, so names line up. */
1989
+ .schematic-credit-usage__icon {
1990
+ align-items: center;
1991
+ background: var(--schematic-surface);
1992
+ border-radius: 9999px;
1993
+ display: inline-flex;
1994
+ flex-shrink: 0;
1995
+ font-size: 1.5rem;
1996
+ height: 2.75rem;
1997
+ justify-content: center;
1998
+ width: 2.75rem;
1999
+ }
2000
+
2001
+ .schematic-credit-usage__icon .schematic-icon {
2002
+ color: var(--schematic-accent);
2003
+ }
2004
+
2005
+ /* The embed's spacing: the balance well clear of the name, the composition
2006
+ tucked close under the balance. */
2007
+ .schematic-credit-usage__body {
2008
+ display: flex;
2009
+ flex-direction: column;
2010
+ flex-grow: 1;
2011
+ gap: calc(var(--schematic-space) * 2);
2012
+ min-width: 0;
2013
+ }
2014
+
2015
+ .schematic-credit-usage__composition {
2016
+ margin-top: calc(var(--schematic-space) * -1.5);
2017
+ }
2018
+
2019
+ .schematic-credit-usage__title {
2020
+ display: flex;
2021
+ flex-direction: column;
2022
+ gap: 0.5rem;
2023
+ }
2024
+
2025
+ .schematic-credit-usage__name {
2026
+ font-family: var(--schematic-font-heading);
2027
+ font-size: 1.8125rem;
2028
+ font-weight: 800;
2029
+ line-height: var(--schematic-line-height-heading);
2030
+ margin: 0;
2031
+ }
2032
+
2033
+ .schematic-credit-usage__balance {
2034
+ align-items: center;
2035
+ display: flex;
2036
+ gap: var(--schematic-space);
2037
+ justify-content: space-between;
2038
+ }
2039
+
2040
+ .schematic-credit-usage__remaining {
2041
+ font-size: 1.0625rem;
2042
+ font-variant-numeric: tabular-nums;
2043
+ font-weight: 500;
2044
+ }
2045
+
2046
+ .schematic-credit-usage__buy-more {
2047
+ white-space: nowrap;
2048
+ }
2049
+
2050
+ .schematic-credit-usage__details,
2051
+ .schematic-credit-usage__see-all {
2052
+ align-items: center;
2053
+ display: inline-flex;
2054
+ gap: 0.25rem;
2055
+ }
2056
+
2057
+ .schematic-credit-usage__details .schematic-chevron,
2058
+ .schematic-credit-usage__see-all .schematic-chevron {
2059
+ margin-inline-start: -0.333rem;
2060
+ }
2061
+
2062
+ /* Opens above its toggle, as in the embed. */
2063
+ .schematic-credit-usage__grants {
2064
+ background: var(--schematic-inset);
2065
+ border-radius: calc(var(--schematic-radius) * 0.8);
2066
+ display: flex;
2067
+ flex-direction: column;
2068
+ gap: 0.5rem;
2069
+ margin-bottom: 0.5rem;
2070
+ padding: calc(var(--schematic-space) * 1.5);
2071
+ }
2072
+
2073
+ .schematic-credit-usage__grant-list {
2074
+ display: flex;
2075
+ flex-direction: column;
2076
+ gap: 0.75rem;
2077
+ list-style: none;
2078
+ margin: 0;
2079
+ padding: 0;
2080
+ }
2081
+
2082
+ /* Where the grant and its date do not fit on one line, the date wraps
2083
+ rather than overflowing the panel. */
2084
+ .schematic-credit-usage__grant {
2085
+ display: flex;
2086
+ flex-wrap: wrap;
2087
+ gap: 0.25rem var(--schematic-space);
2088
+ justify-content: space-between;
2089
+ }
2090
+
2091
+ .schematic-credit-usage__grant-text {
2092
+ flex: 1 1 12rem;
2093
+ min-width: 0;
2094
+ overflow-wrap: anywhere;
2095
+ }
2096
+
2097
+ .schematic-credit-usage__grant-date {
2098
+ margin-inline-start: auto;
2099
+ text-align: end;
2100
+ white-space: nowrap;
2101
+ }
2102
+
2103
+ .schematic-credit-usage .schematic-skeleton__cell[data-column="name"] {
2104
+ width: 10rem;
2105
+ }
2106
+
2107
+ .schematic-credit-usage .schematic-skeleton__cell[data-column="remaining"] {
2108
+ width: 6rem;
2109
+ }
2110
+ `;
2111
+
1622
2112
  // src/elements/styles/dialog.ts
1623
2113
  var dialogCss = `
1624
2114
  /* Up to 768px wide, with a tighter radius than a card. */
@@ -2305,26 +2795,258 @@ var invoicesCss = `
2305
2795
  }
2306
2796
  `;
2307
2797
 
2308
- // src/elements/styles/payment-methods.ts
2309
- var paymentMethodsCss = `
2310
- .schematic-payment-methods {
2798
+ // src/elements/styles/metered-features.ts
2799
+ var meteredFeaturesCss = `
2800
+ .schematic-metered-features__list {
2311
2801
  display: flex;
2312
2802
  flex-direction: column;
2313
2803
  gap: var(--schematic-space);
2804
+ list-style: none;
2805
+ margin: 0;
2806
+ padding: 0;
2314
2807
  }
2315
2808
 
2316
- .schematic-payment-methods .schematic-header {
2317
- align-items: center;
2318
- margin-bottom: 0;
2319
- }
2320
-
2321
- .schematic-payment-methods__expiry-warning {
2322
- color: var(--schematic-danger);
2323
- white-space: nowrap;
2809
+ /* Each feature is a card; while pending or failed, the root is the card. */
2810
+ .schematic-metered-features[data-state="pending"],
2811
+ .schematic-metered-features[data-state="error"] {
2812
+ background: var(--schematic-background);
2813
+ border-radius: var(--schematic-radius);
2814
+ box-shadow: var(--schematic-shadow);
2815
+ padding: calc(var(--schematic-card-padding) * 0.75)
2816
+ var(--schematic-card-padding);
2324
2817
  }
2325
2818
 
2326
- /* The pill: the default method on the left, Edit or Add on the right. */
2327
- .schematic-payment-methods__current {
2819
+ .schematic-metered-features__feature {
2820
+ container-type: inline-size;
2821
+ display: flex;
2822
+ flex-direction: column;
2823
+ gap: calc(var(--schematic-space) * 1.5);
2824
+ overflow: hidden;
2825
+ }
2826
+
2827
+ .schematic-metered-features__main {
2828
+ display: flex;
2829
+ gap: calc(var(--schematic-space) * 1.5);
2830
+ }
2831
+
2832
+ /* Kept without a glyph, as in the embed, so names line up. */
2833
+ .schematic-metered-features__icon {
2834
+ align-items: center;
2835
+ background: var(--schematic-surface);
2836
+ border-radius: 9999px;
2837
+ color: var(--schematic-accent);
2838
+ display: inline-flex;
2839
+ flex-shrink: 0;
2840
+ font-size: 1.5rem;
2841
+ height: 2.75rem;
2842
+ justify-content: center;
2843
+ width: 2.75rem;
2844
+ }
2845
+
2846
+ /* The glyph takes the base text colour rather than inheriting, so the accent
2847
+ is set on it too. */
2848
+ .schematic-metered-features__icon .schematic-icon {
2849
+ color: var(--schematic-accent);
2850
+ }
2851
+
2852
+ .schematic-metered-features__body {
2853
+ display: flex;
2854
+ flex-direction: column;
2855
+ flex-grow: 1;
2856
+ gap: calc(var(--schematic-space) * 2);
2857
+ min-width: 0;
2858
+ }
2859
+
2860
+ .schematic-metered-features__top {
2861
+ display: flex;
2862
+ flex-wrap: wrap;
2863
+ gap: var(--schematic-space);
2864
+ }
2865
+
2866
+ .schematic-metered-features__title {
2867
+ display: flex;
2868
+ flex: 1 1 min-content;
2869
+ flex-direction: column;
2870
+ gap: 0.5rem;
2871
+ }
2872
+
2873
+ .schematic-metered-features__name {
2874
+ font-family: var(--schematic-font-heading);
2875
+ font-size: 1.8125rem;
2876
+ font-weight: 800;
2877
+ line-height: var(--schematic-line-height-heading);
2878
+ margin: 0;
2879
+ }
2880
+
2881
+ /* Beside the title when both fit, otherwise beneath it as in the embed,
2882
+ rather than wrapping in a narrow column. */
2883
+ .schematic-metered-features__figures {
2884
+ display: flex;
2885
+ flex: 0 0 auto;
2886
+ flex-direction: column;
2887
+ gap: 0.25rem;
2888
+ max-width: 100%;
2889
+ text-align: end;
2890
+ }
2891
+
2892
+ .schematic-metered-features__headline {
2893
+ font-size: 1.0625rem;
2894
+ font-variant-numeric: tabular-nums;
2895
+ font-weight: 500;
2896
+ white-space: nowrap;
2897
+ }
2898
+
2899
+ @container (max-width: 30rem) {
2900
+ .schematic-metered-features__figures {
2901
+ min-width: 0;
2902
+ text-align: start;
2903
+ }
2904
+
2905
+ /* Too narrow to keep "1,300 GB of storage used" on one line. */
2906
+ .schematic-metered-features__headline {
2907
+ white-space: normal;
2908
+ }
2909
+ }
2910
+
2911
+ .schematic-metered-features__limit {
2912
+ font-variant-numeric: tabular-nums;
2913
+ }
2914
+
2915
+ .schematic-metered-features__add-more {
2916
+ align-self: flex-start;
2917
+ white-space: nowrap;
2918
+ }
2919
+
2920
+ /* Negative margins undo the card's padding so the footer bleeds to its edges. */
2921
+ .schematic-metered-features__price-details {
2922
+ align-items: center;
2923
+ background: var(--schematic-surface);
2924
+ display: flex;
2925
+ gap: var(--schematic-space);
2926
+ justify-content: space-between;
2927
+ margin: 0 calc(var(--schematic-card-padding) * -1)
2928
+ calc(var(--schematic-card-padding) * -0.75);
2929
+ padding: calc(var(--schematic-card-padding) * 0.4375)
2930
+ var(--schematic-card-padding);
2931
+ }
2932
+
2933
+ .schematic-metered-features .schematic-skeleton__cell[data-column="name"] {
2934
+ width: 10rem;
2935
+ }
2936
+
2937
+ .schematic-metered-features .schematic-skeleton__cell[data-column="usage"] {
2938
+ width: 6rem;
2939
+ }
2940
+
2941
+ .schematic-metered-features__meter {
2942
+ align-items: center;
2943
+ display: flex;
2944
+ gap: var(--schematic-space);
2945
+ }
2946
+
2947
+ .schematic-metered-features__meter .schematic-meter {
2948
+ flex-grow: 1;
2949
+ min-width: 6rem;
2950
+ }
2951
+
2952
+ .schematic-meter--tier {
2953
+ background: color-mix(in srgb, var(--schematic-accent) 50%, transparent);
2954
+ }
2955
+
2956
+ /* Past the soft limit, the fill is the included share over a warning track. */
2957
+ .schematic-meter--overage {
2958
+ background: var(--schematic-warning);
2959
+ }
2960
+
2961
+ .schematic-metered-features__meter-label {
2962
+ font-size: 0.875rem;
2963
+ font-variant-numeric: tabular-nums;
2964
+ font-weight: 500;
2965
+ white-space: nowrap;
2966
+ }
2967
+
2968
+ .schematic-usage-by-user {
2969
+ align-items: flex-start;
2970
+ display: flex;
2971
+ flex-direction: column;
2972
+ gap: 0.25rem;
2973
+ }
2974
+
2975
+ .schematic-usage-by-user__title {
2976
+ font-family: var(--schematic-font-heading);
2977
+ font-size: 1.125rem;
2978
+ font-weight: 800;
2979
+ }
2980
+
2981
+ .schematic-usage-by-user__list {
2982
+ align-self: stretch;
2983
+ list-style: none;
2984
+ margin: 0.5rem 0 0;
2985
+ padding: 0;
2986
+ }
2987
+
2988
+ .schematic-usage-by-user__user {
2989
+ align-items: center;
2990
+ display: flex;
2991
+ gap: 0.75rem;
2992
+ padding: 0.5rem 0;
2993
+ }
2994
+
2995
+ .schematic-usage-by-user__avatar {
2996
+ align-items: center;
2997
+ background: var(--schematic-surface);
2998
+ border-radius: 9999px;
2999
+ display: inline-flex;
3000
+ flex-shrink: 0;
3001
+ font-size: 0.6875rem;
3002
+ font-weight: 500;
3003
+ height: 1.75rem;
3004
+ justify-content: center;
3005
+ width: 1.75rem;
3006
+ }
3007
+
3008
+ .schematic-usage-by-user__name {
3009
+ flex-grow: 1;
3010
+ overflow: hidden;
3011
+ text-overflow: ellipsis;
3012
+ white-space: nowrap;
3013
+ }
3014
+
3015
+ .schematic-usage-by-user__amount {
3016
+ text-align: end;
3017
+ }
3018
+
3019
+ .schematic-usage-by-user__toggle {
3020
+ align-items: center;
3021
+ display: inline-flex;
3022
+ gap: 0.25rem;
3023
+ }
3024
+
3025
+ .schematic-usage-by-user__toggle .schematic-chevron {
3026
+ margin-inline-start: -0.333rem;
3027
+ }
3028
+ `;
3029
+
3030
+ // src/elements/styles/payment-methods.ts
3031
+ var paymentMethodsCss = `
3032
+ .schematic-payment-methods {
3033
+ display: flex;
3034
+ flex-direction: column;
3035
+ gap: var(--schematic-space);
3036
+ }
3037
+
3038
+ .schematic-payment-methods .schematic-header {
3039
+ align-items: center;
3040
+ margin-bottom: 0;
3041
+ }
3042
+
3043
+ .schematic-payment-methods__expiry-warning {
3044
+ color: var(--schematic-danger);
3045
+ white-space: nowrap;
3046
+ }
3047
+
3048
+ /* The pill: the default method on the left, Edit or Add on the right. */
3049
+ .schematic-payment-methods__current {
2328
3050
  align-items: center;
2329
3051
  background: var(--schematic-surface);
2330
3052
  border-radius: 9999px;
@@ -3272,13 +3994,18 @@ ${upcomingBillCss}
3272
3994
  ${paymentMethodsCss}
3273
3995
  ${tooltipCss}
3274
3996
  ${includedFeaturesCss}
3997
+ ${meteredFeaturesCss}
3998
+ ${creditUsageCss}
3275
3999
  `;
3276
4000
  var schematicStylesCss = withTokenDefaults(rulesCss) + iconsCss;
3277
4001
  var SchematicStyles = () => /* @__PURE__ */ jsx("style", { "data-schematic-styles": "", children: schematicStylesCss });
3278
4002
 
3279
- // src/elements/IncludedFeatures.tsx
3280
- import { useFeatureUsage } from "@schematichq/schematic-react";
3281
- import { useMemo, useState } from "react";
4003
+ // src/elements/CreditUsage.tsx
4004
+ import {
4005
+ useCreditBalances,
4006
+ useCreditUserUsage
4007
+ } from "@schematichq/schematic-react";
4008
+ import { useMemo as useMemo2, useState as useState2 } from "react";
3282
4009
 
3283
4010
  // src/elements/common.tsx
3284
4011
  import {
@@ -3322,6 +4049,9 @@ function useTranslator(overrides, locale) {
3322
4049
  const { onMissingString, strings, translate } = useSchematicI18n();
3323
4050
  return useCallback(
3324
4051
  (key, vars) => {
4052
+ if (isDevelopment) {
4053
+ warnRawNumbers(key, vars);
4054
+ }
3325
4055
  const override = lookup(overrides, key, vars, resolved2) ?? lookup(strings, key, vars, resolved2);
3326
4056
  if (override !== void 0) {
3327
4057
  return override;
@@ -3343,6 +4073,18 @@ function useTranslator(overrides, locale) {
3343
4073
  [onMissingString, overrides, resolved2, strings, translate]
3344
4074
  );
3345
4075
  }
4076
+ var rawNumberWarnings = /* @__PURE__ */ new Set();
4077
+ function warnRawNumbers(key, vars) {
4078
+ for (const [name, value] of Object.entries(vars ?? {})) {
4079
+ const id = `${key}.${name}`;
4080
+ if (name !== "count" && typeof value === "number" && !rawNumberWarnings.has(id)) {
4081
+ rawNumberWarnings.add(id);
4082
+ console.warn(
4083
+ `Schematic: "${key}" got a raw number for "${name}"; format it before it reaches the translator.`
4084
+ );
4085
+ }
4086
+ }
4087
+ }
3346
4088
  var isDevelopment = (() => {
3347
4089
  try {
3348
4090
  return process.env.NODE_ENV !== "production";
@@ -3469,7 +4211,10 @@ var Dialog = ({ children, className, closeLabel, onClose, open, title, titleId }
3469
4211
  };
3470
4212
 
3471
4213
  // src/elements/usage.tsx
4214
+ import { useMemo, useState } from "react";
3472
4215
  import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
4216
+ var COLLAPSED_USER_COUNT = 3;
4217
+ var EXPANDED_USER_COUNT = 20;
3473
4218
  function shortPeriod(period, t) {
3474
4219
  switch (period) {
3475
4220
  case "month":
@@ -3523,17 +4268,396 @@ function PriceTiers({
3523
4268
  return /* @__PURE__ */ jsxs2("span", { className: "schematic-tiers", children: [
3524
4269
  /* @__PURE__ */ jsx3("dl", { className: "schematic-tiers__list", children: ranges.map((tier) => /* @__PURE__ */ jsxs2("div", { className: "schematic-tiers__tier", children: [
3525
4270
  /* @__PURE__ */ jsxs2("dt", { className: "schematic-tiers__range", children: [
3526
- tier.from,
3527
- tier.to === null ? "+" : tier.to !== tier.from ? `\u2013${tier.to}` : ""
4271
+ formatNumber(tier.from, locale),
4272
+ tier.to === null ? "+" : tier.to !== tier.from ? `\u2013${formatNumber(tier.to, locale)}` : ""
3528
4273
  ] }),
3529
4274
  /* @__PURE__ */ jsx3("dd", { className: "schematic-tiers__price", children: tierPrice(tier.flatPrice ?? 0, tier.perUnitPrice ?? 0) })
3530
4275
  ] }, tier.from)) }),
3531
4276
  mode !== null && /* @__PURE__ */ jsx3("span", { className: "schematic-tiers__mode", children: mode === "volume" ? t("usageTiersVolume") : t("usageTiersGraduated") })
3532
4277
  ] });
3533
4278
  }
4279
+ function UserBreakdown({
4280
+ breakdown,
4281
+ error,
4282
+ formatAmount,
4283
+ locale,
4284
+ onRetry,
4285
+ t,
4286
+ unit
4287
+ }) {
4288
+ const [expanded, setExpanded] = useState(false);
4289
+ const users = useMemo(
4290
+ () => [...breakdown?.users ?? []].sort((a, b) => b.amount - a.amount),
4291
+ [breakdown?.users]
4292
+ );
4293
+ const amount = (value) => `${formatAmount?.(value) ?? formatNumber(value, locale)} ${featureName(unit, value, locale)}`;
4294
+ if (breakdown === void 0 && error !== void 0) {
4295
+ return /* @__PURE__ */ jsxs2("div", { className: "schematic-usage-by-user", role: "alert", children: [
4296
+ /* @__PURE__ */ jsx3("span", { className: "schematic-usage-by-user__title", children: t("usageByUserHeader") }),
4297
+ /* @__PURE__ */ jsx3("span", { className: "schematic-error", children: t("usageByUserError") }),
4298
+ /* @__PURE__ */ jsx3(
4299
+ "button",
4300
+ {
4301
+ className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-status__retry",
4302
+ type: "button",
4303
+ onClick: onRetry,
4304
+ children: t("retry")
4305
+ }
4306
+ )
4307
+ ] });
4308
+ }
4309
+ const unattributed = breakdown?.unattributed ?? null;
4310
+ if (breakdown === void 0 || users.length === 0 && unattributed === null) {
4311
+ return null;
4312
+ }
4313
+ const visible = users.slice(
4314
+ 0,
4315
+ expanded ? EXPANDED_USER_COUNT : COLLAPSED_USER_COUNT
4316
+ );
4317
+ const remaining = Math.max(breakdown.count - visible.length, 0);
4318
+ const hidden = Math.max(
4319
+ Math.min(breakdown.count, EXPANDED_USER_COUNT) - Math.min(users.length, COLLAPSED_USER_COUNT),
4320
+ 0
4321
+ );
4322
+ const expandLabel = breakdown.count > EXPANDED_USER_COUNT ? t("usageByUserShowTop", {
4323
+ count: EXPANDED_USER_COUNT,
4324
+ shown: formatNumber(EXPANDED_USER_COUNT, locale)
4325
+ }) : hidden > 0 ? t("usageByUserShowAllCount", {
4326
+ count: breakdown.count,
4327
+ shown: formatNumber(breakdown.count, locale)
4328
+ }) : t("usageByUserShowAll");
4329
+ const user = (key, label, value, muted = false) => /* @__PURE__ */ jsxs2("li", { className: "schematic-usage-by-user__user", children: [
4330
+ /* @__PURE__ */ jsx3("span", { "aria-hidden": "true", className: "schematic-usage-by-user__avatar", children: muted ? "?" : (label.trim()[0] ?? "?").toUpperCase() }),
4331
+ /* @__PURE__ */ jsx3(
4332
+ "span",
4333
+ {
4334
+ className: cx(
4335
+ "schematic-usage-by-user__name",
4336
+ muted && "schematic-muted"
4337
+ ),
4338
+ children: label
4339
+ }
4340
+ ),
4341
+ /* @__PURE__ */ jsx3("span", { className: "schematic-muted schematic-usage-by-user__amount", children: amount(value) })
4342
+ ] }, key);
4343
+ return /* @__PURE__ */ jsxs2("div", { className: "schematic-usage-by-user", children: [
4344
+ /* @__PURE__ */ jsx3("span", { className: "schematic-usage-by-user__title", children: t("usageByUserHeader") }),
4345
+ /* @__PURE__ */ jsx3("span", { className: "schematic-muted", children: t("usageByUserTotal", { amount: amount(breakdown.total) }) }),
4346
+ /* @__PURE__ */ jsxs2("ul", { className: "schematic-usage-by-user__list", children: [
4347
+ visible.map((entry) => user(entry.id, entry.label, entry.amount)),
4348
+ expanded && unattributed !== null && user(
4349
+ "unattributed",
4350
+ t("usageByUserUnattributed"),
4351
+ unattributed,
4352
+ true
4353
+ )
4354
+ ] }),
4355
+ expanded && remaining > 0 && /* @__PURE__ */ jsx3("span", { className: "schematic-muted", children: t("usageByUserMore", {
4356
+ count: remaining,
4357
+ shown: formatNumber(remaining, locale)
4358
+ }) }),
4359
+ (hidden > 0 || unattributed !== null) && /* @__PURE__ */ jsxs2(
4360
+ "button",
4361
+ {
4362
+ "aria-expanded": expanded,
4363
+ className: "schematic-link-button schematic-usage-by-user__toggle",
4364
+ type: "button",
4365
+ onClick: () => setExpanded((value) => !value),
4366
+ children: [
4367
+ /* @__PURE__ */ jsx3(
4368
+ "i",
4369
+ {
4370
+ "aria-hidden": "true",
4371
+ className: `schematic-icon schematic-icon--${expanded ? "chevron-up" : "chevron-down"} schematic-chevron`
4372
+ }
4373
+ ),
4374
+ /* @__PURE__ */ jsx3("span", { className: "schematic-link-button__label", children: expanded ? t("usageByUserShowFewer") : expandLabel })
4375
+ ]
4376
+ }
4377
+ )
4378
+ ] });
4379
+ }
3534
4380
 
3535
- // src/elements/IncludedFeatures.tsx
4381
+ // src/elements/CreditUsage.tsx
3536
4382
  import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
4383
+ var VISIBLE_GRANT_COUNT = 3;
4384
+ var GRANT_KEY = {
4385
+ autoTopup: "creditUsageGrantAutoTopup",
4386
+ bundle: "creditUsageGrantBundle",
4387
+ plan: "creditUsageGrantPlan",
4388
+ promotional: "creditUsageGrantPromotional"
4389
+ };
4390
+ function CreditUsage({
4391
+ buyMoreTarget,
4392
+ buyMoreUrl,
4393
+ className,
4394
+ headingLevel = 2,
4395
+ locale: localeProp,
4396
+ onBuyMore,
4397
+ showDescription = true,
4398
+ showExpiration = true,
4399
+ showHeader = false,
4400
+ showIcon = true,
4401
+ showUsage = true,
4402
+ showUsageByUser = true,
4403
+ strings,
4404
+ visibleCredits
4405
+ }) {
4406
+ const { data: balances, error, isPending, refetch } = useCreditBalances();
4407
+ const locale = useResolvedLocale(localeProp);
4408
+ const t = useTranslator(strings, localeProp);
4409
+ const credits = useMemo2(
4410
+ () => balances === void 0 ? [] : deriveCreditUsage(balances, { locale, visibleCredits }),
4411
+ [balances, locale, visibleCredits]
4412
+ );
4413
+ const unavailable = balances === void 0 && httpStatus(error) === 404;
4414
+ const errorMessage = error === void 0 ? void 0 : unavailable ? t("creditUsageUnavailable") : t("creditUsageError");
4415
+ if (balances !== void 0 && error === void 0 && credits.length === 0) {
4416
+ return null;
4417
+ }
4418
+ const Heading = `h${headingLevel}`;
4419
+ const CreditHeading = showHeader ? `h${Math.min(6, headingLevel + 1)}` : Heading;
4420
+ return /* @__PURE__ */ jsxs3(
4421
+ StatusFrame,
4422
+ {
4423
+ className: cx("schematic-credit-usage", className),
4424
+ error,
4425
+ errorMessage,
4426
+ hasData: balances !== void 0,
4427
+ isPending,
4428
+ loadingLabel: t("creditUsageLoading"),
4429
+ onRetry: refetch,
4430
+ retryText: t("retry"),
4431
+ skeleton: /* @__PURE__ */ jsx4(CreditUsageSkeleton, { showHeader }),
4432
+ children: [
4433
+ showHeader && /* @__PURE__ */ jsx4("div", { className: "schematic-header", children: /* @__PURE__ */ jsx4(Heading, { className: "schematic-header__title", children: t("creditUsageHeader") }) }),
4434
+ /* @__PURE__ */ jsx4("div", { className: "schematic-credit-usage__credits", children: credits.map((credit) => /* @__PURE__ */ jsxs3(
4435
+ "section",
4436
+ {
4437
+ "aria-label": credit.name,
4438
+ className: "schematic-card schematic-credit-usage__credit",
4439
+ "data-testid": "schematic-credit",
4440
+ children: [
4441
+ /* @__PURE__ */ jsxs3("div", { className: "schematic-credit-usage__main", children: [
4442
+ showIcon && /* @__PURE__ */ jsx4("span", { className: "schematic-credit-usage__icon", children: credit.icon !== null && /* @__PURE__ */ jsx4(
4443
+ "i",
4444
+ {
4445
+ "aria-hidden": "true",
4446
+ className: `schematic-icon schematic-icon--${credit.icon}`
4447
+ }
4448
+ ) }),
4449
+ /* @__PURE__ */ jsxs3("div", { className: "schematic-credit-usage__body", children: [
4450
+ /* @__PURE__ */ jsxs3("div", { className: "schematic-credit-usage__title", children: [
4451
+ /* @__PURE__ */ jsx4(CreditHeading, { className: "schematic-credit-usage__name", children: credit.name }),
4452
+ showDescription && credit.description !== null && /* @__PURE__ */ jsx4("p", { className: "schematic-muted", children: credit.description })
4453
+ ] }),
4454
+ /* @__PURE__ */ jsxs3("div", { className: "schematic-credit-usage__balance", children: [
4455
+ showUsage && /* @__PURE__ */ jsx4(
4456
+ "span",
4457
+ {
4458
+ className: "schematic-credit-usage__remaining",
4459
+ "data-testid": "schematic-credit-remaining",
4460
+ children: t("creditUsageRemaining", credit.remaining)
4461
+ }
4462
+ ),
4463
+ credit.purchasable && /* @__PURE__ */ jsx4(
4464
+ BuyMore,
4465
+ {
4466
+ credit,
4467
+ label: t("creditUsageBuyMore"),
4468
+ onBuyMore,
4469
+ target: buyMoreTarget,
4470
+ url: buyMoreUrl
4471
+ }
4472
+ )
4473
+ ] }),
4474
+ credit.composition !== null && /* @__PURE__ */ jsx4("p", { className: "schematic-muted schematic-small schematic-credit-usage__composition", children: compositionText(credit, t) })
4475
+ ] })
4476
+ ] }),
4477
+ credit.ledger.length > 0 && /* @__PURE__ */ jsx4(
4478
+ Ledger,
4479
+ {
4480
+ credit,
4481
+ locale,
4482
+ showExpiration,
4483
+ t
4484
+ }
4485
+ ),
4486
+ showUsageByUser && credit.ledger.length > 0 && /* @__PURE__ */ jsx4(CreditUserBreakdown, { credit, locale, t })
4487
+ ]
4488
+ },
4489
+ credit.creditId
4490
+ )) })
4491
+ ]
4492
+ }
4493
+ );
4494
+ }
4495
+ function compositionText(credit, t) {
4496
+ const composition = credit.composition;
4497
+ if (composition === null) {
4498
+ return "";
4499
+ }
4500
+ const vars = {
4501
+ creditName: composition.creditName,
4502
+ perLicense: t("creditUsagePerLicense", composition.perLicense),
4503
+ period: shortPeriod(composition.period, t) ?? composition.period,
4504
+ total: composition.total
4505
+ };
4506
+ const sentence = composition.companyGrant === null ? t("creditUsageComposition", vars) : t("creditUsageCompositionWithGrant", {
4507
+ ...vars,
4508
+ companyGrant: t("creditUsageCompanyGrant", {
4509
+ amount: composition.companyGrant
4510
+ })
4511
+ });
4512
+ return composition.renewsOn === null ? sentence : `${sentence} ${t("creditUsageRenewsOn", { day: composition.renewsOn })}`;
4513
+ }
4514
+ function Ledger({
4515
+ credit,
4516
+ locale,
4517
+ showExpiration,
4518
+ t
4519
+ }) {
4520
+ const [open, setOpen] = useState2(false);
4521
+ const [all, setAll] = useState2(false);
4522
+ const rows = all ? credit.ledger : credit.ledger.slice(0, VISIBLE_GRANT_COUNT);
4523
+ return /* @__PURE__ */ jsxs3("div", { className: "schematic-credit-usage__ledger", children: [
4524
+ open && /* @__PURE__ */ jsxs3("div", { className: "schematic-credit-usage__grants", children: [
4525
+ /* @__PURE__ */ jsx4("ul", { className: "schematic-credit-usage__grant-list", children: rows.map((row) => /* @__PURE__ */ jsxs3(
4526
+ "li",
4527
+ {
4528
+ className: "schematic-credit-usage__grant",
4529
+ "data-testid": "schematic-credit-grant",
4530
+ children: [
4531
+ /* @__PURE__ */ jsx4("span", { className: "schematic-credit-usage__grant-text", children: t(GRANT_KEY[row.kind], {
4532
+ amount: row.amount,
4533
+ createdAt: row.createdAt,
4534
+ item: row.item
4535
+ }) }),
4536
+ showExpiration && row.date !== null && /* @__PURE__ */ jsx4("span", { className: "schematic-credit-usage__grant-date", children: row.date.kind === "resets" ? t("creditUsageResets", { date: row.date.text }) : t("creditUsageExpires", { date: row.date.text }) })
4537
+ ]
4538
+ },
4539
+ row.id
4540
+ )) }),
4541
+ credit.ledger.length > VISIBLE_GRANT_COUNT && /* @__PURE__ */ jsxs3(
4542
+ "button",
4543
+ {
4544
+ "aria-expanded": all,
4545
+ className: "schematic-link-button schematic-credit-usage__see-all",
4546
+ type: "button",
4547
+ onClick: () => setAll((value) => !value),
4548
+ children: [
4549
+ /* @__PURE__ */ jsx4(
4550
+ "i",
4551
+ {
4552
+ "aria-hidden": "true",
4553
+ className: `schematic-icon schematic-icon--${all ? "chevron-up" : "chevron-down"} schematic-chevron`
4554
+ }
4555
+ ),
4556
+ /* @__PURE__ */ jsx4("span", { className: "schematic-link-button__label", children: all ? t("creditUsageHideAll") : t("creditUsageSeeAll", {
4557
+ total: formatNumber(credit.ledger.length, locale)
4558
+ }) })
4559
+ ]
4560
+ }
4561
+ )
4562
+ ] }),
4563
+ /* @__PURE__ */ jsxs3(
4564
+ "button",
4565
+ {
4566
+ "aria-expanded": open,
4567
+ className: "schematic-link-button schematic-credit-usage__details",
4568
+ type: "button",
4569
+ onClick: () => {
4570
+ setOpen((value) => !value);
4571
+ setAll(false);
4572
+ },
4573
+ children: [
4574
+ /* @__PURE__ */ jsx4(
4575
+ "i",
4576
+ {
4577
+ "aria-hidden": "true",
4578
+ className: `schematic-icon schematic-icon--${open ? "chevron-up" : "chevron-down"} schematic-chevron`
4579
+ }
4580
+ ),
4581
+ /* @__PURE__ */ jsx4("span", { className: "schematic-link-button__label", children: open ? t("creditUsageHideDetails") : t("creditUsageSeeDetails") })
4582
+ ]
4583
+ }
4584
+ )
4585
+ ] });
4586
+ }
4587
+ function BuyMore({
4588
+ credit,
4589
+ label,
4590
+ onBuyMore,
4591
+ target,
4592
+ url
4593
+ }) {
4594
+ if (onBuyMore !== void 0) {
4595
+ return /* @__PURE__ */ jsx4(
4596
+ "button",
4597
+ {
4598
+ className: "schematic-cta schematic-cta--small schematic-credit-usage__buy-more",
4599
+ type: "button",
4600
+ onClick: () => onBuyMore(credit.source),
4601
+ children: label
4602
+ }
4603
+ );
4604
+ }
4605
+ if (url !== void 0) {
4606
+ return /* @__PURE__ */ jsx4(
4607
+ "a",
4608
+ {
4609
+ className: "schematic-cta schematic-cta--small schematic-credit-usage__buy-more",
4610
+ href: url,
4611
+ target,
4612
+ children: label
4613
+ }
4614
+ );
4615
+ }
4616
+ return null;
4617
+ }
4618
+ function CreditUserBreakdown({
4619
+ credit,
4620
+ locale,
4621
+ t
4622
+ }) {
4623
+ const { data, error, refetch } = useCreditUserUsage(credit.creditId);
4624
+ return /* @__PURE__ */ jsx4(
4625
+ UserBreakdown,
4626
+ {
4627
+ breakdown: data === void 0 ? void 0 : {
4628
+ count: data.count,
4629
+ total: data.total,
4630
+ unattributed: data.unattributed ?? null,
4631
+ users: data.users.map((user) => ({
4632
+ amount: user.used,
4633
+ id: user.userId,
4634
+ label: user.name ?? user.userId
4635
+ }))
4636
+ },
4637
+ error,
4638
+ formatAmount: (value) => formatCredits(value, locale),
4639
+ locale,
4640
+ onRetry: refetch,
4641
+ t,
4642
+ unit: credit.unit
4643
+ }
4644
+ );
4645
+ }
4646
+ function CreditUsageSkeleton({ showHeader }) {
4647
+ return /* @__PURE__ */ jsxs3("div", { className: "schematic-skeleton", children: [
4648
+ showHeader && /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__heading" }),
4649
+ [0, 1].map((index) => /* @__PURE__ */ jsxs3("div", { className: "schematic-skeleton__row", children: [
4650
+ /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
4651
+ /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__cell", "data-column": "remaining" })
4652
+ ] }, index))
4653
+ ] });
4654
+ }
4655
+ CreditUsage.resources = ["creditBalances"];
4656
+
4657
+ // src/elements/IncludedFeatures.tsx
4658
+ import { useFeatureUsage } from "@schematichq/schematic-react";
4659
+ import { useMemo as useMemo3, useState as useState3 } from "react";
4660
+ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
3537
4661
  var VISIBLE_FEATURE_COUNT = 4;
3538
4662
  function IncludedFeatures({
3539
4663
  className,
@@ -3554,8 +4678,8 @@ function IncludedFeatures({
3554
4678
  const { data: features, error, isPending, refetch } = useFeatureUsage();
3555
4679
  const locale = useResolvedLocale(localeProp);
3556
4680
  const t = useTranslator(strings, localeProp);
3557
- const [expanded, setExpanded] = useState(false);
3558
- const rows = useMemo(
4681
+ const [expanded, setExpanded] = useState3(false);
4682
+ const rows = useMemo3(
3559
4683
  () => features === void 0 ? [] : deriveIncludedFeatures(features, {
3560
4684
  locale,
3561
4685
  showCredits,
@@ -3575,7 +4699,7 @@ function IncludedFeatures({
3575
4699
  const shown = canExpand && !expanded ? rows.slice(0, VISIBLE_FEATURE_COUNT) : rows;
3576
4700
  const unavailable = features === void 0 && httpStatus(error) === 404;
3577
4701
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("includedFeaturesUnavailable") : t("includedFeaturesError");
3578
- return /* @__PURE__ */ jsxs3(
4702
+ return /* @__PURE__ */ jsxs4(
3579
4703
  StatusFrame,
3580
4704
  {
3581
4705
  className: cx("schematic-card", "schematic-included-features", className),
@@ -3586,26 +4710,26 @@ function IncludedFeatures({
3586
4710
  loadingLabel: t("includedFeaturesLoading"),
3587
4711
  onRetry: refetch,
3588
4712
  retryText: t("retry"),
3589
- skeleton: /* @__PURE__ */ jsx4(IncludedFeaturesSkeleton, { showHeader }),
4713
+ skeleton: /* @__PURE__ */ jsx5(IncludedFeaturesSkeleton, { showHeader }),
3590
4714
  children: [
3591
- showHeader && /* @__PURE__ */ jsx4("div", { className: "schematic-header", children: /* @__PURE__ */ jsx4(Heading, { className: "schematic-header__title", children: t("includedFeaturesHeader") }) }),
3592
- /* @__PURE__ */ jsx4("ul", { className: "schematic-included-features__list", children: shown.map((row) => /* @__PURE__ */ jsxs3(
4715
+ showHeader && /* @__PURE__ */ jsx5("div", { className: "schematic-header", children: /* @__PURE__ */ jsx5(Heading, { className: "schematic-header__title", children: t("includedFeaturesHeader") }) }),
4716
+ /* @__PURE__ */ jsx5("ul", { className: "schematic-included-features__list", children: shown.map((row) => /* @__PURE__ */ jsxs4(
3593
4717
  "li",
3594
4718
  {
3595
4719
  className: "schematic-included-features__row",
3596
4720
  "data-testid": "schematic-included-feature",
3597
4721
  children: [
3598
- showIcon && row.icon !== null && /* @__PURE__ */ jsx4(
4722
+ showIcon && row.icon !== null && /* @__PURE__ */ jsx5(
3599
4723
  "i",
3600
4724
  {
3601
4725
  "aria-hidden": "true",
3602
4726
  className: `schematic-icon schematic-icon--${row.icon} schematic-included-features__icon`
3603
4727
  }
3604
4728
  ),
3605
- /* @__PURE__ */ jsxs3("div", { className: "schematic-included-features__details", children: [
3606
- /* @__PURE__ */ jsx4("span", { className: "schematic-included-features__name", children: row.name }),
3607
- showDescription && row.description !== null && /* @__PURE__ */ jsx4("span", { className: "schematic-muted schematic-small", children: row.description }),
3608
- row.perLicenseCredits.map((credits, index) => /* @__PURE__ */ jsx4(
4729
+ /* @__PURE__ */ jsxs4("div", { className: "schematic-included-features__details", children: [
4730
+ /* @__PURE__ */ jsx5("span", { className: "schematic-included-features__name", children: row.name }),
4731
+ showDescription && row.description !== null && /* @__PURE__ */ jsx5("span", { className: "schematic-muted schematic-small", children: row.description }),
4732
+ row.perLicenseCredits.map((credits, index) => /* @__PURE__ */ jsx5(
3609
4733
  "span",
3610
4734
  {
3611
4735
  className: "schematic-muted schematic-small",
@@ -3617,9 +4741,9 @@ function IncludedFeatures({
3617
4741
  },
3618
4742
  `${credits.creditName}-${index}`
3619
4743
  )),
3620
- showExpiration && row.expiresAt !== null && /* @__PURE__ */ jsx4("em", { className: "schematic-muted schematic-small", children: t("includedFeaturesExpires", { date: row.expiresAt.text }) })
4744
+ showExpiration && row.expiresAt !== null && /* @__PURE__ */ jsx5("em", { className: "schematic-muted schematic-small", children: t("includedFeaturesExpires", { date: row.expiresAt.text }) })
3621
4745
  ] }),
3622
- /* @__PURE__ */ jsx4(
4746
+ /* @__PURE__ */ jsx5(
3623
4747
  UsageDetails,
3624
4748
  {
3625
4749
  row,
@@ -3634,7 +4758,7 @@ function IncludedFeatures({
3634
4758
  },
3635
4759
  row.featureId
3636
4760
  )) }),
3637
- canExpand && /* @__PURE__ */ jsxs3(
4761
+ canExpand && /* @__PURE__ */ jsxs4(
3638
4762
  "button",
3639
4763
  {
3640
4764
  "aria-expanded": expanded,
@@ -3642,14 +4766,14 @@ function IncludedFeatures({
3642
4766
  type: "button",
3643
4767
  onClick: () => setExpanded((value) => !value),
3644
4768
  children: [
3645
- /* @__PURE__ */ jsx4(
4769
+ /* @__PURE__ */ jsx5(
3646
4770
  "i",
3647
4771
  {
3648
4772
  "aria-hidden": "true",
3649
4773
  className: `schematic-icon schematic-icon--${expanded ? "chevron-up" : "chevron-down"} schematic-chevron`
3650
4774
  }
3651
4775
  ),
3652
- /* @__PURE__ */ jsx4("span", { className: "schematic-link-button__label", children: expanded ? t("includedFeaturesHideAll") : t("includedFeaturesSeeAll") })
4776
+ /* @__PURE__ */ jsx5("span", { className: "schematic-link-button__label", children: expanded ? t("includedFeaturesHideAll") : t("includedFeaturesSeeAll") })
3653
4777
  ]
3654
4778
  }
3655
4779
  )
@@ -3669,17 +4793,17 @@ function UsageDetails({
3669
4793
  if (row.entitlement === null && usage === null) {
3670
4794
  return null;
3671
4795
  }
3672
- return /* @__PURE__ */ jsxs3("div", { className: "schematic-included-features__usage", children: [
3673
- showEntitlement && row.entitlement !== null && /* @__PURE__ */ jsxs3("span", { className: "schematic-included-features__entitlement", children: [
4796
+ return /* @__PURE__ */ jsxs4("div", { className: "schematic-included-features__usage", children: [
4797
+ showEntitlement && row.entitlement !== null && /* @__PURE__ */ jsxs4("span", { className: "schematic-included-features__entitlement", children: [
3674
4798
  entitlementText2(row.entitlement, t),
3675
- showHardLimit && row.hardLimit !== null && /* @__PURE__ */ jsx4(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
4799
+ showHardLimit && row.hardLimit !== null && /* @__PURE__ */ jsx5(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
3676
4800
  amount: row.hardLimit.amount,
3677
4801
  units: row.hardLimit.units
3678
4802
  }) })
3679
4803
  ] }),
3680
- showUsage && usage !== null && /* @__PURE__ */ jsxs3("span", { className: "schematic-muted schematic-small schematic-included-features__used", children: [
4804
+ showUsage && usage !== null && /* @__PURE__ */ jsxs4("span", { className: "schematic-muted schematic-small schematic-included-features__used", children: [
3681
4805
  usage,
3682
- row.tiers !== null && row.tiers.ranges.length > 0 && /* @__PURE__ */ jsx4(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ jsx4(
4806
+ row.tiers !== null && row.tiers.ranges.length > 0 && /* @__PURE__ */ jsx5(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ jsx5(
3683
4807
  PriceTiers,
3684
4808
  {
3685
4809
  currency: row.tiers.currency,
@@ -3732,7 +4856,7 @@ function segmentText(segment, t) {
3732
4856
  switch (segment.kind) {
3733
4857
  case "unitPricePerPeriod": {
3734
4858
  const period = shortPeriod(segment.period, t) ?? segment.period;
3735
- return segment.size > 1 ? t("usagePackagePricePerPeriod", {
4859
+ return segment.size !== null ? t("usagePackagePricePerPeriod", {
3736
4860
  cost: segment.cost,
3737
4861
  size: segment.size,
3738
4862
  units: segment.units,
@@ -3754,11 +4878,11 @@ function segmentText(segment, t) {
3754
4878
  }
3755
4879
  }
3756
4880
  function IncludedFeaturesSkeleton({ showHeader }) {
3757
- return /* @__PURE__ */ jsxs3("div", { className: "schematic-skeleton", children: [
3758
- showHeader && /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__heading" }),
3759
- [0, 1, 2].map((index) => /* @__PURE__ */ jsxs3("div", { className: "schematic-skeleton__row", children: [
3760
- /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
3761
- /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__cell", "data-column": "usage" })
4881
+ return /* @__PURE__ */ jsxs4("div", { className: "schematic-skeleton", children: [
4882
+ showHeader && /* @__PURE__ */ jsx5("div", { className: "schematic-skeleton__heading" }),
4883
+ [0, 1, 2].map((index) => /* @__PURE__ */ jsxs4("div", { className: "schematic-skeleton__row", children: [
4884
+ /* @__PURE__ */ jsx5("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
4885
+ /* @__PURE__ */ jsx5("div", { className: "schematic-skeleton__cell", "data-column": "usage" })
3762
4886
  ] }, index))
3763
4887
  ] });
3764
4888
  }
@@ -3766,8 +4890,8 @@ IncludedFeatures.resources = ["featureUsage"];
3766
4890
 
3767
4891
  // src/elements/Invoices.tsx
3768
4892
  import { useInvoices } from "@schematichq/schematic-react";
3769
- import { useId as useId2, useMemo as useMemo2, useState as useState2 } from "react";
3770
- import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
4893
+ import { useId as useId2, useMemo as useMemo4, useState as useState4 } from "react";
4894
+ import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
3771
4895
  var SKELETON_ROWS = 4;
3772
4896
  function Invoices({
3773
4897
  className,
@@ -3790,8 +4914,8 @@ function Invoices({
3790
4914
  } = useInvoices(query);
3791
4915
  const locale = useResolvedLocale(localeProp);
3792
4916
  const t = useTranslator(strings, localeProp);
3793
- const [expanded, setExpanded] = useState2(false);
3794
- const list = useMemo2(
4917
+ const [expanded, setExpanded] = useState4(false);
4918
+ const list = useMemo4(
3795
4919
  () => page === void 0 ? void 0 : deriveInvoiceList(page, { locale }),
3796
4920
  [locale, page]
3797
4921
  );
@@ -3807,7 +4931,7 @@ function Invoices({
3807
4931
  );
3808
4932
  const unavailable = list === void 0 && httpStatus(error) === 404;
3809
4933
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("invoicesUnavailable") : t("invoicesError");
3810
- return /* @__PURE__ */ jsx5(
4934
+ return /* @__PURE__ */ jsx6(
3811
4935
  StatusFrame,
3812
4936
  {
3813
4937
  className: cx("schematic-card", "schematic-invoices", className),
@@ -3818,7 +4942,7 @@ function Invoices({
3818
4942
  loadingLabel: t("invoicesLoading"),
3819
4943
  onRetry: refetch,
3820
4944
  retryText: t("retry"),
3821
- skeleton: /* @__PURE__ */ jsx5(
4945
+ skeleton: /* @__PURE__ */ jsx6(
3822
4946
  InvoicesSkeleton,
3823
4947
  {
3824
4948
  columns,
@@ -3826,22 +4950,22 @@ function Invoices({
3826
4950
  showHeader
3827
4951
  }
3828
4952
  ),
3829
- children: list !== void 0 && /* @__PURE__ */ jsxs4(Fragment2, { children: [
3830
- showHeader && /* @__PURE__ */ jsx5("div", { className: "schematic-header", children: /* @__PURE__ */ jsx5(Heading, { className: "schematic-header__title", id: headingId, children: t("invoicesHeader") }) }),
3831
- rows.length === 0 ? /* @__PURE__ */ jsx5("p", { className: "schematic-muted schematic-invoices__empty", children: t("invoicesEmpty") }) : /* @__PURE__ */ jsx5(
4953
+ children: list !== void 0 && /* @__PURE__ */ jsxs5(Fragment2, { children: [
4954
+ showHeader && /* @__PURE__ */ jsx6("div", { className: "schematic-header", children: /* @__PURE__ */ jsx6(Heading, { className: "schematic-header__title", id: headingId, children: t("invoicesHeader") }) }),
4955
+ rows.length === 0 ? /* @__PURE__ */ jsx6("p", { className: "schematic-muted schematic-invoices__empty", children: t("invoicesEmpty") }) : /* @__PURE__ */ jsx6(
3832
4956
  "ul",
3833
4957
  {
3834
4958
  className: "schematic-invoices__list",
3835
4959
  "aria-label": showHeader ? void 0 : t("invoicesHeader"),
3836
4960
  "aria-labelledby": showHeader ? headingId : void 0,
3837
- children: visible.map((row) => /* @__PURE__ */ jsxs4(
4961
+ children: visible.map((row) => /* @__PURE__ */ jsxs5(
3838
4962
  "li",
3839
4963
  {
3840
4964
  className: "schematic-invoices__row",
3841
4965
  "data-testid": "schematic-invoice",
3842
4966
  children: [
3843
- showDate && /* @__PURE__ */ jsx5("span", { className: "schematic-invoices__date", children: /* @__PURE__ */ jsx5(InvoiceDate, { row, t }) }),
3844
- showAmount && /* @__PURE__ */ jsx5(
4967
+ showDate && /* @__PURE__ */ jsx6("span", { className: "schematic-invoices__date", children: /* @__PURE__ */ jsx6(InvoiceDate, { row, t }) }),
4968
+ showAmount && /* @__PURE__ */ jsx6(
3845
4969
  "span",
3846
4970
  {
3847
4971
  className: cx(
@@ -3858,8 +4982,8 @@ function Invoices({
3858
4982
  ))
3859
4983
  }
3860
4984
  ),
3861
- (canCollapse || showingAll && list.hasMore) && /* @__PURE__ */ jsxs4("div", { className: "schematic-invoices__actions", children: [
3862
- canCollapse && /* @__PURE__ */ jsxs4(
4985
+ (canCollapse || showingAll && list.hasMore) && /* @__PURE__ */ jsxs5("div", { className: "schematic-invoices__actions", children: [
4986
+ canCollapse && /* @__PURE__ */ jsxs5(
3863
4987
  "button",
3864
4988
  {
3865
4989
  "aria-expanded": expanded,
@@ -3867,7 +4991,7 @@ function Invoices({
3867
4991
  type: "button",
3868
4992
  onClick: () => setExpanded((value) => !value),
3869
4993
  children: [
3870
- /* @__PURE__ */ jsx5(
4994
+ /* @__PURE__ */ jsx6(
3871
4995
  "i",
3872
4996
  {
3873
4997
  "aria-hidden": "true",
@@ -3879,11 +5003,11 @@ function Invoices({
3879
5003
  )
3880
5004
  }
3881
5005
  ),
3882
- /* @__PURE__ */ jsx5("span", { className: "schematic-link-button__label", children: expanded ? t("invoicesSeeLess") : t("invoicesSeeMore") })
5006
+ /* @__PURE__ */ jsx6("span", { className: "schematic-link-button__label", children: expanded ? t("invoicesSeeLess") : t("invoicesSeeMore") })
3883
5007
  ]
3884
5008
  }
3885
5009
  ),
3886
- showingAll && list.hasMore && /* @__PURE__ */ jsx5(
5010
+ showingAll && list.hasMore && /* @__PURE__ */ jsx6(
3887
5011
  "button",
3888
5012
  {
3889
5013
  className: "schematic-link-button schematic-invoices__load-more",
@@ -3906,9 +5030,9 @@ function InvoicesSkeleton({
3906
5030
  rows,
3907
5031
  showHeader
3908
5032
  }) {
3909
- return /* @__PURE__ */ jsxs4("div", { className: "schematic-skeleton", children: [
3910
- showHeader && /* @__PURE__ */ jsx5("div", { className: "schematic-skeleton__heading" }),
3911
- Array.from({ length: rows }, (_, row) => /* @__PURE__ */ jsx5("div", { className: "schematic-skeleton__row", children: columns.map((column) => /* @__PURE__ */ jsx5(
5033
+ return /* @__PURE__ */ jsxs5("div", { className: "schematic-skeleton", children: [
5034
+ showHeader && /* @__PURE__ */ jsx6("div", { className: "schematic-skeleton__heading" }),
5035
+ Array.from({ length: rows }, (_, row) => /* @__PURE__ */ jsx6("div", { className: "schematic-skeleton__row", children: columns.map((column) => /* @__PURE__ */ jsx6(
3912
5036
  "div",
3913
5037
  {
3914
5038
  className: "schematic-skeleton__cell",
@@ -3920,10 +5044,10 @@ function InvoicesSkeleton({
3920
5044
  }
3921
5045
  function InvoiceDate({ row, t }) {
3922
5046
  if (row.url === null) {
3923
- return /* @__PURE__ */ jsx5("span", { className: "schematic-invoices__date-text", children: row.dateText });
5047
+ return /* @__PURE__ */ jsx6("span", { className: "schematic-invoices__date-text", children: row.dateText });
3924
5048
  }
3925
5049
  const label = row.dateText === "" ? t("invoicesUndated") : row.dateText;
3926
- return /* @__PURE__ */ jsx5(
5050
+ return /* @__PURE__ */ jsx6(
3927
5051
  "a",
3928
5052
  {
3929
5053
  className: "schematic-invoices__link",
@@ -3936,10 +5060,356 @@ function InvoiceDate({ row, t }) {
3936
5060
  }
3937
5061
  Invoices.resources = ["invoices"];
3938
5062
 
5063
+ // src/elements/MeteredFeatures.tsx
5064
+ import {
5065
+ useFeatureUsage as useFeatureUsage2,
5066
+ useFeatureUserUsage
5067
+ } from "@schematichq/schematic-react";
5068
+ import { useMemo as useMemo5 } from "react";
5069
+ import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
5070
+ function MeteredFeatures({
5071
+ addMoreTarget,
5072
+ addMoreUrl,
5073
+ className,
5074
+ headingLevel = 2,
5075
+ locale: localeProp,
5076
+ onAddMore,
5077
+ showAllocation = true,
5078
+ showCredits = true,
5079
+ showDescription = true,
5080
+ showHardLimit = false,
5081
+ showHeader = false,
5082
+ showIcon = true,
5083
+ showMeter = true,
5084
+ showUsage = true,
5085
+ showUsageByUser = true,
5086
+ showWarningThresholdAsLimit = false,
5087
+ strings,
5088
+ visibleFeatures
5089
+ }) {
5090
+ const { data: features, error, isPending, refetch } = useFeatureUsage2();
5091
+ const locale = useResolvedLocale(localeProp);
5092
+ const t = useTranslator(strings, localeProp);
5093
+ const rows = useMemo5(
5094
+ () => features === void 0 ? [] : deriveMeteredFeatures(features, {
5095
+ locale,
5096
+ showCredits,
5097
+ showWarningThresholdAsLimit,
5098
+ visibleFeatures
5099
+ }),
5100
+ [
5101
+ features,
5102
+ locale,
5103
+ showCredits,
5104
+ showWarningThresholdAsLimit,
5105
+ visibleFeatures
5106
+ ]
5107
+ );
5108
+ const unavailable = features === void 0 && httpStatus(error) === 404;
5109
+ const errorMessage = error === void 0 ? void 0 : unavailable ? t("meteredFeaturesUnavailable") : t("meteredFeaturesError");
5110
+ if (features !== void 0 && error === void 0 && rows.length === 0) {
5111
+ return null;
5112
+ }
5113
+ const Heading = `h${headingLevel}`;
5114
+ const NameHeading = showHeader ? `h${Math.min(6, headingLevel + 1)}` : Heading;
5115
+ return /* @__PURE__ */ jsxs6(
5116
+ StatusFrame,
5117
+ {
5118
+ className: cx("schematic-metered-features", className),
5119
+ error,
5120
+ errorMessage,
5121
+ hasData: features !== void 0,
5122
+ isPending,
5123
+ loadingLabel: t("meteredFeaturesLoading"),
5124
+ onRetry: refetch,
5125
+ retryText: t("retry"),
5126
+ skeleton: /* @__PURE__ */ jsx7(MeteredFeaturesSkeleton, { showHeader }),
5127
+ children: [
5128
+ showHeader && /* @__PURE__ */ jsx7("div", { className: "schematic-header", children: /* @__PURE__ */ jsx7(Heading, { className: "schematic-header__title", children: t("meteredFeaturesHeader") }) }),
5129
+ /* @__PURE__ */ jsx7("ul", { className: "schematic-metered-features__list", children: rows.map((row) => /* @__PURE__ */ jsxs6(
5130
+ "li",
5131
+ {
5132
+ className: "schematic-card schematic-metered-features__feature",
5133
+ "data-testid": "schematic-metered-feature",
5134
+ children: [
5135
+ /* @__PURE__ */ jsxs6("div", { className: "schematic-metered-features__main", children: [
5136
+ showIcon && /* @__PURE__ */ jsx7("span", { className: "schematic-metered-features__icon", children: row.icon !== null && /* @__PURE__ */ jsx7(
5137
+ "i",
5138
+ {
5139
+ "aria-hidden": "true",
5140
+ className: `schematic-icon schematic-icon--${row.icon}`
5141
+ }
5142
+ ) }),
5143
+ /* @__PURE__ */ jsxs6("div", { className: "schematic-metered-features__body", children: [
5144
+ /* @__PURE__ */ jsxs6("div", { className: "schematic-metered-features__top", children: [
5145
+ /* @__PURE__ */ jsxs6("div", { className: "schematic-metered-features__title", children: [
5146
+ /* @__PURE__ */ jsx7(NameHeading, { className: "schematic-metered-features__name", children: row.name }),
5147
+ showDescription && row.description !== null && /* @__PURE__ */ jsx7("p", { className: "schematic-muted", children: row.description })
5148
+ ] }),
5149
+ /* @__PURE__ */ jsxs6("div", { className: "schematic-metered-features__figures", children: [
5150
+ showUsage && row.headline !== null && /* @__PURE__ */ jsx7("span", { className: "schematic-metered-features__headline", children: headlineText(row.headline, t) }),
5151
+ showAllocation && /* @__PURE__ */ jsx7(
5152
+ LimitLine,
5153
+ {
5154
+ row,
5155
+ showHardLimit,
5156
+ t
5157
+ }
5158
+ )
5159
+ ] })
5160
+ ] }),
5161
+ showMeter && row.meter !== null && /* @__PURE__ */ jsx7(Meter, { meter: row.meter }),
5162
+ row.canAddMore && /* @__PURE__ */ jsx7(
5163
+ AddMore,
5164
+ {
5165
+ label: t("meteredFeaturesAddMore"),
5166
+ onAddMore: onAddMore === void 0 ? void 0 : () => onAddMore(row.source),
5167
+ target: addMoreTarget,
5168
+ url: addMoreUrl
5169
+ }
5170
+ )
5171
+ ] })
5172
+ ] }),
5173
+ showUsageByUser && row.hasUsageByUser && /* @__PURE__ */ jsx7(UsageByUser, { locale, row, t }),
5174
+ row.priceDetails !== null && /* @__PURE__ */ jsx7(
5175
+ PriceDetails,
5176
+ {
5177
+ details: row.priceDetails,
5178
+ locale,
5179
+ row,
5180
+ t
5181
+ }
5182
+ )
5183
+ ]
5184
+ },
5185
+ row.featureId
5186
+ )) })
5187
+ ]
5188
+ }
5189
+ );
5190
+ }
5191
+ function headlineText(headline2, t) {
5192
+ if (headline2.kind === "used") {
5193
+ return t("meteredFeaturesUsed", {
5194
+ amount: headline2.amount,
5195
+ units: headline2.units
5196
+ });
5197
+ }
5198
+ return headline2.amount === null ? headline2.units : t("usageUnits", { amount: headline2.amount, units: headline2.units });
5199
+ }
5200
+ function limitText(limit, t) {
5201
+ switch (limit.kind) {
5202
+ case "tierUpTo":
5203
+ return t("usageTierUpTo", {
5204
+ amount: limit.amount,
5205
+ feature: limit.feature
5206
+ });
5207
+ case "tierUnlimited":
5208
+ return t("usageTierUnlimited", { feature: limit.feature });
5209
+ case "included":
5210
+ return t("meteredFeaturesIncluded", { amount: limit.amount });
5211
+ case "used":
5212
+ return t("meteredFeaturesInUse", { amount: limit.amount });
5213
+ case "cost":
5214
+ return limit.cost;
5215
+ case "perUse":
5216
+ return t("usagePerUse", { amount: limit.amount, units: limit.units });
5217
+ case "limitOf":
5218
+ return t("meteredFeaturesLimitOf", { amount: limit.amount });
5219
+ case "noLimit":
5220
+ return t("meteredFeaturesNoLimit");
5221
+ }
5222
+ }
5223
+ function LimitLine({
5224
+ row,
5225
+ showHardLimit,
5226
+ t
5227
+ }) {
5228
+ const parts = [];
5229
+ if (row.limit !== null) {
5230
+ parts.push(limitText(row.limit, t));
5231
+ }
5232
+ if (row.resetsAt !== null) {
5233
+ parts.push(t("usageResets", { date: row.resetsAt }));
5234
+ }
5235
+ if (parts.length === 0) {
5236
+ return null;
5237
+ }
5238
+ return /* @__PURE__ */ jsxs6("span", { className: "schematic-muted schematic-metered-features__limit", children: [
5239
+ parts.join(" \u2022 "),
5240
+ showHardLimit && row.hardLimit !== null && /* @__PURE__ */ jsx7(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
5241
+ amount: row.hardLimit.amount,
5242
+ units: row.hardLimit.units
5243
+ }) })
5244
+ ] });
5245
+ }
5246
+ var METER_TONE_CLASS = {
5247
+ ok: void 0,
5248
+ warning: "schematic-meter--warning",
5249
+ critical: "schematic-meter--over",
5250
+ tier: "schematic-meter--tier",
5251
+ overage: "schematic-meter--overage"
5252
+ };
5253
+ function Meter({ meter: meter2 }) {
5254
+ return /* @__PURE__ */ jsxs6("div", { className: "schematic-metered-features__meter", children: [
5255
+ /* @__PURE__ */ jsx7(
5256
+ "div",
5257
+ {
5258
+ "aria-valuemax": meter2.total,
5259
+ "aria-valuemin": 0,
5260
+ "aria-valuenow": meter2.value,
5261
+ className: cx("schematic-meter", METER_TONE_CLASS[meter2.tone]),
5262
+ "data-tone": meter2.tone,
5263
+ role: "meter",
5264
+ children: /* @__PURE__ */ jsx7(
5265
+ "div",
5266
+ {
5267
+ className: "schematic-meter__fill",
5268
+ style: { width: `${meter2.percent}%` }
5269
+ }
5270
+ )
5271
+ }
5272
+ ),
5273
+ meter2.total > 0 && /* @__PURE__ */ jsxs6("span", { className: "schematic-metered-features__meter-label", children: [
5274
+ meter2.valueText,
5275
+ "/",
5276
+ meter2.totalText
5277
+ ] })
5278
+ ] });
5279
+ }
5280
+ function AddMore({
5281
+ label,
5282
+ onAddMore,
5283
+ target,
5284
+ url
5285
+ }) {
5286
+ if (onAddMore !== void 0) {
5287
+ return /* @__PURE__ */ jsx7(
5288
+ "button",
5289
+ {
5290
+ className: "schematic-cta schematic-metered-features__add-more",
5291
+ type: "button",
5292
+ onClick: onAddMore,
5293
+ children: label
5294
+ }
5295
+ );
5296
+ }
5297
+ if (url !== void 0) {
5298
+ return /* @__PURE__ */ jsx7(
5299
+ "a",
5300
+ {
5301
+ className: "schematic-cta schematic-metered-features__add-more",
5302
+ href: url,
5303
+ target,
5304
+ children: label
5305
+ }
5306
+ );
5307
+ }
5308
+ return null;
5309
+ }
5310
+ function PriceDetails({
5311
+ details,
5312
+ locale,
5313
+ row,
5314
+ t
5315
+ }) {
5316
+ const period = details.period === null ? void 0 : shortPeriod(details.period, t);
5317
+ if (details.kind === "overage") {
5318
+ return /* @__PURE__ */ jsxs6("div", { className: "schematic-metered-features__price-details", children: [
5319
+ /* @__PURE__ */ jsxs6("span", { children: [
5320
+ t("meteredFeaturesAdditional"),
5321
+ ": ",
5322
+ details.unitPrice,
5323
+ /* @__PURE__ */ jsxs6("sub", { children: [
5324
+ "/",
5325
+ details.packageSize !== null && `${details.packageSize} `,
5326
+ details.units,
5327
+ period !== void 0 && `/${period}`
5328
+ ] })
5329
+ ] }),
5330
+ /* @__PURE__ */ jsxs6("span", { children: [
5331
+ details.overage.amount,
5332
+ " ",
5333
+ details.overage.units,
5334
+ " \xB7 ",
5335
+ details.overage.cost,
5336
+ period !== void 0 && /* @__PURE__ */ jsxs6("sub", { children: [
5337
+ "/",
5338
+ period
5339
+ ] })
5340
+ ] })
5341
+ ] });
5342
+ }
5343
+ return /* @__PURE__ */ jsxs6("div", { className: "schematic-metered-features__price-details", children: [
5344
+ /* @__PURE__ */ jsxs6("span", { children: [
5345
+ t("meteredFeaturesTier"),
5346
+ ": ",
5347
+ details.from,
5348
+ details.to === null ? "+" : details.to !== details.from ? `\u2013${details.to}` : "",
5349
+ /* @__PURE__ */ jsx7(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ jsx7(
5350
+ PriceTiers,
5351
+ {
5352
+ currency: details.tiers.currency,
5353
+ locale,
5354
+ mode: details.tiers.mode,
5355
+ period: details.period,
5356
+ ranges: details.tiers.ranges,
5357
+ t,
5358
+ unit: featureName(row.unit, 1, locale)
5359
+ }
5360
+ ) })
5361
+ ] }),
5362
+ details.cost !== null && /* @__PURE__ */ jsxs6("span", { children: [
5363
+ details.cost,
5364
+ period !== void 0 && /* @__PURE__ */ jsxs6("sub", { children: [
5365
+ "/",
5366
+ period
5367
+ ] })
5368
+ ] })
5369
+ ] });
5370
+ }
5371
+ function UsageByUser({
5372
+ locale,
5373
+ row,
5374
+ t
5375
+ }) {
5376
+ const { data, error, refetch } = useFeatureUserUsage(row.featureId);
5377
+ return /* @__PURE__ */ jsx7(
5378
+ UserBreakdown,
5379
+ {
5380
+ breakdown: data === void 0 ? void 0 : {
5381
+ count: data.count,
5382
+ total: data.total,
5383
+ unattributed: data.unattributed ?? null,
5384
+ users: data.users.map((user) => ({
5385
+ amount: user.usage,
5386
+ id: user.userId,
5387
+ label: user.name ?? user.userId
5388
+ }))
5389
+ },
5390
+ error,
5391
+ locale,
5392
+ onRetry: refetch,
5393
+ t,
5394
+ unit: row.unit
5395
+ }
5396
+ );
5397
+ }
5398
+ function MeteredFeaturesSkeleton({ showHeader }) {
5399
+ return /* @__PURE__ */ jsxs6("div", { className: "schematic-skeleton", children: [
5400
+ showHeader && /* @__PURE__ */ jsx7("div", { className: "schematic-skeleton__heading" }),
5401
+ [0, 1].map((index) => /* @__PURE__ */ jsxs6("div", { className: "schematic-skeleton__row", children: [
5402
+ /* @__PURE__ */ jsx7("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
5403
+ /* @__PURE__ */ jsx7("div", { className: "schematic-skeleton__cell", "data-column": "usage" })
5404
+ ] }, index))
5405
+ ] });
5406
+ }
5407
+ MeteredFeatures.resources = ["featureUsage"];
5408
+
3939
5409
  // src/elements/PaymentMethods.tsx
3940
5410
  import { usePaymentMethods } from "@schematichq/schematic-react";
3941
- import { Suspense, lazy, useCallback as useCallback2, useMemo as useMemo3, useState as useState4 } from "react";
3942
- import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
5411
+ import { Suspense, lazy, useCallback as useCallback2, useMemo as useMemo6, useState as useState6 } from "react";
5412
+ import { Fragment as Fragment3, jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
3943
5413
  var PaymentMethodForm2 = lazy(() => Promise.resolve().then(() => (init_PaymentMethodForm(), PaymentMethodForm_exports)));
3944
5414
  function PaymentMethods({
3945
5415
  allowEdit = true,
@@ -3964,10 +5434,10 @@ function PaymentMethods({
3964
5434
  } = usePaymentMethods();
3965
5435
  const locale = useResolvedLocale(localeProp);
3966
5436
  const t = useTranslator(strings, localeProp);
3967
- const [dialog, setDialog] = useState4(null);
3968
- const [choosing, setChoosing] = useState4(false);
3969
- const [lastWrite, setLastWrite] = useState4(null);
3970
- const derived = useMemo3(
5437
+ const [dialog, setDialog] = useState6(null);
5438
+ const [choosing, setChoosing] = useState6(false);
5439
+ const [lastWrite, setLastWrite] = useState6(null);
5440
+ const derived = useMemo6(
3971
5441
  () => methods === void 0 ? void 0 : derivePaymentMethods(methods, { locale }),
3972
5442
  [locale, methods]
3973
5443
  );
@@ -3998,7 +5468,7 @@ function PaymentMethods({
3998
5468
  const Heading = `h${headingLevel}`;
3999
5469
  const unavailable = derived === void 0 && httpStatus(error) === 404;
4000
5470
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("paymentMethodsUnavailable") : t("paymentMethodsError");
4001
- return /* @__PURE__ */ jsx7(
5471
+ return /* @__PURE__ */ jsx9(
4002
5472
  StatusFrame,
4003
5473
  {
4004
5474
  className: cx("schematic-card", "schematic-payment-methods", className),
@@ -4009,18 +5479,19 @@ function PaymentMethods({
4009
5479
  loadingLabel: t("paymentMethodsLoading"),
4010
5480
  onRetry: refetch,
4011
5481
  retryText: t("retry"),
4012
- skeleton: /* @__PURE__ */ jsx7(PaymentMethodsSkeleton, { showHeader }),
4013
- children: derived !== void 0 && /* @__PURE__ */ jsxs6(Fragment3, { children: [
4014
- showHeader && /* @__PURE__ */ jsx7(
5482
+ skeleton: /* @__PURE__ */ jsx9(PaymentMethodsSkeleton, { showHeader }),
5483
+ children: derived !== void 0 && /* @__PURE__ */ jsxs8(Fragment3, { children: [
5484
+ showHeader && /* @__PURE__ */ jsx9(
4015
5485
  PaymentMethodsHeader,
4016
5486
  {
4017
5487
  derived,
4018
5488
  heading: Heading,
5489
+ locale,
4019
5490
  showExpiration,
4020
5491
  t
4021
5492
  }
4022
5493
  ),
4023
- /* @__PURE__ */ jsx7(MethodPill, { row: derived.current, t, children: allowEdit && /* @__PURE__ */ jsx7(
5494
+ /* @__PURE__ */ jsx9(MethodPill, { row: derived.current, t, children: allowEdit && /* @__PURE__ */ jsx9(
4024
5495
  "button",
4025
5496
  {
4026
5497
  className: "schematic-link-button schematic-payment-methods__edit",
@@ -4029,7 +5500,7 @@ function PaymentMethods({
4029
5500
  children: derived.current === null ? t("paymentMethodsAdd") : t("paymentMethodsEdit")
4030
5501
  }
4031
5502
  ) }),
4032
- dialog !== null && /* @__PURE__ */ jsx7(
5503
+ dialog !== null && /* @__PURE__ */ jsx9(
4033
5504
  PaymentMethodsDialog,
4034
5505
  {
4035
5506
  checkoutPrefill,
@@ -4081,7 +5552,7 @@ function PaymentMethodsDialog({
4081
5552
  const { current, others, rows } = derived;
4082
5553
  const hasMethods = rows.length > 0;
4083
5554
  const showForm = view === "add" || !hasMethods;
4084
- return /* @__PURE__ */ jsxs6(
5555
+ return /* @__PURE__ */ jsxs8(
4085
5556
  Dialog,
4086
5557
  {
4087
5558
  className: "schematic-payment-methods__dialog",
@@ -4090,11 +5561,11 @@ function PaymentMethodsDialog({
4090
5561
  title: t("paymentMethodsDialogTitle"),
4091
5562
  onClose,
4092
5563
  children: [
4093
- showForm ? /* @__PURE__ */ jsx7(
5564
+ showForm ? /* @__PURE__ */ jsx9(
4094
5565
  Suspense,
4095
5566
  {
4096
- fallback: /* @__PURE__ */ jsx7(FormSkeleton, { label: t("paymentMethodsFormLoading") }),
4097
- children: /* @__PURE__ */ jsx7(
5567
+ fallback: /* @__PURE__ */ jsx9(FormSkeleton, { label: t("paymentMethodsFormLoading") }),
5568
+ children: /* @__PURE__ */ jsx9(
4098
5569
  PaymentMethodForm2,
4099
5570
  {
4100
5571
  checkoutPrefill,
@@ -4106,17 +5577,18 @@ function PaymentMethodsDialog({
4106
5577
  }
4107
5578
  )
4108
5579
  }
4109
- ) : /* @__PURE__ */ jsxs6(Fragment3, { children: [
4110
- /* @__PURE__ */ jsx7(
5580
+ ) : /* @__PURE__ */ jsxs8(Fragment3, { children: [
5581
+ /* @__PURE__ */ jsx9(
4111
5582
  PaymentMethodsHeader,
4112
5583
  {
4113
5584
  derived,
4114
5585
  heading: "h3",
5586
+ locale,
4115
5587
  showExpiration: true,
4116
5588
  t
4117
5589
  }
4118
5590
  ),
4119
- /* @__PURE__ */ jsx7(MethodPill, { row: current, t, children: current?.canRemove === true && /* @__PURE__ */ jsx7(
5591
+ /* @__PURE__ */ jsx9(MethodPill, { row: current, t, children: current?.canRemove === true && /* @__PURE__ */ jsx9(
4120
5592
  "button",
4121
5593
  {
4122
5594
  className: "schematic-link-button schematic-payment-methods__remove-current",
@@ -4126,7 +5598,7 @@ function PaymentMethodsDialog({
4126
5598
  children: t("paymentMethodsRemove")
4127
5599
  }
4128
5600
  ) }),
4129
- /* @__PURE__ */ jsxs6(
5601
+ /* @__PURE__ */ jsxs8(
4130
5602
  "button",
4131
5603
  {
4132
5604
  "aria-expanded": choosing,
@@ -4134,8 +5606,8 @@ function PaymentMethodsDialog({
4134
5606
  type: "button",
4135
5607
  onClick: onChoose,
4136
5608
  children: [
4137
- /* @__PURE__ */ jsx7("span", { className: "schematic-payment-methods__choose-label", children: t("paymentMethodsChooseDifferent") }),
4138
- /* @__PURE__ */ jsx7(
5609
+ /* @__PURE__ */ jsx9("span", { className: "schematic-payment-methods__choose-label", children: t("paymentMethodsChooseDifferent") }),
5610
+ /* @__PURE__ */ jsx9(
4139
5611
  "i",
4140
5612
  {
4141
5613
  "aria-hidden": "true",
@@ -4150,13 +5622,13 @@ function PaymentMethodsDialog({
4150
5622
  ]
4151
5623
  }
4152
5624
  ),
4153
- choosing && /* @__PURE__ */ jsxs6(Fragment3, { children: [
4154
- others.length > 0 && /* @__PURE__ */ jsx7(
5625
+ choosing && /* @__PURE__ */ jsxs8(Fragment3, { children: [
5626
+ others.length > 0 && /* @__PURE__ */ jsx9(
4155
5627
  "ul",
4156
5628
  {
4157
5629
  "aria-label": t("paymentMethodsChooseDifferent"),
4158
5630
  className: "schematic-payment-methods__list",
4159
- children: others.map((row) => /* @__PURE__ */ jsxs6(
5631
+ children: others.map((row) => /* @__PURE__ */ jsxs8(
4160
5632
  "li",
4161
5633
  {
4162
5634
  className: "schematic-payment-methods__row",
@@ -4164,11 +5636,11 @@ function PaymentMethodsDialog({
4164
5636
  "data-kind": row.kind,
4165
5637
  "data-testid": "schematic-payment-method",
4166
5638
  children: [
4167
- /* @__PURE__ */ jsx7(Method, { row, t }),
4168
- row.expiresShort !== null && /* @__PURE__ */ jsx7("span", { className: "schematic-payment-methods__expires", children: t("paymentMethodsExpires", {
5639
+ /* @__PURE__ */ jsx9(Method, { row, t }),
5640
+ row.expiresShort !== null && /* @__PURE__ */ jsx9("span", { className: "schematic-payment-methods__expires", children: t("paymentMethodsExpires", {
4169
5641
  date: row.expiresShort
4170
5642
  }) }),
4171
- /* @__PURE__ */ jsx7(
5643
+ /* @__PURE__ */ jsx9(
4172
5644
  "button",
4173
5645
  {
4174
5646
  className: "schematic-link-button schematic-payment-methods__set-default",
@@ -4178,7 +5650,7 @@ function PaymentMethodsDialog({
4178
5650
  children: t("paymentMethodsSetDefault")
4179
5651
  }
4180
5652
  ),
4181
- row.canRemove && /* @__PURE__ */ jsx7(
5653
+ row.canRemove && /* @__PURE__ */ jsx9(
4182
5654
  "button",
4183
5655
  {
4184
5656
  "aria-label": t("paymentMethodsRemove"),
@@ -4186,7 +5658,7 @@ function PaymentMethodsDialog({
4186
5658
  disabled: isMutating,
4187
5659
  type: "button",
4188
5660
  onClick: () => onRemove(row),
4189
- children: /* @__PURE__ */ jsx7(
5661
+ children: /* @__PURE__ */ jsx9(
4190
5662
  "i",
4191
5663
  {
4192
5664
  "aria-hidden": "true",
@@ -4201,7 +5673,7 @@ function PaymentMethodsDialog({
4201
5673
  ))
4202
5674
  }
4203
5675
  ),
4204
- /* @__PURE__ */ jsx7(
5676
+ /* @__PURE__ */ jsx9(
4205
5677
  "button",
4206
5678
  {
4207
5679
  className: "schematic-cta schematic-payment-methods__add-new",
@@ -4213,14 +5685,14 @@ function PaymentMethodsDialog({
4213
5685
  )
4214
5686
  ] })
4215
5687
  ] }),
4216
- mutationError !== void 0 && /* @__PURE__ */ jsxs6(
5688
+ mutationError !== void 0 && /* @__PURE__ */ jsxs8(
4217
5689
  "p",
4218
5690
  {
4219
5691
  className: "schematic-status-note schematic-error schematic-payment-methods__error",
4220
5692
  role: "alert",
4221
5693
  children: [
4222
- /* @__PURE__ */ jsx7("span", { className: "schematic-payment-methods__error-message", children: mutationError }),
4223
- onRetry !== void 0 && /* @__PURE__ */ jsx7(
5694
+ /* @__PURE__ */ jsx9("span", { className: "schematic-payment-methods__error-message", children: mutationError }),
5695
+ onRetry !== void 0 && /* @__PURE__ */ jsx9(
4224
5696
  "button",
4225
5697
  {
4226
5698
  className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-payment-methods__error-retry",
@@ -4240,17 +5712,18 @@ function PaymentMethodsDialog({
4240
5712
  function PaymentMethodsHeader({
4241
5713
  derived,
4242
5714
  heading: Heading,
5715
+ locale,
4243
5716
  showExpiration,
4244
5717
  t
4245
5718
  }) {
4246
- return /* @__PURE__ */ jsxs6("div", { className: "schematic-header", children: [
4247
- /* @__PURE__ */ jsx7(Heading, { className: "schematic-header__title", children: t("paymentMethodsHeader") }),
4248
- showExpiration && derived.expiryWarning !== "none" && /* @__PURE__ */ jsx7(
5719
+ return /* @__PURE__ */ jsxs8("div", { className: "schematic-header", children: [
5720
+ /* @__PURE__ */ jsx9(Heading, { className: "schematic-header__title", children: t("paymentMethodsHeader") }),
5721
+ showExpiration && derived.expiryWarning !== "none" && /* @__PURE__ */ jsx9(
4249
5722
  "span",
4250
5723
  {
4251
5724
  className: "schematic-small schematic-payment-methods__expiry-warning",
4252
5725
  "data-expiry": derived.expiryWarning,
4253
- children: expiryWarningText(derived, t)
5726
+ children: expiryWarningText(derived, locale, t)
4254
5727
  }
4255
5728
  )
4256
5729
  ] });
@@ -4260,37 +5733,37 @@ function MethodPill({
4260
5733
  row,
4261
5734
  t
4262
5735
  }) {
4263
- return /* @__PURE__ */ jsxs6(
5736
+ return /* @__PURE__ */ jsxs8(
4264
5737
  "div",
4265
5738
  {
4266
5739
  className: "schematic-payment-methods__current",
4267
5740
  "data-testid": "schematic-payment-method-current",
4268
5741
  children: [
4269
- row === null ? /* @__PURE__ */ jsx7("span", { className: "schematic-payment-methods__empty", children: t("paymentMethodsEmpty") }) : /* @__PURE__ */ jsx7(Method, { row, t }),
5742
+ row === null ? /* @__PURE__ */ jsx9("span", { className: "schematic-payment-methods__empty", children: t("paymentMethodsEmpty") }) : /* @__PURE__ */ jsx9(Method, { row, t }),
4270
5743
  children
4271
5744
  ]
4272
5745
  }
4273
5746
  );
4274
5747
  }
4275
5748
  function Method({ row, t }) {
4276
- return /* @__PURE__ */ jsxs6(
5749
+ return /* @__PURE__ */ jsxs8(
4277
5750
  "span",
4278
5751
  {
4279
5752
  className: "schematic-payment-methods__method",
4280
5753
  "data-brand": row.brand,
4281
5754
  "data-kind": row.kind,
4282
5755
  children: [
4283
- /* @__PURE__ */ jsx7(
5756
+ /* @__PURE__ */ jsx9(
4284
5757
  "i",
4285
5758
  {
4286
5759
  "aria-hidden": "true",
4287
5760
  className: `schematic-icon schematic-icon--${row.icon} schematic-payment-methods__icon`
4288
5761
  }
4289
5762
  ),
4290
- /* @__PURE__ */ jsx7("span", { className: "schematic-payment-methods__label", children: labelText(row.label, t) }),
4291
- row.last4 !== null && /* @__PURE__ */ jsxs6(Fragment3, { children: [
5763
+ /* @__PURE__ */ jsx9("span", { className: "schematic-payment-methods__label", children: labelText(row.label, t) }),
5764
+ row.last4 !== null && /* @__PURE__ */ jsxs8(Fragment3, { children: [
4292
5765
  " ",
4293
- /* @__PURE__ */ jsx7("span", { className: "schematic-payment-methods__last4", children: row.last4 })
5766
+ /* @__PURE__ */ jsx9("span", { className: "schematic-payment-methods__last4", children: row.last4 })
4294
5767
  ] })
4295
5768
  ]
4296
5769
  }
@@ -4299,29 +5772,31 @@ function Method({ row, t }) {
4299
5772
  function labelText(label, t) {
4300
5773
  return label.key === void 0 ? label.text : t(label.key);
4301
5774
  }
4302
- function expiryWarningText(derived, t) {
5775
+ function expiryWarningText(derived, locale, t) {
4303
5776
  const months = derived.monthsToExpiration ?? 0;
4304
- return derived.expiryWarning === "expired" ? t("paymentMethodsExpired") : t("paymentMethodsExpiresInMonths", { months });
5777
+ return derived.expiryWarning === "expired" ? t("paymentMethodsExpired") : t("paymentMethodsExpiresInMonths", {
5778
+ months: formatNumber(months, locale)
5779
+ });
4305
5780
  }
4306
5781
  function PaymentMethodsSkeleton({ showHeader }) {
4307
- return /* @__PURE__ */ jsxs6("div", { className: "schematic-skeleton", children: [
4308
- showHeader && /* @__PURE__ */ jsx7("div", { className: "schematic-skeleton__heading" }),
4309
- /* @__PURE__ */ jsxs6("div", { className: "schematic-skeleton__row", children: [
4310
- /* @__PURE__ */ jsx7("div", { className: "schematic-skeleton__cell", "data-column": "method" }),
4311
- /* @__PURE__ */ jsx7("div", { className: "schematic-skeleton__cell", "data-column": "action" })
5782
+ return /* @__PURE__ */ jsxs8("div", { className: "schematic-skeleton", children: [
5783
+ showHeader && /* @__PURE__ */ jsx9("div", { className: "schematic-skeleton__heading" }),
5784
+ /* @__PURE__ */ jsxs8("div", { className: "schematic-skeleton__row", children: [
5785
+ /* @__PURE__ */ jsx9("div", { className: "schematic-skeleton__cell", "data-column": "method" }),
5786
+ /* @__PURE__ */ jsx9("div", { className: "schematic-skeleton__cell", "data-column": "action" })
4312
5787
  ] })
4313
5788
  ] });
4314
5789
  }
4315
5790
  function FormSkeleton({ label }) {
4316
- return /* @__PURE__ */ jsxs6(
5791
+ return /* @__PURE__ */ jsxs8(
4317
5792
  "div",
4318
5793
  {
4319
5794
  "aria-busy": "true",
4320
5795
  className: "schematic-payment-methods__form",
4321
5796
  "data-state": "pending",
4322
5797
  children: [
4323
- /* @__PURE__ */ jsx7("span", { className: "schematic-hidden", children: label }),
4324
- /* @__PURE__ */ jsx7("div", { className: "schematic-skeleton", children: /* @__PURE__ */ jsx7("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx7("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
5798
+ /* @__PURE__ */ jsx9("span", { className: "schematic-hidden", children: label }),
5799
+ /* @__PURE__ */ jsx9("div", { className: "schematic-skeleton", children: /* @__PURE__ */ jsx9("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx9("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
4325
5800
  ]
4326
5801
  }
4327
5802
  );
@@ -4330,8 +5805,8 @@ PaymentMethods.resources = ["paymentMethods"];
4330
5805
 
4331
5806
  // src/elements/UpcomingBill.tsx
4332
5807
  import { useUpcomingInvoice } from "@schematichq/schematic-react";
4333
- import { useMemo as useMemo4 } from "react";
4334
- import { Fragment as Fragment4, jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
5808
+ import { useMemo as useMemo7 } from "react";
5809
+ import { Fragment as Fragment4, jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
4335
5810
  function UpcomingBill({
4336
5811
  className,
4337
5812
  headingLevel = 2,
@@ -4345,7 +5820,7 @@ function UpcomingBill({
4345
5820
  const { data: invoice, error, isPending, refetch } = useUpcomingInvoice();
4346
5821
  const locale = useResolvedLocale(localeProp);
4347
5822
  const t = useTranslator(strings, localeProp);
4348
- const bill = useMemo4(
5823
+ const bill = useMemo7(
4349
5824
  () => invoice === void 0 || invoice === null ? null : deriveUpcomingInvoice(invoice, { locale }),
4350
5825
  [invoice, locale]
4351
5826
  );
@@ -4354,7 +5829,7 @@ function UpcomingBill({
4354
5829
  const discountRow = showDiscounts && bill !== null && bill.discounts.length > 0;
4355
5830
  const unavailable = invoice === void 0 && httpStatus(error) === 404;
4356
5831
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("upcomingBillUnavailable") : t("upcomingBillError");
4357
- return /* @__PURE__ */ jsx8(
5832
+ return /* @__PURE__ */ jsx10(
4358
5833
  StatusFrame,
4359
5834
  {
4360
5835
  className: cx("schematic-card", "schematic-upcoming-bill", className),
@@ -4365,11 +5840,11 @@ function UpcomingBill({
4365
5840
  loadingLabel: t("upcomingBillLoading"),
4366
5841
  onRetry: refetch,
4367
5842
  retryText: t("retry"),
4368
- skeleton: /* @__PURE__ */ jsx8(UpcomingBillSkeleton, { showHeader }),
4369
- children: bill === null ? invoice !== void 0 && /* @__PURE__ */ jsx8("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ jsxs7(Fragment4, { children: [
4370
- showHeader && bill.dueAt !== null && /* @__PURE__ */ jsx8("div", { className: "schematic-header", children: /* @__PURE__ */ jsx8(Heading, { className: "schematic-header__title", children: t("upcomingBillHeader", { date: bill.dueAt.text }) }) }),
4371
- showAmount && /* @__PURE__ */ jsxs7("div", { className: "schematic-upcoming-bill__amount", children: [
4372
- /* @__PURE__ */ jsx8(
5843
+ skeleton: /* @__PURE__ */ jsx10(UpcomingBillSkeleton, { showHeader }),
5844
+ children: bill === null ? invoice !== void 0 && /* @__PURE__ */ jsx10("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ jsxs9(Fragment4, { children: [
5845
+ showHeader && bill.dueAt !== null && /* @__PURE__ */ jsx10("div", { className: "schematic-header", children: /* @__PURE__ */ jsx10(Heading, { className: "schematic-header__title", children: t("upcomingBillHeader", { date: bill.dueAt.text }) }) }),
5846
+ showAmount && /* @__PURE__ */ jsxs9("div", { className: "schematic-upcoming-bill__amount", children: [
5847
+ /* @__PURE__ */ jsx10(
4373
5848
  "span",
4374
5849
  {
4375
5850
  className: "schematic-upcoming-bill__total",
@@ -4377,46 +5852,46 @@ function UpcomingBill({
4377
5852
  children: bill.amountDueText
4378
5853
  }
4379
5854
  ),
4380
- /* @__PURE__ */ jsx8("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
5855
+ /* @__PURE__ */ jsx10("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
4381
5856
  ] }),
4382
- (balanceRows || discountRow) && /* @__PURE__ */ jsxs7("div", { className: "schematic-upcoming-bill__rows", children: [
4383
- balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ jsxs7(
5857
+ (balanceRows || discountRow) && /* @__PURE__ */ jsxs9("div", { className: "schematic-upcoming-bill__rows", children: [
5858
+ balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ jsxs9(
4384
5859
  "div",
4385
5860
  {
4386
5861
  className: "schematic-row schematic-upcoming-bill__balance-applied",
4387
5862
  "data-testid": "schematic-balance-applied",
4388
5863
  children: [
4389
- /* @__PURE__ */ jsx8("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
4390
- /* @__PURE__ */ jsx8("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
5864
+ /* @__PURE__ */ jsx10("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
5865
+ /* @__PURE__ */ jsx10("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
4391
5866
  ]
4392
5867
  }
4393
5868
  ),
4394
- balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ jsxs7(
5869
+ balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ jsxs9(
4395
5870
  "div",
4396
5871
  {
4397
5872
  className: "schematic-row schematic-upcoming-bill__balance-remaining",
4398
5873
  "data-testid": "schematic-balance-remaining",
4399
5874
  children: [
4400
- /* @__PURE__ */ jsx8("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
4401
- /* @__PURE__ */ jsx8("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
5875
+ /* @__PURE__ */ jsx10("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
5876
+ /* @__PURE__ */ jsx10("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
4402
5877
  ]
4403
5878
  }
4404
5879
  ),
4405
- discountRow && /* @__PURE__ */ jsxs7(
5880
+ discountRow && /* @__PURE__ */ jsxs9(
4406
5881
  "div",
4407
5882
  {
4408
5883
  className: "schematic-row schematic-upcoming-bill__discount-row",
4409
5884
  "data-testid": "schematic-discounts",
4410
5885
  children: [
4411
- /* @__PURE__ */ jsx8("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
4412
- /* @__PURE__ */ jsx8("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ jsxs7(
5886
+ /* @__PURE__ */ jsx10("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
5887
+ /* @__PURE__ */ jsx10("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ jsxs9(
4413
5888
  "li",
4414
5889
  {
4415
5890
  className: "schematic-upcoming-bill__discount",
4416
5891
  "data-testid": "schematic-discount",
4417
5892
  children: [
4418
- discount.code !== null && /* @__PURE__ */ jsx8("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
4419
- /* @__PURE__ */ jsx8("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
5893
+ discount.code !== null && /* @__PURE__ */ jsx10("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
5894
+ /* @__PURE__ */ jsx10("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
4420
5895
  ]
4421
5896
  },
4422
5897
  `${discount.couponName}-${index}`
@@ -4430,10 +5905,10 @@ function UpcomingBill({
4430
5905
  );
4431
5906
  }
4432
5907
  function UpcomingBillSkeleton({ showHeader }) {
4433
- return /* @__PURE__ */ jsxs7("div", { className: "schematic-skeleton", children: [
4434
- showHeader && /* @__PURE__ */ jsx8("div", { className: "schematic-skeleton__heading" }),
4435
- /* @__PURE__ */ jsx8("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx8("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
4436
- /* @__PURE__ */ jsx8("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx8("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
5908
+ return /* @__PURE__ */ jsxs9("div", { className: "schematic-skeleton", children: [
5909
+ showHeader && /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__heading" }),
5910
+ /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
5911
+ /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
4437
5912
  ] });
4438
5913
  }
4439
5914
  function discountText(discount, t) {
@@ -4448,10 +5923,12 @@ function discountText(discount, t) {
4448
5923
  UpcomingBill.resources = ["upcomingInvoice"];
4449
5924
  export {
4450
5925
  BillingDataProvider,
5926
+ CreditUsage,
4451
5927
  DEFAULT_STRINGS,
4452
5928
  FEATURE_USER_USAGE_LIMIT,
4453
5929
  IncludedFeatures,
4454
5930
  Invoices,
5931
+ MeteredFeatures,
4455
5932
  PaymentMethods,
4456
5933
  SCHEMATIC_TOKENS,
4457
5934
  SchematicI18nProvider,
@@ -4460,8 +5937,10 @@ export {
4460
5937
  UpcomingBill,
4461
5938
  billingResources,
4462
5939
  currentTier,
5940
+ deriveCreditUsage,
4463
5941
  deriveIncludedFeatures,
4464
5942
  deriveInvoiceList,
5943
+ deriveMeteredFeatures,
4465
5944
  derivePaymentMethods,
4466
5945
  deriveUpcomingInvoice,
4467
5946
  featureName,
@@ -4485,8 +5964,10 @@ export {
4485
5964
  tierRanges,
4486
5965
  unitPrice,
4487
5966
  usageLimit,
4488
- useFeatureUsage2 as useFeatureUsage,
4489
- useFeatureUserUsage,
5967
+ useCreditBalances2 as useCreditBalances,
5968
+ useCreditUserUsage2 as useCreditUserUsage,
5969
+ useFeatureUsage3 as useFeatureUsage,
5970
+ useFeatureUserUsage2 as useFeatureUserUsage,
4490
5971
  useInvalidateBillingData,
4491
5972
  useInvoices2 as useInvoices,
4492
5973
  usePaymentMethods2 as usePaymentMethods,