@schematichq/schematic-components 2.31.0 → 2.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,13 +45,15 @@ var init_tokens = __esm({
45
45
  "hsla(0, 0%, 0%, 0.175)",
46
46
  "hsla(0, 0%, 100%, 0.2)"
47
47
  ),
48
- "--schematic-card-padding": "2.8125rem",
48
+ // 45px from a 750px viewport up; narrower screens give the content the
49
+ // room instead (about 22px on a 375px phone).
50
+ "--schematic-card-padding": "min(2.8125rem, 6vw)",
49
51
  "--schematic-danger": ld("#d75a5c", "#ff6b6e"),
50
52
  "--schematic-font-body": '"Public Sans", system-ui, sans-serif',
51
53
  "--schematic-font-heading": '"Manrope", system-ui, sans-serif',
52
54
  // Link buttons' face: Edit, Set default, Try again, and the rest.
53
55
  "--schematic-font-link": '"Inter", system-ui, sans-serif',
54
- "--schematic-line-height": "1.5",
56
+ "--schematic-line-height": "1.375",
55
57
  "--schematic-line-height-heading": "1.2",
56
58
  "--schematic-meter-track": ld("#f2f4f7", "#26282d"),
57
59
  "--schematic-muted": ld("#8a8a8a", "#a1a1a1"),
@@ -85,8 +87,8 @@ __export(PaymentMethodForm_exports, {
85
87
  resolveAppearance: () => resolveAppearance
86
88
  });
87
89
  import { useSetupIntent } from "@schematichq/schematic-react";
88
- import { useEffect as useEffect2, useId as useId3, useRef as useRef2, useState as useState2 } from "react";
89
- import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
90
+ import { useEffect as useEffect2, useId as useId3, useRef as useRef2, useState as useState4 } from "react";
91
+ import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
90
92
  function orUndefined(value) {
91
93
  return value === void 0 || value === "" ? void 0 : value;
92
94
  }
@@ -108,13 +110,27 @@ function resolveAppearance(host) {
108
110
  fontFamily: style.fontFamily
109
111
  };
110
112
  probe.remove();
111
- const variables = {};
113
+ const variables = {
114
+ gridColumnSpacing: "1.5rem",
115
+ gridRowSpacing: "1.5rem",
116
+ spacingUnit: "0.25rem"
117
+ };
112
118
  for (const [name, value] of Object.entries(candidates)) {
113
119
  if (resolved(value)) {
114
120
  variables[name] = value;
115
121
  }
116
122
  }
117
- return { theme: "stripe", variables };
123
+ return {
124
+ theme: "stripe",
125
+ variables,
126
+ rules: {
127
+ ".Label": {
128
+ fontSize: "1rem",
129
+ fontWeight: "400",
130
+ marginBottom: "0.75rem"
131
+ }
132
+ }
133
+ };
118
134
  }
