@schematichq/schematic-components 2.32.0 → 2.34.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.
@@ -75,6 +75,9 @@ var init_tokens = __esm({
75
75
  "--schematic-font-heading": '"Manrope", system-ui, sans-serif',
76
76
  // Link buttons' face: Edit, Set default, Try again, and the rest.
77
77
  "--schematic-font-link": '"Inter", system-ui, sans-serif',
78
+ // A lighter tint than the surface, for panels set into a card: a credit's
79
+ // grants, a plan's auto top-up.
80
+ "--schematic-inset": ld("hsla(0, 0%, 0%, 0.04)", "hsla(0, 0%, 100%, 0.06)"),
78
81
  "--schematic-line-height": "1.375",
79
82
  "--schematic-line-height-heading": "1.2",
80
83
  "--schematic-meter-track": ld("#f2f4f7", "#26282d"),
@@ -159,10 +162,10 @@ function PaymentMethodForm({
159
162
  onSelectExisting,
160
163
  t
161
164
  }) {
162
- const { create } = (0, import_schematic_react5.useSetupIntent)();
163
- const [state, setState] = (0, import_react6.useState)({ status: "loading" });
164
- const hostRef = (0, import_react6.useRef)(null);
165
- (0, import_react6.useEffect)(() => {
165
+ const { create } = (0, import_schematic_react6.useSetupIntent)();
166
+ const [state, setState] = (0, import_react7.useState)({ status: "loading" });
167
+ const hostRef = (0, import_react7.useRef)(null);
168
+ (0, import_react7.useEffect)(() => {
166
169
  let cancelled = false;
167
170
  let setupFailed = false;
168
171
  Promise.all([
@@ -208,7 +211,7 @@ function PaymentMethodForm({
208
211
  };
209
212
  }, [create, locale]);
210
213
  if (state.status === "loading") {
211
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
214
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
212
215
  "div",
213
216
  {
214
217
  "aria-busy": "true",
@@ -216,15 +219,15 @@ function PaymentMethodForm({
216
219
  "data-state": "pending",
217
220
  ref: hostRef,
218
221
  children: [
219
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "schematic-hidden", children: t("paymentMethodsFormLoading") }),
220
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
222
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-hidden", children: t("paymentMethodsFormLoading") }),
223
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
221
224
  ]
222
225
  }
223
226
  );
224
227
  }
225
228
  if (state.status === "failed") {
226
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-payment-methods__form", "data-state": "error", children: [
227
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
229
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "schematic-payment-methods__form", "data-state": "error", children: [
230
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
228
231
  "p",
229
232
  {
230
233
  className: "schematic-error schematic-small schematic-payment-methods__form-error",
@@ -232,11 +235,11 @@ function PaymentMethodForm({
232
235
  children: t(state.errorKey)
233
236
  }
234
237
  ),
235
- onSelectExisting !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SelectExisting, { t, onSelectExisting })
238
+ onSelectExisting !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SelectExisting, { t, onSelectExisting })
236
239
  ] });
237
240
  }
238
241
  const { Elements } = state.ui;
239
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
242
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
240
243
  Elements,
241
244
  {
242
245
  stripe: state.stripe,
@@ -244,7 +247,7 @@ function PaymentMethodForm({
244
247
  appearance: state.appearance,
245
248
  clientSecret: state.clientSecret
246
249
  },
247
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
250
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
248
251
  Fields,
249
252
  {
250
253
  checkoutPrefill,
@@ -273,19 +276,19 @@ function Fields({
273
276
  const showAddress = collectAddress || collectPhone;
274
277
  const prefill = checkoutPrefill?.billingDetails;
275
278
  const prefillName = orUndefined(prefill?.name);
276
- const emailId = (0, import_react6.useId)();
279
+ const emailId = (0, import_react7.useId)();
277
280
  const stripe = useStripe();
278
281
  const elements = useElements();
279
- const [saving, setSaving] = (0, import_react6.useState)(false);
280
- const [message, setMessage] = (0, import_react6.useState)(null);
281
- const [complete, setComplete] = (0, import_react6.useState)(false);
282
- const [ready, setReady] = (0, import_react6.useState)(false);
283
- const [loadFailed, setLoadFailed] = (0, import_react6.useState)(false);
284
- const [addressComplete, setAddressComplete] = (0, import_react6.useState)(!collectAddress);
285
- const [typedEmail, setTypedEmail] = (0, import_react6.useState)(null);
282
+ const [saving, setSaving] = (0, import_react7.useState)(false);
283
+ const [message, setMessage] = (0, import_react7.useState)(null);
284
+ const [complete, setComplete] = (0, import_react7.useState)(false);
285
+ const [ready, setReady] = (0, import_react7.useState)(false);
286
+ const [loadFailed, setLoadFailed] = (0, import_react7.useState)(false);
287
+ const [addressComplete, setAddressComplete] = (0, import_react7.useState)(!collectAddress);
288
+ const [typedEmail, setTypedEmail] = (0, import_react7.useState)(null);
286
289
  const email = typedEmail ?? orUndefined(prefill?.email) ?? "";
287
290
  const emailValid = !collectEmail || VALID_EMAIL.test(email);
288
- (0, import_react6.useEffect)(() => {
291
+ (0, import_react7.useEffect)(() => {
289
292
  if (ready) {
290
293
  return;
291
294
  }
@@ -337,14 +340,14 @@ function Fields({
337
340
  setSaving(false);
338
341
  }
339
342
  };
340
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
343
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
341
344
  "form",
342
345
  {
343
346
  className: "schematic-payment-methods__form",
344
347
  "data-state": "ready",
345
348
  onSubmit: (event) => void submit(event),
346
349
  children: [
347
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-payment-methods__fields", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
350
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-payment-methods__fields", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
348
351
  PaymentElement,
349
352
  {
350
353
  onChange: (event) => setComplete(event.complete),
@@ -355,8 +358,8 @@ function Fields({
355
358
  }
356
359
  }
357
360
  ) }),
358
- collectEmail && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-payment-methods__field", children: [
359
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
361
+ collectEmail && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "schematic-payment-methods__field", children: [
362
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
360
363
  "label",
361
364
  {
362
365
  className: "schematic-payment-methods__field-label",
@@ -364,7 +367,7 @@ function Fields({
364
367
  children: t("paymentMethodsEmail")
365
368
  }
366
369
  ),
367
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
370
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
368
371
  "input",
369
372
  {
370
373
  autoComplete: "email",
@@ -378,7 +381,7 @@ function Fields({
378
381
  }
379
382
  )
380
383
  ] }),
381
- showAddress && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-payment-methods__address", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
384
+ showAddress && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-payment-methods__address", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
382
385
  AddressElement,
383
386
  {
384
387
  options: {
@@ -392,7 +395,7 @@ function Fields({
392
395
  },
393
396
  prefillName ?? ""
394
397
  ) }),
395
- loadFailed && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
398
+ loadFailed && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
396
399
  "p",
397
400
  {
398
401
  className: "schematic-error schematic-small schematic-payment-methods__form-error",
@@ -400,7 +403,7 @@ function Fields({
400
403
  children: t("paymentMethodsFormError")
401
404
  }
402
405
  ),
403
- message !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
406
+ message !== null && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
404
407
  "p",
405
408
  {
406
409
  className: "schematic-error schematic-small schematic-payment-methods__form-error",
@@ -408,7 +411,7 @@ function Fields({
408
411
  children: message
409
412
  }
410
413
  ),
411
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
414
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
412
415
  "button",
413
416
  {
414
417
  className: "schematic-cta schematic-payment-methods__save",
@@ -417,7 +420,7 @@ function Fields({
417
420
  children: saving ? t("paymentMethodsSaving") : t("paymentMethodsSave")
418
421
  }
419
422
  ),
420
- onSelectExisting !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
423
+ onSelectExisting !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
421
424
  SelectExisting,
422
425
  {
423
426
  disabled: saving,
@@ -434,7 +437,7 @@ function SelectExisting({
434
437
  onSelectExisting,
435
438
  t
436
439
  }) {
437
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
440
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
438
441
  "button",
439
442
  {
440
443
  className: "schematic-link-button schematic-payment-methods__select-existing",
@@ -445,14 +448,14 @@ function SelectExisting({
445
448
  }
446
449
  );
447
450
  }
448
- var import_schematic_react5, import_react6, import_jsx_runtime7, NO_CLIENT_SECRET, STRIPE_NOT_LOADED, PROBE_CSS, READY_TIMEOUT_MS, VALID_EMAIL, PaymentMethodForm_default;
451
+ var import_schematic_react6, import_react7, import_jsx_runtime8, NO_CLIENT_SECRET, STRIPE_NOT_LOADED, PROBE_CSS, READY_TIMEOUT_MS, VALID_EMAIL, PaymentMethodForm_default;
449
452
  var init_PaymentMethodForm = __esm({
450
453
  "src/elements/PaymentMethodForm.tsx"() {
451
454
  "use strict";
452
- import_schematic_react5 = require("@schematichq/schematic-react");
453
- import_react6 = require("react");
455
+ import_schematic_react6 = require("@schematichq/schematic-react");
456
+ import_react7 = require("react");
454
457
  init_tokens();
455
- import_jsx_runtime7 = require("react/jsx-runtime");
458
+ import_jsx_runtime8 = require("react/jsx-runtime");
456
459
  NO_CLIENT_SECRET = "The setup intent carries no client secret.";
457
460
  STRIPE_NOT_LOADED = "Stripe.js did not load.";
458
461
  PROBE_CSS = withTokenDefaults(
@@ -476,24 +479,30 @@ var init_PaymentMethodForm = __esm({
476
479
  // src/elements/index.ts
477
480
  var index_exports = {};
478
481
  __export(index_exports, {
479
- BillingDataProvider: () => import_schematic_react8.BillingDataProvider,
482
+ BillingDataProvider: () => import_schematic_react11.BillingDataProvider,
483
+ CreditUsage: () => CreditUsage,
480
484
  DEFAULT_STRINGS: () => DEFAULT_STRINGS,
481
- FEATURE_USER_USAGE_LIMIT: () => import_schematic_react8.FEATURE_USER_USAGE_LIMIT,
485
+ FEATURE_USER_USAGE_LIMIT: () => import_schematic_react11.FEATURE_USER_USAGE_LIMIT,
482
486
  IncludedFeatures: () => IncludedFeatures,
483
487
  Invoices: () => Invoices,
484
488
  MeteredFeatures: () => MeteredFeatures,
485
489
  PaymentMethods: () => PaymentMethods,
490
+ PlanManager: () => PlanManager,
486
491
  SCHEMATIC_TOKENS: () => SCHEMATIC_TOKENS,
487
- SchematicI18nProvider: () => import_schematic_react8.SchematicI18nProvider,
492
+ SchematicI18nProvider: () => import_schematic_react11.SchematicI18nProvider,
488
493
  SchematicStyles: () => SchematicStyles,
489
494
  Tooltip: () => Tooltip,
495
+ UnsubscribeButton: () => UnsubscribeButton,
490
496
  UpcomingBill: () => UpcomingBill,
491
497
  billingResources: () => billingResources,
492
498
  currentTier: () => currentTier,
499
+ deriveCreditUsage: () => deriveCreditUsage,
493
500
  deriveIncludedFeatures: () => deriveIncludedFeatures,
494
501
  deriveInvoiceList: () => deriveInvoiceList,
495
502
  deriveMeteredFeatures: () => deriveMeteredFeatures,
496
503
  derivePaymentMethods: () => derivePaymentMethods,
504
+ derivePlanManager: () => derivePlanManager,
505
+ deriveUnsubscribe: () => deriveUnsubscribe,
497
506
  deriveUpcomingInvoice: () => deriveUpcomingInvoice,
498
507
  featureName: () => featureName,
499
508
  formatConsumptionRate: () => formatConsumptionRate,
@@ -516,23 +525,27 @@ __export(index_exports, {
516
525
  tierRanges: () => tierRanges,
517
526
  unitPrice: () => unitPrice,
518
527
  usageLimit: () => usageLimit,
519
- useFeatureUsage: () => import_schematic_react8.useFeatureUsage,
520
- useFeatureUserUsage: () => import_schematic_react8.useFeatureUserUsage,
521
- useInvalidateBillingData: () => import_schematic_react8.useInvalidateBillingData,
522
- useInvoices: () => import_schematic_react8.useInvoices,
523
- usePaymentMethods: () => import_schematic_react8.usePaymentMethods,
528
+ useCompany: () => import_schematic_react11.useCompany,
529
+ useCreditBalances: () => import_schematic_react11.useCreditBalances,
530
+ useCreditUserUsage: () => import_schematic_react11.useCreditUserUsage,
531
+ useFeatureUsage: () => import_schematic_react11.useFeatureUsage,
532
+ useFeatureUserUsage: () => import_schematic_react11.useFeatureUserUsage,
533
+ useInvalidateBillingData: () => import_schematic_react11.useInvalidateBillingData,
534
+ useInvoices: () => import_schematic_react11.useInvoices,
535
+ usePaymentMethods: () => import_schematic_react11.usePaymentMethods,
524
536
  useResolvedLocale: () => useResolvedLocale,
525
- useSchematicI18n: () => import_schematic_react8.useSchematicI18n,
526
- useSchematicLocale: () => import_schematic_react8.useSchematicLocale,
527
- useSchematicStrings: () => import_schematic_react8.useSchematicStrings,
528
- useSchematicTranslate: () => import_schematic_react8.useSchematicTranslate,
529
- useSetupIntent: () => import_schematic_react8.useSetupIntent,
537
+ useSchematicI18n: () => import_schematic_react11.useSchematicI18n,
538
+ useSchematicLocale: () => import_schematic_react11.useSchematicLocale,
539
+ useSchematicStrings: () => import_schematic_react11.useSchematicStrings,
540
+ useSchematicTranslate: () => import_schematic_react11.useSchematicTranslate,
541
+ useSetupIntent: () => import_schematic_react11.useSetupIntent,
530
542
  useTranslator: () => useTranslator,
531
- useUpcomingInvoice: () => import_schematic_react8.useUpcomingInvoice,
543
+ useUnsubscribe: () => import_schematic_react11.useUnsubscribe,
544
+ useUpcomingInvoice: () => import_schematic_react11.useUpcomingInvoice,
532
545
  viewerLocale: () => viewerLocale
533
546
  });
534
547
  module.exports = __toCommonJS(index_exports);
535
- var import_schematic_react8 = require("@schematichq/schematic-react");
548
+ var import_schematic_react11 = require("@schematichq/schematic-react");
536
549
 
537
550
  // src/elements/model/errors.ts
538
551
  function httpStatus(error) {
@@ -987,6 +1000,9 @@ function formatCurrency(amountMinor, currency, locale, options = {}) {
987
1000
  function formatNumber(value, locale, options) {
988
1001
  return new Intl.NumberFormat(usableLocale(locale), options).format(value);
989
1002
  }
1003
+ function formatCredits(value, locale) {
1004
+ return formatNumber(value, locale, { maximumFractionDigits: 10 });
1005
+ }
990
1006
  function formatConsumptionRate(rate, locale) {
991
1007
  return formatNumber(rate, locale, {
992
1008
  maximumFractionDigits: MAXIMUM_FRACTION_DIGITS
@@ -1383,7 +1399,10 @@ function includedFeatureRow(row, options) {
1383
1399
  description: nonEmpty(row.featureDescription),
1384
1400
  icon: nonEmpty(row.featureIcon),
1385
1401
  perLicenseCredits: row.perLicenseCreditGrants.filter((grant) => grant.scaling === "per_license").map((grant) => ({
1386
- amount: grant.creditAmount,
1402
+ // Credits come in fractions as small as 1e-10.
1403
+ amount: formatNumber(grant.creditAmount, locale, {
1404
+ maximumFractionDigits: 10
1405
+ }),
1387
1406
  creditName: featureName(
1388
1407
  {
1389
1408
  name: grant.creditName,
@@ -1403,7 +1422,7 @@ function includedFeatureRow(row, options) {
1403
1422
  usage: usageSegments(row, locale, tiered, period),
1404
1423
  usageSummary: usageSummary(row, options),
1405
1424
  hardLimit: row.priceBehavior !== void 0 && row.priceBehavior !== null && row.priceBehavior !== "credit_burndown" && row.valueType === "numeric" && typeof row.allocation === "number" ? {
1406
- amount: row.allocation,
1425
+ amount: formatNumber(row.allocation, locale),
1407
1426
  units: featureName(feature, row.allocation, locale)
1408
1427
  } : null,
1409
1428
  tiers: (row.priceBehavior === "tier" || tiered) && row.price !== void 0 ? {
@@ -1448,7 +1467,7 @@ function entitlementText(row, options) {
1448
1467
  return size > 1 ? {
1449
1468
  kind: "perPackage",
1450
1469
  cost,
1451
- size,
1470
+ size: formatNumber(size, locale),
1452
1471
  units: featureName(feature, size, locale)
1453
1472
  } : { kind: "perUnit", cost, unit: featureName(feature, 1, locale) };
1454
1473
  }
@@ -1509,14 +1528,14 @@ function usageSegments(row, locale, tiered, period) {
1509
1528
  segments.push({
1510
1529
  kind: "unitPricePerPeriod",
1511
1530
  cost: formatCurrency(unitPrice(row.price), row.price.currency, locale),
1512
- size,
1531
+ size: size > 1 ? formatNumber(size, locale) : null,
1513
1532
  units: featureName(feature, size, locale),
1514
1533
  period
1515
1534
  });
1516
1535
  } else if ((row.priceBehavior === "pay_as_you_go" || row.priceBehavior === "overage" || row.priceBehavior === "tier" || row.priceBehavior === "credit_burndown" || tiered) && typeof row.usage === "number") {
1517
1536
  segments.push({
1518
1537
  kind: "used",
1519
- amount: String(row.usage),
1538
+ amount: formatNumber(row.usage, locale),
1520
1539
  units: featureName(feature, row.usage, locale)
1521
1540
  });
1522
1541
  }
@@ -1591,7 +1610,7 @@ function meteredFeatureRow(row, options) {
1591
1610
  limit: limitLine(row, limit, unit, options),
1592
1611
  resetsAt: resetsAt === void 0 ? null : formatDate(resetsAt, locale, { month: "short", year: void 0 }),
1593
1612
  hardLimit: row.priceBehavior !== void 0 && row.priceBehavior !== null && row.priceBehavior !== "credit_burndown" && row.valueType === "numeric" && typeof row.allocation === "number" ? {
1594
- amount: row.allocation,
1613
+ amount: formatNumber(row.allocation, locale),
1595
1614
  units: featureName(unit, row.allocation, locale)
1596
1615
  } : null,
1597
1616
  meter: meter(row, options),
@@ -1713,7 +1732,7 @@ function priceDetails(row, unit, locale) {
1713
1732
  return {
1714
1733
  kind: "overage",
1715
1734
  unitPrice: money(tier.perUnitPrice),
1716
- packageSize: size,
1735
+ packageSize: size > 1 ? formatNumber(size, locale) : null,
1717
1736
  units: featureName(unit, size, locale),
1718
1737
  period,
1719
1738
  overage: {
@@ -1729,8 +1748,8 @@ function priceDetails(row, unit, locale) {
1729
1748
  }
1730
1749
  return {
1731
1750
  kind: "tier",
1732
- from: tier.from === 0 ? 1 : tier.from,
1733
- to: tier.to,
1751
+ from: formatNumber(tier.from === 0 ? 1 : tier.from, locale),
1752
+ to: tier.to === null ? null : formatNumber(tier.to, locale),
1734
1753
  cost: typeof row.currentCost === "number" ? money(row.currentCost) : null,
1735
1754
  period,
1736
1755
  tiers: {
@@ -1743,6 +1762,508 @@ function priceDetails(row, unit, locale) {
1743
1762
  return null;
1744
1763
  }
1745
1764
 
1765
+ // src/elements/model/creditUsage.ts
1766
+ function deriveCreditUsage(balances, options) {
1767
+ const ordered = options.visibleCredits === void 0 ? balances : options.visibleCredits.flatMap((id) => {
1768
+ const balance = balances.find((b) => b.creditId === id);
1769
+ return balance === void 0 ? [] : [balance];
1770
+ });
1771
+ return ordered.map((balance) => creditUsageRow(balance, options.locale));
1772
+ }
1773
+ function creditUsageRow(balance, locale) {
1774
+ const unit = {
1775
+ name: balance.creditName,
1776
+ singularName: balance.creditSingularName ?? void 0,
1777
+ pluralName: balance.creditPluralName ?? void 0
1778
+ };
1779
+ const composition = balance.composition;
1780
+ return {
1781
+ creditId: balance.creditId,
1782
+ name: balance.creditName,
1783
+ description: balance.creditDescription === "" ? null : balance.creditDescription,
1784
+ icon: balance.creditIcon === void 0 || balance.creditIcon === null || balance.creditIcon === "" ? null : balance.creditIcon,
1785
+ remaining: {
1786
+ amount: formatCredits(balance.remaining, locale),
1787
+ units: featureName(unit, balance.remaining, locale)
1788
+ },
1789
+ purchasable: balance.purchasable,
1790
+ ledger: balance.grants.map((grant) => ledgerRow(grant, unit, locale)),
1791
+ composition: composition === void 0 || composition === null ? null : {
1792
+ total: formatCredits(composition.total, locale),
1793
+ creditName: featureName(unit, composition.total, locale),
1794
+ period: composition.period,
1795
+ perLicense: {
1796
+ quantity: formatNumber(composition.licenseQuantity, locale),
1797
+ licenseName: featureName(
1798
+ {
1799
+ name: composition.licenseName,
1800
+ singularName: composition.licenseSingularName,
1801
+ pluralName: composition.licensePluralName
1802
+ },
1803
+ composition.licenseQuantity,
1804
+ locale
1805
+ ),
1806
+ perUnit: formatCredits(composition.perLicenseAmount, locale)
1807
+ },
1808
+ companyGrant: composition.fixedQuantity > 0 ? formatCredits(composition.fixedQuantity, locale) : null,
1809
+ renewsOn: renewsOn(composition.renewsAt, locale)
1810
+ },
1811
+ unit,
1812
+ source: balance
1813
+ };
1814
+ }
1815
+ function ledgerRow(grant, unit, locale) {
1816
+ const kind = grant.grantReason === "plan" ? "plan" : grant.grantReason === "purchased" ? "bundle" : grant.grantReason === "billing_credit_auto_topup" ? "autoTopup" : "promotional";
1817
+ const short = (date) => formatDate(date, locale, { month: "short" });
1818
+ const resetsAt = usableDate(grant.resetsAt);
1819
+ const expiresAt = usableDate(grant.expiresAt);
1820
+ return {
1821
+ id: grant.id,
1822
+ kind,
1823
+ amount: formatCredits(grant.quantity, locale),
1824
+ item: featureName(unit, kind === "bundle" ? 1 : grant.quantity, locale),
1825
+ createdAt: short(grant.createdAt),
1826
+ date: resetsAt !== void 0 ? { kind: "resets", text: short(resetsAt) } : expiresAt !== void 0 ? { kind: "expires", text: short(expiresAt) } : null,
1827
+ source: grant
1828
+ };
1829
+ }
1830
+ function renewsOn(date, locale) {
1831
+ const due = usableDate(date);
1832
+ if (due === void 0) {
1833
+ return null;
1834
+ }
1835
+ const day = due.getDate();
1836
+ if (!isEnglish2(locale)) {
1837
+ return formatNumber(day, locale);
1838
+ }
1839
+ const suffix = {
1840
+ few: "rd",
1841
+ many: "th",
1842
+ one: "st",
1843
+ other: "th",
1844
+ two: "nd",
1845
+ zero: "th"
1846
+ };
1847
+ return `${day}${suffix[new Intl.PluralRules("en", { type: "ordinal" }).select(day)]}`;
1848
+ }
1849
+ function isEnglish2(locale) {
1850
+ try {
1851
+ return new Intl.Locale(locale).language === "en";
1852
+ } catch {
1853
+ return false;
1854
+ }
1855
+ }
1856
+
1857
+ // src/elements/model/planManager.ts
1858
+ var DAY_MS = 24 * 60 * 60 * 1e3;
1859
+ var HOUR_MS = 60 * 60 * 1e3;
1860
+ var MINUTE_MS = 60 * 1e3;
1861
+ function derivePlanManager(data, options) {
1862
+ const { company, creditBalances, featureUsage } = data;
1863
+ const { locale } = options;
1864
+ const subscription = company.subscription ?? null;
1865
+ const currency = subscription?.currency ?? "usd";
1866
+ const planPeriod = subscription?.period ?? company.plan?.period ?? null;
1867
+ const usageBasedSources = featureUsage.filter(
1868
+ (row) => typeof row.priceBehavior === "string"
1869
+ );
1870
+ return {
1871
+ notice: notice(company, options),
1872
+ plan: company.plan === void 0 || company.plan === null ? null : {
1873
+ name: company.plan.name,
1874
+ description: orNull3(company.plan.description),
1875
+ price: planPrice(
1876
+ company.plan.price,
1877
+ planPeriod,
1878
+ currency,
1879
+ usageBasedSources.length > 0,
1880
+ options
1881
+ )
1882
+ },
1883
+ addOns: company.addOns.map((addOn) => {
1884
+ const period = addOn.period === "one-time" ? "one-time" : planPeriod ?? addOn.period ?? null;
1885
+ return {
1886
+ id: addOn.id,
1887
+ name: addOn.name,
1888
+ price: typeof addOn.price === "number" && period !== null ? {
1889
+ amount: formatCurrency(addOn.price, currency, locale),
1890
+ period
1891
+ } : null
1892
+ };
1893
+ }),
1894
+ usageBased: usageBasedSources.flatMap((row) => {
1895
+ const derived = usageBasedRow(row, planPeriod ?? "month", options);
1896
+ return derived === null ? [] : [derived];
1897
+ }),
1898
+ planCredits: planCredits(company, creditBalances, locale),
1899
+ autoTopup: autoTopupBox(company, creditBalances, locale),
1900
+ ...creditGroups(creditBalances, locale),
1901
+ canChangePlan: company.customPlanBilling?.activationStrategy !== "on_payment"
1902
+ };
1903
+ }
1904
+ function notice(company, options) {
1905
+ const { locale } = options;
1906
+ const subscription = company.subscription ?? null;
1907
+ const cancelAt = usableDate(subscription?.cancelAt);
1908
+ const willCancel = cancelAt !== void 0 && subscription?.cancelAtPeriodEnd === true;
1909
+ if (subscription?.status === "trialing" && !willCancel) {
1910
+ const trialEnd = usableDate(subscription.trialEnd);
1911
+ return {
1912
+ kind: "trial",
1913
+ endsIn: trialEnd === void 0 ? null : countdown(
1914
+ trialEnd.getTime() - (options.now ?? /* @__PURE__ */ new Date()).getTime()
1915
+ )
1916
+ };
1917
+ }
1918
+ if (willCancel) {
1919
+ return {
1920
+ kind: "canceled",
1921
+ planName: orNull3(company.plan?.name),
1922
+ date: formatDate(cancelAt, locale)
1923
+ };
1924
+ }
1925
+ const billing = company.customPlanBilling;
1926
+ if (billing !== void 0 && billing !== null) {
1927
+ return {
1928
+ kind: "customPlanBilling",
1929
+ awaitingActivation: billing.activationStrategy === "on_payment",
1930
+ planName: orNull3(billing.planName),
1931
+ date: formatDate(billing.dueAt, locale),
1932
+ invoiceUrl: orNull3(billing.invoiceUrl)
1933
+ };
1934
+ }
1935
+ const downgrade = company.scheduledDowngrade;
1936
+ if (downgrade !== void 0 && downgrade !== null && downgrade.toPlanName !== "") {
1937
+ const periodEnd = usableDate(subscription?.periodEnd);
1938
+ return {
1939
+ kind: "scheduledDowngrade",
1940
+ fromPlanName: downgrade.fromPlanName,
1941
+ toPlanName: downgrade.toPlanName,
1942
+ date: periodEnd === void 0 ? null : formatDate(periodEnd, locale)
1943
+ };
1944
+ }
1945
+ return null;
1946
+ }
1947
+ function countdown(ms) {
1948
+ if (ms >= DAY_MS) {
1949
+ return { amount: Math.floor(ms / DAY_MS), unit: "day" };
1950
+ }
1951
+ if (ms >= HOUR_MS) {
1952
+ return { amount: Math.floor(ms / HOUR_MS), unit: "hour" };
1953
+ }
1954
+ if (ms >= MINUTE_MS) {
1955
+ return { amount: Math.floor(ms / MINUTE_MS), unit: "minute" };
1956
+ }
1957
+ return ms > 0 ? "soon" : "ended";
1958
+ }
1959
+ function planPrice(price, period, currency, hasUsageBased, options) {
1960
+ if (typeof price !== "number") {
1961
+ return null;
1962
+ }
1963
+ const isFree = price === 0;
1964
+ if (isFree && hasUsageBased) {
1965
+ return { kind: "usageBased" };
1966
+ }
1967
+ if (isFree && options.showZeroPriceAsFree === true) {
1968
+ return { kind: "free" };
1969
+ }
1970
+ return {
1971
+ kind: "amount",
1972
+ amount: formatCurrency(price, currency, options.locale),
1973
+ period: isFree ? null : period
1974
+ };
1975
+ }
1976
+ function usageBasedRow(row, period, options) {
1977
+ const { locale } = options;
1978
+ const behavior = row.priceBehavior ?? null;
1979
+ const showCredits = options.showCredits ?? true;
1980
+ if (behavior === "credit_burndown" && !showCredits || row.featureName === "") {
1981
+ return null;
1982
+ }
1983
+ const unit = {
1984
+ name: row.featureName,
1985
+ singularName: row.featureSingularName ?? void 0,
1986
+ pluralName: row.featurePluralName ?? void 0
1987
+ };
1988
+ const isTrait = row.featureType === "trait";
1989
+ const price = row.price ?? void 0;
1990
+ const priceCurrency = price?.currency ?? "usd";
1991
+ const limit = behavior === "credit_burndown" ? null : usageLimit(row, options);
1992
+ let unitPriceText = null;
1993
+ if ((behavior === "pay_as_you_go" || behavior === "overage") && price !== void 0) {
1994
+ const packageSize = price.packageSize ?? 1;
1995
+ const ranges = behavior === "overage" ? tierRanges(price) : [];
1996
+ const lastTier = ranges[ranges.length - 1];
1997
+ const amount = lastTier === void 0 ? unitPrice(price) : lastTier.perUnitPrice ?? price.price;
1998
+ unitPriceText = {
1999
+ cost: formatCurrency(amount, priceCurrency, locale),
2000
+ packageSize: packageSize > 1 ? formatNumber(packageSize, locale) : null,
2001
+ units: featureName(unit, packageSize, locale),
2002
+ period: isTrait ? period : null
2003
+ };
2004
+ }
2005
+ let perUse = null;
2006
+ if (behavior === "credit_burndown" && typeof row.consumptionRate === "number" && row.consumptionRate !== 0 && typeof row.creditName === "string") {
2007
+ perUse = {
2008
+ amount: formatConsumptionRate(row.consumptionRate, locale),
2009
+ units: featureName(
2010
+ {
2011
+ name: row.creditName,
2012
+ singularName: row.creditSingularName,
2013
+ pluralName: row.creditPluralName
2014
+ },
2015
+ row.consumptionRate,
2016
+ locale
2017
+ )
2018
+ };
2019
+ }
2020
+ return {
2021
+ featureId: row.featureId,
2022
+ name: row.featureName,
2023
+ // The bare name, inflected, as the embed counts a limit.
2024
+ quantity: limit === null ? null : {
2025
+ amount: formatNumber(limit, locale),
2026
+ units: featureName({ name: row.featureName }, limit, locale)
2027
+ },
2028
+ additional: behavior === "overage",
2029
+ tierBased: behavior === "tier",
2030
+ unitPrice: unitPriceText,
2031
+ perUse,
2032
+ cost: behavior === "pay_in_advance" ? {
2033
+ amount: formatCurrency(row.currentCost ?? 0, priceCurrency, locale),
2034
+ period: isTrait ? period : null
2035
+ } : null,
2036
+ tiers: behavior === "tier" && isTieredPrice(price) ? {
2037
+ currency: priceCurrency,
2038
+ mode: price?.tiersMode ?? null,
2039
+ period,
2040
+ ranges: tierRanges(price),
2041
+ unit: row.featureSingularName ?? row.featureName
2042
+ } : null,
2043
+ hardLimit: behavior !== null && behavior !== "credit_burndown" && row.valueType === "numeric" && typeof row.allocation === "number" ? {
2044
+ amount: formatNumber(row.allocation, locale),
2045
+ units: featureName(unit, row.allocation, locale)
2046
+ } : null,
2047
+ source: row
2048
+ };
2049
+ }
2050
+ function planCredits(company, balances, locale) {
2051
+ const order = company.plan?.includedCreditIds ?? [];
2052
+ const rank = (creditId) => {
2053
+ const index = order.indexOf(creditId);
2054
+ return index === -1 ? order.length : index;
2055
+ };
2056
+ const subscriptionPeriod = company.subscription?.period ?? null;
2057
+ return balances.flatMap((balance) => {
2058
+ const grants = balance.grants.filter(
2059
+ (grant) => grant.grantReason === "plan"
2060
+ );
2061
+ if (grants.length === 0) {
2062
+ return [];
2063
+ }
2064
+ const unit = creditUnit(balance);
2065
+ const value = sum(grants, (grant) => grant.quantity);
2066
+ const used = sum(grants, (grant) => grant.quantityUsed);
2067
+ const composition = balance.composition ?? null;
2068
+ const autoTopup = balance.autoTopup ?? null;
2069
+ const row = {
2070
+ creditId: balance.creditId,
2071
+ text: composition === null ? {
2072
+ kind: "total",
2073
+ amount: formatCredits(value, locale),
2074
+ creditName: featureName(unit, value, locale),
2075
+ period: subscriptionPeriod
2076
+ } : {
2077
+ kind: "perLicense",
2078
+ amount: formatCredits(composition.perLicenseAmount, locale),
2079
+ creditName: featureName(
2080
+ unit,
2081
+ composition.perLicenseAmount,
2082
+ locale
2083
+ ),
2084
+ licenseName: featureName(licenseUnit(composition), 1, locale),
2085
+ plus: composition.fixedQuantity > 0 ? {
2086
+ amount: formatCredits(
2087
+ composition.fixedQuantity,
2088
+ locale
2089
+ ),
2090
+ creditName: featureName(
2091
+ unit,
2092
+ composition.fixedQuantity,
2093
+ locale
2094
+ ),
2095
+ period: composition.period
2096
+ } : null
2097
+ },
2098
+ used: spent(used, locale),
2099
+ autoTopup: autoTopup !== null && autoTopup.enabled && typeof autoTopup.thresholdCredits === "number" && typeof autoTopup.amount === "number" ? {
2100
+ amount: formatCredits(autoTopup.amount, locale),
2101
+ threshold: formatCredits(autoTopup.thresholdCredits, locale)
2102
+ } : null,
2103
+ composition: composition === null ? null : {
2104
+ quantity: formatNumber(composition.licenseQuantity, locale),
2105
+ licenseName: featureName(
2106
+ licenseUnit(composition),
2107
+ composition.licenseQuantity,
2108
+ locale
2109
+ ),
2110
+ perUnit: formatCredits(composition.perLicenseAmount, locale),
2111
+ fixed: composition.fixedQuantity > 0 ? formatCredits(composition.fixedQuantity, locale) : null,
2112
+ total: formatCredits(composition.total, locale),
2113
+ creditName: featureName(unit, composition.total, locale),
2114
+ period: composition.period
2115
+ }
2116
+ };
2117
+ return [row];
2118
+ }).map((row, index) => ({ row, index })).sort(
2119
+ (a, b) => rank(a.row.creditId) - rank(b.row.creditId) || a.index - b.index
2120
+ ).map(({ row }) => row);
2121
+ }
2122
+ function autoTopupBox(company, balances, locale) {
2123
+ const order = company.plan?.includedCreditIds ?? [];
2124
+ const selfService = order.flatMap((creditId) => {
2125
+ const balance = balances.find((b) => b.creditId === creditId);
2126
+ const autoTopup = balance?.autoTopup ?? null;
2127
+ return balance === void 0 || autoTopup === null || !autoTopup.selfService ? [] : [{ balance, autoTopup }];
2128
+ });
2129
+ if (selfService.length === 0) {
2130
+ return null;
2131
+ }
2132
+ return {
2133
+ lines: selfService.flatMap(({ balance, autoTopup }) => {
2134
+ const unit = creditUnit(balance);
2135
+ if (!autoTopup.enabled) {
2136
+ return [
2137
+ {
2138
+ kind: "disabled",
2139
+ creditId: balance.creditId,
2140
+ unit: featureName(unit, 1, locale)
2141
+ }
2142
+ ];
2143
+ }
2144
+ if (typeof autoTopup.thresholdCredits !== "number" || typeof autoTopup.amount !== "number") {
2145
+ return [];
2146
+ }
2147
+ return [
2148
+ {
2149
+ kind: "adds",
2150
+ creditId: balance.creditId,
2151
+ amount: formatCredits(autoTopup.amount, locale),
2152
+ unit: featureName(unit, autoTopup.amount, locale),
2153
+ threshold: formatCredits(autoTopup.thresholdCredits, locale)
2154
+ }
2155
+ ];
2156
+ })
2157
+ };
2158
+ }
2159
+ function creditGroups(balances, locale) {
2160
+ const groups = /* @__PURE__ */ new Map();
2161
+ for (const balance of balances) {
2162
+ for (const grant of balance.grants) {
2163
+ if (grant.grantReason === "plan") {
2164
+ continue;
2165
+ }
2166
+ const key = `${grant.grantReason}:${grant.bundleId ?? grant.id}`;
2167
+ const group = groups.get(key);
2168
+ if (group === void 0) {
2169
+ groups.set(key, { balance, grants: [grant] });
2170
+ } else {
2171
+ group.grants.push(grant);
2172
+ }
2173
+ }
2174
+ }
2175
+ const rows = Array.from(groups.entries()).map(([key, { balance, grants }]) => {
2176
+ const sorted = [...grants].sort(byRecency);
2177
+ const latest = sorted[0];
2178
+ return {
2179
+ reason: latest.grantReason,
2180
+ createdAt: latest.createdAt,
2181
+ row: {
2182
+ key,
2183
+ count: sorted.length,
2184
+ bundleName: orNull3(latest.bundleName),
2185
+ quantity: formatCredits(latest.quantity, locale),
2186
+ creditName: featureName(creditUnit(balance), latest.quantity, locale),
2187
+ used: spent(
2188
+ sum(sorted, (grant) => grant.quantityUsed),
2189
+ locale
2190
+ )
2191
+ }
2192
+ };
2193
+ }).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
2194
+ const pick = (reason) => rows.filter((entry) => entry.reason === reason).map((entry) => entry.row);
2195
+ return {
2196
+ bundles: pick("purchased"),
2197
+ promotional: pick("free"),
2198
+ topUps: pick("billing_credit_auto_topup")
2199
+ };
2200
+ }
2201
+ function byRecency(a, b) {
2202
+ return b.createdAt.getTime() - a.createdAt.getTime();
2203
+ }
2204
+ function creditUnit(balance) {
2205
+ return {
2206
+ name: balance.creditName,
2207
+ singularName: balance.creditSingularName ?? void 0,
2208
+ pluralName: balance.creditPluralName ?? void 0
2209
+ };
2210
+ }
2211
+ function licenseUnit(composition) {
2212
+ return {
2213
+ name: composition.licenseName,
2214
+ singularName: composition.licenseSingularName,
2215
+ pluralName: composition.licensePluralName
2216
+ };
2217
+ }
2218
+ function spent(used, locale) {
2219
+ return used > 0 ? formatCredits(used, locale) : null;
2220
+ }
2221
+ function sum(items, value) {
2222
+ return items.reduce((total, item) => total + value(item), 0);
2223
+ }
2224
+ function orNull3(value) {
2225
+ return value === void 0 || value === null || value === "" ? null : value;
2226
+ }
2227
+
2228
+ // src/elements/model/unsubscribe.ts
2229
+ function deriveUnsubscribe(company, featureUsage, options) {
2230
+ const { locale } = options;
2231
+ const subscription = company.subscription ?? null;
2232
+ const currency = subscription?.currency ?? "usd";
2233
+ const cancelAt = usableDate(subscription?.cancelAt);
2234
+ const endsOn = cancelAt ?? usableDate(subscription?.nextBillAt) ?? options.now ?? /* @__PURE__ */ new Date();
2235
+ const money = (amount) => formatCurrency(amount, currency, locale);
2236
+ const addOns = company.addOns.flatMap(
2237
+ (addOn) => typeof addOn.price === "number" ? [
2238
+ {
2239
+ id: addOn.id,
2240
+ name: addOn.name,
2241
+ price: money(addOn.price),
2242
+ oneTime: addOn.period === "one-time"
2243
+ }
2244
+ ] : []
2245
+ );
2246
+ const planPrice2 = company.plan?.price;
2247
+ const total = (typeof planPrice2 === "number" ? planPrice2 : 0) + company.addOns.reduce(
2248
+ (sum2, addOn) => addOn.period !== "one-time" && typeof addOn.price === "number" ? sum2 + addOn.price : sum2,
2249
+ 0
2250
+ ) + featureUsage.reduce(
2251
+ (sum2, row) => row.priceBehavior === "pay_in_advance" ? sum2 + (row.currentCost ?? 0) : sum2,
2252
+ 0
2253
+ );
2254
+ return {
2255
+ canUnsubscribe: subscription !== null && cancelAt === void 0,
2256
+ accessEndsOn: formatDate(endsOn, locale),
2257
+ period: subscription?.period ?? company.plan?.period ?? "month",
2258
+ plan: company.plan === void 0 || company.plan === null ? null : {
2259
+ name: company.plan.name,
2260
+ price: typeof planPrice2 === "number" ? money(planPrice2) : null
2261
+ },
2262
+ addOns,
2263
+ total: money(total)
2264
+ };
2265
+ }
2266
+
1746
2267
  // src/elements/strings.ts
1747
2268
  var DEFAULT_STRINGS_LOCALE = "en";
1748
2269
  var DEFAULT_STRINGS = {
@@ -1830,6 +2351,94 @@ var DEFAULT_STRINGS = {
1830
2351
  meteredFeaturesAddMore: "Add More",
1831
2352
  meteredFeaturesAdditional: "Additional",
1832
2353
  meteredFeaturesTier: "Tier",
2354
+ creditUsageLoading: "Loading credits",
2355
+ creditUsageHeader: "Credits",
2356
+ creditUsageError: "There was a problem retrieving your credits.",
2357
+ creditUsageUnavailable: "Credits are not available for this account.",
2358
+ creditUsageRemaining: "{{amount}} {{units}} remaining",
2359
+ creditUsageBuyMore: "Buy More",
2360
+ creditUsageSeeDetails: "See balance details",
2361
+ creditUsageHideDetails: "Hide balance details",
2362
+ creditUsageSeeAll: "See all ({{total}})",
2363
+ creditUsageHideAll: "Hide all",
2364
+ creditUsageGrantPlan: "{{amount}} {{item}} included in plan",
2365
+ creditUsageGrantBundle: "{{amount}} {{item}} bundle purchased {{createdAt}}",
2366
+ creditUsageGrantAutoTopup: "{{amount}} {{item}} auto-topup purchased {{createdAt}}",
2367
+ creditUsageGrantPromotional: "{{amount}} promotional {{item}} granted {{createdAt}}",
2368
+ creditUsageResets: "Resets {{date}}",
2369
+ creditUsageExpires: "Expires {{date}}",
2370
+ creditUsageComposition: "Your plan includes {{total}} {{creditName}}/{{period}} \u2014 {{perLicense}}.",
2371
+ creditUsageCompositionWithGrant: "Your plan includes {{total}} {{creditName}}/{{period}} \u2014 {{perLicense}} + {{companyGrant}}.",
2372
+ creditUsagePerLicense: "{{quantity}} {{licenseName}} \xD7 {{perUnit}}",
2373
+ creditUsageCompanyGrant: "{{amount}} company grant",
2374
+ creditUsageRenewsOn: "Renews on the {{day}}.",
2375
+ planManagerLoading: "Loading your plan",
2376
+ planManagerError: "There was a problem retrieving your plan.",
2377
+ planManagerUnavailable: "Your plan is not available for this account.",
2378
+ planManagerTrialEndsIn: "Trial ends in {{amount}} {{units}}",
2379
+ planManagerTrialEndsSoon: "Trial ends in less than a minute",
2380
+ planManagerTrialEnded: "Your trial has ended",
2381
+ // The trial countdown's units, looked up by the bare key with `{ count }`.
2382
+ planManagerDays: "days",
2383
+ planManagerDays_one: "day",
2384
+ planManagerDays_other: "days",
2385
+ planManagerHours: "hours",
2386
+ planManagerHours_one: "hour",
2387
+ planManagerHours_other: "hours",
2388
+ planManagerMinutes: "minutes",
2389
+ planManagerMinutes_one: "minute",
2390
+ planManagerMinutes_other: "minutes",
2391
+ planManagerCanceled: "Subscription canceled",
2392
+ planManagerAccessEnds: "Access to {{plan}} will end on {{date}}.",
2393
+ planManagerPlanFallback: "plan",
2394
+ planManagerCustomAwaiting: "Pay to activate {{plan}}",
2395
+ planManagerCustomAwaitingDescription: "Pay the invoice to activate your custom plan. Due by {{date}}.",
2396
+ planManagerCustomDue: "Pay by {{date}} to keep {{plan}}",
2397
+ planManagerCustomDueDescription: "Access to {{plan}} will end on {{date}} unless the invoice is paid.",
2398
+ planManagerYourPlan: "your plan",
2399
+ planManagerPayNow: "Pay now",
2400
+ planManagerDowngradeScheduled: "Downgrade to {{plan}} scheduled",
2401
+ planManagerUsageBased: "Usage-based",
2402
+ planManagerFree: "Free",
2403
+ planManagerAddOns: "Add-ons",
2404
+ planManagerAdditional: "Additional",
2405
+ planManagerTierBased: "Tier-based",
2406
+ planManagerCreditsInPlan: "Credits in plan",
2407
+ planManagerCreditsError: "There was a problem retrieving your credits.",
2408
+ planManagerCreditsLoading: "Loading your credits",
2409
+ planManagerTopUps: "Top-ups",
2410
+ planManagerCreditBundles: "Credit bundles",
2411
+ planManagerPromotionalCredits: "Promotional credits",
2412
+ planManagerChangePlan: "Change plan",
2413
+ planManagerCredits: "{{amount}} {{creditName}}",
2414
+ planManagerCreditsPerPeriod: "{{amount}} {{creditName}} per {{period}}",
2415
+ planManagerCreditsPerLicense: "{{amount}} {{creditName}} per {{licenseName}}",
2416
+ planManagerCreditsPlusPerPeriod: "+ {{amount}} {{creditName}} per {{period}}",
2417
+ planManagerLicensesTimesCredits: "{{quantity}} {{licenseName}} \xD7 {{perUnit}} = {{total}} {{creditName}}/{{period}}",
2418
+ planManagerLicensesTimesCreditsPlusCompany: "{{quantity}} {{licenseName}} \xD7 {{perUnit}} + {{fixed}} = {{total}} {{creditName}}/{{period}}",
2419
+ planManagerUsed: "{{amount}} used",
2420
+ planManagerAutoTopup: "Auto top-up",
2421
+ planManagerAutoTopupDisabled: "Auto top-up disabled for {{unit}}",
2422
+ planManagerAutoTopupAdds: "Adds {{amount}} {{unit}} when {{threshold}} remaining in balance",
2423
+ planManagerAutoTopupTip: "When credit balance reaches {{threshold}} remaining, an auto top-up of {{amount}} credits will be processed.",
2424
+ planManagerEdit: "Edit",
2425
+ planManagerSeeAll: "See all ({{total}})",
2426
+ planManagerHideAll: "Hide all",
2427
+ unsubscribeButton: "Unsubscribe",
2428
+ unsubscribeTitle: "Cancel subscription",
2429
+ unsubscribeAccessUntil: "You will retain access to your plan until the end of the billing period, on {{date}}",
2430
+ unsubscribeNotReady: "Not ready to cancel?",
2431
+ unsubscribeManagePlan: "Manage plan",
2432
+ unsubscribePlan: "Plan",
2433
+ unsubscribeAddOns: "Add-ons",
2434
+ unsubscribeMonthlyTotal: "Monthly total:",
2435
+ unsubscribeQuarterlyTotal: "Quarterly total:",
2436
+ unsubscribeYearlyTotal: "Yearly total:",
2437
+ unsubscribeConfirm: "Cancel subscription",
2438
+ unsubscribeFailed: "Unsubscribe failed",
2439
+ unsubscribeClose: "Close",
2440
+ unsubscribeError: "There was a problem retrieving your subscription.",
2441
+ unsubscribeUnavailable: "Your subscription is not available for this account.",
1833
2442
  usageByUserHeader: "Usage by user",
1834
2443
  usageByUserTotal: "{{amount}} used by your team this period",
1835
2444
  usageByUserError: "There was a problem retrieving usage by user.",
@@ -1865,7 +2474,12 @@ var DEFAULT_STRINGS = {
1865
2474
  usageTiersGraduated: "Tiers apply progressively as quantity increases.",
1866
2475
  periodMonthShort: "mo",
1867
2476
  periodQuarterShort: "qtr",
1868
- periodYearShort: "yr"
2477
+ periodYearShort: "yr",
2478
+ periodDay: "day",
2479
+ periodWeek: "week",
2480
+ periodMonth: "month",
2481
+ periodQuarter: "quarter",
2482
+ periodYear: "year"
1869
2483
  };
1870
2484
  var MISSING_STRING = "\0schematic:missing";
1871
2485
  function interpolate(template, vars) {
@@ -1896,97 +2510,251 @@ function defaultString(key, vars) {
1896
2510
  return lookup(DEFAULT_STRINGS, key, vars) ?? DEFAULT_STRINGS[key] ?? key;
1897
2511
  }
1898
2512
 
1899
- // src/elements/styles/dialog.ts
1900
- var dialogCss = `
1901
- /* Up to 768px wide, with a tighter radius than a card. */
1902
- .schematic-dialog {
1903
- background: var(--schematic-background);
1904
- border: 0;
1905
- border-radius: 0.5rem;
1906
- box-shadow: var(--schematic-shadow);
1907
- box-sizing: border-box;
1908
- color: var(--schematic-text);
1909
- margin: auto;
1910
- max-height: calc(100vh - 2 * var(--schematic-space));
1911
- max-width: none;
1912
- /* No padding of its own: a click on the backdrop lands on the dialog
1913
- itself, and one inside lands on the header or body. */
1914
- padding: 0;
1915
- /* Never wider than the screen, whatever it holds. */
1916
- width: min(48rem, calc(100vw - 2 * var(--schematic-space)));
1917
- }
1918
-
1919
- /* Centred by vw on a phone: a host page wider than the screen widens the
1920
- layout viewport, and auto margins would centre the dialog half off the
1921
- screen. Desktop keeps auto margins, as vw counts the scrollbar there. */
1922
- @media (max-width: 52rem) {
1923
- .schematic-dialog {
1924
- inset-inline: 0 auto;
1925
- margin-inline: calc(
1926
- (100vw - min(48rem, calc(100vw - 2 * var(--schematic-space)))) / 2
1927
- )
1928
- 0;
1929
- }
2513
+ // src/elements/styles/credit-usage.ts
2514
+ var creditUsageCss = `
2515
+ .schematic-credit-usage__credits {
2516
+ display: flex;
2517
+ flex-direction: column;
2518
+ gap: var(--schematic-space);
1930
2519
  }
1931
2520
 
1932
- .schematic-dialog::backdrop {
1933
- -webkit-backdrop-filter: blur(8px);
1934
- backdrop-filter: blur(8px);
1935
- background: var(--schematic-backdrop);
2521
+ /* Each credit draws its own card, so the root draws one only while pending
2522
+ or failed. */
2523
+ .schematic-credit-usage[data-state="pending"],
2524
+ .schematic-credit-usage[data-state="error"] {
2525
+ background: var(--schematic-background);
2526
+ border-radius: var(--schematic-radius);
2527
+ box-shadow: var(--schematic-shadow);
2528
+ padding: calc(var(--schematic-card-padding) * 0.75)
2529
+ var(--schematic-card-padding);
1936
2530
  }
1937
2531
 
1938
- /* Narrow on the right, where the close control's own hit area makes up the
1939
- rest. */
1940
- .schematic-dialog__header {
1941
- align-items: center;
1942
- border-bottom: 1px solid
1943
- color-mix(in srgb, var(--schematic-text) 15%, transparent);
2532
+ .schematic-credit-usage__credit {
1944
2533
  display: flex;
2534
+ flex-direction: column;
1945
2535
  gap: var(--schematic-space);
1946
- justify-content: space-between;
1947
- padding: 0.5rem 0.5rem 0.5rem 1.5rem;
1948
2536
  }
1949
2537
 
1950
- @media (min-width: 768px) {
1951
- .schematic-dialog__header {
1952
- padding: 1rem 0.75rem 1rem 3rem;
1953
- }
1954
- }
1955
-
1956
- /* Body text at 18px, not a heading face. */
1957
- .schematic-dialog__title {
1958
- font-family: var(--schematic-font-body);
1959
- font-size: 1.125rem;
1960
- font-weight: 400;
1961
- line-height: var(--schematic-line-height);
1962
- margin: 0;
2538
+ .schematic-credit-usage__main {
2539
+ display: flex;
2540
+ gap: calc(var(--schematic-space) * 1.5);
1963
2541
  }
1964
2542
 
1965
- .schematic-dialog__close {
2543
+ /* Held even without a glyph, as the embed does, so names line up. */
2544
+ .schematic-credit-usage__icon {
1966
2545
  align-items: center;
1967
- background: none;
1968
- border: none;
1969
- color: color-mix(in srgb, var(--schematic-text) 27.5%, transparent);
1970
- cursor: pointer;
2546
+ background: var(--schematic-surface);
2547
+ border-radius: 9999px;
1971
2548
  display: inline-flex;
1972
2549
  flex-shrink: 0;
1973
- font-size: 2.5rem;
2550
+ font-size: 1.5rem;
1974
2551
  height: 2.75rem;
1975
2552
  justify-content: center;
1976
- line-height: 1;
1977
- padding: 0;
1978
2553
  width: 2.75rem;
1979
2554
  }
1980
2555
 
1981
- .schematic-dialog__close:focus-visible {
1982
- outline: 2px solid var(--schematic-accent);
1983
- outline-offset: 2px;
2556
+ .schematic-credit-usage__icon .schematic-icon {
2557
+ color: var(--schematic-accent);
1984
2558
  }
1985
2559
 
1986
- .schematic-dialog__body {
2560
+ /* The embed's spacing: the balance well clear of the name, the composition
2561
+ tucked close under the balance. */
2562
+ .schematic-credit-usage__body {
1987
2563
  display: flex;
1988
2564
  flex-direction: column;
1989
- gap: var(--schematic-space);
2565
+ flex-grow: 1;
2566
+ gap: calc(var(--schematic-space) * 2);
2567
+ min-width: 0;
2568
+ }
2569
+
2570
+ .schematic-credit-usage__composition {
2571
+ margin-top: calc(var(--schematic-space) * -1.5);
2572
+ }
2573
+
2574
+ .schematic-credit-usage__title {
2575
+ display: flex;
2576
+ flex-direction: column;
2577
+ gap: 0.5rem;
2578
+ }
2579
+
2580
+ .schematic-credit-usage__name {
2581
+ font-family: var(--schematic-font-heading);
2582
+ font-size: 1.8125rem;
2583
+ font-weight: 800;
2584
+ line-height: var(--schematic-line-height-heading);
2585
+ margin: 0;
2586
+ }
2587
+
2588
+ .schematic-credit-usage__balance {
2589
+ align-items: center;
2590
+ display: flex;
2591
+ gap: var(--schematic-space);
2592
+ justify-content: space-between;
2593
+ }
2594
+
2595
+ .schematic-credit-usage__remaining {
2596
+ font-size: 1.0625rem;
2597
+ font-variant-numeric: tabular-nums;
2598
+ font-weight: 500;
2599
+ }
2600
+
2601
+ .schematic-credit-usage__buy-more {
2602
+ white-space: nowrap;
2603
+ }
2604
+
2605
+ .schematic-credit-usage__details,
2606
+ .schematic-credit-usage__see-all {
2607
+ align-items: center;
2608
+ display: inline-flex;
2609
+ gap: 0.25rem;
2610
+ }
2611
+
2612
+ .schematic-credit-usage__details .schematic-chevron,
2613
+ .schematic-credit-usage__see-all .schematic-chevron {
2614
+ margin-inline-start: -0.333rem;
2615
+ }
2616
+
2617
+ /* Opens above its toggle, as in the embed. */
2618
+ .schematic-credit-usage__grants {
2619
+ background: var(--schematic-inset);
2620
+ border-radius: calc(var(--schematic-radius) * 0.8);
2621
+ display: flex;
2622
+ flex-direction: column;
2623
+ gap: 0.5rem;
2624
+ margin-bottom: 0.5rem;
2625
+ padding: calc(var(--schematic-space) * 1.5);
2626
+ }
2627
+
2628
+ .schematic-credit-usage__grant-list {
2629
+ display: flex;
2630
+ flex-direction: column;
2631
+ gap: 0.75rem;
2632
+ list-style: none;
2633
+ margin: 0;
2634
+ padding: 0;
2635
+ }
2636
+
2637
+ /* Where the grant and its date do not fit on one line, the date wraps
2638
+ rather than overflowing the panel. */
2639
+ .schematic-credit-usage__grant {
2640
+ display: flex;
2641
+ flex-wrap: wrap;
2642
+ gap: 0.25rem var(--schematic-space);
2643
+ justify-content: space-between;
2644
+ }
2645
+
2646
+ .schematic-credit-usage__grant-text {
2647
+ flex: 1 1 12rem;
2648
+ min-width: 0;
2649
+ overflow-wrap: anywhere;
2650
+ }
2651
+
2652
+ .schematic-credit-usage__grant-date {
2653
+ margin-inline-start: auto;
2654
+ text-align: end;
2655
+ white-space: nowrap;
2656
+ }
2657
+
2658
+ .schematic-credit-usage .schematic-skeleton__cell[data-column="name"] {
2659
+ width: 10rem;
2660
+ }
2661
+
2662
+ .schematic-credit-usage .schematic-skeleton__cell[data-column="remaining"] {
2663
+ width: 6rem;
2664
+ }
2665
+ `;
2666
+
2667
+ // src/elements/styles/dialog.ts
2668
+ var dialogCss = `
2669
+ /* Up to 768px wide, with a tighter radius than a card. */
2670
+ .schematic-dialog {
2671
+ background: var(--schematic-background);
2672
+ border: 0;
2673
+ border-radius: 0.5rem;
2674
+ box-shadow: var(--schematic-shadow);
2675
+ box-sizing: border-box;
2676
+ color: var(--schematic-text);
2677
+ margin: auto;
2678
+ max-height: calc(100vh - 2 * var(--schematic-space));
2679
+ max-width: none;
2680
+ /* No padding of its own: a click on the backdrop lands on the dialog
2681
+ itself, and one inside lands on the header or body. */
2682
+ padding: 0;
2683
+ /* Never wider than the screen, whatever it holds. */
2684
+ width: min(48rem, calc(100vw - 2 * var(--schematic-space)));
2685
+ }
2686
+
2687
+ /* Centred by vw on a phone: a host page wider than the screen widens the
2688
+ layout viewport, and auto margins would centre the dialog half off the
2689
+ screen. Desktop keeps auto margins, as vw counts the scrollbar there. */
2690
+ @media (max-width: 52rem) {
2691
+ .schematic-dialog {
2692
+ inset-inline: 0 auto;
2693
+ margin-inline: calc(
2694
+ (100vw - min(48rem, calc(100vw - 2 * var(--schematic-space)))) / 2
2695
+ )
2696
+ 0;
2697
+ }
2698
+ }
2699
+
2700
+ .schematic-dialog::backdrop {
2701
+ -webkit-backdrop-filter: blur(8px);
2702
+ backdrop-filter: blur(8px);
2703
+ background: var(--schematic-backdrop);
2704
+ }
2705
+
2706
+ /* Narrow on the right, where the close control's own hit area makes up the
2707
+ rest. */
2708
+ .schematic-dialog__header {
2709
+ align-items: center;
2710
+ border-bottom: 1px solid
2711
+ color-mix(in srgb, var(--schematic-text) 15%, transparent);
2712
+ display: flex;
2713
+ gap: var(--schematic-space);
2714
+ justify-content: space-between;
2715
+ padding: 0.5rem 0.5rem 0.5rem 1.5rem;
2716
+ }
2717
+
2718
+ @media (min-width: 768px) {
2719
+ .schematic-dialog__header {
2720
+ padding: 1rem 0.75rem 1rem 3rem;
2721
+ }
2722
+ }
2723
+
2724
+ /* Body text at 18px, not a heading face. */
2725
+ .schematic-dialog__title {
2726
+ font-family: var(--schematic-font-body);
2727
+ font-size: 1.125rem;
2728
+ font-weight: 400;
2729
+ line-height: var(--schematic-line-height);
2730
+ margin: 0;
2731
+ }
2732
+
2733
+ .schematic-dialog__close {
2734
+ align-items: center;
2735
+ background: none;
2736
+ border: none;
2737
+ color: color-mix(in srgb, var(--schematic-text) 27.5%, transparent);
2738
+ cursor: pointer;
2739
+ display: inline-flex;
2740
+ flex-shrink: 0;
2741
+ font-size: 2.5rem;
2742
+ height: 2.75rem;
2743
+ justify-content: center;
2744
+ line-height: 1;
2745
+ padding: 0;
2746
+ width: 2.75rem;
2747
+ }
2748
+
2749
+ .schematic-dialog__close:focus-visible {
2750
+ outline: 2px solid var(--schematic-accent);
2751
+ outline-offset: 2px;
2752
+ }
2753
+
2754
+ .schematic-dialog__body {
2755
+ display: flex;
2756
+ flex-direction: column;
2757
+ gap: var(--schematic-space);
1990
2758
  min-width: 0;
1991
2759
  overflow-wrap: anywhere;
1992
2760
  padding: calc(var(--schematic-space) * 1.5);
@@ -3078,96 +3846,358 @@ var paymentMethodsCss = `
3078
3846
  }
3079
3847
  `;
3080
3848
 
3081
- // src/elements/styles/index.tsx
3082
- init_tokens();
3083
-
3084
- // src/elements/styles/tooltip.ts
3085
- var tooltipCss = `
3086
- .schematic-tooltip {
3087
- display: inline-block;
3088
- margin-inline-start: 0.25rem;
3089
- position: relative;
3090
- vertical-align: middle;
3091
- }
3092
-
3093
- .schematic-tooltip__trigger {
3094
- background: none;
3095
- border: 0;
3096
- color: var(--schematic-muted);
3097
- cursor: help;
3098
- /* A button keeps the browser's control font; the glyph is the embed's
3099
- 24px. */
3100
- font-size: 1.5rem;
3101
- line-height: 0;
3102
- padding: 0;
3849
+ // src/elements/styles/plan-manager.ts
3850
+ var planManagerCss = `
3851
+ .schematic-plan-manager {
3852
+ display: flex;
3853
+ flex-direction: column;
3854
+ gap: var(--schematic-space);
3103
3855
  }
3104
3856
 
3105
- .schematic-tooltip__trigger:focus-visible {
3106
- outline: 2px solid var(--schematic-accent);
3107
- outline-offset: 2px;
3857
+ /* While loading or failed there is no plan card, so the root draws one. */
3858
+ .schematic-plan-manager[data-state="pending"],
3859
+ .schematic-plan-manager[data-state="error"] {
3860
+ background: var(--schematic-background);
3861
+ border-radius: var(--schematic-radius);
3862
+ box-shadow: var(--schematic-shadow);
3863
+ padding: calc(var(--schematic-card-padding) * 0.75)
3864
+ var(--schematic-card-padding);
3108
3865
  }
3109
3866
 
3110
- .schematic-tooltip__content {
3867
+ /* As in the embed, a notice is a band across the top of the card: the
3868
+ root draws the card and the plan's own card goes flat. */
3869
+ .schematic-plan-manager:has(.schematic-plan-manager__notice) {
3111
3870
  background: var(--schematic-background);
3112
- border: 1px solid var(--schematic-border);
3113
- border-radius: calc(var(--schematic-radius) / 2);
3114
- bottom: calc(100% + 0.5rem);
3871
+ border-radius: var(--schematic-radius);
3115
3872
  box-shadow: var(--schematic-shadow);
3116
- color: var(--schematic-text);
3117
- font-size: 0.875rem;
3118
- inset-inline-end: 0;
3119
- padding: 0.5rem 0.75rem;
3120
- pointer-events: none;
3121
- position: absolute;
3122
- text-align: start;
3123
- visibility: hidden;
3124
- white-space: nowrap;
3125
- z-index: 1;
3873
+ gap: 0;
3874
+ overflow: hidden;
3126
3875
  }
3127
3876
 
3128
- .schematic-tooltip:hover .schematic-tooltip__content,
3129
- .schematic-tooltip:focus-within .schematic-tooltip__content {
3130
- visibility: visible;
3877
+ .schematic-plan-manager:has(.schematic-plan-manager__notice)
3878
+ .schematic-plan-manager__card {
3879
+ border-radius: 0;
3880
+ box-shadow: none;
3131
3881
  }
3132
3882
 
3133
- .schematic-tiers {
3883
+ .schematic-plan-manager__notice {
3884
+ align-items: center;
3885
+ background: var(--schematic-inset);
3134
3886
  display: flex;
3135
3887
  flex-direction: column;
3136
3888
  gap: 0.5rem;
3889
+ padding: calc(var(--schematic-space) * 1.5);
3890
+ text-align: center;
3137
3891
  }
3138
3892
 
3139
- .schematic-tiers__list {
3893
+ .schematic-plan-manager__notice-title {
3894
+ font-family: var(--schematic-font-heading);
3895
+ font-size: 1.25rem;
3896
+ font-weight: 600;
3897
+ line-height: var(--schematic-line-height-heading);
3140
3898
  margin: 0;
3141
3899
  }
3142
3900
 
3143
- .schematic-tiers__tier {
3144
- display: flex;
3145
- gap: var(--schematic-space);
3146
- justify-content: space-between;
3147
- padding: 0.25rem 0;
3901
+ .schematic-plan-manager__notice-body {
3902
+ font-size: 0.8125rem;
3148
3903
  }
3149
3904
 
3150
- .schematic-tiers__price {
3151
- margin: 0;
3905
+ .schematic-plan-manager__card {
3906
+ display: flex;
3907
+ flex-direction: column;
3908
+ gap: calc(var(--schematic-space) * 2);
3152
3909
  }
3153
3910
 
3154
- .schematic-tiers__mode {
3155
- border-top: 1px solid var(--schematic-border);
3156
- padding-top: 0.5rem;
3157
- white-space: normal;
3911
+ .schematic-plan-manager__plan {
3912
+ align-items: center;
3913
+ display: flex;
3914
+ gap: var(--schematic-space);
3915
+ justify-content: space-between;
3158
3916
  }
3159
- `;
3160
3917
 
3161
- // src/elements/styles/upcoming-bill.ts
3162
- var upcomingBillCss = `
3163
- .schematic-upcoming-bill {
3918
+ .schematic-plan-manager__title {
3164
3919
  display: flex;
3165
3920
  flex-direction: column;
3166
3921
  gap: var(--schematic-space);
3167
3922
  }
3168
3923
 
3169
- .schematic-upcoming-bill .schematic-header {
3170
- margin-bottom: 0;
3924
+ .schematic-plan-manager__name {
3925
+ font-family: var(--schematic-font-heading);
3926
+ font-size: 2.3125rem;
3927
+ font-weight: 800;
3928
+ line-height: 1;
3929
+ margin: 0;
3930
+ }
3931
+
3932
+ .schematic-plan-manager__price {
3933
+ font-family: var(--schematic-font-heading);
3934
+ font-size: 1.25rem;
3935
+ font-weight: 600;
3936
+ white-space: nowrap;
3937
+ }
3938
+
3939
+ .schematic-plan-manager__section {
3940
+ display: flex;
3941
+ flex-direction: column;
3942
+ gap: 0.5rem;
3943
+ }
3944
+
3945
+ .schematic-plan-manager__label {
3946
+ line-height: 1;
3947
+ }
3948
+
3949
+ .schematic-plan-manager__rows {
3950
+ display: flex;
3951
+ flex-direction: column;
3952
+ gap: var(--schematic-space);
3953
+ list-style: none;
3954
+ margin: 0;
3955
+ padding: 0;
3956
+ }
3957
+
3958
+ /* Centred as in the embed; a plan credit's name and figure share a
3959
+ baseline above the line that explains them. */
3960
+ .schematic-plan-manager__row,
3961
+ .schematic-plan-manager__row-main {
3962
+ align-items: center;
3963
+ display: flex;
3964
+ flex-wrap: wrap;
3965
+ gap: var(--schematic-space);
3966
+ justify-content: space-between;
3967
+ }
3968
+
3969
+ .schematic-plan-manager__row-main {
3970
+ align-items: baseline;
3971
+ gap: 0.5rem;
3972
+ }
3973
+
3974
+ .schematic-plan-manager__row--stacked {
3975
+ align-items: stretch;
3976
+ flex-direction: column;
3977
+ gap: 0.25rem;
3978
+ }
3979
+
3980
+ .schematic-plan-manager__item {
3981
+ font-family: var(--schematic-font-heading);
3982
+ font-size: 1.125rem;
3983
+ font-weight: 800;
3984
+ }
3985
+
3986
+ .schematic-plan-manager__detail,
3987
+ .schematic-plan-manager__used {
3988
+ align-items: center;
3989
+ display: inline-flex;
3990
+ gap: 0.25rem;
3991
+ }
3992
+
3993
+ .schematic-plan-manager__see-all {
3994
+ align-items: center;
3995
+ align-self: flex-start;
3996
+ display: inline-flex;
3997
+ gap: 0.25rem;
3998
+ margin-top: 0.5rem;
3999
+ }
4000
+
4001
+ .schematic-plan-manager__see-all .schematic-chevron {
4002
+ margin-inline-start: -0.333rem;
4003
+ }
4004
+
4005
+ .schematic-plan-manager__auto-topup {
4006
+ align-items: center;
4007
+ background: var(--schematic-inset);
4008
+ border-radius: calc(var(--schematic-radius) * 0.8);
4009
+ display: flex;
4010
+ gap: 0.5rem;
4011
+ justify-content: space-between;
4012
+ padding: calc(var(--schematic-space) * 1.5);
4013
+ }
4014
+
4015
+ .schematic-plan-manager__auto-topup-lines {
4016
+ display: flex;
4017
+ flex-direction: column;
4018
+ gap: 0.5rem;
4019
+ line-height: 1.25;
4020
+ }
4021
+
4022
+ .schematic-plan-manager__change-plan {
4023
+ width: 100%;
4024
+ }
4025
+
4026
+ .schematic-plan-manager .schematic-skeleton__cell[data-column="name"] {
4027
+ width: 10rem;
4028
+ }
4029
+
4030
+ .schematic-plan-manager .schematic-skeleton__cell[data-column="price"] {
4031
+ width: 6rem;
4032
+ }
4033
+ `;
4034
+
4035
+ // src/elements/styles/index.tsx
4036
+ init_tokens();
4037
+
4038
+ // src/elements/styles/tooltip.ts
4039
+ var tooltipCss = `
4040
+ .schematic-tooltip {
4041
+ display: inline-block;
4042
+ margin-inline-start: 0.25rem;
4043
+ position: relative;
4044
+ vertical-align: middle;
4045
+ }
4046
+
4047
+ .schematic-tooltip__trigger {
4048
+ background: none;
4049
+ border: 0;
4050
+ color: var(--schematic-muted);
4051
+ cursor: help;
4052
+ /* A button keeps the browser's control font; the glyph is the embed's
4053
+ 24px. */
4054
+ font-size: 1.5rem;
4055
+ line-height: 0;
4056
+ padding: 0;
4057
+ }
4058
+
4059
+ .schematic-tooltip__trigger:focus-visible {
4060
+ outline: 2px solid var(--schematic-accent);
4061
+ outline-offset: 2px;
4062
+ }
4063
+
4064
+ .schematic-tooltip__content {
4065
+ background: var(--schematic-background);
4066
+ border: 1px solid var(--schematic-border);
4067
+ border-radius: calc(var(--schematic-radius) / 2);
4068
+ bottom: calc(100% + 0.5rem);
4069
+ box-shadow: var(--schematic-shadow);
4070
+ color: var(--schematic-text);
4071
+ font-size: 0.875rem;
4072
+ inset-inline-end: 0;
4073
+ padding: 0.5rem 0.75rem;
4074
+ pointer-events: none;
4075
+ position: absolute;
4076
+ text-align: start;
4077
+ visibility: hidden;
4078
+ white-space: nowrap;
4079
+ z-index: 1;
4080
+ }
4081
+
4082
+ .schematic-tooltip:hover .schematic-tooltip__content,
4083
+ .schematic-tooltip:focus-within .schematic-tooltip__content {
4084
+ visibility: visible;
4085
+ }
4086
+
4087
+ .schematic-tiers {
4088
+ display: flex;
4089
+ flex-direction: column;
4090
+ gap: 0.5rem;
4091
+ }
4092
+
4093
+ .schematic-tiers__list {
4094
+ margin: 0;
4095
+ }
4096
+
4097
+ .schematic-tiers__tier {
4098
+ display: flex;
4099
+ gap: var(--schematic-space);
4100
+ justify-content: space-between;
4101
+ padding: 0.25rem 0;
4102
+ }
4103
+
4104
+ .schematic-tiers__price {
4105
+ margin: 0;
4106
+ }
4107
+
4108
+ .schematic-tiers__mode {
4109
+ border-top: 1px solid var(--schematic-border);
4110
+ padding-top: 0.5rem;
4111
+ white-space: normal;
4112
+ }
4113
+ `;
4114
+
4115
+ // src/elements/styles/unsubscribe.ts
4116
+ var unsubscribeCss = `
4117
+ .schematic-unsubscribe {
4118
+ display: flex;
4119
+ justify-content: center;
4120
+ }
4121
+
4122
+ .schematic-unsubscribe__open {
4123
+ width: 100%;
4124
+ }
4125
+
4126
+ .schematic-unsubscribe__columns {
4127
+ display: flex;
4128
+ flex-wrap: wrap;
4129
+ gap: calc(var(--schematic-space) * 2);
4130
+ }
4131
+
4132
+ .schematic-unsubscribe__summary {
4133
+ display: flex;
4134
+ flex: 1 1 18rem;
4135
+ flex-direction: column;
4136
+ gap: calc(var(--schematic-space) * 2);
4137
+ }
4138
+
4139
+ .schematic-unsubscribe__manage {
4140
+ display: flex;
4141
+ flex-direction: column;
4142
+ gap: 0.5rem;
4143
+ }
4144
+
4145
+ .schematic-unsubscribe__manage-plan {
4146
+ align-self: flex-start;
4147
+ color: var(--schematic-accent);
4148
+ }
4149
+
4150
+ .schematic-unsubscribe__sidebar {
4151
+ background: var(--schematic-inset);
4152
+ border-radius: calc(var(--schematic-radius) * 0.8);
4153
+ display: flex;
4154
+ flex: 1 1 16rem;
4155
+ flex-direction: column;
4156
+ gap: calc(var(--schematic-space) * 1.5);
4157
+ padding: calc(var(--schematic-space) * 1.5);
4158
+ }
4159
+
4160
+ .schematic-unsubscribe__group {
4161
+ display: flex;
4162
+ flex-direction: column;
4163
+ gap: 0.125rem;
4164
+ }
4165
+
4166
+ .schematic-unsubscribe__line {
4167
+ align-items: baseline;
4168
+ display: flex;
4169
+ gap: var(--schematic-space);
4170
+ justify-content: space-between;
4171
+ white-space: nowrap;
4172
+ }
4173
+
4174
+ .schematic-unsubscribe__name {
4175
+ font-family: var(--schematic-font-heading);
4176
+ font-size: 1.125rem;
4177
+ font-weight: 800;
4178
+ white-space: normal;
4179
+ }
4180
+
4181
+ .schematic-unsubscribe__total {
4182
+ border-top: 1px solid var(--schematic-card-divider);
4183
+ padding-top: calc(var(--schematic-space) * 1.5);
4184
+ }
4185
+
4186
+ .schematic-unsubscribe__confirm {
4187
+ width: 100%;
4188
+ }
4189
+ `;
4190
+
4191
+ // src/elements/styles/upcoming-bill.ts
4192
+ var upcomingBillCss = `
4193
+ .schematic-upcoming-bill {
4194
+ display: flex;
4195
+ flex-direction: column;
4196
+ gap: var(--schematic-space);
4197
+ }
4198
+
4199
+ .schematic-upcoming-bill .schematic-header {
4200
+ margin-bottom: 0;
3171
4201
  }
3172
4202
 
3173
4203
  .schematic-upcoming-bill__amount {
@@ -3782,11 +4812,14 @@ ${paymentMethodsCss}
3782
4812
  ${tooltipCss}
3783
4813
  ${includedFeaturesCss}
3784
4814
  ${meteredFeaturesCss}
4815
+ ${creditUsageCss}
4816
+ ${planManagerCss}
4817
+ ${unsubscribeCss}
3785
4818
  `;
3786
4819
  var schematicStylesCss = withTokenDefaults(rulesCss) + iconsCss;
3787
4820
  var SchematicStyles = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { "data-schematic-styles": "", children: schematicStylesCss });
3788
4821
 
3789
- // src/elements/IncludedFeatures.tsx
4822
+ // src/elements/CreditUsage.tsx
3790
4823
  var import_schematic_react2 = require("@schematichq/schematic-react");
3791
4824
  var import_react3 = require("react");
3792
4825
 
@@ -3823,6 +4856,9 @@ function useTranslator(overrides, locale) {
3823
4856
  const { onMissingString, strings, translate } = (0, import_schematic_react.useSchematicI18n)();
3824
4857
  return (0, import_react.useCallback)(
3825
4858
  (key, vars) => {
4859
+ if (isDevelopment) {
4860
+ warnRawNumbers(key, vars);
4861
+ }
3826
4862
  const override = lookup(overrides, key, vars, resolved2) ?? lookup(strings, key, vars, resolved2);
3827
4863
  if (override !== void 0) {
3828
4864
  return override;
@@ -3844,6 +4880,18 @@ function useTranslator(overrides, locale) {
3844
4880
  [onMissingString, overrides, resolved2, strings, translate]
3845
4881
  );
3846
4882
  }
4883
+ var rawNumberWarnings = /* @__PURE__ */ new Set();
4884
+ function warnRawNumbers(key, vars) {
4885
+ for (const [name, value] of Object.entries(vars ?? {})) {
4886
+ const id = `${key}.${name}`;
4887
+ if (name !== "count" && typeof value === "number" && !rawNumberWarnings.has(id)) {
4888
+ rawNumberWarnings.add(id);
4889
+ console.warn(
4890
+ `Schematic: "${key}" got a raw number for "${name}"; format it before it reaches the translator.`
4891
+ );
4892
+ }
4893
+ }
4894
+ }
3847
4895
  var isDevelopment = (() => {
3848
4896
  try {
3849
4897
  return process.env.NODE_ENV !== "production";
@@ -4027,8 +5075,8 @@ function PriceTiers({
4027
5075
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: "schematic-tiers", children: [
4028
5076
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dl", { className: "schematic-tiers__list", children: ranges.map((tier) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "schematic-tiers__tier", children: [
4029
5077
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("dt", { className: "schematic-tiers__range", children: [
4030
- tier.from,
4031
- tier.to === null ? "+" : tier.to !== tier.from ? `\u2013${tier.to}` : ""
5078
+ formatNumber(tier.from, locale),
5079
+ tier.to === null ? "+" : tier.to !== tier.from ? `\u2013${formatNumber(tier.to, locale)}` : ""
4032
5080
  ] }),
4033
5081
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("dd", { className: "schematic-tiers__price", children: tierPrice(tier.flatPrice ?? 0, tier.perUnitPrice ?? 0) })
4034
5082
  ] }, tier.from)) }),
@@ -4038,6 +5086,7 @@ function PriceTiers({
4038
5086
  function UserBreakdown({
4039
5087
  breakdown,
4040
5088
  error,
5089
+ formatAmount,
4041
5090
  locale,
4042
5091
  onRetry,
4043
5092
  t,
@@ -4048,7 +5097,7 @@ function UserBreakdown({
4048
5097
  () => [...breakdown?.users ?? []].sort((a, b) => b.amount - a.amount),
4049
5098
  [breakdown?.users]
4050
5099
  );
4051
- const amount = (value) => `${formatNumber(value, locale)} ${featureName(unit, value, locale)}`;
5100
+ const amount = (value) => `${formatAmount?.(value) ?? formatNumber(value, locale)} ${featureName(unit, value, locale)}`;
4052
5101
  if (breakdown === void 0 && error !== void 0) {
4053
5102
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "schematic-usage-by-user", role: "alert", children: [
4054
5103
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "schematic-usage-by-user__title", children: t("usageByUserHeader") }),
@@ -4136,42 +5185,320 @@ function UserBreakdown({
4136
5185
  ] });
4137
5186
  }
4138
5187
 
4139
- // src/elements/IncludedFeatures.tsx
5188
+ // src/elements/CreditUsage.tsx
4140
5189
  var import_jsx_runtime4 = require("react/jsx-runtime");
4141
- var VISIBLE_FEATURE_COUNT = 4;
4142
- function IncludedFeatures({
5190
+ var VISIBLE_GRANT_COUNT = 3;
5191
+ var GRANT_KEY = {
5192
+ autoTopup: "creditUsageGrantAutoTopup",
5193
+ bundle: "creditUsageGrantBundle",
5194
+ plan: "creditUsageGrantPlan",
5195
+ promotional: "creditUsageGrantPromotional"
5196
+ };
5197
+ function CreditUsage({
5198
+ buyMoreTarget,
5199
+ buyMoreUrl,
4143
5200
  className,
4144
5201
  headingLevel = 2,
4145
5202
  locale: localeProp,
4146
- showCredits = true,
5203
+ onBuyMore,
4147
5204
  showDescription = true,
4148
- showEntitlement = true,
4149
5205
  showExpiration = true,
4150
- showHardLimit = false,
4151
- showHeader = true,
5206
+ showHeader = false,
4152
5207
  showIcon = true,
4153
5208
  showUsage = true,
4154
- showWarningThresholdAsLimit = false,
5209
+ showUsageByUser = true,
4155
5210
  strings,
4156
- visibleFeatures
5211
+ visibleCredits
4157
5212
  }) {
4158
- const { data: features, error, isPending, refetch } = (0, import_schematic_react2.useFeatureUsage)();
5213
+ const { data: balances, error, isPending, refetch } = (0, import_schematic_react2.useCreditBalances)();
4159
5214
  const locale = useResolvedLocale(localeProp);
4160
5215
  const t = useTranslator(strings, localeProp);
4161
- const [expanded, setExpanded] = (0, import_react3.useState)(false);
4162
- const rows = (0, import_react3.useMemo)(
4163
- () => features === void 0 ? [] : deriveIncludedFeatures(features, {
4164
- locale,
4165
- showCredits,
4166
- showWarningThresholdAsLimit,
4167
- visibleFeatures
4168
- }),
4169
- [
4170
- features,
4171
- locale,
4172
- showCredits,
4173
- showWarningThresholdAsLimit,
4174
- visibleFeatures
5216
+ const credits = (0, import_react3.useMemo)(
5217
+ () => balances === void 0 ? [] : deriveCreditUsage(balances, { locale, visibleCredits }),
5218
+ [balances, locale, visibleCredits]
5219
+ );
5220
+ const unavailable = balances === void 0 && httpStatus(error) === 404;
5221
+ const errorMessage = error === void 0 ? void 0 : unavailable ? t("creditUsageUnavailable") : t("creditUsageError");
5222
+ if (balances !== void 0 && error === void 0 && credits.length === 0) {
5223
+ return null;
5224
+ }
5225
+ const Heading = `h${headingLevel}`;
5226
+ const CreditHeading = showHeader ? `h${Math.min(6, headingLevel + 1)}` : Heading;
5227
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5228
+ StatusFrame,
5229
+ {
5230
+ className: cx("schematic-credit-usage", className),
5231
+ error,
5232
+ errorMessage,
5233
+ hasData: balances !== void 0,
5234
+ isPending,
5235
+ loadingLabel: t("creditUsageLoading"),
5236
+ onRetry: refetch,
5237
+ retryText: t("retry"),
5238
+ skeleton: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CreditUsageSkeleton, { showHeader }),
5239
+ children: [
5240
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Heading, { className: "schematic-header__title", children: t("creditUsageHeader") }) }),
5241
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-credit-usage__credits", children: credits.map((credit) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5242
+ "section",
5243
+ {
5244
+ "aria-label": credit.name,
5245
+ className: "schematic-card schematic-credit-usage__credit",
5246
+ "data-testid": "schematic-credit",
5247
+ children: [
5248
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-credit-usage__main", children: [
5249
+ showIcon && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-credit-usage__icon", children: credit.icon !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5250
+ "i",
5251
+ {
5252
+ "aria-hidden": "true",
5253
+ className: `schematic-icon schematic-icon--${credit.icon}`
5254
+ }
5255
+ ) }),
5256
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-credit-usage__body", children: [
5257
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-credit-usage__title", children: [
5258
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CreditHeading, { className: "schematic-credit-usage__name", children: credit.name }),
5259
+ showDescription && credit.description !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "schematic-muted", children: credit.description })
5260
+ ] }),
5261
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-credit-usage__balance", children: [
5262
+ showUsage && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5263
+ "span",
5264
+ {
5265
+ className: "schematic-credit-usage__remaining",
5266
+ "data-testid": "schematic-credit-remaining",
5267
+ children: t("creditUsageRemaining", credit.remaining)
5268
+ }
5269
+ ),
5270
+ credit.purchasable && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5271
+ BuyMore,
5272
+ {
5273
+ credit,
5274
+ label: t("creditUsageBuyMore"),
5275
+ onBuyMore,
5276
+ target: buyMoreTarget,
5277
+ url: buyMoreUrl
5278
+ }
5279
+ )
5280
+ ] }),
5281
+ credit.composition !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "schematic-muted schematic-small schematic-credit-usage__composition", children: compositionText(credit, t) })
5282
+ ] })
5283
+ ] }),
5284
+ credit.ledger.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5285
+ Ledger,
5286
+ {
5287
+ credit,
5288
+ locale,
5289
+ showExpiration,
5290
+ t
5291
+ }
5292
+ ),
5293
+ showUsageByUser && credit.ledger.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CreditUserBreakdown, { credit, locale, t })
5294
+ ]
5295
+ },
5296
+ credit.creditId
5297
+ )) })
5298
+ ]
5299
+ }
5300
+ );
5301
+ }
5302
+ function compositionText(credit, t) {
5303
+ const composition = credit.composition;
5304
+ if (composition === null) {
5305
+ return "";
5306
+ }
5307
+ const vars = {
5308
+ creditName: composition.creditName,
5309
+ perLicense: t("creditUsagePerLicense", composition.perLicense),
5310
+ period: shortPeriod(composition.period, t) ?? composition.period,
5311
+ total: composition.total
5312
+ };
5313
+ const sentence = composition.companyGrant === null ? t("creditUsageComposition", vars) : t("creditUsageCompositionWithGrant", {
5314
+ ...vars,
5315
+ companyGrant: t("creditUsageCompanyGrant", {
5316
+ amount: composition.companyGrant
5317
+ })
5318
+ });
5319
+ return composition.renewsOn === null ? sentence : `${sentence} ${t("creditUsageRenewsOn", { day: composition.renewsOn })}`;
5320
+ }
5321
+ function Ledger({
5322
+ credit,
5323
+ locale,
5324
+ showExpiration,
5325
+ t
5326
+ }) {
5327
+ const [open, setOpen] = (0, import_react3.useState)(false);
5328
+ const [all, setAll] = (0, import_react3.useState)(false);
5329
+ const rows = all ? credit.ledger : credit.ledger.slice(0, VISIBLE_GRANT_COUNT);
5330
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-credit-usage__ledger", children: [
5331
+ open && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-credit-usage__grants", children: [
5332
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "schematic-credit-usage__grant-list", children: rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5333
+ "li",
5334
+ {
5335
+ className: "schematic-credit-usage__grant",
5336
+ "data-testid": "schematic-credit-grant",
5337
+ children: [
5338
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-credit-usage__grant-text", children: t(GRANT_KEY[row.kind], {
5339
+ amount: row.amount,
5340
+ createdAt: row.createdAt,
5341
+ item: row.item
5342
+ }) }),
5343
+ showExpiration && row.date !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-credit-usage__grant-date", children: row.date.kind === "resets" ? t("creditUsageResets", { date: row.date.text }) : t("creditUsageExpires", { date: row.date.text }) })
5344
+ ]
5345
+ },
5346
+ row.id
5347
+ )) }),
5348
+ credit.ledger.length > VISIBLE_GRANT_COUNT && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5349
+ "button",
5350
+ {
5351
+ "aria-expanded": all,
5352
+ className: "schematic-link-button schematic-credit-usage__see-all",
5353
+ type: "button",
5354
+ onClick: () => setAll((value) => !value),
5355
+ children: [
5356
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5357
+ "i",
5358
+ {
5359
+ "aria-hidden": "true",
5360
+ className: `schematic-icon schematic-icon--${all ? "chevron-up" : "chevron-down"} schematic-chevron`
5361
+ }
5362
+ ),
5363
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-link-button__label", children: all ? t("creditUsageHideAll") : t("creditUsageSeeAll", {
5364
+ total: formatNumber(credit.ledger.length, locale)
5365
+ }) })
5366
+ ]
5367
+ }
5368
+ )
5369
+ ] }),
5370
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5371
+ "button",
5372
+ {
5373
+ "aria-expanded": open,
5374
+ className: "schematic-link-button schematic-credit-usage__details",
5375
+ type: "button",
5376
+ onClick: () => {
5377
+ setOpen((value) => !value);
5378
+ setAll(false);
5379
+ },
5380
+ children: [
5381
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5382
+ "i",
5383
+ {
5384
+ "aria-hidden": "true",
5385
+ className: `schematic-icon schematic-icon--${open ? "chevron-up" : "chevron-down"} schematic-chevron`
5386
+ }
5387
+ ),
5388
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-link-button__label", children: open ? t("creditUsageHideDetails") : t("creditUsageSeeDetails") })
5389
+ ]
5390
+ }
5391
+ )
5392
+ ] });
5393
+ }
5394
+ function BuyMore({
5395
+ credit,
5396
+ label,
5397
+ onBuyMore,
5398
+ target,
5399
+ url
5400
+ }) {
5401
+ if (onBuyMore !== void 0) {
5402
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5403
+ "button",
5404
+ {
5405
+ className: "schematic-cta schematic-cta--small schematic-credit-usage__buy-more",
5406
+ type: "button",
5407
+ onClick: () => onBuyMore(credit.source),
5408
+ children: label
5409
+ }
5410
+ );
5411
+ }
5412
+ if (url !== void 0) {
5413
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5414
+ "a",
5415
+ {
5416
+ className: "schematic-cta schematic-cta--small schematic-credit-usage__buy-more",
5417
+ href: url,
5418
+ target,
5419
+ children: label
5420
+ }
5421
+ );
5422
+ }
5423
+ return null;
5424
+ }
5425
+ function CreditUserBreakdown({
5426
+ credit,
5427
+ locale,
5428
+ t
5429
+ }) {
5430
+ const { data, error, refetch } = (0, import_schematic_react2.useCreditUserUsage)(credit.creditId);
5431
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5432
+ UserBreakdown,
5433
+ {
5434
+ breakdown: data === void 0 ? void 0 : {
5435
+ count: data.count,
5436
+ total: data.total,
5437
+ unattributed: data.unattributed ?? null,
5438
+ users: data.users.map((user) => ({
5439
+ amount: user.used,
5440
+ id: user.userId,
5441
+ label: user.name ?? user.userId
5442
+ }))
5443
+ },
5444
+ error,
5445
+ formatAmount: (value) => formatCredits(value, locale),
5446
+ locale,
5447
+ onRetry: refetch,
5448
+ t,
5449
+ unit: credit.unit
5450
+ }
5451
+ );
5452
+ }
5453
+ function CreditUsageSkeleton({ showHeader }) {
5454
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-skeleton", children: [
5455
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__heading" }),
5456
+ [0, 1].map((index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-skeleton__row", children: [
5457
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
5458
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "remaining" })
5459
+ ] }, index))
5460
+ ] });
5461
+ }
5462
+ CreditUsage.resources = ["creditBalances"];
5463
+
5464
+ // src/elements/IncludedFeatures.tsx
5465
+ var import_schematic_react3 = require("@schematichq/schematic-react");
5466
+ var import_react4 = require("react");
5467
+ var import_jsx_runtime5 = require("react/jsx-runtime");
5468
+ var VISIBLE_FEATURE_COUNT = 4;
5469
+ function IncludedFeatures({
5470
+ className,
5471
+ headingLevel = 2,
5472
+ locale: localeProp,
5473
+ showCredits = true,
5474
+ showDescription = true,
5475
+ showEntitlement = true,
5476
+ showExpiration = true,
5477
+ showHardLimit = false,
5478
+ showHeader = true,
5479
+ showIcon = true,
5480
+ showUsage = true,
5481
+ showWarningThresholdAsLimit = false,
5482
+ strings,
5483
+ visibleFeatures
5484
+ }) {
5485
+ const { data: features, error, isPending, refetch } = (0, import_schematic_react3.useFeatureUsage)();
5486
+ const locale = useResolvedLocale(localeProp);
5487
+ const t = useTranslator(strings, localeProp);
5488
+ const [expanded, setExpanded] = (0, import_react4.useState)(false);
5489
+ const rows = (0, import_react4.useMemo)(
5490
+ () => features === void 0 ? [] : deriveIncludedFeatures(features, {
5491
+ locale,
5492
+ showCredits,
5493
+ showWarningThresholdAsLimit,
5494
+ visibleFeatures
5495
+ }),
5496
+ [
5497
+ features,
5498
+ locale,
5499
+ showCredits,
5500
+ showWarningThresholdAsLimit,
5501
+ visibleFeatures
4175
5502
  ]
4176
5503
  );
4177
5504
  const Heading = `h${headingLevel}`;
@@ -4179,7 +5506,7 @@ function IncludedFeatures({
4179
5506
  const shown = canExpand && !expanded ? rows.slice(0, VISIBLE_FEATURE_COUNT) : rows;
4180
5507
  const unavailable = features === void 0 && httpStatus(error) === 404;
4181
5508
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("includedFeaturesUnavailable") : t("includedFeaturesError");
4182
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5509
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
4183
5510
  StatusFrame,
4184
5511
  {
4185
5512
  className: cx("schematic-card", "schematic-included-features", className),
@@ -4190,26 +5517,26 @@ function IncludedFeatures({
4190
5517
  loadingLabel: t("includedFeaturesLoading"),
4191
5518
  onRetry: refetch,
4192
5519
  retryText: t("retry"),
4193
- skeleton: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IncludedFeaturesSkeleton, { showHeader }),
5520
+ skeleton: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(IncludedFeaturesSkeleton, { showHeader }),
4194
5521
  children: [
4195
- showHeader && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Heading, { className: "schematic-header__title", children: t("includedFeaturesHeader") }) }),
4196
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("ul", { className: "schematic-included-features__list", children: shown.map((row) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5522
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Heading, { className: "schematic-header__title", children: t("includedFeaturesHeader") }) }),
5523
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ul", { className: "schematic-included-features__list", children: shown.map((row) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
4197
5524
  "li",
4198
5525
  {
4199
5526
  className: "schematic-included-features__row",
4200
5527
  "data-testid": "schematic-included-feature",
4201
5528
  children: [
4202
- showIcon && row.icon !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5529
+ showIcon && row.icon !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4203
5530
  "i",
4204
5531
  {
4205
5532
  "aria-hidden": "true",
4206
5533
  className: `schematic-icon schematic-icon--${row.icon} schematic-included-features__icon`
4207
5534
  }
4208
5535
  ),
4209
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-included-features__details", children: [
4210
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-included-features__name", children: row.name }),
4211
- showDescription && row.description !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-muted schematic-small", children: row.description }),
4212
- row.perLicenseCredits.map((credits, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5536
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "schematic-included-features__details", children: [
5537
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "schematic-included-features__name", children: row.name }),
5538
+ showDescription && row.description !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "schematic-muted schematic-small", children: row.description }),
5539
+ row.perLicenseCredits.map((credits, index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4213
5540
  "span",
4214
5541
  {
4215
5542
  className: "schematic-muted schematic-small",
@@ -4221,9 +5548,9 @@ function IncludedFeatures({
4221
5548
  },
4222
5549
  `${credits.creditName}-${index}`
4223
5550
  )),
4224
- showExpiration && row.expiresAt !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("em", { className: "schematic-muted schematic-small", children: t("includedFeaturesExpires", { date: row.expiresAt.text }) })
5551
+ showExpiration && row.expiresAt !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("em", { className: "schematic-muted schematic-small", children: t("includedFeaturesExpires", { date: row.expiresAt.text }) })
4225
5552
  ] }),
4226
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5553
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4227
5554
  UsageDetails,
4228
5555
  {
4229
5556
  row,
@@ -4238,7 +5565,7 @@ function IncludedFeatures({
4238
5565
  },
4239
5566
  row.featureId
4240
5567
  )) }),
4241
- canExpand && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
5568
+ canExpand && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
4242
5569
  "button",
4243
5570
  {
4244
5571
  "aria-expanded": expanded,
@@ -4246,14 +5573,14 @@ function IncludedFeatures({
4246
5573
  type: "button",
4247
5574
  onClick: () => setExpanded((value) => !value),
4248
5575
  children: [
4249
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5576
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4250
5577
  "i",
4251
5578
  {
4252
5579
  "aria-hidden": "true",
4253
5580
  className: `schematic-icon schematic-icon--${expanded ? "chevron-up" : "chevron-down"} schematic-chevron`
4254
5581
  }
4255
5582
  ),
4256
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "schematic-link-button__label", children: expanded ? t("includedFeaturesHideAll") : t("includedFeaturesSeeAll") })
5583
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "schematic-link-button__label", children: expanded ? t("includedFeaturesHideAll") : t("includedFeaturesSeeAll") })
4257
5584
  ]
4258
5585
  }
4259
5586
  )
@@ -4273,17 +5600,17 @@ function UsageDetails({
4273
5600
  if (row.entitlement === null && usage === null) {
4274
5601
  return null;
4275
5602
  }
4276
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-included-features__usage", children: [
4277
- showEntitlement && row.entitlement !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "schematic-included-features__entitlement", children: [
5603
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "schematic-included-features__usage", children: [
5604
+ showEntitlement && row.entitlement !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "schematic-included-features__entitlement", children: [
4278
5605
  entitlementText2(row.entitlement, t),
4279
- showHardLimit && row.hardLimit !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
5606
+ showHardLimit && row.hardLimit !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
4280
5607
  amount: row.hardLimit.amount,
4281
5608
  units: row.hardLimit.units
4282
5609
  }) })
4283
5610
  ] }),
4284
- showUsage && usage !== null && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "schematic-muted schematic-small schematic-included-features__used", children: [
5611
+ showUsage && usage !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "schematic-muted schematic-small schematic-included-features__used", children: [
4285
5612
  usage,
4286
- row.tiers !== null && row.tiers.ranges.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
5613
+ row.tiers !== null && row.tiers.ranges.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
4287
5614
  PriceTiers,
4288
5615
  {
4289
5616
  currency: row.tiers.currency,
@@ -4336,7 +5663,7 @@ function segmentText(segment, t) {
4336
5663
  switch (segment.kind) {
4337
5664
  case "unitPricePerPeriod": {
4338
5665
  const period = shortPeriod(segment.period, t) ?? segment.period;
4339
- return segment.size > 1 ? t("usagePackagePricePerPeriod", {
5666
+ return segment.size !== null ? t("usagePackagePricePerPeriod", {
4340
5667
  cost: segment.cost,
4341
5668
  size: segment.size,
4342
5669
  units: segment.units,
@@ -4358,20 +5685,20 @@ function segmentText(segment, t) {
4358
5685
  }
4359
5686
  }
4360
5687
  function IncludedFeaturesSkeleton({ showHeader }) {
4361
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-skeleton", children: [
4362
- showHeader && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__heading" }),
4363
- [0, 1, 2].map((index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "schematic-skeleton__row", children: [
4364
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
4365
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "usage" })
5688
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "schematic-skeleton", children: [
5689
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "schematic-skeleton__heading" }),
5690
+ [0, 1, 2].map((index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "schematic-skeleton__row", children: [
5691
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
5692
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "usage" })
4366
5693
  ] }, index))
4367
5694
  ] });
4368
5695
  }
4369
5696
  IncludedFeatures.resources = ["featureUsage"];
4370
5697
 
4371
5698
  // src/elements/Invoices.tsx
4372
- var import_schematic_react3 = require("@schematichq/schematic-react");
4373
- var import_react4 = require("react");
4374
- var import_jsx_runtime5 = require("react/jsx-runtime");
5699
+ var import_schematic_react4 = require("@schematichq/schematic-react");
5700
+ var import_react5 = require("react");
5701
+ var import_jsx_runtime6 = require("react/jsx-runtime");
4375
5702
  var SKELETON_ROWS = 4;
4376
5703
  function Invoices({
4377
5704
  className,
@@ -4391,15 +5718,15 @@ function Invoices({
4391
5718
  isPending,
4392
5719
  loadMore,
4393
5720
  refetch
4394
- } = (0, import_schematic_react3.useInvoices)(query);
5721
+ } = (0, import_schematic_react4.useInvoices)(query);
4395
5722
  const locale = useResolvedLocale(localeProp);
4396
5723
  const t = useTranslator(strings, localeProp);
4397
- const [expanded, setExpanded] = (0, import_react4.useState)(false);
4398
- const list = (0, import_react4.useMemo)(
5724
+ const [expanded, setExpanded] = (0, import_react5.useState)(false);
5725
+ const list = (0, import_react5.useMemo)(
4399
5726
  () => page === void 0 ? void 0 : deriveInvoiceList(page, { locale }),
4400
5727
  [locale, page]
4401
5728
  );
4402
- const headingId = (0, import_react4.useId)();
5729
+ const headingId = (0, import_react5.useId)();
4403
5730
  const rows = list?.rows ?? [];
4404
5731
  const canCollapse = collapsible && rows.length > limit;
4405
5732
  const showingAll = !canCollapse || expanded;
@@ -4411,7 +5738,7 @@ function Invoices({
4411
5738
  );
4412
5739
  const unavailable = list === void 0 && httpStatus(error) === 404;
4413
5740
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("invoicesUnavailable") : t("invoicesError");
4414
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5741
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4415
5742
  StatusFrame,
4416
5743
  {
4417
5744
  className: cx("schematic-card", "schematic-invoices", className),
@@ -4422,7 +5749,7 @@ function Invoices({
4422
5749
  loadingLabel: t("invoicesLoading"),
4423
5750
  onRetry: refetch,
4424
5751
  retryText: t("retry"),
4425
- skeleton: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5752
+ skeleton: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4426
5753
  InvoicesSkeleton,
4427
5754
  {
4428
5755
  columns,
@@ -4430,22 +5757,22 @@ function Invoices({
4430
5757
  showHeader
4431
5758
  }
4432
5759
  ),
4433
- children: list !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
4434
- showHeader && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Heading, { className: "schematic-header__title", id: headingId, children: t("invoicesHeader") }) }),
4435
- rows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "schematic-muted schematic-invoices__empty", children: t("invoicesEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5760
+ children: list !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
5761
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Heading, { className: "schematic-header__title", id: headingId, children: t("invoicesHeader") }) }),
5762
+ rows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "schematic-muted schematic-invoices__empty", children: t("invoicesEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4436
5763
  "ul",
4437
5764
  {
4438
5765
  className: "schematic-invoices__list",
4439
5766
  "aria-label": showHeader ? void 0 : t("invoicesHeader"),
4440
5767
  "aria-labelledby": showHeader ? headingId : void 0,
4441
- children: visible.map((row) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
5768
+ children: visible.map((row) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
4442
5769
  "li",
4443
5770
  {
4444
5771
  className: "schematic-invoices__row",
4445
5772
  "data-testid": "schematic-invoice",
4446
5773
  children: [
4447
- showDate && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "schematic-invoices__date", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(InvoiceDate, { row, t }) }),
4448
- showAmount && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5774
+ showDate && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "schematic-invoices__date", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(InvoiceDate, { row, t }) }),
5775
+ showAmount && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4449
5776
  "span",
4450
5777
  {
4451
5778
  className: cx(
@@ -4462,8 +5789,8 @@ function Invoices({
4462
5789
  ))
4463
5790
  }
4464
5791
  ),
4465
- (canCollapse || showingAll && list.hasMore) && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "schematic-invoices__actions", children: [
4466
- canCollapse && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
5792
+ (canCollapse || showingAll && list.hasMore) && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-invoices__actions", children: [
5793
+ canCollapse && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
4467
5794
  "button",
4468
5795
  {
4469
5796
  "aria-expanded": expanded,
@@ -4471,7 +5798,7 @@ function Invoices({
4471
5798
  type: "button",
4472
5799
  onClick: () => setExpanded((value) => !value),
4473
5800
  children: [
4474
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5801
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4475
5802
  "i",
4476
5803
  {
4477
5804
  "aria-hidden": "true",
@@ -4483,11 +5810,11 @@ function Invoices({
4483
5810
  )
4484
5811
  }
4485
5812
  ),
4486
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "schematic-link-button__label", children: expanded ? t("invoicesSeeLess") : t("invoicesSeeMore") })
5813
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "schematic-link-button__label", children: expanded ? t("invoicesSeeLess") : t("invoicesSeeMore") })
4487
5814
  ]
4488
5815
  }
4489
5816
  ),
4490
- showingAll && list.hasMore && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5817
+ showingAll && list.hasMore && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4491
5818
  "button",
4492
5819
  {
4493
5820
  className: "schematic-link-button schematic-invoices__load-more",
@@ -4510,9 +5837,9 @@ function InvoicesSkeleton({
4510
5837
  rows,
4511
5838
  showHeader
4512
5839
  }) {
4513
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "schematic-skeleton", children: [
4514
- showHeader && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "schematic-skeleton__heading" }),
4515
- Array.from({ length: rows }, (_, row) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "schematic-skeleton__row", children: columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5840
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-skeleton", children: [
5841
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-skeleton__heading" }),
5842
+ Array.from({ length: rows }, (_, row) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-skeleton__row", children: columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4516
5843
  "div",
4517
5844
  {
4518
5845
  className: "schematic-skeleton__cell",
@@ -4524,10 +5851,10 @@ function InvoicesSkeleton({
4524
5851
  }
4525
5852
  function InvoiceDate({ row, t }) {
4526
5853
  if (row.url === null) {
4527
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "schematic-invoices__date-text", children: row.dateText });
5854
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "schematic-invoices__date-text", children: row.dateText });
4528
5855
  }
4529
5856
  const label = row.dateText === "" ? t("invoicesUndated") : row.dateText;
4530
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
5857
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
4531
5858
  "a",
4532
5859
  {
4533
5860
  className: "schematic-invoices__link",
@@ -4541,9 +5868,9 @@ function InvoiceDate({ row, t }) {
4541
5868
  Invoices.resources = ["invoices"];
4542
5869
 
4543
5870
  // src/elements/MeteredFeatures.tsx
4544
- var import_schematic_react4 = require("@schematichq/schematic-react");
4545
- var import_react5 = require("react");
4546
- var import_jsx_runtime6 = require("react/jsx-runtime");
5871
+ var import_schematic_react5 = require("@schematichq/schematic-react");
5872
+ var import_react6 = require("react");
5873
+ var import_jsx_runtime7 = require("react/jsx-runtime");
4547
5874
  function MeteredFeatures({
4548
5875
  addMoreTarget,
4549
5876
  addMoreUrl,
@@ -4564,10 +5891,10 @@ function MeteredFeatures({
4564
5891
  strings,
4565
5892
  visibleFeatures
4566
5893
  }) {
4567
- const { data: features, error, isPending, refetch } = (0, import_schematic_react4.useFeatureUsage)();
5894
+ const { data: features, error, isPending, refetch } = (0, import_schematic_react5.useFeatureUsage)();
4568
5895
  const locale = useResolvedLocale(localeProp);
4569
5896
  const t = useTranslator(strings, localeProp);
4570
- const rows = (0, import_react5.useMemo)(
5897
+ const rows = (0, import_react6.useMemo)(
4571
5898
  () => features === void 0 ? [] : deriveMeteredFeatures(features, {
4572
5899
  locale,
4573
5900
  showCredits,
@@ -4589,7 +5916,7 @@ function MeteredFeatures({
4589
5916
  }
4590
5917
  const Heading = `h${headingLevel}`;
4591
5918
  const NameHeading = showHeader ? `h${Math.min(6, headingLevel + 1)}` : Heading;
4592
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
5919
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
4593
5920
  StatusFrame,
4594
5921
  {
4595
5922
  className: cx("schematic-metered-features", className),
@@ -4600,32 +5927,32 @@ function MeteredFeatures({
4600
5927
  loadingLabel: t("meteredFeaturesLoading"),
4601
5928
  onRetry: refetch,
4602
5929
  retryText: t("retry"),
4603
- skeleton: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(MeteredFeaturesSkeleton, { showHeader }),
5930
+ skeleton: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MeteredFeaturesSkeleton, { showHeader }),
4604
5931
  children: [
4605
- showHeader && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Heading, { className: "schematic-header__title", children: t("meteredFeaturesHeader") }) }),
4606
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: "schematic-metered-features__list", children: rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
5932
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Heading, { className: "schematic-header__title", children: t("meteredFeaturesHeader") }) }),
5933
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { className: "schematic-metered-features__list", children: rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
4607
5934
  "li",
4608
5935
  {
4609
5936
  className: "schematic-card schematic-metered-features__feature",
4610
5937
  "data-testid": "schematic-metered-feature",
4611
5938
  children: [
4612
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__main", children: [
4613
- showIcon && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "schematic-metered-features__icon", children: row.icon !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
5939
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__main", children: [
5940
+ showIcon && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "schematic-metered-features__icon", children: row.icon !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4614
5941
  "i",
4615
5942
  {
4616
5943
  "aria-hidden": "true",
4617
5944
  className: `schematic-icon schematic-icon--${row.icon}`
4618
5945
  }
4619
5946
  ) }),
4620
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__body", children: [
4621
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__top", children: [
4622
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__title", children: [
4623
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(NameHeading, { className: "schematic-metered-features__name", children: row.name }),
4624
- showDescription && row.description !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "schematic-muted", children: row.description })
5947
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__body", children: [
5948
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__top", children: [
5949
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__title", children: [
5950
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(NameHeading, { className: "schematic-metered-features__name", children: row.name }),
5951
+ showDescription && row.description !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "schematic-muted", children: row.description })
4625
5952
  ] }),
4626
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__figures", children: [
4627
- showUsage && row.headline !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "schematic-metered-features__headline", children: headlineText(row.headline, t) }),
4628
- showAllocation && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
5953
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__figures", children: [
5954
+ showUsage && row.headline !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "schematic-metered-features__headline", children: headlineText(row.headline, t) }),
5955
+ showAllocation && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4629
5956
  LimitLine,
4630
5957
  {
4631
5958
  row,
@@ -4635,8 +5962,8 @@ function MeteredFeatures({
4635
5962
  )
4636
5963
  ] })
4637
5964
  ] }),
4638
- showMeter && row.meter !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Meter, { meter: row.meter }),
4639
- row.canAddMore && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
5965
+ showMeter && row.meter !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Meter, { meter: row.meter }),
5966
+ row.canAddMore && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4640
5967
  AddMore,
4641
5968
  {
4642
5969
  label: t("meteredFeaturesAddMore"),
@@ -4647,8 +5974,8 @@ function MeteredFeatures({
4647
5974
  )
4648
5975
  ] })
4649
5976
  ] }),
4650
- showUsageByUser && row.hasUsageByUser && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(UsageByUser, { locale, row, t }),
4651
- row.priceDetails !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
5977
+ showUsageByUser && row.hasUsageByUser && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(UsageByUser, { locale, row, t }),
5978
+ row.priceDetails !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4652
5979
  PriceDetails,
4653
5980
  {
4654
5981
  details: row.priceDetails,
@@ -4712,9 +6039,9 @@ function LimitLine({
4712
6039
  if (parts.length === 0) {
4713
6040
  return null;
4714
6041
  }
4715
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "schematic-muted schematic-metered-features__limit", children: [
6042
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "schematic-muted schematic-metered-features__limit", children: [
4716
6043
  parts.join(" \u2022 "),
4717
- showHardLimit && row.hardLimit !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
6044
+ showHardLimit && row.hardLimit !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
4718
6045
  amount: row.hardLimit.amount,
4719
6046
  units: row.hardLimit.units
4720
6047
  }) })
@@ -4728,8 +6055,8 @@ var METER_TONE_CLASS = {
4728
6055
  overage: "schematic-meter--overage"
4729
6056
  };
4730
6057
  function Meter({ meter: meter2 }) {
4731
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__meter", children: [
4732
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
6058
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__meter", children: [
6059
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4733
6060
  "div",
4734
6061
  {
4735
6062
  "aria-valuemax": meter2.total,
@@ -4738,7 +6065,7 @@ function Meter({ meter: meter2 }) {
4738
6065
  className: cx("schematic-meter", METER_TONE_CLASS[meter2.tone]),
4739
6066
  "data-tone": meter2.tone,
4740
6067
  role: "meter",
4741
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
6068
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4742
6069
  "div",
4743
6070
  {
4744
6071
  className: "schematic-meter__fill",
@@ -4747,7 +6074,7 @@ function Meter({ meter: meter2 }) {
4747
6074
  )
4748
6075
  }
4749
6076
  ),
4750
- meter2.total > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "schematic-metered-features__meter-label", children: [
6077
+ meter2.total > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "schematic-metered-features__meter-label", children: [
4751
6078
  meter2.valueText,
4752
6079
  "/",
4753
6080
  meter2.totalText
@@ -4761,7 +6088,7 @@ function AddMore({
4761
6088
  url
4762
6089
  }) {
4763
6090
  if (onAddMore !== void 0) {
4764
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
6091
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4765
6092
  "button",
4766
6093
  {
4767
6094
  className: "schematic-cta schematic-metered-features__add-more",
@@ -4772,7 +6099,7 @@ function AddMore({
4772
6099
  );
4773
6100
  }
4774
6101
  if (url !== void 0) {
4775
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
6102
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4776
6103
  "a",
4777
6104
  {
4778
6105
  className: "schematic-cta schematic-metered-features__add-more",
@@ -4792,38 +6119,38 @@ function PriceDetails({
4792
6119
  }) {
4793
6120
  const period = details.period === null ? void 0 : shortPeriod(details.period, t);
4794
6121
  if (details.kind === "overage") {
4795
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__price-details", children: [
4796
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
6122
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__price-details", children: [
6123
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
4797
6124
  t("meteredFeaturesAdditional"),
4798
6125
  ": ",
4799
6126
  details.unitPrice,
4800
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("sub", { children: [
6127
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("sub", { children: [
4801
6128
  "/",
4802
- details.packageSize > 1 && `${details.packageSize} `,
6129
+ details.packageSize !== null && `${details.packageSize} `,
4803
6130
  details.units,
4804
6131
  period !== void 0 && `/${period}`
4805
6132
  ] })
4806
6133
  ] }),
4807
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
6134
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
4808
6135
  details.overage.amount,
4809
6136
  " ",
4810
6137
  details.overage.units,
4811
6138
  " \xB7 ",
4812
6139
  details.overage.cost,
4813
- period !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("sub", { children: [
6140
+ period !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("sub", { children: [
4814
6141
  "/",
4815
6142
  period
4816
6143
  ] })
4817
6144
  ] })
4818
6145
  ] });
4819
6146
  }
4820
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-metered-features__price-details", children: [
4821
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
6147
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-metered-features__price-details", children: [
6148
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
4822
6149
  t("meteredFeaturesTier"),
4823
6150
  ": ",
4824
6151
  details.from,
4825
6152
  details.to === null ? "+" : details.to !== details.from ? `\u2013${details.to}` : "",
4826
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
6153
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4827
6154
  PriceTiers,
4828
6155
  {
4829
6156
  currency: details.tiers.currency,
@@ -4836,9 +6163,9 @@ function PriceDetails({
4836
6163
  }
4837
6164
  ) })
4838
6165
  ] }),
4839
- details.cost !== null && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
6166
+ details.cost !== null && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
4840
6167
  details.cost,
4841
- period !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("sub", { children: [
6168
+ period !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("sub", { children: [
4842
6169
  "/",
4843
6170
  period
4844
6171
  ] })
@@ -4850,8 +6177,8 @@ function UsageByUser({
4850
6177
  row,
4851
6178
  t
4852
6179
  }) {
4853
- const { data, error, refetch } = (0, import_schematic_react4.useFeatureUserUsage)(row.featureId);
4854
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
6180
+ const { data, error, refetch } = (0, import_schematic_react5.useFeatureUserUsage)(row.featureId);
6181
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
4855
6182
  UserBreakdown,
4856
6183
  {
4857
6184
  breakdown: data === void 0 ? void 0 : {
@@ -4873,21 +6200,21 @@ function UsageByUser({
4873
6200
  );
4874
6201
  }
4875
6202
  function MeteredFeaturesSkeleton({ showHeader }) {
4876
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-skeleton", children: [
4877
- showHeader && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-skeleton__heading" }),
4878
- [0, 1].map((index) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "schematic-skeleton__row", children: [
4879
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
4880
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "usage" })
6203
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-skeleton", children: [
6204
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__heading" }),
6205
+ [0, 1].map((index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "schematic-skeleton__row", children: [
6206
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
6207
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "usage" })
4881
6208
  ] }, index))
4882
6209
  ] });
4883
6210
  }
4884
6211
  MeteredFeatures.resources = ["featureUsage"];
4885
6212
 
4886
6213
  // src/elements/PaymentMethods.tsx
4887
- var import_schematic_react6 = require("@schematichq/schematic-react");
4888
- var import_react7 = require("react");
4889
- var import_jsx_runtime8 = require("react/jsx-runtime");
4890
- var PaymentMethodForm2 = (0, import_react7.lazy)(() => Promise.resolve().then(() => (init_PaymentMethodForm(), PaymentMethodForm_exports)));
6214
+ var import_schematic_react7 = require("@schematichq/schematic-react");
6215
+ var import_react8 = require("react");
6216
+ var import_jsx_runtime9 = require("react/jsx-runtime");
6217
+ var PaymentMethodForm2 = (0, import_react8.lazy)(() => Promise.resolve().then(() => (init_PaymentMethodForm(), PaymentMethodForm_exports)));
4891
6218
  function PaymentMethods({
4892
6219
  allowEdit = true,
4893
6220
  checkoutPrefill,
@@ -4908,24 +6235,24 @@ function PaymentMethods({
4908
6235
  refetch,
4909
6236
  remove,
4910
6237
  setDefault
4911
- } = (0, import_schematic_react6.usePaymentMethods)();
6238
+ } = (0, import_schematic_react7.usePaymentMethods)();
4912
6239
  const locale = useResolvedLocale(localeProp);
4913
6240
  const t = useTranslator(strings, localeProp);
4914
- const [dialog, setDialog] = (0, import_react7.useState)(null);
4915
- const [choosing, setChoosing] = (0, import_react7.useState)(false);
4916
- const [lastWrite, setLastWrite] = (0, import_react7.useState)(null);
4917
- const derived = (0, import_react7.useMemo)(
6241
+ const [dialog, setDialog] = (0, import_react8.useState)(null);
6242
+ const [choosing, setChoosing] = (0, import_react8.useState)(false);
6243
+ const [lastWrite, setLastWrite] = (0, import_react8.useState)(null);
6244
+ const derived = (0, import_react8.useMemo)(
4918
6245
  () => methods === void 0 ? void 0 : derivePaymentMethods(methods, { locale }),
4919
6246
  [locale, methods]
4920
6247
  );
4921
- const write = (0, import_react7.useCallback)(async (next) => {
6248
+ const write = (0, import_react8.useCallback)(async (next) => {
4922
6249
  setLastWrite(next);
4923
6250
  try {
4924
6251
  await next.action();
4925
6252
  } catch {
4926
6253
  }
4927
6254
  }, []);
4928
- const saved = (0, import_react7.useCallback)(
6255
+ const saved = (0, import_react8.useCallback)(
4929
6256
  async (paymentMethodId) => {
4930
6257
  await write({
4931
6258
  action: () => setDefault(paymentMethodId),
@@ -4936,16 +6263,16 @@ function PaymentMethods({
4936
6263
  },
4937
6264
  [setDefault, write]
4938
6265
  );
4939
- const open = (0, import_react7.useCallback)(() => {
6266
+ const open = (0, import_react8.useCallback)(() => {
4940
6267
  setLastWrite(null);
4941
6268
  setChoosing(false);
4942
6269
  setDialog("current");
4943
6270
  }, []);
4944
- const close = (0, import_react7.useCallback)(() => setDialog(null), []);
6271
+ const close = (0, import_react8.useCallback)(() => setDialog(null), []);
4945
6272
  const Heading = `h${headingLevel}`;
4946
6273
  const unavailable = derived === void 0 && httpStatus(error) === 404;
4947
6274
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("paymentMethodsUnavailable") : t("paymentMethodsError");
4948
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6275
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4949
6276
  StatusFrame,
4950
6277
  {
4951
6278
  className: cx("schematic-card", "schematic-payment-methods", className),
@@ -4956,18 +6283,19 @@ function PaymentMethods({
4956
6283
  loadingLabel: t("paymentMethodsLoading"),
4957
6284
  onRetry: refetch,
4958
6285
  retryText: t("retry"),
4959
- skeleton: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PaymentMethodsSkeleton, { showHeader }),
4960
- children: derived !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
4961
- showHeader && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6286
+ skeleton: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PaymentMethodsSkeleton, { showHeader }),
6287
+ children: derived !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
6288
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4962
6289
  PaymentMethodsHeader,
4963
6290
  {
4964
6291
  derived,
4965
6292
  heading: Heading,
6293
+ locale,
4966
6294
  showExpiration,
4967
6295
  t
4968
6296
  }
4969
6297
  ),
4970
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MethodPill, { row: derived.current, t, children: allowEdit && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6298
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(MethodPill, { row: derived.current, t, children: allowEdit && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4971
6299
  "button",
4972
6300
  {
4973
6301
  className: "schematic-link-button schematic-payment-methods__edit",
@@ -4976,7 +6304,7 @@ function PaymentMethods({
4976
6304
  children: derived.current === null ? t("paymentMethodsAdd") : t("paymentMethodsEdit")
4977
6305
  }
4978
6306
  ) }),
4979
- dialog !== null && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6307
+ dialog !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
4980
6308
  PaymentMethodsDialog,
4981
6309
  {
4982
6310
  checkoutPrefill,
@@ -5028,7 +6356,7 @@ function PaymentMethodsDialog({
5028
6356
  const { current, others, rows } = derived;
5029
6357
  const hasMethods = rows.length > 0;
5030
6358
  const showForm = view === "add" || !hasMethods;
5031
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
6359
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
5032
6360
  Dialog,
5033
6361
  {
5034
6362
  className: "schematic-payment-methods__dialog",
@@ -5037,11 +6365,11 @@ function PaymentMethodsDialog({
5037
6365
  title: t("paymentMethodsDialogTitle"),
5038
6366
  onClose,
5039
6367
  children: [
5040
- showForm ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
5041
- import_react7.Suspense,
6368
+ showForm ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
6369
+ import_react8.Suspense,
5042
6370
  {
5043
- fallback: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(FormSkeleton, { label: t("paymentMethodsFormLoading") }),
5044
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6371
+ fallback: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(FormSkeleton, { label: t("paymentMethodsFormLoading") }),
6372
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
5045
6373
  PaymentMethodForm2,
5046
6374
  {
5047
6375
  checkoutPrefill,
@@ -5053,17 +6381,18 @@ function PaymentMethodsDialog({
5053
6381
  }
5054
6382
  )
5055
6383
  }
5056
- ) : /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
5057
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6384
+ ) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
6385
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
5058
6386
  PaymentMethodsHeader,
5059
6387
  {
5060
6388
  derived,
5061
6389
  heading: "h3",
6390
+ locale,
5062
6391
  showExpiration: true,
5063
6392
  t
5064
6393
  }
5065
6394
  ),
5066
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MethodPill, { row: current, t, children: current?.canRemove === true && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6395
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(MethodPill, { row: current, t, children: current?.canRemove === true && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
5067
6396
  "button",
5068
6397
  {
5069
6398
  className: "schematic-link-button schematic-payment-methods__remove-current",
@@ -5073,7 +6402,7 @@ function PaymentMethodsDialog({
5073
6402
  children: t("paymentMethodsRemove")
5074
6403
  }
5075
6404
  ) }),
5076
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
6405
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
5077
6406
  "button",
5078
6407
  {
5079
6408
  "aria-expanded": choosing,
@@ -5081,8 +6410,8 @@ function PaymentMethodsDialog({
5081
6410
  type: "button",
5082
6411
  onClick: onChoose,
5083
6412
  children: [
5084
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-payment-methods__choose-label", children: t("paymentMethodsChooseDifferent") }),
5085
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6413
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-payment-methods__choose-label", children: t("paymentMethodsChooseDifferent") }),
6414
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
5086
6415
  "i",
5087
6416
  {
5088
6417
  "aria-hidden": "true",
@@ -5097,13 +6426,13 @@ function PaymentMethodsDialog({
5097
6426
  ]
5098
6427
  }
5099
6428
  ),
5100
- choosing && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
5101
- others.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6429
+ choosing && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
6430
+ others.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
5102
6431
  "ul",
5103
6432
  {
5104
6433
  "aria-label": t("paymentMethodsChooseDifferent"),
5105
6434
  className: "schematic-payment-methods__list",
5106
- children: others.map((row) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
6435
+ children: others.map((row) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
5107
6436
  "li",
5108
6437
  {
5109
6438
  className: "schematic-payment-methods__row",
@@ -5111,11 +6440,11 @@ function PaymentMethodsDialog({
5111
6440
  "data-kind": row.kind,
5112
6441
  "data-testid": "schematic-payment-method",
5113
6442
  children: [
5114
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Method, { row, t }),
5115
- row.expiresShort !== null && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-payment-methods__expires", children: t("paymentMethodsExpires", {
6443
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Method, { row, t }),
6444
+ row.expiresShort !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-payment-methods__expires", children: t("paymentMethodsExpires", {
5116
6445
  date: row.expiresShort
5117
6446
  }) }),
5118
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6447
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
5119
6448
  "button",
5120
6449
  {
5121
6450
  className: "schematic-link-button schematic-payment-methods__set-default",
@@ -5125,7 +6454,7 @@ function PaymentMethodsDialog({
5125
6454
  children: t("paymentMethodsSetDefault")
5126
6455
  }
5127
6456
  ),
5128
- row.canRemove && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6457
+ row.canRemove && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
5129
6458
  "button",
5130
6459
  {
5131
6460
  "aria-label": t("paymentMethodsRemove"),
@@ -5133,7 +6462,7 @@ function PaymentMethodsDialog({
5133
6462
  disabled: isMutating,
5134
6463
  type: "button",
5135
6464
  onClick: () => onRemove(row),
5136
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6465
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
5137
6466
  "i",
5138
6467
  {
5139
6468
  "aria-hidden": "true",
@@ -5148,7 +6477,7 @@ function PaymentMethodsDialog({
5148
6477
  ))
5149
6478
  }
5150
6479
  ),
5151
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6480
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
5152
6481
  "button",
5153
6482
  {
5154
6483
  className: "schematic-cta schematic-payment-methods__add-new",
@@ -5160,14 +6489,14 @@ function PaymentMethodsDialog({
5160
6489
  )
5161
6490
  ] })
5162
6491
  ] }),
5163
- mutationError !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
6492
+ mutationError !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
5164
6493
  "p",
5165
6494
  {
5166
6495
  className: "schematic-status-note schematic-error schematic-payment-methods__error",
5167
6496
  role: "alert",
5168
6497
  children: [
5169
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-payment-methods__error-message", children: mutationError }),
5170
- onRetry !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6498
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-payment-methods__error-message", children: mutationError }),
6499
+ onRetry !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
5171
6500
  "button",
5172
6501
  {
5173
6502
  className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-payment-methods__error-retry",
@@ -5187,17 +6516,18 @@ function PaymentMethodsDialog({
5187
6516
  function PaymentMethodsHeader({
5188
6517
  derived,
5189
6518
  heading: Heading,
6519
+ locale,
5190
6520
  showExpiration,
5191
6521
  t
5192
6522
  }) {
5193
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "schematic-header", children: [
5194
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Heading, { className: "schematic-header__title", children: t("paymentMethodsHeader") }),
5195
- showExpiration && derived.expiryWarning !== "none" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6523
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "schematic-header", children: [
6524
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Heading, { className: "schematic-header__title", children: t("paymentMethodsHeader") }),
6525
+ showExpiration && derived.expiryWarning !== "none" && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
5196
6526
  "span",
5197
6527
  {
5198
6528
  className: "schematic-small schematic-payment-methods__expiry-warning",
5199
6529
  "data-expiry": derived.expiryWarning,
5200
- children: expiryWarningText(derived, t)
6530
+ children: expiryWarningText(derived, locale, t)
5201
6531
  }
5202
6532
  )
5203
6533
  ] });
@@ -5207,37 +6537,37 @@ function MethodPill({
5207
6537
  row,
5208
6538
  t
5209
6539
  }) {
5210
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
6540
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
5211
6541
  "div",
5212
6542
  {
5213
6543
  className: "schematic-payment-methods__current",
5214
6544
  "data-testid": "schematic-payment-method-current",
5215
6545
  children: [
5216
- row === null ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-payment-methods__empty", children: t("paymentMethodsEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Method, { row, t }),
6546
+ row === null ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-payment-methods__empty", children: t("paymentMethodsEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Method, { row, t }),
5217
6547
  children
5218
6548
  ]
5219
6549
  }
5220
6550
  );
5221
6551
  }
5222
6552
  function Method({ row, t }) {
5223
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
6553
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
5224
6554
  "span",
5225
6555
  {
5226
6556
  className: "schematic-payment-methods__method",
5227
6557
  "data-brand": row.brand,
5228
6558
  "data-kind": row.kind,
5229
6559
  children: [
5230
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
6560
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
5231
6561
  "i",
5232
6562
  {
5233
6563
  "aria-hidden": "true",
5234
6564
  className: `schematic-icon schematic-icon--${row.icon} schematic-payment-methods__icon`
5235
6565
  }
5236
6566
  ),
5237
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-payment-methods__label", children: labelText(row.label, t) }),
5238
- row.last4 !== null && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
6567
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-payment-methods__label", children: labelText(row.label, t) }),
6568
+ row.last4 !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
5239
6569
  " ",
5240
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-payment-methods__last4", children: row.last4 })
6570
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-payment-methods__last4", children: row.last4 })
5241
6571
  ] })
5242
6572
  ]
5243
6573
  }
@@ -5246,39 +6576,790 @@ function Method({ row, t }) {
5246
6576
  function labelText(label, t) {
5247
6577
  return label.key === void 0 ? label.text : t(label.key);
5248
6578
  }
5249
- function expiryWarningText(derived, t) {
6579
+ function expiryWarningText(derived, locale, t) {
5250
6580
  const months = derived.monthsToExpiration ?? 0;
5251
- return derived.expiryWarning === "expired" ? t("paymentMethodsExpired") : t("paymentMethodsExpiresInMonths", { months });
6581
+ return derived.expiryWarning === "expired" ? t("paymentMethodsExpired") : t("paymentMethodsExpiresInMonths", {
6582
+ months: formatNumber(months, locale)
6583
+ });
5252
6584
  }
5253
6585
  function PaymentMethodsSkeleton({ showHeader }) {
5254
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "schematic-skeleton", children: [
5255
- showHeader && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__heading" }),
5256
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "schematic-skeleton__row", children: [
5257
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "method" }),
5258
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "action" })
6586
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "schematic-skeleton", children: [
6587
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__heading" }),
6588
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "schematic-skeleton__row", children: [
6589
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "method" }),
6590
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "action" })
5259
6591
  ] })
5260
6592
  ] });
5261
6593
  }
5262
6594
  function FormSkeleton({ label }) {
5263
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
6595
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
5264
6596
  "div",
5265
6597
  {
5266
6598
  "aria-busy": "true",
5267
6599
  className: "schematic-payment-methods__form",
5268
6600
  "data-state": "pending",
5269
6601
  children: [
5270
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "schematic-hidden", children: label }),
5271
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
6602
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-hidden", children: label }),
6603
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
5272
6604
  ]
5273
6605
  }
5274
6606
  );
5275
6607
  }
5276
6608
  PaymentMethods.resources = ["paymentMethods"];
5277
6609
 
6610
+ // src/elements/PlanManager.tsx
6611
+ var import_schematic_react8 = require("@schematichq/schematic-react");
6612
+ var import_react9 = require("react");
6613
+ var import_jsx_runtime10 = require("react/jsx-runtime");
6614
+ var VISIBLE_CREDIT_COUNT = 3;
6615
+ var UNIT_KEY = {
6616
+ day: "planManagerDays",
6617
+ hour: "planManagerHours",
6618
+ minute: "planManagerMinutes"
6619
+ };
6620
+ var PERIOD_KEY = {
6621
+ day: "periodDay",
6622
+ month: "periodMonth",
6623
+ quarter: "periodQuarter",
6624
+ week: "periodWeek",
6625
+ year: "periodYear"
6626
+ };
6627
+ function PlanManager({
6628
+ changePlanTarget,
6629
+ changePlanUrl,
6630
+ className,
6631
+ editAutoTopupTarget,
6632
+ editAutoTopupUrl,
6633
+ headingLevel = 2,
6634
+ locale: localeProp,
6635
+ onChangePlan,
6636
+ onEditAutoTopup,
6637
+ showAddOns = true,
6638
+ showCredits = true,
6639
+ showDescription = true,
6640
+ showHardLimit = false,
6641
+ showHeader = true,
6642
+ showLabels = true,
6643
+ showNotice = true,
6644
+ showPrice = true,
6645
+ showUsageBased = true,
6646
+ showWarningThresholdAsLimit = false,
6647
+ showZeroPriceAsFree = false,
6648
+ strings
6649
+ }) {
6650
+ const company = (0, import_schematic_react8.useCompany)();
6651
+ const usage = (0, import_schematic_react8.useFeatureUsage)();
6652
+ const credits = (0, import_schematic_react8.useCreditBalances)();
6653
+ const locale = useResolvedLocale(localeProp);
6654
+ const t = useTranslator(strings, localeProp);
6655
+ const creditsFailed = credits.data === void 0 && credits.error !== void 0;
6656
+ const [creditsHaveFailed, setCreditsHaveFailed] = (0, import_react9.useState)(false);
6657
+ if (creditsFailed && !creditsHaveFailed) {
6658
+ setCreditsHaveFailed(true);
6659
+ } else if (!creditsFailed && creditsHaveFailed && (credits.data !== void 0 || company.data === void 0 || usage.data === void 0)) {
6660
+ setCreditsHaveFailed(false);
6661
+ }
6662
+ const creditsSettled = !showCredits || credits.data !== void 0 || creditsHaveFailed;
6663
+ const view = (0, import_react9.useMemo)(
6664
+ () => company.data === void 0 || usage.data === void 0 || !creditsSettled ? void 0 : derivePlanManager(
6665
+ {
6666
+ company: company.data,
6667
+ creditBalances: credits.data ?? [],
6668
+ featureUsage: usage.data
6669
+ },
6670
+ {
6671
+ locale,
6672
+ showCredits,
6673
+ showWarningThresholdAsLimit,
6674
+ showZeroPriceAsFree
6675
+ }
6676
+ ),
6677
+ [
6678
+ company.data,
6679
+ credits.data,
6680
+ creditsSettled,
6681
+ locale,
6682
+ showCredits,
6683
+ showWarningThresholdAsLimit,
6684
+ showZeroPriceAsFree,
6685
+ usage.data
6686
+ ]
6687
+ );
6688
+ const creditsRefetchError = showCredits && credits.data !== void 0 ? credits.error : void 0;
6689
+ const cardError = company.error ?? usage.error;
6690
+ const error = cardError ?? creditsRefetchError;
6691
+ const unavailable = view === void 0 && httpStatus(error) === 404;
6692
+ const errorMessage = error === void 0 ? void 0 : unavailable ? t("planManagerUnavailable") : cardError === void 0 ? t("planManagerCreditsError") : t("planManagerError");
6693
+ const retry = () => {
6694
+ for (const handle of showCredits ? [company, usage, credits] : [company, usage]) {
6695
+ if (handle.error !== void 0) {
6696
+ handle.refetch();
6697
+ }
6698
+ }
6699
+ };
6700
+ const Heading = `h${headingLevel}`;
6701
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
6702
+ StatusFrame,
6703
+ {
6704
+ className: cx("schematic-plan-manager", className),
6705
+ error,
6706
+ errorMessage,
6707
+ hasData: view !== void 0,
6708
+ isPending: company.isPending || usage.isPending || credits.isPending,
6709
+ loadingLabel: t("planManagerLoading"),
6710
+ onRetry: retry,
6711
+ retryText: t("retry"),
6712
+ skeleton: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PlanManagerSkeleton, {}),
6713
+ children: view !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
6714
+ showNotice && view.notice !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Notice, { locale, notice: view.notice, t }),
6715
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "schematic-card schematic-plan-manager__card", children: [
6716
+ showHeader && view.plan !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "schematic-plan-manager__plan", children: [
6717
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "schematic-plan-manager__title", children: [
6718
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Heading, { className: "schematic-plan-manager__name", children: view.plan.name }),
6719
+ showDescription && view.plan.description !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "schematic-plan-manager__description", children: view.plan.description })
6720
+ ] }),
6721
+ showPrice && view.plan.price !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Price, { price: view.plan.price, t })
6722
+ ] }),
6723
+ showAddOns && view.addOns.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Section, { label: t("planManagerAddOns"), showLabel: showLabels, children: view.addOns.map((addOn) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("li", { className: "schematic-plan-manager__row", children: [
6724
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-plan-manager__item", children: addOn.name }),
6725
+ addOn.price !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "schematic-plan-manager__price-value", children: [
6726
+ addOn.price.amount,
6727
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PeriodSuffix, { period: addOn.price.period, t })
6728
+ ] })
6729
+ ] }, addOn.id)) }),
6730
+ showUsageBased && view.usageBased.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
6731
+ Section,
6732
+ {
6733
+ label: t("planManagerUsageBased"),
6734
+ showLabel: showLabels,
6735
+ children: view.usageBased.map((row) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
6736
+ UsageBasedItem,
6737
+ {
6738
+ locale,
6739
+ row,
6740
+ showHardLimit,
6741
+ t
6742
+ },
6743
+ row.featureId
6744
+ ))
6745
+ }
6746
+ ),
6747
+ showCredits && credits.data === void 0 && creditsHaveFailed && (credits.error !== void 0 || credits.isPending) && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
6748
+ StatusFrame,
6749
+ {
6750
+ className: "schematic-plan-manager__section",
6751
+ error: credits.error,
6752
+ errorMessage: t("planManagerCreditsError"),
6753
+ hasData: false,
6754
+ isPending: credits.isPending,
6755
+ loadingLabel: t("planManagerCreditsLoading"),
6756
+ onRetry: credits.refetch,
6757
+ retryText: t("retry"),
6758
+ children: null
6759
+ }
6760
+ ),
6761
+ showCredits && view.planCredits.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
6762
+ Truncated,
6763
+ {
6764
+ locale,
6765
+ after: view.autoTopup !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
6766
+ AutoTopupBox,
6767
+ {
6768
+ lines: view.autoTopup.lines,
6769
+ onEdit: onEditAutoTopup,
6770
+ t,
6771
+ target: editAutoTopupTarget,
6772
+ url: editAutoTopupUrl
6773
+ }
6774
+ ),
6775
+ label: t("planManagerCreditsInPlan"),
6776
+ rows: view.planCredits,
6777
+ showLabel: showLabels,
6778
+ t,
6779
+ children: (row) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PlanCreditItem, { row, t }, row.creditId)
6780
+ }
6781
+ ),
6782
+ showCredits && view.topUps.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
6783
+ Truncated,
6784
+ {
6785
+ locale,
6786
+ label: t("planManagerTopUps"),
6787
+ rows: view.topUps,
6788
+ showLabel: showLabels,
6789
+ t,
6790
+ children: (row) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CreditGroupItem, { countAlways: true, row, t }, row.key)
6791
+ }
6792
+ ),
6793
+ showCredits && view.bundles.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
6794
+ Truncated,
6795
+ {
6796
+ locale,
6797
+ label: t("planManagerCreditBundles"),
6798
+ rows: view.bundles,
6799
+ showLabel: showLabels,
6800
+ t,
6801
+ children: (row) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CreditGroupItem, { row, t }, row.key)
6802
+ }
6803
+ ),
6804
+ showCredits && view.promotional.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
6805
+ Truncated,
6806
+ {
6807
+ locale,
6808
+ label: t("planManagerPromotionalCredits"),
6809
+ rows: view.promotional,
6810
+ showLabel: showLabels,
6811
+ t,
6812
+ children: (row) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CreditGroupItem, { plain: true, row, t }, row.key)
6813
+ }
6814
+ ),
6815
+ view.canChangePlan && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
6816
+ Cta,
6817
+ {
6818
+ className: "schematic-cta schematic-plan-manager__change-plan",
6819
+ label: t("planManagerChangePlan"),
6820
+ onClick: onChangePlan,
6821
+ target: changePlanTarget,
6822
+ url: changePlanUrl
6823
+ }
6824
+ )
6825
+ ] })
6826
+ ] })
6827
+ }
6828
+ );
6829
+ }
6830
+ function Notice({
6831
+ locale,
6832
+ notice: notice2,
6833
+ t
6834
+ }) {
6835
+ let title = null;
6836
+ let body = null;
6837
+ let payUrl = null;
6838
+ switch (notice2.kind) {
6839
+ case "trial":
6840
+ title = notice2.endsIn === null ? null : notice2.endsIn === "soon" ? t("planManagerTrialEndsSoon") : notice2.endsIn === "ended" ? t("planManagerTrialEnded") : t("planManagerTrialEndsIn", {
6841
+ amount: formatNumber(notice2.endsIn.amount, locale),
6842
+ units: t(UNIT_KEY[notice2.endsIn.unit], {
6843
+ count: notice2.endsIn.amount
6844
+ })
6845
+ });
6846
+ break;
6847
+ case "canceled":
6848
+ title = t("planManagerCanceled");
6849
+ body = notice2.date === null ? null : t("planManagerAccessEnds", {
6850
+ date: notice2.date,
6851
+ plan: notice2.planName ?? t("planManagerPlanFallback")
6852
+ });
6853
+ break;
6854
+ case "customPlanBilling": {
6855
+ const plan = notice2.planName ?? t("planManagerYourPlan");
6856
+ title = notice2.awaitingActivation ? t("planManagerCustomAwaiting", { plan }) : t("planManagerCustomDue", { date: notice2.date, plan });
6857
+ body = notice2.awaitingActivation ? t("planManagerCustomAwaitingDescription", { date: notice2.date }) : t("planManagerCustomDueDescription", { date: notice2.date, plan });
6858
+ payUrl = notice2.invoiceUrl;
6859
+ break;
6860
+ }
6861
+ case "scheduledDowngrade":
6862
+ title = t("planManagerDowngradeScheduled", { plan: notice2.toPlanName });
6863
+ body = notice2.date === null ? null : t("planManagerAccessEnds", {
6864
+ date: notice2.date,
6865
+ plan: notice2.fromPlanName
6866
+ });
6867
+ break;
6868
+ }
6869
+ if (title === null && body === null) {
6870
+ return null;
6871
+ }
6872
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
6873
+ "div",
6874
+ {
6875
+ className: "schematic-plan-manager__notice",
6876
+ "data-kind": notice2.kind,
6877
+ role: "status",
6878
+ children: [
6879
+ title !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "schematic-plan-manager__notice-title", children: title }),
6880
+ body !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "schematic-small schematic-plan-manager__notice-body", children: body }),
6881
+ payUrl !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
6882
+ "a",
6883
+ {
6884
+ className: "schematic-cta schematic-plan-manager__pay-now",
6885
+ href: payUrl,
6886
+ rel: "noreferrer",
6887
+ target: "_blank",
6888
+ children: t("planManagerPayNow")
6889
+ }
6890
+ )
6891
+ ]
6892
+ }
6893
+ );
6894
+ }
6895
+ function Price({ price, t }) {
6896
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "schematic-plan-manager__price", children: [
6897
+ price.kind === "usageBased" ? t("planManagerUsageBased") : price.kind === "free" ? t("planManagerFree") : price.amount,
6898
+ price.kind === "amount" && price.period !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PeriodSuffix, { period: price.period, t })
6899
+ ] });
6900
+ }
6901
+ function PeriodSuffix({ period, t }) {
6902
+ const short = shortPeriod(period, t);
6903
+ return short === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("sub", { children: [
6904
+ "/",
6905
+ short
6906
+ ] });
6907
+ }
6908
+ function Section({
6909
+ children,
6910
+ label,
6911
+ showLabel
6912
+ }) {
6913
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("section", { "aria-label": label, className: "schematic-plan-manager__section", children: [
6914
+ showLabel && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-muted schematic-plan-manager__label", children: label }),
6915
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("ul", { className: "schematic-plan-manager__rows", children })
6916
+ ] });
6917
+ }
6918
+ function Truncated({
6919
+ after,
6920
+ children,
6921
+ label,
6922
+ locale,
6923
+ rows,
6924
+ showLabel,
6925
+ t
6926
+ }) {
6927
+ const [expanded, setExpanded] = (0, import_react9.useState)(false);
6928
+ const shown = expanded ? rows : rows.slice(0, VISIBLE_CREDIT_COUNT);
6929
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("section", { "aria-label": label, className: "schematic-plan-manager__section", children: [
6930
+ showLabel && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-muted schematic-plan-manager__label", children: label }),
6931
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("ul", { className: "schematic-plan-manager__rows", children: shown.map(children) }),
6932
+ rows.length > VISIBLE_CREDIT_COUNT && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
6933
+ "button",
6934
+ {
6935
+ "aria-expanded": expanded,
6936
+ className: "schematic-link-button schematic-plan-manager__see-all",
6937
+ type: "button",
6938
+ onClick: () => setExpanded((value) => !value),
6939
+ children: [
6940
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
6941
+ "i",
6942
+ {
6943
+ "aria-hidden": "true",
6944
+ className: `schematic-icon schematic-icon--${expanded ? "chevron-up" : "chevron-down"} schematic-chevron`
6945
+ }
6946
+ ),
6947
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-link-button__label", children: expanded ? t("planManagerHideAll") : t("planManagerSeeAll", {
6948
+ total: formatNumber(rows.length, locale)
6949
+ }) })
6950
+ ]
6951
+ }
6952
+ ),
6953
+ after
6954
+ ] });
6955
+ }
6956
+ function UsageBasedItem({
6957
+ locale,
6958
+ row,
6959
+ showHardLimit,
6960
+ t
6961
+ }) {
6962
+ const details = [];
6963
+ if (row.additional) {
6964
+ details.push(`${t("planManagerAdditional")}: `);
6965
+ }
6966
+ if (row.tierBased) {
6967
+ details.push(t("planManagerTierBased"));
6968
+ }
6969
+ if (row.unitPrice !== null) {
6970
+ const short = row.unitPrice.period === null ? void 0 : shortPeriod(row.unitPrice.period, t);
6971
+ details.push(
6972
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { children: [
6973
+ row.unitPrice.cost,
6974
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("sub", { children: [
6975
+ "/",
6976
+ row.unitPrice.packageSize !== null && `${row.unitPrice.packageSize} `,
6977
+ row.unitPrice.units,
6978
+ short !== void 0 && `/${short}`
6979
+ ] })
6980
+ ] }, "price")
6981
+ );
6982
+ }
6983
+ if (row.perUse !== null) {
6984
+ details.push(
6985
+ t("usagePerUse", { amount: row.perUse.amount, units: row.perUse.units })
6986
+ );
6987
+ }
6988
+ const costPeriod = row.cost?.period === null || row.cost === null ? void 0 : shortPeriod(row.cost.period, t);
6989
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
6990
+ "li",
6991
+ {
6992
+ className: "schematic-plan-manager__row",
6993
+ "data-testid": "schematic-usage-based",
6994
+ children: [
6995
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-plan-manager__item", children: row.quantity === null ? row.name : `${row.quantity.amount} ${row.quantity.units}` }),
6996
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "schematic-plan-manager__detail", children: [
6997
+ details.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-muted schematic-small", children: details }),
6998
+ row.cost !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { children: [
6999
+ row.cost.amount,
7000
+ costPeriod !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("sub", { children: [
7001
+ "/",
7002
+ costPeriod
7003
+ ] })
7004
+ ] }),
7005
+ row.tiers !== null && row.tiers.ranges.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
7006
+ PriceTiers,
7007
+ {
7008
+ currency: row.tiers.currency,
7009
+ locale,
7010
+ mode: row.tiers.mode,
7011
+ period: row.tiers.period,
7012
+ ranges: row.tiers.ranges,
7013
+ t,
7014
+ unit: row.tiers.unit
7015
+ }
7016
+ ) }),
7017
+ showHardLimit && row.hardLimit !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
7018
+ amount: row.hardLimit.amount,
7019
+ units: row.hardLimit.units
7020
+ }) })
7021
+ ] })
7022
+ ]
7023
+ }
7024
+ );
7025
+ }
7026
+ function PlanCreditItem({ row, t }) {
7027
+ const text = row.text;
7028
+ const composition = row.composition;
7029
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
7030
+ "li",
7031
+ {
7032
+ className: "schematic-plan-manager__row schematic-plan-manager__row--stacked",
7033
+ "data-testid": "schematic-plan-credit",
7034
+ children: [
7035
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "schematic-plan-manager__row-main", children: [
7036
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-plan-manager__item", children: text.kind === "perLicense" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
7037
+ t("planManagerCreditsPerLicense", {
7038
+ amount: text.amount,
7039
+ creditName: text.creditName,
7040
+ licenseName: text.licenseName
7041
+ }),
7042
+ text.plus !== null && ` ${t("planManagerCreditsPlusPerPeriod", {
7043
+ amount: text.plus.amount,
7044
+ creditName: text.plus.creditName,
7045
+ period: periodWord(text.plus.period, t)
7046
+ })}`
7047
+ ] }) : text.period === null ? t("planManagerCredits", {
7048
+ amount: text.amount,
7049
+ creditName: text.creditName
7050
+ }) : t("planManagerCreditsPerPeriod", {
7051
+ amount: text.amount,
7052
+ creditName: text.creditName,
7053
+ period: periodWord(text.period, t)
7054
+ }) }),
7055
+ row.used !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "schematic-muted schematic-small schematic-plan-manager__used", children: [
7056
+ t("planManagerUsed", { amount: row.used }),
7057
+ row.autoTopup !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Tooltip, { label: t("planManagerAutoTopup"), children: t("planManagerAutoTopupTip", {
7058
+ amount: row.autoTopup.amount,
7059
+ threshold: row.autoTopup.threshold
7060
+ }) })
7061
+ ] })
7062
+ ] }),
7063
+ composition !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-muted schematic-small", children: t(
7064
+ composition.fixed === null ? "planManagerLicensesTimesCredits" : "planManagerLicensesTimesCreditsPlusCompany",
7065
+ {
7066
+ creditName: composition.creditName,
7067
+ fixed: composition.fixed ?? void 0,
7068
+ licenseName: composition.licenseName,
7069
+ period: shortPeriod(composition.period, t) ?? periodWord(composition.period, t),
7070
+ perUnit: composition.perUnit,
7071
+ quantity: composition.quantity,
7072
+ total: composition.total
7073
+ }
7074
+ ) })
7075
+ ]
7076
+ }
7077
+ );
7078
+ }
7079
+ function CreditGroupItem({
7080
+ countAlways = false,
7081
+ plain = false,
7082
+ row,
7083
+ t
7084
+ }) {
7085
+ const named = !plain && row.bundleName !== null;
7086
+ const showCount = !plain && row.count > 1 && (named || countAlways);
7087
+ const amount = `${row.quantity} ${row.creditName}`;
7088
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
7089
+ "li",
7090
+ {
7091
+ className: "schematic-plan-manager__row",
7092
+ "data-testid": "schematic-credit-group",
7093
+ children: [
7094
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "schematic-plan-manager__item", children: [
7095
+ showCount && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "schematic-muted", children: [
7096
+ "(",
7097
+ row.count,
7098
+ ") "
7099
+ ] }),
7100
+ named ? `${row.bundleName} (${amount})` : amount
7101
+ ] }),
7102
+ row.used !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-muted schematic-small schematic-plan-manager__used", children: t("planManagerUsed", { amount: row.used }) })
7103
+ ]
7104
+ }
7105
+ );
7106
+ }
7107
+ function AutoTopupBox({
7108
+ lines,
7109
+ onEdit,
7110
+ t,
7111
+ target,
7112
+ url
7113
+ }) {
7114
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "schematic-plan-manager__auto-topup", children: [
7115
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "schematic-plan-manager__auto-topup-lines", children: [
7116
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "schematic-plan-manager__item", children: t("planManagerAutoTopup") }),
7117
+ lines.map((line) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: line.kind === "disabled" ? t("planManagerAutoTopupDisabled", { unit: line.unit }) : t("planManagerAutoTopupAdds", {
7118
+ amount: line.amount,
7119
+ threshold: line.threshold,
7120
+ unit: line.unit
7121
+ }) }, line.creditId))
7122
+ ] }),
7123
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
7124
+ Cta,
7125
+ {
7126
+ className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-plan-manager__edit",
7127
+ label: t("planManagerEdit"),
7128
+ onClick: onEdit,
7129
+ target,
7130
+ url
7131
+ }
7132
+ )
7133
+ ] });
7134
+ }
7135
+ function Cta({
7136
+ className,
7137
+ label,
7138
+ onClick,
7139
+ target,
7140
+ url
7141
+ }) {
7142
+ if (onClick !== void 0) {
7143
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { className, type: "button", onClick, children: label });
7144
+ }
7145
+ if (url !== void 0) {
7146
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("a", { className, href: url, target, children: label });
7147
+ }
7148
+ return null;
7149
+ }
7150
+ function periodWord(period, t) {
7151
+ const key = PERIOD_KEY[period];
7152
+ return key === void 0 ? period : t(key);
7153
+ }
7154
+ function PlanManagerSkeleton() {
7155
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "schematic-skeleton", children: [
7156
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "schematic-skeleton__heading" }),
7157
+ [0, 1].map((index) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "schematic-skeleton__row", children: [
7158
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
7159
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "price" })
7160
+ ] }, index))
7161
+ ] });
7162
+ }
7163
+ PlanManager.resources = ["company", "featureUsage", "creditBalances"];
7164
+
7165
+ // src/elements/UnsubscribeButton.tsx
7166
+ var import_schematic_react9 = require("@schematichq/schematic-react");
7167
+ var import_react10 = require("react");
7168
+ var import_jsx_runtime11 = require("react/jsx-runtime");
7169
+ var TOTAL_KEY = {
7170
+ quarter: "unsubscribeQuarterlyTotal",
7171
+ year: "unsubscribeYearlyTotal"
7172
+ };
7173
+ function UnsubscribeButton({
7174
+ className,
7175
+ locale: localeProp,
7176
+ managePlanTarget,
7177
+ managePlanUrl,
7178
+ onManagePlan,
7179
+ onUnsubscribed,
7180
+ strings
7181
+ }) {
7182
+ const company = (0, import_schematic_react9.useCompany)();
7183
+ const usage = (0, import_schematic_react9.useFeatureUsage)();
7184
+ const { isMutating, unsubscribe } = (0, import_schematic_react9.useUnsubscribe)();
7185
+ const locale = useResolvedLocale(localeProp);
7186
+ const t = useTranslator(strings, localeProp);
7187
+ const [open, setOpen] = (0, import_react10.useState)(false);
7188
+ const [failed, setFailed] = (0, import_react10.useState)(false);
7189
+ const view = (0, import_react10.useMemo)(
7190
+ () => company.data === void 0 || usage.data === void 0 ? void 0 : deriveUnsubscribe(company.data, usage.data, { locale }),
7191
+ [company.data, locale, usage.data]
7192
+ );
7193
+ if (view === void 0) {
7194
+ const error = company.error ?? usage.error;
7195
+ if (error === void 0) {
7196
+ return null;
7197
+ }
7198
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
7199
+ StatusFrame,
7200
+ {
7201
+ className: cx("schematic-card", "schematic-unsubscribe", className),
7202
+ error,
7203
+ errorMessage: httpStatus(error) === 404 ? t("unsubscribeUnavailable") : t("unsubscribeError"),
7204
+ hasData: false,
7205
+ isPending: false,
7206
+ loadingLabel: "",
7207
+ onRetry: () => {
7208
+ for (const handle of [company, usage]) {
7209
+ if (handle.error !== void 0) {
7210
+ handle.refetch();
7211
+ }
7212
+ }
7213
+ },
7214
+ retryText: t("retry"),
7215
+ children: null
7216
+ }
7217
+ );
7218
+ }
7219
+ if (!view.canUnsubscribe && !open) {
7220
+ return null;
7221
+ }
7222
+ const close = () => {
7223
+ setOpen(false);
7224
+ setFailed(false);
7225
+ };
7226
+ const confirm = async () => {
7227
+ setFailed(false);
7228
+ try {
7229
+ await unsubscribe();
7230
+ } catch {
7231
+ setFailed(true);
7232
+ return;
7233
+ }
7234
+ setOpen(false);
7235
+ onUnsubscribed?.();
7236
+ };
7237
+ const per = shortPeriod(view.period, t);
7238
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: cx("schematic-card", "schematic-unsubscribe", className), children: [
7239
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
7240
+ "button",
7241
+ {
7242
+ className: "schematic-cta schematic-unsubscribe__open",
7243
+ type: "button",
7244
+ onClick: () => {
7245
+ setFailed(false);
7246
+ setOpen(true);
7247
+ },
7248
+ children: t("unsubscribeButton")
7249
+ }
7250
+ ),
7251
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
7252
+ Dialog,
7253
+ {
7254
+ className: "schematic-unsubscribe__dialog",
7255
+ closeLabel: t("unsubscribeClose"),
7256
+ open,
7257
+ title: t("unsubscribeTitle"),
7258
+ onClose: close,
7259
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "schematic-unsubscribe__columns", children: [
7260
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "schematic-unsubscribe__summary", children: [
7261
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { children: t("unsubscribeAccessUntil", { date: view.accessEndsOn }) }),
7262
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
7263
+ ManagePlan,
7264
+ {
7265
+ onClick: onManagePlan,
7266
+ t,
7267
+ target: managePlanTarget,
7268
+ url: managePlanUrl
7269
+ }
7270
+ )
7271
+ ] }),
7272
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "schematic-unsubscribe__sidebar", children: [
7273
+ view.plan !== null && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "schematic-unsubscribe__group", children: [
7274
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "schematic-muted schematic-small", children: t("unsubscribePlan") }),
7275
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "schematic-unsubscribe__line", children: [
7276
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "schematic-unsubscribe__name", children: view.plan.name }),
7277
+ view.plan.price !== null && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { children: [
7278
+ view.plan.price,
7279
+ per !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("sub", { children: [
7280
+ "/",
7281
+ per
7282
+ ] })
7283
+ ] })
7284
+ ] })
7285
+ ] }),
7286
+ view.addOns.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "schematic-unsubscribe__group", children: [
7287
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "schematic-muted schematic-small", children: t("unsubscribeAddOns") }),
7288
+ view.addOns.map((addOn) => /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "schematic-unsubscribe__line", children: [
7289
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "schematic-unsubscribe__name", children: addOn.name }),
7290
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { children: [
7291
+ addOn.price,
7292
+ !addOn.oneTime && per !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("sub", { children: [
7293
+ "/",
7294
+ per
7295
+ ] })
7296
+ ] })
7297
+ ] }, addOn.id))
7298
+ ] }),
7299
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "schematic-unsubscribe__line schematic-unsubscribe__total", children: [
7300
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "schematic-muted", children: t(TOTAL_KEY[view.period] ?? "unsubscribeMonthlyTotal") }),
7301
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { children: [
7302
+ view.total,
7303
+ per !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("sub", { children: [
7304
+ "/",
7305
+ per
7306
+ ] })
7307
+ ] })
7308
+ ] }),
7309
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
7310
+ "button",
7311
+ {
7312
+ className: "schematic-cta schematic-unsubscribe__confirm",
7313
+ disabled: isMutating,
7314
+ type: "button",
7315
+ onClick: () => void confirm(),
7316
+ children: t("unsubscribeConfirm")
7317
+ }
7318
+ ),
7319
+ failed && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: "schematic-error", role: "alert", children: t("unsubscribeFailed") })
7320
+ ] })
7321
+ ] })
7322
+ }
7323
+ )
7324
+ ] });
7325
+ }
7326
+ function ManagePlan({
7327
+ onClick,
7328
+ t,
7329
+ target,
7330
+ url
7331
+ }) {
7332
+ if (onClick === void 0 && url === void 0) {
7333
+ return null;
7334
+ }
7335
+ const label = t("unsubscribeManagePlan");
7336
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "schematic-unsubscribe__manage", children: [
7337
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { children: t("unsubscribeNotReady") }),
7338
+ onClick !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
7339
+ "button",
7340
+ {
7341
+ className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-unsubscribe__manage-plan",
7342
+ type: "button",
7343
+ onClick,
7344
+ children: label
7345
+ }
7346
+ ) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
7347
+ "a",
7348
+ {
7349
+ className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-unsubscribe__manage-plan",
7350
+ href: url,
7351
+ target,
7352
+ children: label
7353
+ }
7354
+ )
7355
+ ] });
7356
+ }
7357
+ UnsubscribeButton.resources = ["company", "featureUsage"];
7358
+
5278
7359
  // src/elements/UpcomingBill.tsx
5279
- var import_schematic_react7 = require("@schematichq/schematic-react");
5280
- var import_react8 = require("react");
5281
- var import_jsx_runtime9 = require("react/jsx-runtime");
7360
+ var import_schematic_react10 = require("@schematichq/schematic-react");
7361
+ var import_react11 = require("react");
7362
+ var import_jsx_runtime12 = require("react/jsx-runtime");
5282
7363
  function UpcomingBill({
5283
7364
  className,
5284
7365
  headingLevel = 2,
@@ -5289,10 +7370,10 @@ function UpcomingBill({
5289
7370
  showHeader = true,
5290
7371
  strings
5291
7372
  }) {
5292
- const { data: invoice, error, isPending, refetch } = (0, import_schematic_react7.useUpcomingInvoice)();
7373
+ const { data: invoice, error, isPending, refetch } = (0, import_schematic_react10.useUpcomingInvoice)();
5293
7374
  const locale = useResolvedLocale(localeProp);
5294
7375
  const t = useTranslator(strings, localeProp);
5295
- const bill = (0, import_react8.useMemo)(
7376
+ const bill = (0, import_react11.useMemo)(
5296
7377
  () => invoice === void 0 || invoice === null ? null : deriveUpcomingInvoice(invoice, { locale }),
5297
7378
  [invoice, locale]
5298
7379
  );
@@ -5301,7 +7382,7 @@ function UpcomingBill({
5301
7382
  const discountRow = showDiscounts && bill !== null && bill.discounts.length > 0;
5302
7383
  const unavailable = invoice === void 0 && httpStatus(error) === 404;
5303
7384
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("upcomingBillUnavailable") : t("upcomingBillError");
5304
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
7385
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
5305
7386
  StatusFrame,
5306
7387
  {
5307
7388
  className: cx("schematic-card", "schematic-upcoming-bill", className),
@@ -5312,11 +7393,11 @@ function UpcomingBill({
5312
7393
  loadingLabel: t("upcomingBillLoading"),
5313
7394
  onRetry: refetch,
5314
7395
  retryText: t("retry"),
5315
- skeleton: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(UpcomingBillSkeleton, { showHeader }),
5316
- children: bill === null ? invoice !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
5317
- showHeader && bill.dueAt !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Heading, { className: "schematic-header__title", children: t("upcomingBillHeader", { date: bill.dueAt.text }) }) }),
5318
- showAmount && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "schematic-upcoming-bill__amount", children: [
5319
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
7396
+ skeleton: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(UpcomingBillSkeleton, { showHeader }),
7397
+ children: bill === null ? invoice !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
7398
+ showHeader && bill.dueAt !== null && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "schematic-header", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Heading, { className: "schematic-header__title", children: t("upcomingBillHeader", { date: bill.dueAt.text }) }) }),
7399
+ showAmount && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "schematic-upcoming-bill__amount", children: [
7400
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
5320
7401
  "span",
5321
7402
  {
5322
7403
  className: "schematic-upcoming-bill__total",
@@ -5324,46 +7405,46 @@ function UpcomingBill({
5324
7405
  children: bill.amountDueText
5325
7406
  }
5326
7407
  ),
5327
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
7408
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
5328
7409
  ] }),
5329
- (balanceRows || discountRow) && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "schematic-upcoming-bill__rows", children: [
5330
- balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
7410
+ (balanceRows || discountRow) && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "schematic-upcoming-bill__rows", children: [
7411
+ balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
5331
7412
  "div",
5332
7413
  {
5333
7414
  className: "schematic-row schematic-upcoming-bill__balance-applied",
5334
7415
  "data-testid": "schematic-balance-applied",
5335
7416
  children: [
5336
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
5337
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
7417
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
7418
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
5338
7419
  ]
5339
7420
  }
5340
7421
  ),
5341
- balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
7422
+ balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
5342
7423
  "div",
5343
7424
  {
5344
7425
  className: "schematic-row schematic-upcoming-bill__balance-remaining",
5345
7426
  "data-testid": "schematic-balance-remaining",
5346
7427
  children: [
5347
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
5348
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
7428
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
7429
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
5349
7430
  ]
5350
7431
  }
5351
7432
  ),
5352
- discountRow && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
7433
+ discountRow && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
5353
7434
  "div",
5354
7435
  {
5355
7436
  className: "schematic-row schematic-upcoming-bill__discount-row",
5356
7437
  "data-testid": "schematic-discounts",
5357
7438
  children: [
5358
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
5359
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
7439
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
7440
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
5360
7441
  "li",
5361
7442
  {
5362
7443
  className: "schematic-upcoming-bill__discount",
5363
7444
  "data-testid": "schematic-discount",
5364
7445
  children: [
5365
- discount.code !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
5366
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
7446
+ discount.code !== null && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
7447
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
5367
7448
  ]
5368
7449
  },
5369
7450
  `${discount.couponName}-${index}`
@@ -5377,10 +7458,10 @@ function UpcomingBill({
5377
7458
  );
5378
7459
  }
5379
7460
  function UpcomingBillSkeleton({ showHeader }) {
5380
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "schematic-skeleton", children: [
5381
- showHeader && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__heading" }),
5382
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
5383
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
7461
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "schematic-skeleton", children: [
7462
+ showHeader && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "schematic-skeleton__heading" }),
7463
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
7464
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
5384
7465
  ] });
5385
7466
  }
5386
7467
  function discountText(discount, t) {