119
135
  function PaymentMethodForm({
120
136
  checkoutPrefill,
@@ -125,7 +141,7 @@ function PaymentMethodForm({
125
141
  t
126
142
  }) {
127
143
  const { create } = useSetupIntent();
128
- const [state, setState] = useState2({ status: "loading" });
144
+ const [state, setState] = useState4({ status: "loading" });
129
145
  const hostRef = useRef2(null);
130
146
  useEffect2(() => {
131
147
  let cancelled = false;
@@ -173,7 +189,7 @@ function PaymentMethodForm({
173
189
  };
174
190
  }, [create, locale]);
175
191
  if (state.status === "loading") {
176
- return /* @__PURE__ */ jsxs3(
192
+ return /* @__PURE__ */ jsxs6(
177
193
  "div",
178
194
  {
179
195
  "aria-busy": "true",
@@ -181,15 +197,15 @@ function PaymentMethodForm({
181
197
  "data-state": "pending",
182
198
  ref: hostRef,
183
199
  children: [
184
- /* @__PURE__ */ jsx4("span", { className: "schematic-hidden", children: t("paymentMethodsFormLoading") }),
185
- /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton", children: /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
200
+ /* @__PURE__ */ jsx7("span", { className: "schematic-hidden", children: t("paymentMethodsFormLoading") }),
201
+ /* @__PURE__ */ jsx7("div", { className: "schematic-skeleton", children: /* @__PURE__ */ jsx7("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx7("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
186
202
  ]
187
203
  }
188
204
  );
189
205
  }
190
206
  if (state.status === "failed") {
191
- return /* @__PURE__ */ jsxs3("div", { className: "schematic-payment-methods__form", "data-state": "error", children: [
192
- /* @__PURE__ */ jsx4(
207
+ return /* @__PURE__ */ jsxs6("div", { className: "schematic-payment-methods__form", "data-state": "error", children: [
208
+ /* @__PURE__ */ jsx7(
193
209
  "p",
194
210
  {
195
211
  className: "schematic-error schematic-small schematic-payment-methods__form-error",
@@ -197,11 +213,11 @@ function PaymentMethodForm({
197
213
  children: t(state.errorKey)
198
214
  }
199
215
  ),
200
- onSelectExisting !== void 0 && /* @__PURE__ */ jsx4(SelectExisting, { t, onSelectExisting })
216
+ onSelectExisting !== void 0 && /* @__PURE__ */ jsx7(SelectExisting, { t, onSelectExisting })
201
217
  ] });
202
218
  }
203
219
  const { Elements } = state.ui;
204
- return /* @__PURE__ */ jsx4(
220
+ return /* @__PURE__ */ jsx7(
205
221
  Elements,
206
222
  {
207
223
  stripe: state.stripe,
@@ -209,7 +225,7 @@ function PaymentMethodForm({
209
225
  appearance: state.appearance,
210
226
  clientSecret: state.clientSecret
211
227
  },
212
- children: /* @__PURE__ */ jsx4(
228
+ children: /* @__PURE__ */ jsx7(
213
229
  Fields,
214
230
  {
215
231
  checkoutPrefill,
@@ -241,13 +257,13 @@ function Fields({
241
257
  const emailId = useId3();
242
258
  const stripe = useStripe();
243
259
  const elements = useElements();
244
- const [saving, setSaving] = useState2(false);
245
- const [message, setMessage] = useState2(null);
246
- const [complete, setComplete] = useState2(false);
247
- const [ready, setReady] = useState2(false);
248
- const [loadFailed, setLoadFailed] = useState2(false);
249
- const [addressComplete, setAddressComplete] = useState2(!collectAddress);
250
- const [typedEmail, setTypedEmail] = useState2(null);
260
+ const [saving, setSaving] = useState4(false);
261
+ const [message, setMessage] = useState4(null);
262
+ const [complete, setComplete] = useState4(false);
263
+ const [ready, setReady] = useState4(false);
264
+ const [loadFailed, setLoadFailed] = useState4(false);
265
+ const [addressComplete, setAddressComplete] = useState4(!collectAddress);
266
+ const [typedEmail, setTypedEmail] = useState4(null);
251
267
  const email = typedEmail ?? orUndefined(prefill?.email) ?? "";
252
268
  const emailValid = !collectEmail || VALID_EMAIL.test(email);
253
269
  useEffect2(() => {
@@ -302,14 +318,14 @@ function Fields({
302
318
  setSaving(false);
303
319
  }
304
320
  };
305
- return /* @__PURE__ */ jsxs3(
321
+ return /* @__PURE__ */ jsxs6(
306
322
  "form",
307
323
  {
308
324
  className: "schematic-payment-methods__form",
309
325
  "data-state": "ready",
310
326
  onSubmit: (event) => void submit(event),
311
327
  children: [
312
- /* @__PURE__ */ jsx4("div", { className: "schematic-payment-methods__fields", children: /* @__PURE__ */ jsx4(
328
+ /* @__PURE__ */ jsx7("div", { className: "schematic-payment-methods__fields", children: /* @__PURE__ */ jsx7(
313
329
  PaymentElement,
314
330
  {
315
331
  onChange: (event) => setComplete(event.complete),
@@ -320,8 +336,8 @@ function Fields({
320
336
  }
321
337
  }
322
338
  ) }),
323
- collectEmail && /* @__PURE__ */ jsxs3("div", { className: "schematic-payment-methods__field", children: [
324
- /* @__PURE__ */ jsx4(
339
+ collectEmail && /* @__PURE__ */ jsxs6("div", { className: "schematic-payment-methods__field", children: [
340
+ /* @__PURE__ */ jsx7(
325
341
  "label",
326
342
  {
327
343
  className: "schematic-payment-methods__field-label",
@@ -329,7 +345,7 @@ function Fields({
329
345
  children: t("paymentMethodsEmail")
330
346
  }
331
347
  ),
332
- /* @__PURE__ */ jsx4(
348
+ /* @__PURE__ */ jsx7(
333
349
  "input",
334
350
  {
335
351
  autoComplete: "email",
@@ -343,7 +359,7 @@ function Fields({
343
359
  }
344
360
  )
345
361
  ] }),
346
- showAddress && /* @__PURE__ */ jsx4("div", { className: "schematic-payment-methods__address", children: /* @__PURE__ */ jsx4(
362
+ showAddress && /* @__PURE__ */ jsx7("div", { className: "schematic-payment-methods__address", children: /* @__PURE__ */ jsx7(
347
363
  AddressElement,
348
364
  {
349
365
  options: {
@@ -357,7 +373,7 @@ function Fields({
357
373
  },
358
374
  prefillName ?? ""
359
375
  ) }),
360
- loadFailed && /* @__PURE__ */ jsx4(
376
+ loadFailed && /* @__PURE__ */ jsx7(
361
377
  "p",
362
378
  {
363
379
  className: "schematic-error schematic-small schematic-payment-methods__form-error",
@@ -365,7 +381,7 @@ function Fields({
365
381
  children: t("paymentMethodsFormError")
366
382
  }
367
383
  ),
368
- message !== null && /* @__PURE__ */ jsx4(
384
+ message !== null && /* @__PURE__ */ jsx7(
369
385
  "p",
370
386
  {
371
387
  className: "schematic-error schematic-small schematic-payment-methods__form-error",
@@ -373,7 +389,7 @@ function Fields({
373
389
  children: message
374
390
  }
375
391
  ),
376
- /* @__PURE__ */ jsx4(
392
+ /* @__PURE__ */ jsx7(
377
393
  "button",
378
394
  {
379
395
  className: "schematic-cta schematic-payment-methods__save",
@@ -382,7 +398,7 @@ function Fields({
382
398
  children: saving ? t("paymentMethodsSaving") : t("paymentMethodsSave")
383
399
  }
384
400
  ),
385
- onSelectExisting !== void 0 && /* @__PURE__ */ jsx4(
401
+ onSelectExisting !== void 0 && /* @__PURE__ */ jsx7(
386
402
  SelectExisting,
387
403
  {
388
404
  disabled: saving,
@@ -399,7 +415,7 @@ function SelectExisting({
399
415
  onSelectExisting,
400
416
  t
401
417
  }) {
402
- return /* @__PURE__ */ jsx4(
418
+ return /* @__PURE__ */ jsx7(
403
419
  "button",
404
420
  {
405
421
  className: "schematic-link-button schematic-payment-methods__select-existing",
@@ -421,7 +437,7 @@ var init_PaymentMethodForm = __esm({
421
437
  [
422
438
  "background-color: var(--schematic-background)",
423
439
  "border-color: var(--schematic-accent)",
424
- "border-radius: var(--schematic-radius)",
440
+ "border-radius: calc(var(--schematic-radius) * 0.8)",
425
441
  "color: var(--schematic-text)",
426
442
  "font-family: var(--schematic-font-body)",
427
443
  "outline-color: var(--schematic-danger)",
@@ -438,7 +454,10 @@ var init_PaymentMethodForm = __esm({
438
454
  // src/elements/index.ts
439
455
  import {
440
456
  BillingDataProvider,
457
+ FEATURE_USER_USAGE_LIMIT,
441
458
  SchematicI18nProvider,
459
+ useFeatureUsage as useFeatureUsage3,
460
+ useFeatureUserUsage as useFeatureUserUsage2,
442
461
  useInvalidateBillingData,
443
462
  useInvoices as useInvoices2,
444
463
  usePaymentMethods as usePaymentMethods2,
@@ -1209,6 +1228,456 @@ function derivePaymentMethods(methods, options) {
1209
1228
  };
1210
1229
  }
1211
1230
 
1231
+ // src/elements/model/featureUsage.ts
1232
+ function pricePeriod(price) {
1233
+ if (price === void 0) {
1234
+ return null;
1235
+ }
1236
+ if (price.interval === "month" && price.intervalCount === 3) {
1237
+ return "quarter";
1238
+ }
1239
+ return price.interval;
1240
+ }
1241
+ function isTieredPrice(price) {
1242
+ return price !== void 0 && (price.priceTiers.length > 1 || price.tiersMode !== void 0 && price.tiersMode !== null);
1243
+ }
1244
+ function unitPrice(price) {
1245
+ return decimalOr(price.priceDecimal, price.price);
1246
+ }
1247
+ function usageLimit(row, options = {}) {
1248
+ let limit = null;
1249
+ const behavior = row.priceBehavior ?? null;
1250
+ if ((behavior === null || behavior === "pay_in_advance") && typeof row.allocation === "number") {
1251
+ limit = row.allocation;
1252
+ } else if (behavior === "overage" && typeof row.softLimit === "number") {
1253
+ limit = row.softLimit;
1254
+ }
1255
+ if (options.showWarningThresholdAsLimit === true && typeof row.warningThreshold === "number") {
1256
+ limit = row.warningThreshold;
1257
+ }
1258
+ return limit;
1259
+ }
1260
+ function currentTier(row) {
1261
+ const tiers = row.price?.priceTiers ?? [];
1262
+ if (row.priceBehavior === "overage" && typeof row.softLimit === "number") {
1263
+ const overage = tiers.length === 2 ? tiers[1] : void 0;
1264
+ return overage === void 0 ? null : { ...tierRange(overage), from: row.softLimit + 1 };
1265
+ }
1266
+ if (row.priceBehavior === "tier" && typeof row.usage === "number") {
1267
+ const usage = row.usage;
1268
+ const tier = tiers.find(
1269
+ (t) => usage >= t.from && (t.to === void 0 || t.to === null || usage <= t.to)
1270
+ );
1271
+ return tier === void 0 ? null : tierRange(tier);
1272
+ }
1273
+ return null;
1274
+ }
1275
+ function tierRanges(price) {
1276
+ return (price?.priceTiers ?? []).map((tier, index) => {
1277
+ const range = tierRange(tier);
1278
+ return index === 0 ? { ...range, from: Math.max(1, range.from) } : range;
1279
+ });
1280
+ }
1281
+ function tierRange(tier) {
1282
+ return {
1283
+ from: tier.from,
1284
+ to: tier.to ?? null,
1285
+ flatPrice: tier.flatPrice ?? null,
1286
+ perUnitPrice: tier.perUnitPriceDecimal !== void 0 && tier.perUnitPriceDecimal !== null ? decimalOr(tier.perUnitPriceDecimal, tier.perUnitPrice ?? 0) : tier.perUnitPrice ?? null
1287
+ };
1288
+ }
1289
+ function decimalOr(decimal, fallback) {
1290
+ if (decimal === void 0 || decimal === null) {
1291
+ return fallback;
1292
+ }
1293
+ const parsed = Number(decimal);
1294
+ return Number.isFinite(parsed) ? parsed : fallback;
1295
+ }
1296
+
1297
+ // src/elements/model/includedFeatures.ts
1298
+ function deriveIncludedFeatures(features, options) {
1299
+ const ordered = options.visibleFeatures === void 0 ? features : options.visibleFeatures.flatMap((id) => {
1300
+ const row = features.find((f) => f.featureId === id);
1301
+ return row === void 0 ? [] : [row];
1302
+ });
1303
+ return ordered.map((row) => includedFeatureRow(row, options));
1304
+ }
1305
+ function includedFeatureRow(row, options) {
1306
+ const { locale } = options;
1307
+ const feature = {
1308
+ name: row.featureName,
1309
+ singularName: row.featureSingularName,
1310
+ pluralName: row.featurePluralName
1311
+ };
1312
+ const expiresAt = usableDate(row.expiresAt);
1313
+ const tiered = row.priceBehavior === "pay_in_advance" && isTieredPrice(row.price);
1314
+ const period = pricePeriod(row.price);
1315
+ return {
1316
+ featureId: row.featureId,
1317
+ name: row.featureName,
1318
+ description: nonEmpty(row.featureDescription),
1319
+ icon: nonEmpty(row.featureIcon),
1320
+ perLicenseCredits: row.perLicenseCreditGrants.filter((grant) => grant.scaling === "per_license").map((grant) => ({
1321
+ amount: grant.creditAmount,
1322
+ creditName: featureName(
1323
+ {
1324
+ name: grant.creditName,
1325
+ singularName: grant.creditSingularName,
1326
+ pluralName: grant.creditPluralName
1327
+ },
1328
+ grant.creditAmount,
1329
+ locale
1330
+ ),
1331
+ licenseName: featureName(feature, 1, locale)
1332
+ })),
1333
+ expiresAt: expiresAt === void 0 ? null : {
1334
+ date: expiresAt,
1335
+ text: formatDate(expiresAt, locale, { month: "short" })
1336
+ },
1337
+ entitlement: entitlementText(row, options),
1338
+ usage: usageSegments(row, locale, tiered, period),
1339
+ usageSummary: usageSummary(row, options),
1340
+ hardLimit: row.priceBehavior !== void 0 && row.priceBehavior !== null && row.priceBehavior !== "credit_burndown" && row.valueType === "numeric" && typeof row.allocation === "number" ? {
1341
+ amount: row.allocation,
1342
+ units: featureName(feature, row.allocation, locale)
1343
+ } : null,
1344
+ tiers: (row.priceBehavior === "tier" || tiered) && row.price !== void 0 ? {
1345
+ ranges: tierRanges(row.price),
1346
+ currency: row.price.currency,
1347
+ mode: row.price.tiersMode ?? null,
1348
+ period
1349
+ } : null,
1350
+ source: row
1351
+ };
1352
+ }
1353
+ function isMetered(row) {
1354
+ return row.featureType === "event" || row.featureType === "trait";
1355
+ }
1356
+ function entitlementText(row, options) {
1357
+ if (!isMetered(row)) {
1358
+ return null;
1359
+ }
1360
+ const { locale } = options;
1361
+ const feature = {
1362
+ name: row.featureName,
1363
+ singularName: row.featureSingularName,
1364
+ pluralName: row.featurePluralName
1365
+ };
1366
+ const units = (count) => ({
1367
+ amount: formatNumber(count, locale),
1368
+ units: featureName(feature, count, locale)
1369
+ });
1370
+ switch (row.priceBehavior) {
1371
+ case "pay_in_advance":
1372
+ return typeof row.allocation === "number" ? { kind: "units", ...units(row.allocation) } : null;
1373
+ case "pay_as_you_go": {
1374
+ if (row.price === void 0) {
1375
+ return null;
1376
+ }
1377
+ const cost = formatCurrency(
1378
+ unitPrice(row.price),
1379
+ row.price.currency,
1380
+ locale
1381
+ );
1382
+ const size = row.price.packageSize;
1383
+ return size > 1 ? {
1384
+ kind: "perPackage",
1385
+ cost,
1386
+ size,
1387
+ units: featureName(feature, size, locale)
1388
+ } : { kind: "perUnit", cost, unit: featureName(feature, 1, locale) };
1389
+ }
1390
+ case "overage":
1391
+ return typeof row.softLimit === "number" ? { kind: "units", ...units(row.softLimit) } : null;
1392
+ case "tier": {
1393
+ const tier = currentTier(row);
1394
+ if (tier === null) {
1395
+ return null;
1396
+ }
1397
+ return tier.to === null ? { kind: "tierUnlimited", feature: featureName(feature, 0, locale) } : {
1398
+ kind: "tierUpTo",
1399
+ amount: formatNumber(tier.to, locale),
1400
+ feature: featureName(feature, tier.to, locale)
1401
+ };
1402
+ }
1403
+ case "credit_burndown":
1404
+ if (options.showCredits === false || typeof row.consumptionRate !== "number" || row.creditName === void 0 || row.creditName === null) {
1405
+ return null;
1406
+ }
1407
+ return {
1408
+ kind: "perUse",
1409
+ amount: formatConsumptionRate(row.consumptionRate, locale),
1410
+ units: featureName(
1411
+ {
1412
+ name: row.creditName,
1413
+ singularName: row.creditSingularName,
1414
+ pluralName: row.creditPluralName
1415
+ },
1416
+ row.consumptionRate,
1417
+ locale
1418
+ )
1419
+ };
1420
+ default:
1421
+ break;
1422
+ }
1423
+ if (typeof row.allocation === "number") {
1424
+ const limit = usageLimit(row, options) ?? row.allocation;
1425
+ return { kind: "units", ...units(limit) };
1426
+ }
1427
+ if (row.valueType === "unlimited") {
1428
+ return { kind: "unlimited", item: featureName(feature, 0, locale) };
1429
+ }
1430
+ return null;
1431
+ }
1432
+ function usageSegments(row, locale, tiered, period) {
1433
+ if (!isMetered(row)) {
1434
+ return [];
1435
+ }
1436
+ const feature = {
1437
+ name: row.featureName,
1438
+ singularName: row.featureSingularName,
1439
+ pluralName: row.featurePluralName
1440
+ };
1441
+ const segments = [];
1442
+ if (row.priceBehavior === "pay_in_advance" && !tiered && period !== null && row.price !== void 0) {
1443
+ const size = row.price.packageSize;
1444
+ segments.push({
1445
+ kind: "unitPricePerPeriod",
1446
+ cost: formatCurrency(unitPrice(row.price), row.price.currency, locale),
1447
+ size,
1448
+ units: featureName(feature, size, locale),
1449
+ period
1450
+ });
1451
+ } else if ((row.priceBehavior === "pay_as_you_go" || row.priceBehavior === "overage" || row.priceBehavior === "tier" || row.priceBehavior === "credit_burndown" || tiered) && typeof row.usage === "number") {
1452
+ segments.push({
1453
+ kind: "used",
1454
+ amount: String(row.usage),
1455
+ units: featureName(feature, row.usage, locale)
1456
+ });
1457
+ }
1458
+ if (typeof row.currentCost === "number" && row.currentCost > 0 && row.price !== void 0) {
1459
+ segments.push({
1460
+ kind: "cost",
1461
+ cost: formatCurrency(row.currentCost, row.price.currency, locale),
1462
+ period: row.featureType === "trait" ? period : null
1463
+ });
1464
+ }
1465
+ const resetsAt = usableDate(row.resetsAt);
1466
+ if (resetsAt !== void 0) {
1467
+ segments.push({
1468
+ kind: "resets",
1469
+ date: formatDate(resetsAt, locale, { month: "short", year: void 0 })
1470
+ });
1471
+ }
1472
+ return segments;
1473
+ }
1474
+ function usageSummary(row, options) {
1475
+ if (!isMetered(row) || typeof row.usage !== "number") {
1476
+ return null;
1477
+ }
1478
+ const amount = formatNumber(row.usage, options.locale);
1479
+ if (typeof row.allocation === "number") {
1480
+ return {
1481
+ kind: "limited",
1482
+ amount,
1483
+ allocation: formatNumber(
1484
+ usageLimit(row, options) ?? row.allocation,
1485
+ options.locale
1486
+ )
1487
+ };
1488
+ }
1489
+ return { kind: "unlimited", amount };
1490
+ }
1491
+ function nonEmpty(value) {
1492
+ return value === void 0 || value === null || value === "" ? null : value;
1493
+ }
1494
+
1495
+ // src/elements/model/meteredFeatures.ts
1496
+ var TONES = [
1497
+ "ok",
1498
+ "ok",
1499
+ "ok",
1500
+ "warning",
1501
+ "critical",
1502
+ "critical"
1503
+ ];
1504
+ function deriveMeteredFeatures(features, options) {
1505
+ const ordered = options.visibleFeatures === void 0 ? features : options.visibleFeatures.flatMap((id) => {
1506
+ const row = features.find((f) => f.featureId === id);
1507
+ return row === void 0 ? [] : [row];
1508
+ });
1509
+ return ordered.filter((row) => row.featureType === "event" || row.featureType === "trait").map((row) => meteredFeatureRow(row, options));
1510
+ }
1511
+ function meteredFeatureRow(row, options) {
1512
+ const { locale } = options;
1513
+ const unit = {
1514
+ name: row.featureName,
1515
+ singularName: row.featureSingularName ?? void 0,
1516
+ pluralName: row.featurePluralName ?? void 0
1517
+ };
1518
+ const limit = usageLimit(row, options);
1519
+ const resetsAt = usableDate(row.resetsAt);
1520
+ return {
1521
+ featureId: row.featureId,
1522
+ name: row.featureName,
1523
+ description: row.featureDescription === "" ? null : row.featureDescription ?? null,
1524
+ icon: row.featureIcon === "" ? null : row.featureIcon ?? null,
1525
+ headline: headline(row, limit, unit, locale),
1526
+ limit: limitLine(row, limit, unit, options),
1527
+ resetsAt: resetsAt === void 0 ? null : formatDate(resetsAt, locale, { month: "short", year: void 0 }),
1528
+ hardLimit: row.priceBehavior !== void 0 && row.priceBehavior !== null && row.priceBehavior !== "credit_burndown" && row.valueType === "numeric" && typeof row.allocation === "number" ? {
1529
+ amount: row.allocation,
1530
+ units: featureName(unit, row.allocation, locale)
1531
+ } : null,
1532
+ meter: meter(row, options),
1533
+ priceDetails: priceDetails(row, unit, locale),
1534
+ canAddMore: row.priceBehavior === "pay_in_advance",
1535
+ hasUsageByUser: row.featureType === "event",
1536
+ unit,
1537
+ source: row
1538
+ };
1539
+ }
1540
+ function headline(row, limit, unit, locale) {
1541
+ if (row.priceBehavior === "pay_in_advance") {
1542
+ return {
1543
+ kind: "quantity",
1544
+ amount: limit === null ? null : formatNumber(limit, locale),
1545
+ units: featureName(unit, limit ?? 0, locale)
1546
+ };
1547
+ }
1548
+ if (typeof row.usage !== "number") {
1549
+ return null;
1550
+ }
1551
+ return {
1552
+ kind: "used",
1553
+ amount: formatNumber(row.usage, locale),
1554
+ units: featureName(unit, row.usage, locale)
1555
+ };
1556
+ }
1557
+ function limitLine(row, limit, unit, options) {
1558
+ const { locale } = options;
1559
+ switch (row.priceBehavior) {
1560
+ case "tier": {
1561
+ const tier = currentTier(row);
1562
+ if (tier !== null) {
1563
+ return tier.to === null ? { kind: "tierUnlimited", feature: featureName(unit, 0, locale) } : {
1564
+ kind: "tierUpTo",
1565
+ amount: formatNumber(tier.to, locale),
1566
+ feature: featureName(unit, tier.to, locale)
1567
+ };
1568
+ }
1569
+ break;
1570
+ }
1571
+ case "overage":
1572
+ if (limit !== null) {
1573
+ return { kind: "included", amount: formatNumber(limit, locale) };
1574
+ }
1575
+ break;
1576
+ case "pay_in_advance":
1577
+ if (typeof row.usage === "number") {
1578
+ return { kind: "used", amount: formatNumber(row.usage, locale) };
1579
+ }
1580
+ break;
1581
+ case "pay_as_you_go":
1582
+ if (typeof row.currentCost === "number" && row.price !== void 0) {
1583
+ return {
1584
+ kind: "cost",
1585
+ cost: formatCurrency(row.currentCost, row.price.currency, locale)
1586
+ };
1587
+ }
1588
+ break;
1589
+ case "credit_burndown":
1590
+ if (options.showCredits === false || typeof row.consumptionRate !== "number" || row.creditName === void 0 || row.creditName === null) {
1591
+ return null;
1592
+ }
1593
+ return {
1594
+ kind: "perUse",
1595
+ amount: formatConsumptionRate(row.consumptionRate, locale),
1596
+ units: featureName(
1597
+ {
1598
+ name: row.creditName,
1599
+ singularName: row.creditSingularName,
1600
+ pluralName: row.creditPluralName
1601
+ },
1602
+ row.consumptionRate,
1603
+ locale
1604
+ )
1605
+ };
1606
+ default:
1607
+ break;
1608
+ }
1609
+ return limit === null ? { kind: "noLimit" } : { kind: "limitOf", amount: formatNumber(limit, locale) };
1610
+ }
1611
+ function meter(row, options) {
1612
+ if (row.priceBehavior === "pay_as_you_go" || row.priceBehavior === "credit_burndown" || typeof row.usage !== "number") {
1613
+ return null;
1614
+ }
1615
+ const total = options.showWarningThresholdAsLimit === true && typeof row.warningThreshold === "number" ? row.warningThreshold : row.softLimit ?? row.allocation ?? null;
1616
+ if (typeof total !== "number") {
1617
+ return null;
1618
+ }
1619
+ const usage = row.usage;
1620
+ const past = row.priceBehavior === "overage" && usage > total;
1621
+ const ratio = past ? Math.min(usage, total) / Math.max(usage, total) : total === 0 ? 1 : usage / total;
1622
+ const digits = { maximumFractionDigits: 10 };
1623
+ return {
1624
+ value: usage,
1625
+ total,
1626
+ percent: Math.min(ratio * 100, 100),
1627
+ tone: row.priceBehavior === "tier" ? "tier" : past ? "overage" : TONES[Math.floor(
1628
+ (total === 0 ? 1 : Math.min(usage, total) / total) * (TONES.length - 1)
1629
+ )],
1630
+ valueText: formatNumber(usage, options.locale, digits),
1631
+ totalText: formatNumber(total, options.locale, digits)
1632
+ };
1633
+ }
1634
+ function priceDetails(row, unit, locale) {
1635
+ const price = row.price;
1636
+ if (price === void 0) {
1637
+ return null;
1638
+ }
1639
+ const tier = currentTier(row);
1640
+ const period = row.featureType === "trait" ? pricePeriod(price) : null;
1641
+ const money = (amount) => formatCurrency(amount, price.currency, locale);
1642
+ if (row.priceBehavior === "overage") {
1643
+ if (tier === null || tier.perUnitPrice === null) {
1644
+ return null;
1645
+ }
1646
+ const size = price.packageSize;
1647
+ const over = typeof row.usage === "number" && typeof row.softLimit === "number" ? Math.max(0, row.usage - row.softLimit) : 0;
1648
+ return {
1649
+ kind: "overage",
1650
+ unitPrice: money(tier.perUnitPrice),
1651
+ packageSize: size,
1652
+ units: featureName(unit, size, locale),
1653
+ period,
1654
+ overage: {
1655
+ amount: formatNumber(over, locale),
1656
+ units: featureName(unit, over, locale),
1657
+ cost: money(tier.perUnitPrice * over)
1658
+ }
1659
+ };
1660
+ }
1661
+ if (row.priceBehavior === "tier") {
1662
+ if (tier === null || tier.perUnitPrice === null) {
1663
+ return null;
1664
+ }
1665
+ return {
1666
+ kind: "tier",
1667
+ from: tier.from === 0 ? 1 : tier.from,
1668
+ to: tier.to,
1669
+ cost: typeof row.currentCost === "number" ? money(row.currentCost) : null,
1670
+ period,
1671
+ tiers: {
1672
+ ranges: tierRanges(price),
1673
+ currency: price.currency,
1674
+ mode: price.tiersMode ?? null
1675
+ }
1676
+ };
1677
+ }
1678
+ return null;
1679
+ }
1680
+
1212
1681
  // src/elements/strings.ts
1213
1682
  var DEFAULT_STRINGS_LOCALE = "en";
1214
1683
  var DEFAULT_STRINGS = {
@@ -1275,7 +1744,63 @@ var DEFAULT_STRINGS = {
1275
1744
  paymentMethodsSaving: "Loading",
1276
1745
  paymentMethodsSaveError: "A problem occurred while saving your payment method.",
1277
1746
  paymentMethodsSetDefaultError: "Error updating payment method. Please try again.",
1278
- paymentMethodsRemoveError: "Error deleting payment method. Please try again."
1747
+ paymentMethodsRemoveError: "Error deleting payment method. Please try again.",
1748
+ includedFeaturesLoading: "Loading features",
1749
+ includedFeaturesHeader: "Included features",
1750
+ includedFeaturesError: "There was a problem retrieving your features.",
1751
+ includedFeaturesUnavailable: "Features are not available for this account.",
1752
+ includedFeaturesSeeAll: "See all",
1753
+ includedFeaturesHideAll: "Hide all",
1754
+ includedFeaturesExpires: "Expires {{date}}",
1755
+ includedFeaturesPerLicense: "Includes {{amount}} {{creditName}} per {{licenseName}}",
1756
+ meteredFeaturesLoading: "Loading usage",
1757
+ meteredFeaturesHeader: "Usage",
1758
+ meteredFeaturesError: "There was a problem retrieving your usage.",
1759
+ meteredFeaturesUnavailable: "Usage is not available for this account.",
1760
+ meteredFeaturesUsed: "{{amount}} {{units}} used",
1761
+ meteredFeaturesIncluded: "{{amount}} included",
1762
+ meteredFeaturesInUse: "{{amount}} used",
1763
+ meteredFeaturesLimitOf: "Limit of {{amount}}",
1764
+ meteredFeaturesNoLimit: "No limit",
1765
+ meteredFeaturesAddMore: "Add More",
1766
+ meteredFeaturesAdditional: "Additional",
1767
+ meteredFeaturesTier: "Tier",
1768
+ usageByUserHeader: "Usage by user",
1769
+ usageByUserTotal: "{{amount}} used by your team this period",
1770
+ usageByUserError: "There was a problem retrieving usage by user.",
1771
+ usageByUserUnattributed: "Unattributed",
1772
+ // Looked up by the bare key with `{ count }`; `shown` is the count formatted.
1773
+ usageByUserMore: "plus {{shown}} more",
1774
+ usageByUserShowTop: "Show top {{shown}} users",
1775
+ usageByUserShowTop_one: "Show top {{shown}} user",
1776
+ usageByUserShowTop_other: "Show top {{shown}} users",
1777
+ usageByUserShowAllCount: "Show all {{shown}} users",
1778
+ usageByUserShowAllCount_one: "Show all {{shown}} user",
1779
+ usageByUserShowAllCount_other: "Show all {{shown}} users",
1780
+ usageByUserShowAll: "Show all",
1781
+ usageByUserShowFewer: "Show fewer",
1782
+ // Shared by the usage elements.
1783
+ usageUnits: "{{amount}} {{units}}",
1784
+ usagePerUnit: "{{cost}} per {{unit}}",
1785
+ usagePerPackage: "{{cost}} per {{size}} {{units}}",
1786
+ usageTierUpTo: "Up to {{amount}} {{feature}} in this tier",
1787
+ usageTierUnlimited: "Unlimited {{feature}} in this tier",
1788
+ usagePerUse: "{{amount}} {{units}} per use",
1789
+ usageUnlimited: "Unlimited {{item}}",
1790
+ usageUnitPricePerPeriod: "{{cost}}/{{unit}}/{{period}}",
1791
+ usagePackagePricePerPeriod: "{{cost}}/{{size}} {{units}}/{{period}}",
1792
+ usageUsed: "{{amount}} {{units}} used",
1793
+ usageResets: "Resets {{date}}",
1794
+ usageLimited: "{{amount}} of {{allocation}} used",
1795
+ usageUnlimitedUsed: "{{amount}} used",
1796
+ usageHardLimitLabel: "Limit",
1797
+ usageHardLimit: "Up to a limit of {{amount}} {{units}}",
1798
+ usageTieredPricingLabel: "Tiered pricing",
1799
+ usageTiersVolume: "Price by unit based on final tier reached.",
1800
+ usageTiersGraduated: "Tiers apply progressively as quantity increases.",
1801
+ periodMonthShort: "mo",
1802
+ periodQuarterShort: "qtr",
1803
+ periodYearShort: "yr"
1279
1804
  };
1280
1805
  var MISSING_STRING = "\0schematic:missing";
1281
1806
  function interpolate(template, vars) {
@@ -1314,15 +1839,29 @@ var dialogCss = `
1314
1839
  border: 0;
1315
1840
  border-radius: 0.5rem;
1316
1841
  box-shadow: var(--schematic-shadow);
1842
+ box-sizing: border-box;
1317
1843
  color: var(--schematic-text);
1318
- line-height: 1.375;
1319
1844
  margin: auto;
1320
1845
  max-height: calc(100vh - 2 * var(--schematic-space));
1321
- max-width: 48rem;
1846
+ max-width: none;
1322
1847
  /* No padding of its own: a click on the backdrop lands on the dialog
1323
1848
  itself, and one inside lands on the header or body. */
1324
1849
  padding: 0;
1325
- width: calc(100% - 2 * var(--schematic-space));
1850
+ /* Never wider than the screen, whatever it holds. */
1851
+ width: min(48rem, calc(100vw - 2 * var(--schematic-space)));
1852
+ }
1853
+
1854
+ /* Centred by vw on a phone: a host page wider than the screen widens the
1855
+ layout viewport, and auto margins would centre the dialog half off the
1856
+ screen. Desktop keeps auto margins, as vw counts the scrollbar there. */
1857
+ @media (max-width: 52rem) {
1858
+ .schematic-dialog {
1859
+ inset-inline: 0 auto;
1860
+ margin-inline: calc(
1861
+ (100vw - min(48rem, calc(100vw - 2 * var(--schematic-space)))) / 2
1862
+ )
1863
+ 0;
1864
+ }
1326
1865
  }
1327
1866
 
1328
1867
  .schematic-dialog::backdrop {
@@ -1354,7 +1893,7 @@ var dialogCss = `
1354
1893
  font-family: var(--schematic-font-body);
1355
1894
  font-size: 1.125rem;
1356
1895
  font-weight: 400;
1357
- line-height: var(--schematic-line-height-heading);
1896
+ line-height: var(--schematic-line-height);
1358
1897
  margin: 0;
1359
1898
  }
1360
1899
 
@@ -1383,6 +1922,8 @@ var dialogCss = `
1383
1922
  display: flex;
1384
1923
  flex-direction: column;
1385
1924
  gap: var(--schematic-space);
1925
+ min-width: 0;
1926
+ overflow-wrap: anywhere;
1386
1927
  padding: calc(var(--schematic-space) * 1.5);
1387
1928
  }
1388
1929
  `;
@@ -1797,6 +2338,109 @@ var iconsCss = String.raw`
1797
2338
  }
1798
2339
  `;
1799
2340
 
2341
+ // src/elements/styles/included-features.ts
2342
+ var includedFeaturesCss = `
2343
+ .schematic-included-features {
2344
+ container-type: inline-size;
2345
+ }
2346
+
2347
+ .schematic-included-features__list {
2348
+ display: flex;
2349
+ flex-direction: column;
2350
+ gap: calc(var(--schematic-space) * 1.5);
2351
+ list-style: none;
2352
+ margin: 0;
2353
+ padding: 0;
2354
+ }
2355
+
2356
+ /* Icon, name and details; the usage drops beneath on a narrow card. */
2357
+ .schematic-included-features__row {
2358
+ column-gap: 0.5rem;
2359
+ display: grid;
2360
+ grid-template-columns: min-content 1fr;
2361
+ }
2362
+
2363
+ /* Two classes: the icon font's own rule comes later in the sheet and sets
2364
+ display, which would leave the glyph in the circle's corner. */
2365
+ .schematic-included-features .schematic-included-features__icon {
2366
+ align-items: center;
2367
+ background: var(--schematic-surface);
2368
+ border-radius: 9999px;
2369
+ color: var(--schematic-accent);
2370
+ display: inline-flex;
2371
+ font-size: 1.5rem;
2372
+ height: 2.75rem;
2373
+ justify-content: center;
2374
+ margin-inline-end: 0.5rem;
2375
+ width: 2.75rem;
2376
+ }
2377
+
2378
+ .schematic-included-features__details {
2379
+ align-self: baseline;
2380
+ display: flex;
2381
+ flex-direction: column;
2382
+ gap: 0.25rem;
2383
+ grid-column: 2;
2384
+ }
2385
+
2386
+ /* An item name, as add-ons and plan lines elsewhere. */
2387
+ .schematic-included-features__name {
2388
+ font-family: var(--schematic-font-heading);
2389
+ font-size: 1.125rem;
2390
+ font-weight: 800;
2391
+ line-height: var(--schematic-line-height-heading);
2392
+ }
2393
+
2394
+ .schematic-included-features__usage {
2395
+ display: flex;
2396
+ flex-direction: column;
2397
+ gap: 0.25rem;
2398
+ grid-column: 1 / span 2;
2399
+ margin-inline-start: 3.75rem;
2400
+ margin-top: 0.75rem;
2401
+ }
2402
+
2403
+ .schematic-included-features__entitlement,
2404
+ .schematic-included-features__used {
2405
+ font-variant-numeric: tabular-nums;
2406
+ }
2407
+
2408
+ @container (min-width: 23.4375rem) {
2409
+ /* The usage takes the room it needs and wraps only when the name leaves
2410
+ it none. */
2411
+ .schematic-included-features__row {
2412
+ grid-template-columns: min-content 1fr auto;
2413
+ }
2414
+
2415
+ .schematic-included-features__usage {
2416
+ align-self: baseline;
2417
+ grid-column: 3;
2418
+ margin-inline-start: 0;
2419
+ margin-top: 0;
2420
+ text-align: end;
2421
+ }
2422
+ }
2423
+
2424
+ .schematic-included-features__toggle {
2425
+ align-items: center;
2426
+ display: inline-flex;
2427
+ gap: 0.25rem;
2428
+ margin-top: var(--schematic-space);
2429
+ }
2430
+
2431
+ .schematic-included-features__toggle .schematic-chevron {
2432
+ margin-inline-start: -0.333rem;
2433
+ }
2434
+
2435
+ .schematic-included-features .schematic-skeleton__cell[data-column="name"] {
2436
+ width: 10rem;
2437
+ }
2438
+
2439
+ .schematic-included-features .schematic-skeleton__cell[data-column="usage"] {
2440
+ width: 6rem;
2441
+ }
2442
+ `;
2443
+
1800
2444
  // src/elements/styles/invoices.ts
1801
2445
  var invoicesCss = `
1802
2446
  .schematic-invoices {
@@ -1826,6 +2470,7 @@ var invoicesCss = `
1826
2470
 
1827
2471
  .schematic-invoices__link {
1828
2472
  color: var(--schematic-accent);
2473
+ font-family: var(--schematic-font-link);
1829
2474
  text-decoration: none;
1830
2475
  }
1831
2476
 
@@ -1841,10 +2486,6 @@ var invoicesCss = `
1841
2486
  text-align: end;
1842
2487
  }
1843
2488
 
1844
- .schematic-invoices__credit {
1845
- color: var(--schematic-muted);
1846
- }
1847
-
1848
2489
  .schematic-invoices__actions {
1849
2490
  align-items: center;
1850
2491
  display: flex;
@@ -1855,23 +2496,12 @@ var invoicesCss = `
1855
2496
  .schematic-invoices__see-more {
1856
2497
  align-items: center;
1857
2498
  display: inline-flex;
1858
- gap: 0.375rem;
2499
+ gap: calc(var(--schematic-space) / 2);
1859
2500
  }
1860
2501
 
1861
- /* A chevron drawn from two borders. The vertical nudge lives in the
1862
- transform with the rotation so one transition carries both. */
2502
+ /* Cancels the glyph's side bearing, so the chevron sits flush. */
1863
2503
  .schematic-invoices__chevron {
1864
- border-block-end: 2px solid var(--schematic-muted);
1865
- border-inline-end: 2px solid var(--schematic-muted);
1866
- display: inline-block;
1867
- height: 0.5em;
1868
- transform: translateY(-0.125em) rotate(45deg);
1869
- transition: transform 0.15s;
1870
- width: 0.5em;
1871
- }
1872
-
1873
- .schematic-invoices__see-more[aria-expanded="true"] .schematic-invoices__chevron {
1874
- transform: translateY(0.125em) rotate(-135deg);
2504
+ margin-inline-start: -0.333rem;
1875
2505
  }
1876
2506
 
1877
2507
  .schematic-invoices__empty {
@@ -1887,77 +2517,317 @@ var invoicesCss = `
1887
2517
  }
1888
2518
  `;
1889
2519
 
1890
- // src/elements/styles/payment-methods.ts
1891
- var paymentMethodsCss = `
1892
- .schematic-payment-methods {
2520
+ // src/elements/styles/metered-features.ts
2521
+ var meteredFeaturesCss = `
2522
+ .schematic-metered-features__list {
1893
2523
  display: flex;
1894
2524
  flex-direction: column;
1895
2525
  gap: var(--schematic-space);
2526
+ list-style: none;
2527
+ margin: 0;
2528
+ padding: 0;
1896
2529
  }
1897
2530
 
1898
- .schematic-payment-methods .schematic-header {
1899
- align-items: center;
1900
- margin-bottom: 0;
2531
+ /* Each feature is a card; while pending or failed, the root is the card. */
2532
+ .schematic-metered-features[data-state="pending"],
2533
+ .schematic-metered-features[data-state="error"] {
2534
+ background: var(--schematic-background);
2535
+ border-radius: var(--schematic-radius);
2536
+ box-shadow: var(--schematic-shadow);
2537
+ padding: calc(var(--schematic-card-padding) * 0.75)
2538
+ var(--schematic-card-padding);
1901
2539
  }
1902
2540
 
1903
- .schematic-payment-methods .schematic-header__title {
1904
- margin-bottom: 0;
2541
+ .schematic-metered-features__feature {
2542
+ container-type: inline-size;
2543
+ display: flex;
2544
+ flex-direction: column;
2545
+ gap: calc(var(--schematic-space) * 1.5);
2546
+ overflow: hidden;
1905
2547
  }
1906
2548
 
1907
- .schematic-payment-methods__expiry-warning {
1908
- color: var(--schematic-danger);
1909
- white-space: nowrap;
2549
+ .schematic-metered-features__main {
2550
+ display: flex;
2551
+ gap: calc(var(--schematic-space) * 1.5);
1910
2552
  }
1911
2553
 
1912
- /* The pill: the default method on the left, Edit or Add on the right. */
1913
- .schematic-payment-methods__current {
2554
+ /* Kept without a glyph, as in the embed, so names line up. */
2555
+ .schematic-metered-features__icon {
1914
2556
  align-items: center;
1915
2557
  background: var(--schematic-surface);
1916
2558
  border-radius: 9999px;
1917
- display: flex;
1918
- gap: var(--schematic-space);
1919
- justify-content: space-between;
1920
- padding: calc(var(--schematic-space) / 2.25) var(--schematic-space);
1921
- }
1922
-
1923
- .schematic-payment-methods__method {
1924
- align-items: center;
2559
+ color: var(--schematic-accent);
1925
2560
  display: inline-flex;
1926
- flex-grow: 1;
1927
- flex-wrap: wrap;
1928
- gap: 0.25em;
1929
- }
1930
-
1931
- /* The brand's mark before the label, in the label's colour. */
1932
- .schematic-payment-methods__icon {
1933
- color: currentColor;
1934
2561
  flex-shrink: 0;
1935
- font-size: 1.5em;
1936
- margin-inline-end: calc(var(--schematic-space) / 4);
2562
+ font-size: 1.5rem;
2563
+ height: 2.75rem;
2564
+ justify-content: center;
2565
+ width: 2.75rem;
1937
2566
  }
1938
2567
 
1939
- .schematic-payment-methods__last4 {
1940
- font-variant-numeric: tabular-nums;
2568
+ /* The glyph takes the base text colour rather than inheriting, so the accent
2569
+ is set on it too. */
2570
+ .schematic-metered-features__icon .schematic-icon {
2571
+ color: var(--schematic-accent);
1941
2572
  }
1942
2573
 
1943
- .schematic-payment-methods__empty {
2574
+ .schematic-metered-features__body {
2575
+ display: flex;
2576
+ flex-direction: column;
1944
2577
  flex-grow: 1;
2578
+ gap: calc(var(--schematic-space) * 2);
2579
+ min-width: 0;
1945
2580
  }
1946
2581
 
1947
- .schematic-payment-methods__edit,
1948
- .schematic-payment-methods__remove-current {
1949
- flex-shrink: 0;
1950
- white-space: nowrap;
2582
+ .schematic-metered-features__top {
2583
+ display: flex;
2584
+ flex-wrap: wrap;
2585
+ gap: var(--schematic-space);
1951
2586
  }
1952
2587
 
1953
- /* The toggle that reveals the other methods, with its chevron: down while
1954
- folded, up while unfolded, each its own glyph. The chevron sits beside
1955
- the link in the text colour rather than as part of it. A flex container hands its underline to every item, and an item
1956
- cannot take it off, so the hover underline goes on the label alone. */
2588
+ .schematic-metered-features__title {
2589
+ display: flex;
2590
+ flex: 1 1 min-content;
2591
+ flex-direction: column;
2592
+ gap: 0.5rem;
2593
+ }
2594
+
2595
+ .schematic-metered-features__name {
2596
+ font-family: var(--schematic-font-heading);
2597
+ font-size: 1.8125rem;
2598
+ font-weight: 800;
2599
+ line-height: var(--schematic-line-height-heading);
2600
+ margin: 0;
2601
+ }
2602
+
2603
+ /* Beside the title when both fit, otherwise beneath it as in the embed,
2604
+ rather than wrapping in a narrow column. */
2605
+ .schematic-metered-features__figures {
2606
+ display: flex;
2607
+ flex: 0 0 auto;
2608
+ flex-direction: column;
2609
+ gap: 0.25rem;
2610
+ max-width: 100%;
2611
+ text-align: end;
2612
+ }
2613
+
2614
+ .schematic-metered-features__headline {
2615
+ font-size: 1.0625rem;
2616
+ font-variant-numeric: tabular-nums;
2617
+ font-weight: 500;
2618
+ white-space: nowrap;
2619
+ }
2620
+
2621
+ @container (max-width: 30rem) {
2622
+ .schematic-metered-features__figures {
2623
+ min-width: 0;
2624
+ text-align: start;
2625
+ }
2626
+
2627
+ /* Too narrow to keep "1,300 GB of storage used" on one line. */
2628
+ .schematic-metered-features__headline {
2629
+ white-space: normal;
2630
+ }
2631
+ }
2632
+
2633
+ .schematic-metered-features__limit {
2634
+ font-variant-numeric: tabular-nums;
2635
+ }
2636
+
2637
+ .schematic-metered-features__add-more {
2638
+ align-self: flex-start;
2639
+ white-space: nowrap;
2640
+ }
2641
+
2642
+ /* Negative margins undo the card's padding so the footer bleeds to its edges. */
2643
+ .schematic-metered-features__price-details {
2644
+ align-items: center;
2645
+ background: var(--schematic-surface);
2646
+ display: flex;
2647
+ gap: var(--schematic-space);
2648
+ justify-content: space-between;
2649
+ margin: 0 calc(var(--schematic-card-padding) * -1)
2650
+ calc(var(--schematic-card-padding) * -0.75);
2651
+ padding: calc(var(--schematic-card-padding) * 0.4375)
2652
+ var(--schematic-card-padding);
2653
+ }
2654
+
2655
+ .schematic-metered-features .schematic-skeleton__cell[data-column="name"] {
2656
+ width: 10rem;
2657
+ }
2658
+
2659
+ .schematic-metered-features .schematic-skeleton__cell[data-column="usage"] {
2660
+ width: 6rem;
2661
+ }
2662
+
2663
+ .schematic-metered-features__meter {
2664
+ align-items: center;
2665
+ display: flex;
2666
+ gap: var(--schematic-space);
2667
+ }
2668
+
2669
+ .schematic-metered-features__meter .schematic-meter {
2670
+ flex-grow: 1;
2671
+ min-width: 6rem;
2672
+ }
2673
+
2674
+ .schematic-meter--tier {
2675
+ background: color-mix(in srgb, var(--schematic-accent) 50%, transparent);
2676
+ }
2677
+
2678
+ /* Past the soft limit, the fill is the included share over a warning track. */
2679
+ .schematic-meter--overage {
2680
+ background: var(--schematic-warning);
2681
+ }
2682
+
2683
+ .schematic-metered-features__meter-label {
2684
+ font-size: 0.875rem;
2685
+ font-variant-numeric: tabular-nums;
2686
+ font-weight: 500;
2687
+ white-space: nowrap;
2688
+ }
2689
+
2690
+ .schematic-usage-by-user {
2691
+ align-items: flex-start;
2692
+ display: flex;
2693
+ flex-direction: column;
2694
+ gap: 0.25rem;
2695
+ }
2696
+
2697
+ .schematic-usage-by-user__title {
2698
+ font-family: var(--schematic-font-heading);
2699
+ font-size: 1.125rem;
2700
+ font-weight: 800;
2701
+ }
2702
+
2703
+ .schematic-usage-by-user__list {
2704
+ align-self: stretch;
2705
+ list-style: none;
2706
+ margin: 0.5rem 0 0;
2707
+ padding: 0;
2708
+ }
2709
+
2710
+ .schematic-usage-by-user__user {
2711
+ align-items: center;
2712
+ display: flex;
2713
+ gap: 0.75rem;
2714
+ padding: 0.5rem 0;
2715
+ }
2716
+
2717
+ .schematic-usage-by-user__avatar {
2718
+ align-items: center;
2719
+ background: var(--schematic-surface);
2720
+ border-radius: 9999px;
2721
+ display: inline-flex;
2722
+ flex-shrink: 0;
2723
+ font-size: 0.6875rem;
2724
+ font-weight: 500;
2725
+ height: 1.75rem;
2726
+ justify-content: center;
2727
+ width: 1.75rem;
2728
+ }
2729
+
2730
+ .schematic-usage-by-user__name {
2731
+ flex-grow: 1;
2732
+ overflow: hidden;
2733
+ text-overflow: ellipsis;
2734
+ white-space: nowrap;
2735
+ }
2736
+
2737
+ .schematic-usage-by-user__amount {
2738
+ text-align: end;
2739
+ }
2740
+
2741
+ .schematic-usage-by-user__toggle {
2742
+ align-items: center;
2743
+ display: inline-flex;
2744
+ gap: 0.25rem;
2745
+ }
2746
+
2747
+ .schematic-usage-by-user__toggle .schematic-chevron {
2748
+ margin-inline-start: -0.333rem;
2749
+ }
2750
+ `;
2751
+
2752
+ // src/elements/styles/payment-methods.ts
2753
+ var paymentMethodsCss = `
2754
+ .schematic-payment-methods {
2755
+ display: flex;
2756
+ flex-direction: column;
2757
+ gap: var(--schematic-space);
2758
+ }
2759
+
2760
+ .schematic-payment-methods .schematic-header {
2761
+ align-items: center;
2762
+ margin-bottom: 0;
2763
+ }
2764
+
2765
+ .schematic-payment-methods__expiry-warning {
2766
+ color: var(--schematic-danger);
2767
+ white-space: nowrap;
2768
+ }
2769
+
2770
+ /* The pill: the default method on the left, Edit or Add on the right. */
2771
+ .schematic-payment-methods__current {
2772
+ align-items: center;
2773
+ background: var(--schematic-surface);
2774
+ border-radius: 9999px;
2775
+ display: flex;
2776
+ gap: var(--schematic-space);
2777
+ justify-content: space-between;
2778
+ padding: calc(var(--schematic-space) / 2.25) var(--schematic-space);
2779
+ }
2780
+
2781
+ /* One line: a label too long for the space truncates rather than wrapping
2782
+ "Card ending in" away from its digits or widening the dialog. */
2783
+ .schematic-payment-methods__method {
2784
+ align-items: center;
2785
+ display: inline-flex;
2786
+ flex-grow: 1;
2787
+ gap: 0.25em;
2788
+ min-width: 0;
2789
+ }
2790
+
2791
+ .schematic-payment-methods__label {
2792
+ min-width: 0;
2793
+ overflow: hidden;
2794
+ text-overflow: ellipsis;
2795
+ white-space: nowrap;
2796
+ }
2797
+
2798
+ /* The brand's mark before the label, in the label's colour. */
2799
+ .schematic-payment-methods__icon {
2800
+ color: currentColor;
2801
+ flex-shrink: 0;
2802
+ font-size: 1.5em;
2803
+ margin-inline-end: calc(var(--schematic-space) / 4);
2804
+ }
2805
+
2806
+ .schematic-payment-methods__last4 {
2807
+ flex-shrink: 0;
2808
+ font-variant-numeric: tabular-nums;
2809
+ }
2810
+
2811
+ .schematic-payment-methods__empty {
2812
+ flex-grow: 1;
2813
+ }
2814
+
2815
+ .schematic-payment-methods__edit,
2816
+ .schematic-payment-methods__remove-current {
2817
+ flex-shrink: 0;
2818
+ white-space: nowrap;
2819
+ }
2820
+
2821
+ /* The toggle that reveals the other methods. Its chevron is a glyph per
2822
+ state, down while folded and up while unfolded, and the hover underline
2823
+ goes on the label alone, as on every toggle. */
1957
2824
  .schematic-payment-methods__choose {
1958
2825
  align-items: center;
1959
2826
  align-self: flex-start;
1960
2827
  display: inline-flex;
2828
+ /* A button centres its text; a label that wraps on a phone keeps to the
2829
+ start. */
2830
+ text-align: start;
1961
2831
  gap: calc(var(--schematic-space) / 2);
1962
2832
  }
1963
2833
 
@@ -1969,10 +2839,6 @@ var paymentMethodsCss = `
1969
2839
  text-decoration: underline;
1970
2840
  }
1971
2841
 
1972
- .schematic-payment-methods__chevron {
1973
- color: var(--schematic-text);
1974
- font-size: 1.5em;
1975
- }
1976
2842
 
1977
2843
  /* A faintly tinted panel, roomier than the shared dialog body, with its
1978
2844
  parts spaced further apart. */
@@ -2016,6 +2882,12 @@ var paymentMethodsCss = `
2016
2882
  padding: calc(var(--schematic-space) / 2) 0;
2017
2883
  }
2018
2884
 
2885
+ /* The name takes the line's room first; the actions wrap under it before
2886
+ the name is cut short. */
2887
+ .schematic-payment-methods__row .schematic-payment-methods__method {
2888
+ flex: 1 1 10rem;
2889
+ }
2890
+
2019
2891
  .schematic-payment-methods__expires {
2020
2892
  flex-grow: 1;
2021
2893
  font-variant-numeric: tabular-nums;
@@ -2089,23 +2961,31 @@ var paymentMethodsCss = `
2089
2961
  white-space: nowrap;
2090
2962
  }
2091
2963
 
2964
+ /* Spaced as the embed's form: 24px between parts, and a wider break before
2965
+ Save under the address. */
2092
2966
  .schematic-payment-methods__form {
2093
2967
  display: flex;
2094
2968
  flex-direction: column;
2095
- gap: var(--schematic-space);
2969
+ gap: calc(var(--schematic-space) * 1.5);
2970
+ }
2971
+
2972
+ .schematic-payment-methods__address {
2973
+ margin-bottom: calc(var(--schematic-space) * 2);
2096
2974
  }
2097
2975
 
2098
- /* The fields the checkout settings add beside Stripe's own. */
2976
+ /* The fields the checkout settings add beside Stripe's own, labelled as
2977
+ Stripe's are. */
2099
2978
  .schematic-payment-methods__field {
2100
2979
  display: flex;
2101
2980
  flex-direction: column;
2102
- gap: calc(var(--schematic-space) / 2);
2981
+ gap: calc(var(--schematic-space) * 0.75);
2103
2982
  }
2104
2983
 
2105
2984
  .schematic-payment-methods__input {
2106
2985
  background: var(--schematic-background);
2107
2986
  border: 1px solid var(--schematic-border);
2108
- border-radius: var(--schematic-radius);
2987
+ /* The embed's 8px at the default radius; Stripe's fields take the same. */
2988
+ border-radius: calc(var(--schematic-radius) * 0.8);
2109
2989
  box-sizing: border-box;
2110
2990
  color: var(--schematic-text);
2111
2991
  font: inherit;
@@ -2136,6 +3016,83 @@ var paymentMethodsCss = `
2136
3016
  // src/elements/styles/index.tsx
2137
3017
  init_tokens();
2138
3018
 
3019
+ // src/elements/styles/tooltip.ts
3020
+ var tooltipCss = `
3021
+ .schematic-tooltip {
3022
+ display: inline-block;
3023
+ margin-inline-start: 0.25rem;
3024
+ position: relative;
3025
+ vertical-align: middle;
3026
+ }
3027
+
3028
+ .schematic-tooltip__trigger {
3029
+ background: none;
3030
+ border: 0;
3031
+ color: var(--schematic-muted);
3032
+ cursor: help;
3033
+ /* A button keeps the browser's control font; the glyph is the embed's
3034
+ 24px. */
3035
+ font-size: 1.5rem;
3036
+ line-height: 0;
3037
+ padding: 0;
3038
+ }
3039
+
3040
+ .schematic-tooltip__trigger:focus-visible {
3041
+ outline: 2px solid var(--schematic-accent);
3042
+ outline-offset: 2px;
3043
+ }
3044
+
3045
+ .schematic-tooltip__content {
3046
+ background: var(--schematic-background);
3047
+ border: 1px solid var(--schematic-border);
3048
+ border-radius: calc(var(--schematic-radius) / 2);
3049
+ bottom: calc(100% + 0.5rem);
3050
+ box-shadow: var(--schematic-shadow);
3051
+ color: var(--schematic-text);
3052
+ font-size: 0.875rem;
3053
+ inset-inline-end: 0;
3054
+ padding: 0.5rem 0.75rem;
3055
+ pointer-events: none;
3056
+ position: absolute;
3057
+ text-align: start;
3058
+ visibility: hidden;
3059
+ white-space: nowrap;
3060
+ z-index: 1;
3061
+ }
3062
+
3063
+ .schematic-tooltip:hover .schematic-tooltip__content,
3064
+ .schematic-tooltip:focus-within .schematic-tooltip__content {
3065
+ visibility: visible;
3066
+ }
3067
+
3068
+ .schematic-tiers {
3069
+ display: flex;
3070
+ flex-direction: column;
3071
+ gap: 0.5rem;
3072
+ }
3073
+
3074
+ .schematic-tiers__list {
3075
+ margin: 0;
3076
+ }
3077
+
3078
+ .schematic-tiers__tier {
3079
+ display: flex;
3080
+ gap: var(--schematic-space);
3081
+ justify-content: space-between;
3082
+ padding: 0.25rem 0;
3083
+ }
3084
+
3085
+ .schematic-tiers__price {
3086
+ margin: 0;
3087
+ }
3088
+
3089
+ .schematic-tiers__mode {
3090
+ border-top: 1px solid var(--schematic-border);
3091
+ padding-top: 0.5rem;
3092
+ white-space: normal;
3093
+ }
3094
+ `;
3095
+
2139
3096
  // src/elements/styles/upcoming-bill.ts
2140
3097
  var upcomingBillCss = `
2141
3098
  .schematic-upcoming-bill {
@@ -2148,10 +3105,6 @@ var upcomingBillCss = `
2148
3105
  margin-bottom: 0;
2149
3106
  }
2150
3107
 
2151
- .schematic-upcoming-bill .schematic-header__title {
2152
- margin-bottom: 0;
2153
- }
2154
-
2155
3108
  .schematic-upcoming-bill__amount {
2156
3109
  align-items: flex-start;
2157
3110
  display: flex;
@@ -2161,14 +3114,14 @@ var upcomingBillCss = `
2161
3114
 
2162
3115
  .schematic-upcoming-bill__total {
2163
3116
  font-family: var(--schematic-font-heading);
2164
- font-size: 1.8125rem;
3117
+ font-size: 2.3125rem;
2165
3118
  font-variant-numeric: tabular-nums;
2166
3119
  font-weight: 800;
2167
3120
  line-height: 1;
2168
3121
  }
2169
3122
 
2170
3123
  .schematic-upcoming-bill__estimate {
2171
- font-weight: 600;
3124
+ color: var(--schematic-muted);
2172
3125
  max-width: 10rem;
2173
3126
  text-align: end;
2174
3127
  }
@@ -2234,6 +3187,21 @@ var rulesCss = `
2234
3187
  margin: 0;
2235
3188
  }
2236
3189
 
3190
+ /* Unit suffixes ("/mo", "/seat") sit on the baseline, as in the embed. */
3191
+ :where([class^="schematic-"]) sub,
3192
+ :where([class^="schematic-"]) sup {
3193
+ line-height: 1;
3194
+ position: static;
3195
+ }
3196
+
3197
+ :where([class^="schematic-"]) sub {
3198
+ vertical-align: baseline;
3199
+ }
3200
+
3201
+ :where([class^="schematic-"]) sup {
3202
+ vertical-align: top;
3203
+ }
3204
+
2237
3205
  .schematic-card {
2238
3206
  background: var(--schematic-background);
2239
3207
  border-radius: var(--schematic-radius);
@@ -2329,6 +3297,7 @@ var rulesCss = `
2329
3297
 
2330
3298
  .schematic-error {
2331
3299
  color: var(--schematic-danger);
3300
+ font-weight: 500;
2332
3301
  }
2333
3302
 
2334
3303
  .schematic-status-note {
@@ -2391,10 +3360,26 @@ var rulesCss = `
2391
3360
  border-color: var(--schematic-primary);
2392
3361
  }
2393
3362
 
3363
+ /* The embed's small button: 15px type, 40px tall. */
2394
3364
  .schematic-cta--small {
3365
+ border-radius: 0.375rem;
2395
3366
  font-size: 0.9375rem;
2396
3367
  min-height: 2.5rem;
2397
- padding: 0.375rem 1rem;
3368
+ padding: 0.4375rem 1.25rem;
3369
+ }
3370
+
3371
+ /* The embed's ghost button, for secondary actions such as Try again. */
3372
+ .schematic-cta--ghost {
3373
+ background: transparent;
3374
+ border-color: color-mix(in srgb, var(--schematic-text) 20%, transparent);
3375
+ color: var(--schematic-text);
3376
+ }
3377
+
3378
+ .schematic-cta--ghost:hover:not(:disabled) {
3379
+ background: transparent;
3380
+ border-color: color-mix(in srgb, var(--schematic-text) 12.5%, transparent);
3381
+ box-shadow: 0 1px 2px
3382
+ color-mix(in srgb, var(--schematic-text) 7.5%, transparent);
2398
3383
  }
2399
3384
 
2400
3385
  .schematic-link-button {
@@ -2411,6 +3396,27 @@ var rulesCss = `
2411
3396
  text-decoration: underline;
2412
3397
  }
2413
3398
 
3399
+ /* Every toggle's chevron: the 24px glyph, muted. */
3400
+ .schematic-chevron {
3401
+ color: var(--schematic-muted);
3402
+ font-size: 1.5rem;
3403
+ }
3404
+
3405
+ /* A toggle underlines its label alone: a flex container hands its underline
3406
+ to every item, the chevron included, and an item cannot take it off. */
3407
+ .schematic-link-button:has(.schematic-link-button__label):hover {
3408
+ text-decoration: none;
3409
+ }
3410
+
3411
+ /* The reset colours every schematic- element; the label keeps the link's. */
3412
+ .schematic-link-button__label {
3413
+ color: inherit;
3414
+ }
3415
+
3416
+ .schematic-link-button:hover .schematic-link-button__label {
3417
+ text-decoration: underline;
3418
+ }
3419
+
2414
3420
  .schematic-meter {
2415
3421
  background: var(--schematic-meter-track);
2416
3422
  border-radius: 9999px;
@@ -2500,7 +3506,7 @@ var rulesCss = `
2500
3506
  font-size: 1.125rem;
2501
3507
  font-weight: 800;
2502
3508
  line-height: var(--schematic-line-height-heading);
2503
- margin: 0 0 calc(var(--schematic-space) / 2);
3509
+ margin: 0;
2504
3510
  }
2505
3511
 
2506
3512
  /* A label on the left, its value on the right. */
@@ -2708,13 +3714,16 @@ ${dialogCss}
2708
3714
  ${invoicesCss}
2709
3715
  ${upcomingBillCss}
2710
3716
  ${paymentMethodsCss}
3717
+ ${tooltipCss}
3718
+ ${includedFeaturesCss}
3719
+ ${meteredFeaturesCss}
2711
3720
  `;
2712
3721
  var schematicStylesCss = withTokenDefaults(rulesCss) + iconsCss;
2713
3722
  var SchematicStyles = () => /* @__PURE__ */ jsx("style", { "data-schematic-styles": "", children: schematicStylesCss });
2714
3723
 
2715
- // src/elements/Invoices.tsx
2716
- import { useInvoices } from "@schematichq/schematic-react";
2717
- import { useId as useId2, useMemo, useState } from "react";
3724
+ // src/elements/IncludedFeatures.tsx
3725
+ import { useFeatureUsage } from "@schematichq/schematic-react";
3726
+ import { useMemo as useMemo2, useState as useState2 } from "react";
2718
3727
 
2719
3728
  // src/elements/common.tsx
2720
3729
  import {
@@ -2812,7 +3821,7 @@ var StatusFrame = ({
2812
3821
  onRetry !== void 0 && /* @__PURE__ */ jsx2(
2813
3822
  "button",
2814
3823
  {
2815
- className: "schematic-link-button schematic-status__retry",
3824
+ className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-status__retry",
2816
3825
  type: "button",
2817
3826
  onClick: onRetry,
2818
3827
  children: retryText
@@ -2831,6 +3840,28 @@ var StatusFrame = ({
2831
3840
  error !== void 0 && /* @__PURE__ */ jsx2("p", { className: "schematic-status-note schematic-error", role: "alert", children: errorMessage ?? error.message })
2832
3841
  ] });
2833
3842
  };
3843
+ var Tooltip = ({ children, className, label }) => {
3844
+ const id = useId();
3845
+ return /* @__PURE__ */ jsxs("span", { className: cx("schematic-tooltip", className), children: [
3846
+ /* @__PURE__ */ jsx2(
3847
+ "button",
3848
+ {
3849
+ "aria-describedby": id,
3850
+ "aria-label": label,
3851
+ className: "schematic-tooltip__trigger",
3852
+ type: "button",
3853
+ children: /* @__PURE__ */ jsx2(
3854
+ "i",
3855
+ {
3856
+ "aria-hidden": "true",
3857
+ className: "schematic-icon schematic-icon--info-rounded"
3858
+ }
3859
+ )
3860
+ }
3861
+ ),
3862
+ /* @__PURE__ */ jsx2("span", { className: "schematic-tooltip__content", id, role: "tooltip", children })
3863
+ ] });
3864
+ };
2834
3865
  var Dialog = ({ children, className, closeLabel, onClose, open, title, titleId }) => {
2835
3866
  const ref = useRef(null);
2836
3867
  const generatedId = useId();
@@ -2844,46 +3875,447 @@ var Dialog = ({ children, className, closeLabel, onClose, open, title, titleId }
2844
3875
  if (!open) {
2845
3876
  return null;
2846
3877
  }
2847
- return /* @__PURE__ */ jsxs(
2848
- "dialog",
3878
+ return /* @__PURE__ */ jsxs(
3879
+ "dialog",
3880
+ {
3881
+ "aria-labelledby": headingId,
3882
+ className: cx("schematic-dialog", className),
3883
+ ref,
3884
+ onClick: (event) => {
3885
+ if (event.target === event.currentTarget) {
3886
+ onClose();
3887
+ }
3888
+ },
3889
+ onClose,
3890
+ children: [
3891
+ /* @__PURE__ */ jsxs("div", { className: "schematic-dialog__header", children: [
3892
+ /* @__PURE__ */ jsx2("h2", { className: "schematic-dialog__title", id: headingId, children: title }),
3893
+ /* @__PURE__ */ jsx2(
3894
+ "button",
3895
+ {
3896
+ "aria-label": closeLabel,
3897
+ className: "schematic-dialog__close",
3898
+ type: "button",
3899
+ onClick: onClose,
3900
+ children: /* @__PURE__ */ jsx2(
3901
+ "i",
3902
+ {
3903
+ "aria-hidden": "true",
3904
+ className: "schematic-icon schematic-icon--close"
3905
+ }
3906
+ )
3907
+ }
3908
+ )
3909
+ ] }),
3910
+ /* @__PURE__ */ jsx2("div", { className: "schematic-dialog__body", children })
3911
+ ]
3912
+ }
3913
+ );
3914
+ };
3915
+
3916
+ // src/elements/usage.tsx
3917
+ import { useMemo, useState } from "react";
3918
+ import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
3919
+ var COLLAPSED_USER_COUNT = 3;
3920
+ var EXPANDED_USER_COUNT = 20;
3921
+ function shortPeriod(period, t) {
3922
+ switch (period) {
3923
+ case "month":
3924
+ return t("periodMonthShort");
3925
+ case "quarter":
3926
+ return t("periodQuarterShort");
3927
+ case "year":
3928
+ return t("periodYearShort");
3929
+ default:
3930
+ return void 0;
3931
+ }
3932
+ }
3933
+ function PriceTiers({
3934
+ currency,
3935
+ locale,
3936
+ mode,
3937
+ period,
3938
+ ranges,
3939
+ t,
3940
+ unit
3941
+ }) {
3942
+ const perPeriod = period === null ? void 0 : shortPeriod(period, t);
3943
+ const money = (amount) => formatCurrency(amount, currency, locale);
3944
+ const perUnit = (amount) => /* @__PURE__ */ jsxs2(Fragment, { children: [
3945
+ money(amount),
3946
+ /* @__PURE__ */ jsxs2("sub", { children: [
3947
+ "/",
3948
+ unit
3949
+ ] })
3950
+ ] });
3951
+ const flat = (amount) => /* @__PURE__ */ jsxs2(Fragment, { children: [
3952
+ money(amount),
3953
+ perPeriod !== void 0 && /* @__PURE__ */ jsxs2("sub", { children: [
3954
+ "/",
3955
+ perPeriod
3956
+ ] })
3957
+ ] });
3958
+ const tierPrice = (flatPrice, perUnitPrice) => {
3959
+ if (flatPrice === 0 && perUnitPrice !== 0) {
3960
+ return perUnit(perUnitPrice);
3961
+ }
3962
+ if (flatPrice !== 0 && perUnitPrice === 0) {
3963
+ return flat(flatPrice);
3964
+ }
3965
+ return /* @__PURE__ */ jsxs2(Fragment, { children: [
3966
+ perUnit(perUnitPrice),
3967
+ " + ",
3968
+ flat(flatPrice)
3969
+ ] });
3970
+ };
3971
+ return /* @__PURE__ */ jsxs2("span", { className: "schematic-tiers", children: [
3972
+ /* @__PURE__ */ jsx3("dl", { className: "schematic-tiers__list", children: ranges.map((tier) => /* @__PURE__ */ jsxs2("div", { className: "schematic-tiers__tier", children: [
3973
+ /* @__PURE__ */ jsxs2("dt", { className: "schematic-tiers__range", children: [
3974
+ tier.from,
3975
+ tier.to === null ? "+" : tier.to !== tier.from ? `\u2013${tier.to}` : ""
3976
+ ] }),
3977
+ /* @__PURE__ */ jsx3("dd", { className: "schematic-tiers__price", children: tierPrice(tier.flatPrice ?? 0, tier.perUnitPrice ?? 0) })
3978
+ ] }, tier.from)) }),
3979
+ mode !== null && /* @__PURE__ */ jsx3("span", { className: "schematic-tiers__mode", children: mode === "volume" ? t("usageTiersVolume") : t("usageTiersGraduated") })
3980
+ ] });
3981
+ }
3982
+ function UserBreakdown({
3983
+ breakdown,
3984
+ error,
3985
+ locale,
3986
+ onRetry,
3987
+ t,
3988
+ unit
3989
+ }) {
3990
+ const [expanded, setExpanded] = useState(false);
3991
+ const users = useMemo(
3992
+ () => [...breakdown?.users ?? []].sort((a, b) => b.amount - a.amount),
3993
+ [breakdown?.users]
3994
+ );
3995
+ const amount = (value) => `${formatNumber(value, locale)} ${featureName(unit, value, locale)}`;
3996
+ if (breakdown === void 0 && error !== void 0) {
3997
+ return /* @__PURE__ */ jsxs2("div", { className: "schematic-usage-by-user", role: "alert", children: [
3998
+ /* @__PURE__ */ jsx3("span", { className: "schematic-usage-by-user__title", children: t("usageByUserHeader") }),
3999
+ /* @__PURE__ */ jsx3("span", { className: "schematic-error", children: t("usageByUserError") }),
4000
+ /* @__PURE__ */ jsx3(
4001
+ "button",
4002
+ {
4003
+ className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-status__retry",
4004
+ type: "button",
4005
+ onClick: onRetry,
4006
+ children: t("retry")
4007
+ }
4008
+ )
4009
+ ] });
4010
+ }
4011
+ const unattributed = breakdown?.unattributed ?? null;
4012
+ if (breakdown === void 0 || users.length === 0 && unattributed === null) {
4013
+ return null;
4014
+ }
4015
+ const visible = users.slice(
4016
+ 0,
4017
+ expanded ? EXPANDED_USER_COUNT : COLLAPSED_USER_COUNT
4018
+ );
4019
+ const remaining = Math.max(breakdown.count - visible.length, 0);
4020
+ const hidden = Math.max(
4021
+ Math.min(breakdown.count, EXPANDED_USER_COUNT) - Math.min(users.length, COLLAPSED_USER_COUNT),
4022
+ 0
4023
+ );
4024
+ const expandLabel = breakdown.count > EXPANDED_USER_COUNT ? t("usageByUserShowTop", {
4025
+ count: EXPANDED_USER_COUNT,
4026
+ shown: formatNumber(EXPANDED_USER_COUNT, locale)
4027
+ }) : hidden > 0 ? t("usageByUserShowAllCount", {
4028
+ count: breakdown.count,
4029
+ shown: formatNumber(breakdown.count, locale)
4030
+ }) : t("usageByUserShowAll");
4031
+ const user = (key, label, value, muted = false) => /* @__PURE__ */ jsxs2("li", { className: "schematic-usage-by-user__user", children: [
4032
+ /* @__PURE__ */ jsx3("span", { "aria-hidden": "true", className: "schematic-usage-by-user__avatar", children: muted ? "?" : (label.trim()[0] ?? "?").toUpperCase() }),
4033
+ /* @__PURE__ */ jsx3(
4034
+ "span",
4035
+ {
4036
+ className: cx(
4037
+ "schematic-usage-by-user__name",
4038
+ muted && "schematic-muted"
4039
+ ),
4040
+ children: label
4041
+ }
4042
+ ),
4043
+ /* @__PURE__ */ jsx3("span", { className: "schematic-muted schematic-usage-by-user__amount", children: amount(value) })
4044
+ ] }, key);
4045
+ return /* @__PURE__ */ jsxs2("div", { className: "schematic-usage-by-user", children: [
4046
+ /* @__PURE__ */ jsx3("span", { className: "schematic-usage-by-user__title", children: t("usageByUserHeader") }),
4047
+ /* @__PURE__ */ jsx3("span", { className: "schematic-muted", children: t("usageByUserTotal", { amount: amount(breakdown.total) }) }),
4048
+ /* @__PURE__ */ jsxs2("ul", { className: "schematic-usage-by-user__list", children: [
4049
+ visible.map((entry) => user(entry.id, entry.label, entry.amount)),
4050
+ expanded && unattributed !== null && user(
4051
+ "unattributed",
4052
+ t("usageByUserUnattributed"),
4053
+ unattributed,
4054
+ true
4055
+ )
4056
+ ] }),
4057
+ expanded && remaining > 0 && /* @__PURE__ */ jsx3("span", { className: "schematic-muted", children: t("usageByUserMore", {
4058
+ count: remaining,
4059
+ shown: formatNumber(remaining, locale)
4060
+ }) }),
4061
+ (hidden > 0 || unattributed !== null) && /* @__PURE__ */ jsxs2(
4062
+ "button",
4063
+ {
4064
+ "aria-expanded": expanded,
4065
+ className: "schematic-link-button schematic-usage-by-user__toggle",
4066
+ type: "button",
4067
+ onClick: () => setExpanded((value) => !value),
4068
+ children: [
4069
+ /* @__PURE__ */ jsx3(
4070
+ "i",
4071
+ {
4072
+ "aria-hidden": "true",
4073
+ className: `schematic-icon schematic-icon--${expanded ? "chevron-up" : "chevron-down"} schematic-chevron`
4074
+ }
4075
+ ),
4076
+ /* @__PURE__ */ jsx3("span", { className: "schematic-link-button__label", children: expanded ? t("usageByUserShowFewer") : expandLabel })
4077
+ ]
4078
+ }
4079
+ )
4080
+ ] });
4081
+ }
4082
+
4083
+ // src/elements/IncludedFeatures.tsx
4084
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
4085
+ var VISIBLE_FEATURE_COUNT = 4;
4086
+ function IncludedFeatures({
4087
+ className,
4088
+ headingLevel = 2,
4089
+ locale: localeProp,
4090
+ showCredits = true,
4091
+ showDescription = true,
4092
+ showEntitlement = true,
4093
+ showExpiration = true,
4094
+ showHardLimit = false,
4095
+ showHeader = true,
4096
+ showIcon = true,
4097
+ showUsage = true,
4098
+ showWarningThresholdAsLimit = false,
4099
+ strings,
4100
+ visibleFeatures
4101
+ }) {
4102
+ const { data: features, error, isPending, refetch } = useFeatureUsage();
4103
+ const locale = useResolvedLocale(localeProp);
4104
+ const t = useTranslator(strings, localeProp);
4105
+ const [expanded, setExpanded] = useState2(false);
4106
+ const rows = useMemo2(
4107
+ () => features === void 0 ? [] : deriveIncludedFeatures(features, {
4108
+ locale,
4109
+ showCredits,
4110
+ showWarningThresholdAsLimit,
4111
+ visibleFeatures
4112
+ }),
4113
+ [
4114
+ features,
4115
+ locale,
4116
+ showCredits,
4117
+ showWarningThresholdAsLimit,
4118
+ visibleFeatures
4119
+ ]
4120
+ );
4121
+ const Heading = `h${headingLevel}`;
4122
+ const canExpand = rows.length > VISIBLE_FEATURE_COUNT;
4123
+ const shown = canExpand && !expanded ? rows.slice(0, VISIBLE_FEATURE_COUNT) : rows;
4124
+ const unavailable = features === void 0 && httpStatus(error) === 404;
4125
+ const errorMessage = error === void 0 ? void 0 : unavailable ? t("includedFeaturesUnavailable") : t("includedFeaturesError");
4126
+ return /* @__PURE__ */ jsxs3(
4127
+ StatusFrame,
2849
4128
  {
2850
- "aria-labelledby": headingId,
2851
- className: cx("schematic-dialog", className),
2852
- ref,
2853
- onClick: (event) => {
2854
- if (event.target === event.currentTarget) {
2855
- onClose();
2856
- }
2857
- },
2858
- onClose,
4129
+ className: cx("schematic-card", "schematic-included-features", className),
4130
+ error,
4131
+ errorMessage,
4132
+ hasData: features !== void 0,
4133
+ isPending,
4134
+ loadingLabel: t("includedFeaturesLoading"),
4135
+ onRetry: refetch,
4136
+ retryText: t("retry"),
4137
+ skeleton: /* @__PURE__ */ jsx4(IncludedFeaturesSkeleton, { showHeader }),
2859
4138
  children: [
2860
- /* @__PURE__ */ jsxs("div", { className: "schematic-dialog__header", children: [
2861
- /* @__PURE__ */ jsx2("h2", { className: "schematic-dialog__title", id: headingId, children: title }),
2862
- /* @__PURE__ */ jsx2(
2863
- "button",
2864
- {
2865
- "aria-label": closeLabel,
2866
- className: "schematic-dialog__close",
2867
- type: "button",
2868
- onClick: onClose,
2869
- children: /* @__PURE__ */ jsx2(
4139
+ showHeader && /* @__PURE__ */ jsx4("div", { className: "schematic-header", children: /* @__PURE__ */ jsx4(Heading, { className: "schematic-header__title", children: t("includedFeaturesHeader") }) }),
4140
+ /* @__PURE__ */ jsx4("ul", { className: "schematic-included-features__list", children: shown.map((row) => /* @__PURE__ */ jsxs3(
4141
+ "li",
4142
+ {
4143
+ className: "schematic-included-features__row",
4144
+ "data-testid": "schematic-included-feature",
4145
+ children: [
4146
+ showIcon && row.icon !== null && /* @__PURE__ */ jsx4(
2870
4147
  "i",
2871
4148
  {
2872
4149
  "aria-hidden": "true",
2873
- className: "schematic-icon schematic-icon--close"
4150
+ className: `schematic-icon schematic-icon--${row.icon} schematic-included-features__icon`
4151
+ }
4152
+ ),
4153
+ /* @__PURE__ */ jsxs3("div", { className: "schematic-included-features__details", children: [
4154
+ /* @__PURE__ */ jsx4("span", { className: "schematic-included-features__name", children: row.name }),
4155
+ showDescription && row.description !== null && /* @__PURE__ */ jsx4("span", { className: "schematic-muted schematic-small", children: row.description }),
4156
+ row.perLicenseCredits.map((credits, index) => /* @__PURE__ */ jsx4(
4157
+ "span",
4158
+ {
4159
+ className: "schematic-muted schematic-small",
4160
+ children: t("includedFeaturesPerLicense", {
4161
+ amount: credits.amount,
4162
+ creditName: credits.creditName,
4163
+ licenseName: credits.licenseName
4164
+ })
4165
+ },
4166
+ `${credits.creditName}-${index}`
4167
+ )),
4168
+ showExpiration && row.expiresAt !== null && /* @__PURE__ */ jsx4("em", { className: "schematic-muted schematic-small", children: t("includedFeaturesExpires", { date: row.expiresAt.text }) })
4169
+ ] }),
4170
+ /* @__PURE__ */ jsx4(
4171
+ UsageDetails,
4172
+ {
4173
+ row,
4174
+ showEntitlement,
4175
+ showHardLimit,
4176
+ showUsage,
4177
+ t,
4178
+ locale
2874
4179
  }
2875
4180
  )
2876
- }
2877
- )
2878
- ] }),
2879
- /* @__PURE__ */ jsx2("div", { className: "schematic-dialog__body", children })
4181
+ ]
4182
+ },
4183
+ row.featureId
4184
+ )) }),
4185
+ canExpand && /* @__PURE__ */ jsxs3(
4186
+ "button",
4187
+ {
4188
+ "aria-expanded": expanded,
4189
+ className: "schematic-link-button schematic-included-features__toggle",
4190
+ type: "button",
4191
+ onClick: () => setExpanded((value) => !value),
4192
+ children: [
4193
+ /* @__PURE__ */ jsx4(
4194
+ "i",
4195
+ {
4196
+ "aria-hidden": "true",
4197
+ className: `schematic-icon schematic-icon--${expanded ? "chevron-up" : "chevron-down"} schematic-chevron`
4198
+ }
4199
+ ),
4200
+ /* @__PURE__ */ jsx4("span", { className: "schematic-link-button__label", children: expanded ? t("includedFeaturesHideAll") : t("includedFeaturesSeeAll") })
4201
+ ]
4202
+ }
4203
+ )
2880
4204
  ]
2881
4205
  }
2882
4206
  );
2883
- };
4207
+ }
4208
+ function UsageDetails({
4209
+ locale,
4210
+ row,
4211
+ showEntitlement,
4212
+ showHardLimit,
4213
+ showUsage,
4214
+ t
4215
+ }) {
4216
+ const usage = usageText(row.usage, row.usageSummary, t);
4217
+ if (row.entitlement === null && usage === null) {
4218
+ return null;
4219
+ }
4220
+ return /* @__PURE__ */ jsxs3("div", { className: "schematic-included-features__usage", children: [
4221
+ showEntitlement && row.entitlement !== null && /* @__PURE__ */ jsxs3("span", { className: "schematic-included-features__entitlement", children: [
4222
+ entitlementText2(row.entitlement, t),
4223
+ showHardLimit && row.hardLimit !== null && /* @__PURE__ */ jsx4(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
4224
+ amount: row.hardLimit.amount,
4225
+ units: row.hardLimit.units
4226
+ }) })
4227
+ ] }),
4228
+ showUsage && usage !== null && /* @__PURE__ */ jsxs3("span", { className: "schematic-muted schematic-small schematic-included-features__used", children: [
4229
+ usage,
4230
+ row.tiers !== null && row.tiers.ranges.length > 0 && /* @__PURE__ */ jsx4(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ jsx4(
4231
+ PriceTiers,
4232
+ {
4233
+ currency: row.tiers.currency,
4234
+ locale,
4235
+ mode: row.tiers.mode,
4236
+ period: row.tiers.period,
4237
+ ranges: row.tiers.ranges,
4238
+ t,
4239
+ unit: row.source.featureSingularName ?? row.name
4240
+ }
4241
+ ) })
4242
+ ] })
4243
+ ] });
4244
+ }
4245
+ function entitlementText2(text, t) {
4246
+ switch (text.kind) {
4247
+ case "units":
4248
+ return t("usageUnits", { amount: text.amount, units: text.units });
4249
+ case "perUnit":
4250
+ return t("usagePerUnit", { cost: text.cost, unit: text.unit });
4251
+ case "perPackage":
4252
+ return t("usagePerPackage", {
4253
+ cost: text.cost,
4254
+ size: text.size,
4255
+ units: text.units
4256
+ });
4257
+ case "tierUpTo":
4258
+ return t("usageTierUpTo", { amount: text.amount, feature: text.feature });
4259
+ case "tierUnlimited":
4260
+ return t("usageTierUnlimited", { feature: text.feature });
4261
+ case "perUse":
4262
+ return t("usagePerUse", { amount: text.amount, units: text.units });
4263
+ case "unlimited":
4264
+ return t("usageUnlimited", { item: text.item });
4265
+ }
4266
+ }
4267
+ function usageText(segments, summary, t) {
4268
+ if (segments.length > 0) {
4269
+ return segments.map((segment) => segmentText(segment, t)).join(" \u2022 ");
4270
+ }
4271
+ if (summary === null) {
4272
+ return null;
4273
+ }
4274
+ return summary.kind === "limited" ? t("usageLimited", {
4275
+ amount: summary.amount,
4276
+ allocation: summary.allocation
4277
+ }) : t("usageUnlimitedUsed", { amount: summary.amount });
4278
+ }
4279
+ function segmentText(segment, t) {
4280
+ switch (segment.kind) {
4281
+ case "unitPricePerPeriod": {
4282
+ const period = shortPeriod(segment.period, t) ?? segment.period;
4283
+ return segment.size > 1 ? t("usagePackagePricePerPeriod", {
4284
+ cost: segment.cost,
4285
+ size: segment.size,
4286
+ units: segment.units,
4287
+ period
4288
+ }) : t("usageUnitPricePerPeriod", {
4289
+ cost: segment.cost,
4290
+ unit: segment.units,
4291
+ period
4292
+ });
4293
+ }
4294
+ case "used":
4295
+ return t("usageUsed", { amount: segment.amount, units: segment.units });
4296
+ case "cost": {
4297
+ const period = segment.period === null ? void 0 : shortPeriod(segment.period, t);
4298
+ return period === void 0 ? segment.cost : `${segment.cost}/${period}`;
4299
+ }
4300
+ case "resets":
4301
+ return t("usageResets", { date: segment.date });
4302
+ }
4303
+ }
4304
+ function IncludedFeaturesSkeleton({ showHeader }) {
4305
+ return /* @__PURE__ */ jsxs3("div", { className: "schematic-skeleton", children: [
4306
+ showHeader && /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__heading" }),
4307
+ [0, 1, 2].map((index) => /* @__PURE__ */ jsxs3("div", { className: "schematic-skeleton__row", children: [
4308
+ /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
4309
+ /* @__PURE__ */ jsx4("div", { className: "schematic-skeleton__cell", "data-column": "usage" })
4310
+ ] }, index))
4311
+ ] });
4312
+ }
4313
+ IncludedFeatures.resources = ["featureUsage"];
2884
4314
 
2885
4315
  // src/elements/Invoices.tsx
2886
- import { Fragment, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
4316
+ import { useInvoices } from "@schematichq/schematic-react";
4317
+ import { useId as useId2, useMemo as useMemo3, useState as useState3 } from "react";
4318
+ import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
2887
4319
  var SKELETON_ROWS = 4;
2888
4320
  function Invoices({
2889
4321
  className,
@@ -2906,8 +4338,8 @@ function Invoices({
2906
4338
  } = useInvoices(query);
2907
4339
  const locale = useResolvedLocale(localeProp);
2908
4340
  const t = useTranslator(strings, localeProp);
2909
- const [expanded, setExpanded] = useState(false);
2910
- const list = useMemo(
4341
+ const [expanded, setExpanded] = useState3(false);
4342
+ const list = useMemo3(
2911
4343
  () => page === void 0 ? void 0 : deriveInvoiceList(page, { locale }),
2912
4344
  [locale, page]
2913
4345
  );
@@ -2923,7 +4355,7 @@ function Invoices({
2923
4355
  );
2924
4356
  const unavailable = list === void 0 && httpStatus(error) === 404;
2925
4357
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("invoicesUnavailable") : t("invoicesError");
2926
- return /* @__PURE__ */ jsx3(
4358
+ return /* @__PURE__ */ jsx5(
2927
4359
  StatusFrame,
2928
4360
  {
2929
4361
  className: cx("schematic-card", "schematic-invoices", className),
@@ -2934,7 +4366,7 @@ function Invoices({
2934
4366
  loadingLabel: t("invoicesLoading"),
2935
4367
  onRetry: refetch,
2936
4368
  retryText: t("retry"),
2937
- skeleton: /* @__PURE__ */ jsx3(
4369
+ skeleton: /* @__PURE__ */ jsx5(
2938
4370
  InvoicesSkeleton,
2939
4371
  {
2940
4372
  columns,
@@ -2942,22 +4374,22 @@ function Invoices({
2942
4374
  showHeader
2943
4375
  }
2944
4376
  ),
2945
- children: list !== void 0 && /* @__PURE__ */ jsxs2(Fragment, { children: [
2946
- showHeader && /* @__PURE__ */ jsx3("div", { className: "schematic-header", children: /* @__PURE__ */ jsx3(Heading, { className: "schematic-header__title", id: headingId, children: t("invoicesHeader") }) }),
2947
- rows.length === 0 ? /* @__PURE__ */ jsx3("p", { className: "schematic-muted schematic-invoices__empty", children: t("invoicesEmpty") }) : /* @__PURE__ */ jsx3(
4377
+ children: list !== void 0 && /* @__PURE__ */ jsxs4(Fragment2, { children: [
4378
+ showHeader && /* @__PURE__ */ jsx5("div", { className: "schematic-header", children: /* @__PURE__ */ jsx5(Heading, { className: "schematic-header__title", id: headingId, children: t("invoicesHeader") }) }),
4379
+ rows.length === 0 ? /* @__PURE__ */ jsx5("p", { className: "schematic-muted schematic-invoices__empty", children: t("invoicesEmpty") }) : /* @__PURE__ */ jsx5(
2948
4380
  "ul",
2949
4381
  {
2950
4382
  className: "schematic-invoices__list",
2951
4383
  "aria-label": showHeader ? void 0 : t("invoicesHeader"),
2952
4384
  "aria-labelledby": showHeader ? headingId : void 0,
2953
- children: visible.map((row) => /* @__PURE__ */ jsxs2(
4385
+ children: visible.map((row) => /* @__PURE__ */ jsxs4(
2954
4386
  "li",
2955
4387
  {
2956
4388
  className: "schematic-invoices__row",
2957
4389
  "data-testid": "schematic-invoice",
2958
4390
  children: [
2959
- showDate && /* @__PURE__ */ jsx3("span", { className: "schematic-invoices__date", children: /* @__PURE__ */ jsx3(InvoiceDate, { row, t }) }),
2960
- showAmount && /* @__PURE__ */ jsx3(
4391
+ showDate && /* @__PURE__ */ jsx5("span", { className: "schematic-invoices__date", children: /* @__PURE__ */ jsx5(InvoiceDate, { row, t }) }),
4392
+ showAmount && /* @__PURE__ */ jsx5(
2961
4393
  "span",
2962
4394
  {
2963
4395
  className: cx(
@@ -2974,8 +4406,8 @@ function Invoices({
2974
4406
  ))
2975
4407
  }
2976
4408
  ),
2977
- (canCollapse || showingAll && list.hasMore) && /* @__PURE__ */ jsxs2("div", { className: "schematic-invoices__actions", children: [
2978
- canCollapse && /* @__PURE__ */ jsxs2(
4409
+ (canCollapse || showingAll && list.hasMore) && /* @__PURE__ */ jsxs4("div", { className: "schematic-invoices__actions", children: [
4410
+ canCollapse && /* @__PURE__ */ jsxs4(
2979
4411
  "button",
2980
4412
  {
2981
4413
  "aria-expanded": expanded,
@@ -2983,18 +4415,23 @@ function Invoices({
2983
4415
  type: "button",
2984
4416
  onClick: () => setExpanded((value) => !value),
2985
4417
  children: [
2986
- /* @__PURE__ */ jsx3(
2987
- "span",
4418
+ /* @__PURE__ */ jsx5(
4419
+ "i",
2988
4420
  {
2989
4421
  "aria-hidden": "true",
2990
- className: "schematic-invoices__chevron"
4422
+ className: cx(
4423
+ "schematic-icon",
4424
+ expanded ? "schematic-icon--chevron-up" : "schematic-icon--chevron-down",
4425
+ "schematic-chevron",
4426
+ "schematic-invoices__chevron"
4427
+ )
2991
4428
  }
2992
4429
  ),
2993
- expanded ? t("invoicesSeeLess") : t("invoicesSeeMore")
4430
+ /* @__PURE__ */ jsx5("span", { className: "schematic-link-button__label", children: expanded ? t("invoicesSeeLess") : t("invoicesSeeMore") })
2994
4431
  ]
2995
4432
  }
2996
4433
  ),
2997
- showingAll && list.hasMore && /* @__PURE__ */ jsx3(
4434
+ showingAll && list.hasMore && /* @__PURE__ */ jsx5(
2998
4435
  "button",
2999
4436
  {
3000
4437
  className: "schematic-link-button schematic-invoices__load-more",
@@ -3017,9 +4454,9 @@ function InvoicesSkeleton({
3017
4454
  rows,
3018
4455
  showHeader
3019
4456
  }) {
3020
- return /* @__PURE__ */ jsxs2("div", { className: "schematic-skeleton", children: [
3021
- showHeader && /* @__PURE__ */ jsx3("div", { className: "schematic-skeleton__heading" }),
3022
- Array.from({ length: rows }, (_, row) => /* @__PURE__ */ jsx3("div", { className: "schematic-skeleton__row", children: columns.map((column) => /* @__PURE__ */ jsx3(
4457
+ return /* @__PURE__ */ jsxs4("div", { className: "schematic-skeleton", children: [
4458
+ showHeader && /* @__PURE__ */ jsx5("div", { className: "schematic-skeleton__heading" }),
4459
+ Array.from({ length: rows }, (_, row) => /* @__PURE__ */ jsx5("div", { className: "schematic-skeleton__row", children: columns.map((column) => /* @__PURE__ */ jsx5(
3023
4460
  "div",
3024
4461
  {
3025
4462
  className: "schematic-skeleton__cell",
@@ -3031,10 +4468,10 @@ function InvoicesSkeleton({
3031
4468
  }
3032
4469
  function InvoiceDate({ row, t }) {
3033
4470
  if (row.url === null) {
3034
- return /* @__PURE__ */ jsx3("span", { className: "schematic-invoices__date-text", children: row.dateText });
4471
+ return /* @__PURE__ */ jsx5("span", { className: "schematic-invoices__date-text", children: row.dateText });
3035
4472
  }
3036
4473
  const label = row.dateText === "" ? t("invoicesUndated") : row.dateText;
3037
- return /* @__PURE__ */ jsx3(
4474
+ return /* @__PURE__ */ jsx5(
3038
4475
  "a",
3039
4476
  {
3040
4477
  className: "schematic-invoices__link",
@@ -3047,10 +4484,356 @@ function InvoiceDate({ row, t }) {
3047
4484
  }
3048
4485
  Invoices.resources = ["invoices"];
3049
4486
 
4487
+ // src/elements/MeteredFeatures.tsx
4488
+ import {
4489
+ useFeatureUsage as useFeatureUsage2,
4490
+ useFeatureUserUsage
4491
+ } from "@schematichq/schematic-react";
4492
+ import { useMemo as useMemo4 } from "react";
4493
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
4494
+ function MeteredFeatures({
4495
+ addMoreTarget,
4496
+ addMoreUrl,
4497
+ className,
4498
+ headingLevel = 2,
4499
+ locale: localeProp,
4500
+ onAddMore,
4501
+ showAllocation = true,
4502
+ showCredits = true,
4503
+ showDescription = true,
4504
+ showHardLimit = false,
4505
+ showHeader = false,
4506
+ showIcon = true,
4507
+ showMeter = true,
4508
+ showUsage = true,
4509
+ showUsageByUser = true,
4510
+ showWarningThresholdAsLimit = false,
4511
+ strings,
4512
+ visibleFeatures
4513
+ }) {
4514
+ const { data: features, error, isPending, refetch } = useFeatureUsage2();
4515
+ const locale = useResolvedLocale(localeProp);
4516
+ const t = useTranslator(strings, localeProp);
4517
+ const rows = useMemo4(
4518
+ () => features === void 0 ? [] : deriveMeteredFeatures(features, {
4519
+ locale,
4520
+ showCredits,
4521
+ showWarningThresholdAsLimit,
4522
+ visibleFeatures
4523
+ }),
4524
+ [
4525
+ features,
4526
+ locale,
4527
+ showCredits,
4528
+ showWarningThresholdAsLimit,
4529
+ visibleFeatures
4530
+ ]
4531
+ );
4532
+ const unavailable = features === void 0 && httpStatus(error) === 404;
4533
+ const errorMessage = error === void 0 ? void 0 : unavailable ? t("meteredFeaturesUnavailable") : t("meteredFeaturesError");
4534
+ if (features !== void 0 && error === void 0 && rows.length === 0) {
4535
+ return null;
4536
+ }
4537
+ const Heading = `h${headingLevel}`;
4538
+ const NameHeading = showHeader ? `h${Math.min(6, headingLevel + 1)}` : Heading;
4539
+ return /* @__PURE__ */ jsxs5(
4540
+ StatusFrame,
4541
+ {
4542
+ className: cx("schematic-metered-features", className),
4543
+ error,
4544
+ errorMessage,
4545
+ hasData: features !== void 0,
4546
+ isPending,
4547
+ loadingLabel: t("meteredFeaturesLoading"),
4548
+ onRetry: refetch,
4549
+ retryText: t("retry"),
4550
+ skeleton: /* @__PURE__ */ jsx6(MeteredFeaturesSkeleton, { showHeader }),
4551
+ children: [
4552
+ showHeader && /* @__PURE__ */ jsx6("div", { className: "schematic-header", children: /* @__PURE__ */ jsx6(Heading, { className: "schematic-header__title", children: t("meteredFeaturesHeader") }) }),
4553
+ /* @__PURE__ */ jsx6("ul", { className: "schematic-metered-features__list", children: rows.map((row) => /* @__PURE__ */ jsxs5(
4554
+ "li",
4555
+ {
4556
+ className: "schematic-card schematic-metered-features__feature",
4557
+ "data-testid": "schematic-metered-feature",
4558
+ children: [
4559
+ /* @__PURE__ */ jsxs5("div", { className: "schematic-metered-features__main", children: [
4560
+ showIcon && /* @__PURE__ */ jsx6("span", { className: "schematic-metered-features__icon", children: row.icon !== null && /* @__PURE__ */ jsx6(
4561
+ "i",
4562
+ {
4563
+ "aria-hidden": "true",
4564
+ className: `schematic-icon schematic-icon--${row.icon}`
4565
+ }
4566
+ ) }),
4567
+ /* @__PURE__ */ jsxs5("div", { className: "schematic-metered-features__body", children: [
4568
+ /* @__PURE__ */ jsxs5("div", { className: "schematic-metered-features__top", children: [
4569
+ /* @__PURE__ */ jsxs5("div", { className: "schematic-metered-features__title", children: [
4570
+ /* @__PURE__ */ jsx6(NameHeading, { className: "schematic-metered-features__name", children: row.name }),
4571
+ showDescription && row.description !== null && /* @__PURE__ */ jsx6("p", { className: "schematic-muted", children: row.description })
4572
+ ] }),
4573
+ /* @__PURE__ */ jsxs5("div", { className: "schematic-metered-features__figures", children: [
4574
+ showUsage && row.headline !== null && /* @__PURE__ */ jsx6("span", { className: "schematic-metered-features__headline", children: headlineText(row.headline, t) }),
4575
+ showAllocation && /* @__PURE__ */ jsx6(
4576
+ LimitLine,
4577
+ {
4578
+ row,
4579
+ showHardLimit,
4580
+ t
4581
+ }
4582
+ )
4583
+ ] })
4584
+ ] }),
4585
+ showMeter && row.meter !== null && /* @__PURE__ */ jsx6(Meter, { meter: row.meter }),
4586
+ row.canAddMore && /* @__PURE__ */ jsx6(
4587
+ AddMore,
4588
+ {
4589
+ label: t("meteredFeaturesAddMore"),
4590
+ onAddMore: onAddMore === void 0 ? void 0 : () => onAddMore(row.source),
4591
+ target: addMoreTarget,
4592
+ url: addMoreUrl
4593
+ }
4594
+ )
4595
+ ] })
4596
+ ] }),
4597
+ showUsageByUser && row.hasUsageByUser && /* @__PURE__ */ jsx6(UsageByUser, { locale, row, t }),
4598
+ row.priceDetails !== null && /* @__PURE__ */ jsx6(
4599
+ PriceDetails,
4600
+ {
4601
+ details: row.priceDetails,
4602
+ locale,
4603
+ row,
4604
+ t
4605
+ }
4606
+ )
4607
+ ]
4608
+ },
4609
+ row.featureId
4610
+ )) })
4611
+ ]
4612
+ }
4613
+ );
4614
+ }
4615
+ function headlineText(headline2, t) {
4616
+ if (headline2.kind === "used") {
4617
+ return t("meteredFeaturesUsed", {
4618
+ amount: headline2.amount,
4619
+ units: headline2.units
4620
+ });
4621
+ }
4622
+ return headline2.amount === null ? headline2.units : t("usageUnits", { amount: headline2.amount, units: headline2.units });
4623
+ }
4624
+ function limitText(limit, t) {
4625
+ switch (limit.kind) {
4626
+ case "tierUpTo":
4627
+ return t("usageTierUpTo", {
4628
+ amount: limit.amount,
4629
+ feature: limit.feature
4630
+ });
4631
+ case "tierUnlimited":
4632
+ return t("usageTierUnlimited", { feature: limit.feature });
4633
+ case "included":
4634
+ return t("meteredFeaturesIncluded", { amount: limit.amount });
4635
+ case "used":
4636
+ return t("meteredFeaturesInUse", { amount: limit.amount });
4637
+ case "cost":
4638
+ return limit.cost;
4639
+ case "perUse":
4640
+ return t("usagePerUse", { amount: limit.amount, units: limit.units });
4641
+ case "limitOf":
4642
+ return t("meteredFeaturesLimitOf", { amount: limit.amount });
4643
+ case "noLimit":
4644
+ return t("meteredFeaturesNoLimit");
4645
+ }
4646
+ }
4647
+ function LimitLine({
4648
+ row,
4649
+ showHardLimit,
4650
+ t
4651
+ }) {
4652
+ const parts = [];
4653
+ if (row.limit !== null) {
4654
+ parts.push(limitText(row.limit, t));
4655
+ }
4656
+ if (row.resetsAt !== null) {
4657
+ parts.push(t("usageResets", { date: row.resetsAt }));
4658
+ }
4659
+ if (parts.length === 0) {
4660
+ return null;
4661
+ }
4662
+ return /* @__PURE__ */ jsxs5("span", { className: "schematic-muted schematic-metered-features__limit", children: [
4663
+ parts.join(" \u2022 "),
4664
+ showHardLimit && row.hardLimit !== null && /* @__PURE__ */ jsx6(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
4665
+ amount: row.hardLimit.amount,
4666
+ units: row.hardLimit.units
4667
+ }) })
4668
+ ] });
4669
+ }
4670
+ var METER_TONE_CLASS = {
4671
+ ok: void 0,
4672
+ warning: "schematic-meter--warning",
4673
+ critical: "schematic-meter--over",
4674
+ tier: "schematic-meter--tier",
4675
+ overage: "schematic-meter--overage"
4676
+ };
4677
+ function Meter({ meter: meter2 }) {
4678
+ return /* @__PURE__ */ jsxs5("div", { className: "schematic-metered-features__meter", children: [
4679
+ /* @__PURE__ */ jsx6(
4680
+ "div",
4681
+ {
4682
+ "aria-valuemax": meter2.total,
4683
+ "aria-valuemin": 0,
4684
+ "aria-valuenow": meter2.value,
4685
+ className: cx("schematic-meter", METER_TONE_CLASS[meter2.tone]),
4686
+ "data-tone": meter2.tone,
4687
+ role: "meter",
4688
+ children: /* @__PURE__ */ jsx6(
4689
+ "div",
4690
+ {
4691
+ className: "schematic-meter__fill",
4692
+ style: { width: `${meter2.percent}%` }
4693
+ }
4694
+ )
4695
+ }
4696
+ ),
4697
+ meter2.total > 0 && /* @__PURE__ */ jsxs5("span", { className: "schematic-metered-features__meter-label", children: [
4698
+ meter2.valueText,
4699
+ "/",
4700
+ meter2.totalText
4701
+ ] })
4702
+ ] });
4703
+ }
4704
+ function AddMore({
4705
+ label,
4706
+ onAddMore,
4707
+ target,
4708
+ url
4709
+ }) {
4710
+ if (onAddMore !== void 0) {
4711
+ return /* @__PURE__ */ jsx6(
4712
+ "button",
4713
+ {
4714
+ className: "schematic-cta schematic-metered-features__add-more",
4715
+ type: "button",
4716
+ onClick: onAddMore,
4717
+ children: label
4718
+ }
4719
+ );
4720
+ }
4721
+ if (url !== void 0) {
4722
+ return /* @__PURE__ */ jsx6(
4723
+ "a",
4724
+ {
4725
+ className: "schematic-cta schematic-metered-features__add-more",
4726
+ href: url,
4727
+ target,
4728
+ children: label
4729
+ }
4730
+ );
4731
+ }
4732
+ return null;
4733
+ }
4734
+ function PriceDetails({
4735
+ details,
4736
+ locale,
4737
+ row,
4738
+ t
4739
+ }) {
4740
+ const period = details.period === null ? void 0 : shortPeriod(details.period, t);
4741
+ if (details.kind === "overage") {
4742
+ return /* @__PURE__ */ jsxs5("div", { className: "schematic-metered-features__price-details", children: [
4743
+ /* @__PURE__ */ jsxs5("span", { children: [
4744
+ t("meteredFeaturesAdditional"),
4745
+ ": ",
4746
+ details.unitPrice,
4747
+ /* @__PURE__ */ jsxs5("sub", { children: [
4748
+ "/",
4749
+ details.packageSize > 1 && `${details.packageSize} `,
4750
+ details.units,
4751
+ period !== void 0 && `/${period}`
4752
+ ] })
4753
+ ] }),
4754
+ /* @__PURE__ */ jsxs5("span", { children: [
4755
+ details.overage.amount,
4756
+ " ",
4757
+ details.overage.units,
4758
+ " \xB7 ",
4759
+ details.overage.cost,
4760
+ period !== void 0 && /* @__PURE__ */ jsxs5("sub", { children: [
4761
+ "/",
4762
+ period
4763
+ ] })
4764
+ ] })
4765
+ ] });
4766
+ }
4767
+ return /* @__PURE__ */ jsxs5("div", { className: "schematic-metered-features__price-details", children: [
4768
+ /* @__PURE__ */ jsxs5("span", { children: [
4769
+ t("meteredFeaturesTier"),
4770
+ ": ",
4771
+ details.from,
4772
+ details.to === null ? "+" : details.to !== details.from ? `\u2013${details.to}` : "",
4773
+ /* @__PURE__ */ jsx6(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ jsx6(
4774
+ PriceTiers,
4775
+ {
4776
+ currency: details.tiers.currency,
4777
+ locale,
4778
+ mode: details.tiers.mode,
4779
+ period: details.period,
4780
+ ranges: details.tiers.ranges,
4781
+ t,
4782
+ unit: featureName(row.unit, 1, locale)
4783
+ }
4784
+ ) })
4785
+ ] }),
4786
+ details.cost !== null && /* @__PURE__ */ jsxs5("span", { children: [
4787
+ details.cost,
4788
+ period !== void 0 && /* @__PURE__ */ jsxs5("sub", { children: [
4789
+ "/",
4790
+ period
4791
+ ] })
4792
+ ] })
4793
+ ] });
4794
+ }
4795
+ function UsageByUser({
4796
+ locale,
4797
+ row,
4798
+ t
4799
+ }) {
4800
+ const { data, error, refetch } = useFeatureUserUsage(row.featureId);
4801
+ return /* @__PURE__ */ jsx6(
4802
+ UserBreakdown,
4803
+ {
4804
+ breakdown: data === void 0 ? void 0 : {
4805
+ count: data.count,
4806
+ total: data.total,
4807
+ unattributed: data.unattributed ?? null,
4808
+ users: data.users.map((user) => ({
4809
+ amount: user.usage,
4810
+ id: user.userId,
4811
+ label: user.name ?? user.userId
4812
+ }))
4813
+ },
4814
+ error,
4815
+ locale,
4816
+ onRetry: refetch,
4817
+ t,
4818
+ unit: row.unit
4819
+ }
4820
+ );
4821
+ }
4822
+ function MeteredFeaturesSkeleton({ showHeader }) {
4823
+ return /* @__PURE__ */ jsxs5("div", { className: "schematic-skeleton", children: [
4824
+ showHeader && /* @__PURE__ */ jsx6("div", { className: "schematic-skeleton__heading" }),
4825
+ [0, 1].map((index) => /* @__PURE__ */ jsxs5("div", { className: "schematic-skeleton__row", children: [
4826
+ /* @__PURE__ */ jsx6("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
4827
+ /* @__PURE__ */ jsx6("div", { className: "schematic-skeleton__cell", "data-column": "usage" })
4828
+ ] }, index))
4829
+ ] });
4830
+ }
4831
+ MeteredFeatures.resources = ["featureUsage"];
4832
+
3050
4833
  // src/elements/PaymentMethods.tsx
3051
4834
  import { usePaymentMethods } from "@schematichq/schematic-react";
3052
- import { Suspense, lazy, useCallback as useCallback2, useMemo as useMemo2, useState as useState3 } from "react";
3053
- import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
4835
+ import { Suspense, lazy, useCallback as useCallback2, useMemo as useMemo5, useState as useState5 } from "react";
4836
+ import { Fragment as Fragment3, jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
3054
4837
  var PaymentMethodForm2 = lazy(() => Promise.resolve().then(() => (init_PaymentMethodForm(), PaymentMethodForm_exports)));
3055
4838
  function PaymentMethods({
3056
4839
  allowEdit = true,
@@ -3075,10 +4858,10 @@ function PaymentMethods({
3075
4858
  } = usePaymentMethods();
3076
4859
  const locale = useResolvedLocale(localeProp);
3077
4860
  const t = useTranslator(strings, localeProp);
3078
- const [dialog, setDialog] = useState3(null);
3079
- const [choosing, setChoosing] = useState3(false);
3080
- const [lastWrite, setLastWrite] = useState3(null);
3081
- const derived = useMemo2(
4861
+ const [dialog, setDialog] = useState5(null);
4862
+ const [choosing, setChoosing] = useState5(false);
4863
+ const [lastWrite, setLastWrite] = useState5(null);
4864
+ const derived = useMemo5(
3082
4865
  () => methods === void 0 ? void 0 : derivePaymentMethods(methods, { locale }),
3083
4866
  [locale, methods]
3084
4867
  );
@@ -3109,7 +4892,7 @@ function PaymentMethods({
3109
4892
  const Heading = `h${headingLevel}`;
3110
4893
  const unavailable = derived === void 0 && httpStatus(error) === 404;
3111
4894
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("paymentMethodsUnavailable") : t("paymentMethodsError");
3112
- return /* @__PURE__ */ jsx5(
4895
+ return /* @__PURE__ */ jsx8(
3113
4896
  StatusFrame,
3114
4897
  {
3115
4898
  className: cx("schematic-card", "schematic-payment-methods", className),
@@ -3120,9 +4903,9 @@ function PaymentMethods({
3120
4903
  loadingLabel: t("paymentMethodsLoading"),
3121
4904
  onRetry: refetch,
3122
4905
  retryText: t("retry"),
3123
- skeleton: /* @__PURE__ */ jsx5(PaymentMethodsSkeleton, { showHeader }),
3124
- children: derived !== void 0 && /* @__PURE__ */ jsxs4(Fragment2, { children: [
3125
- showHeader && /* @__PURE__ */ jsx5(
4906
+ skeleton: /* @__PURE__ */ jsx8(PaymentMethodsSkeleton, { showHeader }),
4907
+ children: derived !== void 0 && /* @__PURE__ */ jsxs7(Fragment3, { children: [
4908
+ showHeader && /* @__PURE__ */ jsx8(
3126
4909
  PaymentMethodsHeader,
3127
4910
  {
3128
4911
  derived,
@@ -3131,7 +4914,7 @@ function PaymentMethods({
3131
4914
  t
3132
4915
  }
3133
4916
  ),
3134
- /* @__PURE__ */ jsx5(MethodPill, { row: derived.current, t, children: allowEdit && /* @__PURE__ */ jsx5(
4917
+ /* @__PURE__ */ jsx8(MethodPill, { row: derived.current, t, children: allowEdit && /* @__PURE__ */ jsx8(
3135
4918
  "button",
3136
4919
  {
3137
4920
  className: "schematic-link-button schematic-payment-methods__edit",
@@ -3140,7 +4923,7 @@ function PaymentMethods({
3140
4923
  children: derived.current === null ? t("paymentMethodsAdd") : t("paymentMethodsEdit")
3141
4924
  }
3142
4925
  ) }),
3143
- dialog !== null && /* @__PURE__ */ jsx5(
4926
+ dialog !== null && /* @__PURE__ */ jsx8(
3144
4927
  PaymentMethodsDialog,
3145
4928
  {
3146
4929
  checkoutPrefill,
@@ -3192,7 +4975,7 @@ function PaymentMethodsDialog({
3192
4975
  const { current, others, rows } = derived;
3193
4976
  const hasMethods = rows.length > 0;
3194
4977
  const showForm = view === "add" || !hasMethods;
3195
- return /* @__PURE__ */ jsxs4(
4978
+ return /* @__PURE__ */ jsxs7(
3196
4979
  Dialog,
3197
4980
  {
3198
4981
  className: "schematic-payment-methods__dialog",
@@ -3201,11 +4984,11 @@ function PaymentMethodsDialog({
3201
4984
  title: t("paymentMethodsDialogTitle"),
3202
4985
  onClose,
3203
4986
  children: [
3204
- showForm ? /* @__PURE__ */ jsx5(
4987
+ showForm ? /* @__PURE__ */ jsx8(
3205
4988
  Suspense,
3206
4989
  {
3207
- fallback: /* @__PURE__ */ jsx5(FormSkeleton, { label: t("paymentMethodsFormLoading") }),
3208
- children: /* @__PURE__ */ jsx5(
4990
+ fallback: /* @__PURE__ */ jsx8(FormSkeleton, { label: t("paymentMethodsFormLoading") }),
4991
+ children: /* @__PURE__ */ jsx8(
3209
4992
  PaymentMethodForm2,
3210
4993
  {
3211
4994
  checkoutPrefill,
@@ -3217,8 +5000,8 @@ function PaymentMethodsDialog({
3217
5000
  }
3218
5001
  )
3219
5002
  }
3220
- ) : /* @__PURE__ */ jsxs4(Fragment2, { children: [
3221
- /* @__PURE__ */ jsx5(
5003
+ ) : /* @__PURE__ */ jsxs7(Fragment3, { children: [
5004
+ /* @__PURE__ */ jsx8(
3222
5005
  PaymentMethodsHeader,
3223
5006
  {
3224
5007
  derived,
@@ -3227,7 +5010,7 @@ function PaymentMethodsDialog({
3227
5010
  t
3228
5011
  }
3229
5012
  ),
3230
- /* @__PURE__ */ jsx5(MethodPill, { row: current, t, children: current?.canRemove === true && /* @__PURE__ */ jsx5(
5013
+ /* @__PURE__ */ jsx8(MethodPill, { row: current, t, children: current?.canRemove === true && /* @__PURE__ */ jsx8(
3231
5014
  "button",
3232
5015
  {
3233
5016
  className: "schematic-link-button schematic-payment-methods__remove-current",
@@ -3237,7 +5020,7 @@ function PaymentMethodsDialog({
3237
5020
  children: t("paymentMethodsRemove")
3238
5021
  }
3239
5022
  ) }),
3240
- /* @__PURE__ */ jsxs4(
5023
+ /* @__PURE__ */ jsxs7(
3241
5024
  "button",
3242
5025
  {
3243
5026
  "aria-expanded": choosing,
@@ -3245,14 +5028,15 @@ function PaymentMethodsDialog({
3245
5028
  type: "button",
3246
5029
  onClick: onChoose,
3247
5030
  children: [
3248
- /* @__PURE__ */ jsx5("span", { className: "schematic-payment-methods__choose-label", children: t("paymentMethodsChooseDifferent") }),
3249
- /* @__PURE__ */ jsx5(
5031
+ /* @__PURE__ */ jsx8("span", { className: "schematic-payment-methods__choose-label", children: t("paymentMethodsChooseDifferent") }),
5032
+ /* @__PURE__ */ jsx8(
3250
5033
  "i",
3251
5034
  {
3252
5035
  "aria-hidden": "true",
3253
5036
  className: cx(
3254
5037
  "schematic-icon",
3255
5038
  choosing ? "schematic-icon--chevron-up" : "schematic-icon--chevron-down",
5039
+ "schematic-chevron",
3256
5040
  "schematic-payment-methods__chevron"
3257
5041
  )
3258
5042
  }
@@ -3260,13 +5044,13 @@ function PaymentMethodsDialog({
3260
5044
  ]
3261
5045
  }
3262
5046
  ),
3263
- choosing && /* @__PURE__ */ jsxs4(Fragment2, { children: [
3264
- others.length > 0 && /* @__PURE__ */ jsx5(
5047
+ choosing && /* @__PURE__ */ jsxs7(Fragment3, { children: [
5048
+ others.length > 0 && /* @__PURE__ */ jsx8(
3265
5049
  "ul",
3266
5050
  {
3267
5051
  "aria-label": t("paymentMethodsChooseDifferent"),
3268
5052
  className: "schematic-payment-methods__list",
3269
- children: others.map((row) => /* @__PURE__ */ jsxs4(
5053
+ children: others.map((row) => /* @__PURE__ */ jsxs7(
3270
5054
  "li",
3271
5055
  {
3272
5056
  className: "schematic-payment-methods__row",
@@ -3274,11 +5058,11 @@ function PaymentMethodsDialog({
3274
5058
  "data-kind": row.kind,
3275
5059
  "data-testid": "schematic-payment-method",
3276
5060
  children: [
3277
- /* @__PURE__ */ jsx5(Method, { row, t }),
3278
- row.expiresShort !== null && /* @__PURE__ */ jsx5("span", { className: "schematic-payment-methods__expires", children: t("paymentMethodsExpires", {
5061
+ /* @__PURE__ */ jsx8(Method, { row, t }),
5062
+ row.expiresShort !== null && /* @__PURE__ */ jsx8("span", { className: "schematic-payment-methods__expires", children: t("paymentMethodsExpires", {
3279
5063
  date: row.expiresShort
3280
5064
  }) }),
3281
- /* @__PURE__ */ jsx5(
5065
+ /* @__PURE__ */ jsx8(
3282
5066
  "button",
3283
5067
  {
3284
5068
  className: "schematic-link-button schematic-payment-methods__set-default",
@@ -3288,7 +5072,7 @@ function PaymentMethodsDialog({
3288
5072
  children: t("paymentMethodsSetDefault")
3289
5073
  }
3290
5074
  ),
3291
- row.canRemove && /* @__PURE__ */ jsx5(
5075
+ row.canRemove && /* @__PURE__ */ jsx8(
3292
5076
  "button",
3293
5077
  {
3294
5078
  "aria-label": t("paymentMethodsRemove"),
@@ -3296,7 +5080,7 @@ function PaymentMethodsDialog({
3296
5080
  disabled: isMutating,
3297
5081
  type: "button",
3298
5082
  onClick: () => onRemove(row),
3299
- children: /* @__PURE__ */ jsx5(
5083
+ children: /* @__PURE__ */ jsx8(
3300
5084
  "i",
3301
5085
  {
3302
5086
  "aria-hidden": "true",
@@ -3311,7 +5095,7 @@ function PaymentMethodsDialog({
3311
5095
  ))
3312
5096
  }
3313
5097
  ),
3314
- /* @__PURE__ */ jsx5(
5098
+ /* @__PURE__ */ jsx8(
3315
5099
  "button",
3316
5100
  {
3317
5101
  className: "schematic-cta schematic-payment-methods__add-new",
@@ -3323,17 +5107,17 @@ function PaymentMethodsDialog({
3323
5107
  )
3324
5108
  ] })
3325
5109
  ] }),
3326
- mutationError !== void 0 && /* @__PURE__ */ jsxs4(
5110
+ mutationError !== void 0 && /* @__PURE__ */ jsxs7(
3327
5111
  "p",
3328
5112
  {
3329
5113
  className: "schematic-status-note schematic-error schematic-payment-methods__error",
3330
5114
  role: "alert",
3331
5115
  children: [
3332
- /* @__PURE__ */ jsx5("span", { className: "schematic-payment-methods__error-message", children: mutationError }),
3333
- onRetry !== void 0 && /* @__PURE__ */ jsx5(
5116
+ /* @__PURE__ */ jsx8("span", { className: "schematic-payment-methods__error-message", children: mutationError }),
5117
+ onRetry !== void 0 && /* @__PURE__ */ jsx8(
3334
5118
  "button",
3335
5119
  {
3336
- className: "schematic-link-button schematic-payment-methods__error-retry",
5120
+ className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-payment-methods__error-retry",
3337
5121
  disabled: isMutating,
3338
5122
  type: "button",
3339
5123
  onClick: onRetry,
@@ -3353,9 +5137,9 @@ function PaymentMethodsHeader({
3353
5137
  showExpiration,
3354
5138
  t
3355
5139
  }) {
3356
- return /* @__PURE__ */ jsxs4("div", { className: "schematic-header", children: [
3357
- /* @__PURE__ */ jsx5(Heading, { className: "schematic-header__title", children: t("paymentMethodsHeader") }),
3358
- showExpiration && derived.expiryWarning !== "none" && /* @__PURE__ */ jsx5(
5140
+ return /* @__PURE__ */ jsxs7("div", { className: "schematic-header", children: [
5141
+ /* @__PURE__ */ jsx8(Heading, { className: "schematic-header__title", children: t("paymentMethodsHeader") }),
5142
+ showExpiration && derived.expiryWarning !== "none" && /* @__PURE__ */ jsx8(
3359
5143
  "span",
3360
5144
  {
3361
5145
  className: "schematic-small schematic-payment-methods__expiry-warning",
@@ -3370,37 +5154,37 @@ function MethodPill({
3370
5154
  row,
3371
5155
  t
3372
5156
  }) {
3373
- return /* @__PURE__ */ jsxs4(
5157
+ return /* @__PURE__ */ jsxs7(
3374
5158
  "div",
3375
5159
  {
3376
5160
  className: "schematic-payment-methods__current",
3377
5161
  "data-testid": "schematic-payment-method-current",
3378
5162
  children: [
3379
- row === null ? /* @__PURE__ */ jsx5("span", { className: "schematic-payment-methods__empty", children: t("paymentMethodsEmpty") }) : /* @__PURE__ */ jsx5(Method, { row, t }),
5163
+ row === null ? /* @__PURE__ */ jsx8("span", { className: "schematic-payment-methods__empty", children: t("paymentMethodsEmpty") }) : /* @__PURE__ */ jsx8(Method, { row, t }),
3380
5164
  children
3381
5165
  ]
3382
5166
  }
3383
5167
  );
3384
5168
  }
3385
5169
  function Method({ row, t }) {
3386
- return /* @__PURE__ */ jsxs4(
5170
+ return /* @__PURE__ */ jsxs7(
3387
5171
  "span",
3388
5172
  {
3389
5173
  className: "schematic-payment-methods__method",
3390
5174
  "data-brand": row.brand,
3391
5175
  "data-kind": row.kind,
3392
5176
  children: [
3393
- /* @__PURE__ */ jsx5(
5177
+ /* @__PURE__ */ jsx8(
3394
5178
  "i",
3395
5179
  {
3396
5180
  "aria-hidden": "true",
3397
5181
  className: `schematic-icon schematic-icon--${row.icon} schematic-payment-methods__icon`
3398
5182
  }
3399
5183
  ),
3400
- /* @__PURE__ */ jsx5("span", { className: "schematic-payment-methods__label", children: labelText(row.label, t) }),
3401
- row.last4 !== null && /* @__PURE__ */ jsxs4(Fragment2, { children: [
5184
+ /* @__PURE__ */ jsx8("span", { className: "schematic-payment-methods__label", children: labelText(row.label, t) }),
5185
+ row.last4 !== null && /* @__PURE__ */ jsxs7(Fragment3, { children: [
3402
5186
  " ",
3403
- /* @__PURE__ */ jsx5("span", { className: "schematic-payment-methods__last4", children: row.last4 })
5187
+ /* @__PURE__ */ jsx8("span", { className: "schematic-payment-methods__last4", children: row.last4 })
3404
5188
  ] })
3405
5189
  ]
3406
5190
  }
@@ -3414,24 +5198,24 @@ function expiryWarningText(derived, t) {
3414
5198
  return derived.expiryWarning === "expired" ? t("paymentMethodsExpired") : t("paymentMethodsExpiresInMonths", { months });
3415
5199
  }
3416
5200
  function PaymentMethodsSkeleton({ showHeader }) {
3417
- return /* @__PURE__ */ jsxs4("div", { className: "schematic-skeleton", children: [
3418
- showHeader && /* @__PURE__ */ jsx5("div", { className: "schematic-skeleton__heading" }),
3419
- /* @__PURE__ */ jsxs4("div", { className: "schematic-skeleton__row", children: [
3420
- /* @__PURE__ */ jsx5("div", { className: "schematic-skeleton__cell", "data-column": "method" }),
3421
- /* @__PURE__ */ jsx5("div", { className: "schematic-skeleton__cell", "data-column": "action" })
5201
+ return /* @__PURE__ */ jsxs7("div", { className: "schematic-skeleton", children: [
5202
+ showHeader && /* @__PURE__ */ jsx8("div", { className: "schematic-skeleton__heading" }),
5203
+ /* @__PURE__ */ jsxs7("div", { className: "schematic-skeleton__row", children: [
5204
+ /* @__PURE__ */ jsx8("div", { className: "schematic-skeleton__cell", "data-column": "method" }),
5205
+ /* @__PURE__ */ jsx8("div", { className: "schematic-skeleton__cell", "data-column": "action" })
3422
5206
  ] })
3423
5207
  ] });
3424
5208
  }
3425
5209
  function FormSkeleton({ label }) {
3426
- return /* @__PURE__ */ jsxs4(
5210
+ return /* @__PURE__ */ jsxs7(
3427
5211
  "div",
3428
5212
  {
3429
5213
  "aria-busy": "true",
3430
5214
  className: "schematic-payment-methods__form",
3431
5215
  "data-state": "pending",
3432
5216
  children: [
3433
- /* @__PURE__ */ jsx5("span", { className: "schematic-hidden", children: label }),
3434
- /* @__PURE__ */ jsx5("div", { className: "schematic-skeleton", children: /* @__PURE__ */ jsx5("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx5("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
5217
+ /* @__PURE__ */ jsx8("span", { className: "schematic-hidden", children: label }),
5218
+ /* @__PURE__ */ jsx8("div", { className: "schematic-skeleton", children: /* @__PURE__ */ jsx8("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx8("div", { className: "schematic-skeleton__cell", "data-column": "field" }) }) })
3435
5219
  ]
3436
5220
  }
3437
5221
  );
@@ -3440,8 +5224,8 @@ PaymentMethods.resources = ["paymentMethods"];
3440
5224
 
3441
5225
  // src/elements/UpcomingBill.tsx
3442
5226
  import { useUpcomingInvoice } from "@schematichq/schematic-react";
3443
- import { useMemo as useMemo3 } from "react";
3444
- import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
5227
+ import { useMemo as useMemo6 } from "react";
5228
+ import { Fragment as Fragment4, jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
3445
5229
  function UpcomingBill({
3446
5230
  className,
3447
5231
  headingLevel = 2,
@@ -3455,7 +5239,7 @@ function UpcomingBill({
3455
5239
  const { data: invoice, error, isPending, refetch } = useUpcomingInvoice();
3456
5240
  const locale = useResolvedLocale(localeProp);
3457
5241
  const t = useTranslator(strings, localeProp);
3458
- const bill = useMemo3(
5242
+ const bill = useMemo6(
3459
5243
  () => invoice === void 0 || invoice === null ? null : deriveUpcomingInvoice(invoice, { locale }),
3460
5244
  [invoice, locale]
3461
5245
  );
@@ -3464,7 +5248,7 @@ function UpcomingBill({
3464
5248
  const discountRow = showDiscounts && bill !== null && bill.discounts.length > 0;
3465
5249
  const unavailable = invoice === void 0 && httpStatus(error) === 404;
3466
5250
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("upcomingBillUnavailable") : t("upcomingBillError");
3467
- return /* @__PURE__ */ jsx6(
5251
+ return /* @__PURE__ */ jsx9(
3468
5252
  StatusFrame,
3469
5253
  {
3470
5254
  className: cx("schematic-card", "schematic-upcoming-bill", className),
@@ -3475,11 +5259,11 @@ function UpcomingBill({
3475
5259
  loadingLabel: t("upcomingBillLoading"),
3476
5260
  onRetry: refetch,
3477
5261
  retryText: t("retry"),
3478
- skeleton: /* @__PURE__ */ jsx6(UpcomingBillSkeleton, { showHeader }),
3479
- children: bill === null ? invoice !== void 0 && /* @__PURE__ */ jsx6("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ jsxs5(Fragment3, { children: [
3480
- showHeader && bill.dueAt !== null && /* @__PURE__ */ jsx6("div", { className: "schematic-header", children: /* @__PURE__ */ jsx6(Heading, { className: "schematic-header__title", children: t("upcomingBillHeader", { date: bill.dueAt.text }) }) }),
3481
- showAmount && /* @__PURE__ */ jsxs5("div", { className: "schematic-upcoming-bill__amount", children: [
3482
- /* @__PURE__ */ jsx6(
5262
+ skeleton: /* @__PURE__ */ jsx9(UpcomingBillSkeleton, { showHeader }),
5263
+ children: bill === null ? invoice !== void 0 && /* @__PURE__ */ jsx9("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ jsxs8(Fragment4, { children: [
5264
+ showHeader && bill.dueAt !== null && /* @__PURE__ */ jsx9("div", { className: "schematic-header", children: /* @__PURE__ */ jsx9(Heading, { className: "schematic-header__title", children: t("upcomingBillHeader", { date: bill.dueAt.text }) }) }),
5265
+ showAmount && /* @__PURE__ */ jsxs8("div", { className: "schematic-upcoming-bill__amount", children: [
5266
+ /* @__PURE__ */ jsx9(
3483
5267
  "span",
3484
5268
  {
3485
5269
  className: "schematic-upcoming-bill__total",
@@ -3487,46 +5271,46 @@ function UpcomingBill({
3487
5271
  children: bill.amountDueText
3488
5272
  }
3489
5273
  ),
3490
- /* @__PURE__ */ jsx6("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
5274
+ /* @__PURE__ */ jsx9("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
3491
5275
  ] }),
3492
- (balanceRows || discountRow) && /* @__PURE__ */ jsxs5("div", { className: "schematic-upcoming-bill__rows", children: [
3493
- balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ jsxs5(
5276
+ (balanceRows || discountRow) && /* @__PURE__ */ jsxs8("div", { className: "schematic-upcoming-bill__rows", children: [
5277
+ balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ jsxs8(
3494
5278
  "div",
3495
5279
  {
3496
5280
  className: "schematic-row schematic-upcoming-bill__balance-applied",
3497
5281
  "data-testid": "schematic-balance-applied",
3498
5282
  children: [
3499
- /* @__PURE__ */ jsx6("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
3500
- /* @__PURE__ */ jsx6("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
5283
+ /* @__PURE__ */ jsx9("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
5284
+ /* @__PURE__ */ jsx9("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
3501
5285
  ]
3502
5286
  }
3503
5287
  ),
3504
- balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ jsxs5(
5288
+ balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ jsxs8(
3505
5289
  "div",
3506
5290
  {
3507
5291
  className: "schematic-row schematic-upcoming-bill__balance-remaining",
3508
5292
  "data-testid": "schematic-balance-remaining",
3509
5293
  children: [
3510
- /* @__PURE__ */ jsx6("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
3511
- /* @__PURE__ */ jsx6("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
5294
+ /* @__PURE__ */ jsx9("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
5295
+ /* @__PURE__ */ jsx9("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
3512
5296
  ]
3513
5297
  }
3514
5298
  ),
3515
- discountRow && /* @__PURE__ */ jsxs5(
5299
+ discountRow && /* @__PURE__ */ jsxs8(
3516
5300
  "div",
3517
5301
  {
3518
5302
  className: "schematic-row schematic-upcoming-bill__discount-row",
3519
5303
  "data-testid": "schematic-discounts",
3520
5304
  children: [
3521
- /* @__PURE__ */ jsx6("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
3522
- /* @__PURE__ */ jsx6("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ jsxs5(
5305
+ /* @__PURE__ */ jsx9("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
5306
+ /* @__PURE__ */ jsx9("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ jsxs8(
3523
5307
  "li",
3524
5308
  {
3525
5309
  className: "schematic-upcoming-bill__discount",
3526
5310
  "data-testid": "schematic-discount",
3527
5311
  children: [
3528
- discount.code !== null && /* @__PURE__ */ jsx6("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
3529
- /* @__PURE__ */ jsx6("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
5312
+ discount.code !== null && /* @__PURE__ */ jsx9("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
5313
+ /* @__PURE__ */ jsx9("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
3530
5314
  ]
3531
5315
  },
3532
5316
  `${discount.couponName}-${index}`
@@ -3540,10 +5324,10 @@ function UpcomingBill({
3540
5324
  );
3541
5325
  }
3542
5326
  function UpcomingBillSkeleton({ showHeader }) {
3543
- return /* @__PURE__ */ jsxs5("div", { className: "schematic-skeleton", children: [
3544
- showHeader && /* @__PURE__ */ jsx6("div", { className: "schematic-skeleton__heading" }),
3545
- /* @__PURE__ */ jsx6("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx6("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
3546
- /* @__PURE__ */ jsx6("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx6("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
5327
+ return /* @__PURE__ */ jsxs8("div", { className: "schematic-skeleton", children: [
5328
+ showHeader && /* @__PURE__ */ jsx9("div", { className: "schematic-skeleton__heading" }),
5329
+ /* @__PURE__ */ jsx9("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx9("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
5330
+ /* @__PURE__ */ jsx9("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx9("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
3547
5331
  ] });
3548
5332
  }
3549
5333
  function discountText(discount, t) {
@@ -3559,14 +5343,21 @@ UpcomingBill.resources = ["upcomingInvoice"];
3559
5343
  export {
3560
5344
  BillingDataProvider,
3561
5345
  DEFAULT_STRINGS,
5346
+ FEATURE_USER_USAGE_LIMIT,
5347
+ IncludedFeatures,
3562
5348
  Invoices,
5349
+ MeteredFeatures,
3563
5350
  PaymentMethods,
3564
5351
  SCHEMATIC_TOKENS,
3565
5352
  SchematicI18nProvider,
3566
5353
  SchematicStyles,
5354
+ Tooltip,
3567
5355
  UpcomingBill,
3568
5356
  billingResources,
5357
+ currentTier,
5358
+ deriveIncludedFeatures,
3569
5359
  deriveInvoiceList,
5360
+ deriveMeteredFeatures,
3570
5361
  derivePaymentMethods,
3571
5362
  deriveUpcomingInvoice,
3572
5363
  featureName,
@@ -3580,11 +5371,18 @@ export {
3580
5371
  httpStatus,
3581
5372
  iconsCss,
3582
5373
  interpolate,
5374
+ isTieredPrice,
3583
5375
  lookup,
3584
5376
  plural,
5377
+ pricePeriod,
3585
5378
  resolveLocale,
3586
5379
  schematicStylesCss,
3587
5380
  schematicTokensCss,
5381
+ tierRanges,
5382
+ unitPrice,
5383
+ usageLimit,
5384
+ useFeatureUsage3 as useFeatureUsage,
5385
+ useFeatureUserUsage2 as useFeatureUserUsage,
3588
5386
  useInvalidateBillingData,
3589
5387
  useInvoices2 as useInvoices,
3590
5388
  usePaymentMethods2 as usePaymentMethods,