@schematichq/schematic-components 2.33.0 → 2.34.1

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.
@@ -31,7 +31,6 @@ var init_tokens = __esm({
31
31
  SCHEMATIC_TOKENS = {
32
32
  "--schematic-accent": ld("#194bfb", "#6f92ff"),
33
33
  "--schematic-accent-contrast": ld("#ffffff", "#0a0a0a"),
34
- // Tints the dialog's backdrop, which also blurs the page behind it.
35
34
  "--schematic-backdrop": ld(
36
35
  "hsla(0, 0%, 87.5%, 0.9)",
37
36
  "hsla(0, 0%, 12.5%, 0.9)"
@@ -45,16 +44,11 @@ var init_tokens = __esm({
45
44
  "hsla(0, 0%, 0%, 0.175)",
46
45
  "hsla(0, 0%, 100%, 0.2)"
47
46
  ),
48
- // 45px from a 750px viewport up; narrower screens give the content the
49
- // room instead (about 22px on a 375px phone).
50
47
  "--schematic-card-padding": "min(2.8125rem, 6vw)",
51
48
  "--schematic-danger": ld("#d75a5c", "#ff6b6e"),
52
49
  "--schematic-font-body": '"Public Sans", system-ui, sans-serif',
53
50
  "--schematic-font-heading": '"Manrope", system-ui, sans-serif',
54
- // Link buttons' face: Edit, Set default, Try again, and the rest.
55
51
  "--schematic-font-link": '"Inter", system-ui, sans-serif',
56
- // A lighter tint than the surface, for panels set into a card: a credit's
57
- // grants, a plan's auto top-up.
58
52
  "--schematic-inset": ld("hsla(0, 0%, 0%, 0.04)", "hsla(0, 0%, 100%, 0.06)"),
59
53
  "--schematic-line-height": "1.375",
60
54
  "--schematic-line-height-heading": "1.2",
@@ -63,10 +57,8 @@ var init_tokens = __esm({
63
57
  "--schematic-primary": ld("#000000", "#ffffff"),
64
58
  "--schematic-primary-contrast": ld("#ffffff", "#000000"),
65
59
  "--schematic-radius": "0.625rem",
66
- // `light-dark()` takes colours only, so it is applied per shadow layer.
67
60
  "--schematic-shadow": `0px 1px 20px 0px ${ld("#1018280f", "#00000099")}, 0px 1px 3px 0px ${ld("#1018281a", "#0000007a")}`,
68
61
  "--schematic-space": "1rem",
69
- // A tint over the background: the payment method pill.
70
62
  "--schematic-surface": ld(
71
63
  "hsla(0, 0%, 0%, 0.0625)",
72
64
  "hsla(0, 0%, 100%, 0.125)"
@@ -459,9 +451,10 @@ import {
459
451
  BillingDataProvider,
460
452
  FEATURE_USER_USAGE_LIMIT,
461
453
  SchematicI18nProvider,
462
- useCreditBalances as useCreditBalances2,
454
+ useCompany as useCompany3,
455
+ useCreditBalances as useCreditBalances3,
463
456
  useCreditUserUsage as useCreditUserUsage2,
464
- useFeatureUsage as useFeatureUsage3,
457
+ useFeatureUsage as useFeatureUsage5,
465
458
  useFeatureUserUsage as useFeatureUserUsage2,
466
459
  useInvalidateBillingData,
467
460
  useInvoices as useInvoices2,
@@ -471,6 +464,7 @@ import {
471
464
  useSchematicStrings,
472
465
  useSchematicTranslate,
473
466
  useSetupIntent as useSetupIntent2,
467
+ useUnsubscribe as useUnsubscribe2,
474
468
  useUpcomingInvoice as useUpcomingInvoice2
475
469
  } from "@schematichq/schematic-react";
476
470
 
@@ -1781,6 +1775,416 @@ function isEnglish2(locale) {
1781
1775
  }
1782
1776
  }
1783
1777
 
1778
+ // src/elements/model/planManager.ts
1779
+ var DAY_MS = 24 * 60 * 60 * 1e3;
1780
+ var HOUR_MS = 60 * 60 * 1e3;
1781
+ var MINUTE_MS = 60 * 1e3;
1782
+ function derivePlanManager(data, options) {
1783
+ const { company, creditBalances, featureUsage } = data;
1784
+ const { locale } = options;
1785
+ const subscription = company.subscription ?? null;
1786
+ const currency = subscription?.currency ?? "usd";
1787
+ const planPeriod = subscription?.period ?? company.plan?.period ?? null;
1788
+ const usageBasedSources = featureUsage.filter(
1789
+ (row) => typeof row.priceBehavior === "string"
1790
+ );
1791
+ return {
1792
+ notice: notice(company, options),
1793
+ plan: company.plan === void 0 || company.plan === null ? null : {
1794
+ name: company.plan.name,
1795
+ description: orNull3(company.plan.description),
1796
+ price: planPrice(
1797
+ company.plan.price,
1798
+ planPeriod,
1799
+ currency,
1800
+ usageBasedSources.length > 0,
1801
+ options
1802
+ )
1803
+ },
1804
+ addOns: company.addOns.map((addOn) => {
1805
+ const period = addOn.period === "one-time" ? "one-time" : planPeriod ?? addOn.period ?? null;
1806
+ return {
1807
+ id: addOn.id,
1808
+ name: addOn.name,
1809
+ price: typeof addOn.price === "number" && period !== null ? {
1810
+ amount: formatCurrency(addOn.price, currency, locale),
1811
+ period
1812
+ } : null
1813
+ };
1814
+ }),
1815
+ usageBased: usageBasedSources.flatMap((row) => {
1816
+ const derived = usageBasedRow(row, planPeriod ?? "month", options);
1817
+ return derived === null ? [] : [derived];
1818
+ }),
1819
+ planCredits: planCredits(company, creditBalances, locale),
1820
+ autoTopup: autoTopupBox(company, creditBalances, locale),
1821
+ ...creditGroups(creditBalances, locale),
1822
+ canChangePlan: company.customPlanBilling?.activationStrategy !== "on_payment"
1823
+ };
1824
+ }
1825
+ function notice(company, options) {
1826
+ const { locale } = options;
1827
+ const subscription = company.subscription ?? null;
1828
+ const cancelAt = usableDate(subscription?.cancelAt);
1829
+ const willCancel = cancelAt !== void 0 && subscription?.cancelAtPeriodEnd === true;
1830
+ if (subscription?.status === "trialing" && !willCancel) {
1831
+ const trialEnd = usableDate(subscription.trialEnd);
1832
+ return {
1833
+ kind: "trial",
1834
+ endsIn: trialEnd === void 0 ? null : countdown(
1835
+ trialEnd.getTime() - (options.now ?? /* @__PURE__ */ new Date()).getTime()
1836
+ )
1837
+ };
1838
+ }
1839
+ if (willCancel) {
1840
+ return {
1841
+ kind: "canceled",
1842
+ planName: orNull3(company.plan?.name),
1843
+ date: formatDate(cancelAt, locale)
1844
+ };
1845
+ }
1846
+ const billing = company.customPlanBilling;
1847
+ if (billing !== void 0 && billing !== null) {
1848
+ return {
1849
+ kind: "customPlanBilling",
1850
+ awaitingActivation: billing.activationStrategy === "on_payment",
1851
+ planName: orNull3(billing.planName),
1852
+ date: formatDate(billing.dueAt, locale),
1853
+ invoiceUrl: orNull3(billing.invoiceUrl)
1854
+ };
1855
+ }
1856
+ const downgrade = company.scheduledDowngrade;
1857
+ if (downgrade !== void 0 && downgrade !== null && downgrade.toPlanName !== "") {
1858
+ const periodEnd = usableDate(subscription?.periodEnd);
1859
+ return {
1860
+ kind: "scheduledDowngrade",
1861
+ fromPlanName: downgrade.fromPlanName,
1862
+ toPlanName: downgrade.toPlanName,
1863
+ date: periodEnd === void 0 ? null : formatDate(periodEnd, locale)
1864
+ };
1865
+ }
1866
+ return null;
1867
+ }
1868
+ function countdown(ms) {
1869
+ if (ms >= DAY_MS) {
1870
+ return { amount: Math.floor(ms / DAY_MS), unit: "day" };
1871
+ }
1872
+ if (ms >= HOUR_MS) {
1873
+ return { amount: Math.floor(ms / HOUR_MS), unit: "hour" };
1874
+ }
1875
+ if (ms >= MINUTE_MS) {
1876
+ return { amount: Math.floor(ms / MINUTE_MS), unit: "minute" };
1877
+ }
1878
+ return ms > 0 ? "soon" : "ended";
1879
+ }
1880
+ function planPrice(price, period, currency, hasUsageBased, options) {
1881
+ if (typeof price !== "number") {
1882
+ return null;
1883
+ }
1884
+ const isFree = price === 0;
1885
+ if (isFree && hasUsageBased) {
1886
+ return { kind: "usageBased" };
1887
+ }
1888
+ if (isFree && options.showZeroPriceAsFree === true) {
1889
+ return { kind: "free" };
1890
+ }
1891
+ return {
1892
+ kind: "amount",
1893
+ amount: formatCurrency(price, currency, options.locale),
1894
+ period: isFree ? null : period
1895
+ };
1896
+ }
1897
+ function usageBasedRow(row, period, options) {
1898
+ const { locale } = options;
1899
+ const behavior = row.priceBehavior ?? null;
1900
+ const showCredits = options.showCredits ?? true;
1901
+ if (behavior === "credit_burndown" && !showCredits || row.featureName === "") {
1902
+ return null;
1903
+ }
1904
+ const unit = {
1905
+ name: row.featureName,
1906
+ singularName: row.featureSingularName ?? void 0,
1907
+ pluralName: row.featurePluralName ?? void 0
1908
+ };
1909
+ const isTrait = row.featureType === "trait";
1910
+ const price = row.price ?? void 0;
1911
+ const priceCurrency = price?.currency ?? "usd";
1912
+ const limit = behavior === "credit_burndown" ? null : usageLimit(row, options);
1913
+ let unitPriceText = null;
1914
+ if ((behavior === "pay_as_you_go" || behavior === "overage") && price !== void 0) {
1915
+ const packageSize = price.packageSize ?? 1;
1916
+ const ranges = behavior === "overage" ? tierRanges(price) : [];
1917
+ const lastTier = ranges[ranges.length - 1];
1918
+ const amount = lastTier === void 0 ? unitPrice(price) : lastTier.perUnitPrice ?? price.price;
1919
+ unitPriceText = {
1920
+ cost: formatCurrency(amount, priceCurrency, locale),
1921
+ packageSize: packageSize > 1 ? formatNumber(packageSize, locale) : null,
1922
+ units: featureName(unit, packageSize, locale),
1923
+ period: isTrait ? period : null
1924
+ };
1925
+ }
1926
+ let perUse = null;
1927
+ if (behavior === "credit_burndown" && typeof row.consumptionRate === "number" && row.consumptionRate !== 0 && typeof row.creditName === "string") {
1928
+ perUse = {
1929
+ amount: formatConsumptionRate(row.consumptionRate, locale),
1930
+ units: featureName(
1931
+ {
1932
+ name: row.creditName,
1933
+ singularName: row.creditSingularName,
1934
+ pluralName: row.creditPluralName
1935
+ },
1936
+ row.consumptionRate,
1937
+ locale
1938
+ )
1939
+ };
1940
+ }
1941
+ return {
1942
+ featureId: row.featureId,
1943
+ name: row.featureName,
1944
+ // The bare name, inflected, as the embed counts a limit.
1945
+ quantity: limit === null ? null : {
1946
+ amount: formatNumber(limit, locale),
1947
+ units: featureName({ name: row.featureName }, limit, locale)
1948
+ },
1949
+ additional: behavior === "overage",
1950
+ tierBased: behavior === "tier",
1951
+ unitPrice: unitPriceText,
1952
+ perUse,
1953
+ cost: behavior === "pay_in_advance" ? {
1954
+ amount: formatCurrency(row.currentCost ?? 0, priceCurrency, locale),
1955
+ period: isTrait ? period : null
1956
+ } : null,
1957
+ tiers: behavior === "tier" && isTieredPrice(price) ? {
1958
+ currency: priceCurrency,
1959
+ mode: price?.tiersMode ?? null,
1960
+ period,
1961
+ ranges: tierRanges(price),
1962
+ unit: row.featureSingularName ?? row.featureName
1963
+ } : null,
1964
+ hardLimit: behavior !== null && behavior !== "credit_burndown" && row.valueType === "numeric" && typeof row.allocation === "number" ? {
1965
+ amount: formatNumber(row.allocation, locale),
1966
+ units: featureName(unit, row.allocation, locale)
1967
+ } : null,
1968
+ source: row
1969
+ };
1970
+ }
1971
+ function planCredits(company, balances, locale) {
1972
+ const order = company.plan?.includedCreditIds ?? [];
1973
+ const rank = (creditId) => {
1974
+ const index = order.indexOf(creditId);
1975
+ return index === -1 ? order.length : index;
1976
+ };
1977
+ const subscriptionPeriod = company.subscription?.period ?? null;
1978
+ return balances.flatMap((balance) => {
1979
+ const grants = balance.grants.filter(
1980
+ (grant) => grant.grantReason === "plan"
1981
+ );
1982
+ if (grants.length === 0) {
1983
+ return [];
1984
+ }
1985
+ const unit = creditUnit(balance);
1986
+ const value = sum(grants, (grant) => grant.quantity);
1987
+ const used = sum(grants, (grant) => grant.quantityUsed);
1988
+ const composition = balance.composition ?? null;
1989
+ const autoTopup = balance.autoTopup ?? null;
1990
+ const row = {
1991
+ creditId: balance.creditId,
1992
+ text: composition === null ? {
1993
+ kind: "total",
1994
+ amount: formatCredits(value, locale),
1995
+ creditName: featureName(unit, value, locale),
1996
+ period: subscriptionPeriod
1997
+ } : {
1998
+ kind: "perLicense",
1999
+ amount: formatCredits(composition.perLicenseAmount, locale),
2000
+ creditName: featureName(
2001
+ unit,
2002
+ composition.perLicenseAmount,
2003
+ locale
2004
+ ),
2005
+ licenseName: featureName(licenseUnit(composition), 1, locale),
2006
+ plus: composition.fixedQuantity > 0 ? {
2007
+ amount: formatCredits(
2008
+ composition.fixedQuantity,
2009
+ locale
2010
+ ),
2011
+ creditName: featureName(
2012
+ unit,
2013
+ composition.fixedQuantity,
2014
+ locale
2015
+ ),
2016
+ period: composition.period
2017
+ } : null
2018
+ },
2019
+ used: spent(used, locale),
2020
+ autoTopup: autoTopup !== null && autoTopup.enabled && typeof autoTopup.thresholdCredits === "number" && typeof autoTopup.amount === "number" ? {
2021
+ amount: formatCredits(autoTopup.amount, locale),
2022
+ threshold: formatCredits(autoTopup.thresholdCredits, locale)
2023
+ } : null,
2024
+ composition: composition === null ? null : {
2025
+ quantity: formatNumber(composition.licenseQuantity, locale),
2026
+ licenseName: featureName(
2027
+ licenseUnit(composition),
2028
+ composition.licenseQuantity,
2029
+ locale
2030
+ ),
2031
+ perUnit: formatCredits(composition.perLicenseAmount, locale),
2032
+ fixed: composition.fixedQuantity > 0 ? formatCredits(composition.fixedQuantity, locale) : null,
2033
+ total: formatCredits(composition.total, locale),
2034
+ creditName: featureName(unit, composition.total, locale),
2035
+ period: composition.period
2036
+ }
2037
+ };
2038
+ return [row];
2039
+ }).map((row, index) => ({ row, index })).sort(
2040
+ (a, b) => rank(a.row.creditId) - rank(b.row.creditId) || a.index - b.index
2041
+ ).map(({ row }) => row);
2042
+ }
2043
+ function autoTopupBox(company, balances, locale) {
2044
+ const order = company.plan?.includedCreditIds ?? [];
2045
+ const selfService = order.flatMap((creditId) => {
2046
+ const balance = balances.find((b) => b.creditId === creditId);
2047
+ const autoTopup = balance?.autoTopup ?? null;
2048
+ return balance === void 0 || autoTopup === null || !autoTopup.selfService ? [] : [{ balance, autoTopup }];
2049
+ });
2050
+ if (selfService.length === 0) {
2051
+ return null;
2052
+ }
2053
+ return {
2054
+ lines: selfService.flatMap(({ balance, autoTopup }) => {
2055
+ const unit = creditUnit(balance);
2056
+ if (!autoTopup.enabled) {
2057
+ return [
2058
+ {
2059
+ kind: "disabled",
2060
+ creditId: balance.creditId,
2061
+ unit: featureName(unit, 1, locale)
2062
+ }
2063
+ ];
2064
+ }
2065
+ if (typeof autoTopup.thresholdCredits !== "number" || typeof autoTopup.amount !== "number") {
2066
+ return [];
2067
+ }
2068
+ return [
2069
+ {
2070
+ kind: "adds",
2071
+ creditId: balance.creditId,
2072
+ amount: formatCredits(autoTopup.amount, locale),
2073
+ unit: featureName(unit, autoTopup.amount, locale),
2074
+ threshold: formatCredits(autoTopup.thresholdCredits, locale)
2075
+ }
2076
+ ];
2077
+ })
2078
+ };
2079
+ }
2080
+ function creditGroups(balances, locale) {
2081
+ const groups = /* @__PURE__ */ new Map();
2082
+ for (const balance of balances) {
2083
+ for (const grant of balance.grants) {
2084
+ if (grant.grantReason === "plan") {
2085
+ continue;
2086
+ }
2087
+ const key = `${grant.grantReason}:${grant.bundleId ?? grant.id}`;
2088
+ const group = groups.get(key);
2089
+ if (group === void 0) {
2090
+ groups.set(key, { balance, grants: [grant] });
2091
+ } else {
2092
+ group.grants.push(grant);
2093
+ }
2094
+ }
2095
+ }
2096
+ const rows = Array.from(groups.entries()).map(([key, { balance, grants }]) => {
2097
+ const sorted = [...grants].sort(byRecency);
2098
+ const latest = sorted[0];
2099
+ return {
2100
+ reason: latest.grantReason,
2101
+ createdAt: latest.createdAt,
2102
+ row: {
2103
+ key,
2104
+ count: sorted.length,
2105
+ bundleName: orNull3(latest.bundleName),
2106
+ quantity: formatCredits(latest.quantity, locale),
2107
+ creditName: featureName(creditUnit(balance), latest.quantity, locale),
2108
+ used: spent(
2109
+ sum(sorted, (grant) => grant.quantityUsed),
2110
+ locale
2111
+ )
2112
+ }
2113
+ };
2114
+ }).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
2115
+ const pick = (reason) => rows.filter((entry) => entry.reason === reason).map((entry) => entry.row);
2116
+ return {
2117
+ bundles: pick("purchased"),
2118
+ promotional: pick("free"),
2119
+ topUps: pick("billing_credit_auto_topup")
2120
+ };
2121
+ }
2122
+ function byRecency(a, b) {
2123
+ return b.createdAt.getTime() - a.createdAt.getTime();
2124
+ }
2125
+ function creditUnit(balance) {
2126
+ return {
2127
+ name: balance.creditName,
2128
+ singularName: balance.creditSingularName ?? void 0,
2129
+ pluralName: balance.creditPluralName ?? void 0
2130
+ };
2131
+ }
2132
+ function licenseUnit(composition) {
2133
+ return {
2134
+ name: composition.licenseName,
2135
+ singularName: composition.licenseSingularName,
2136
+ pluralName: composition.licensePluralName
2137
+ };
2138
+ }
2139
+ function spent(used, locale) {
2140
+ return used > 0 ? formatCredits(used, locale) : null;
2141
+ }
2142
+ function sum(items, value) {
2143
+ return items.reduce((total, item) => total + value(item), 0);
2144
+ }
2145
+ function orNull3(value) {
2146
+ return value === void 0 || value === null || value === "" ? null : value;
2147
+ }
2148
+
2149
+ // src/elements/model/unsubscribe.ts
2150
+ function deriveUnsubscribe(company, featureUsage, options) {
2151
+ const { locale } = options;
2152
+ const subscription = company.subscription ?? null;
2153
+ const currency = subscription?.currency ?? "usd";
2154
+ const cancelAt = usableDate(subscription?.cancelAt);
2155
+ const endsOn = cancelAt ?? usableDate(subscription?.nextBillAt) ?? options.now ?? /* @__PURE__ */ new Date();
2156
+ const money = (amount) => formatCurrency(amount, currency, locale);
2157
+ const addOns = company.addOns.flatMap(
2158
+ (addOn) => typeof addOn.price === "number" ? [
2159
+ {
2160
+ id: addOn.id,
2161
+ name: addOn.name,
2162
+ price: money(addOn.price),
2163
+ oneTime: addOn.period === "one-time"
2164
+ }
2165
+ ] : []
2166
+ );
2167
+ const planPrice2 = company.plan?.price;
2168
+ const total = (typeof planPrice2 === "number" ? planPrice2 : 0) + company.addOns.reduce(
2169
+ (sum2, addOn) => addOn.period !== "one-time" && typeof addOn.price === "number" ? sum2 + addOn.price : sum2,
2170
+ 0
2171
+ ) + featureUsage.reduce(
2172
+ (sum2, row) => row.priceBehavior === "pay_in_advance" ? sum2 + (row.currentCost ?? 0) : sum2,
2173
+ 0
2174
+ );
2175
+ return {
2176
+ canUnsubscribe: subscription !== null && cancelAt === void 0,
2177
+ accessEndsOn: formatDate(endsOn, locale),
2178
+ period: subscription?.period ?? company.plan?.period ?? "month",
2179
+ plan: company.plan === void 0 || company.plan === null ? null : {
2180
+ name: company.plan.name,
2181
+ price: typeof planPrice2 === "number" ? money(planPrice2) : null
2182
+ },
2183
+ addOns,
2184
+ total: money(total)
2185
+ };
2186
+ }
2187
+
1784
2188
  // src/elements/strings.ts
1785
2189
  var DEFAULT_STRINGS_LOCALE = "en";
1786
2190
  var DEFAULT_STRINGS = {
@@ -1889,6 +2293,73 @@ var DEFAULT_STRINGS = {
1889
2293
  creditUsagePerLicense: "{{quantity}} {{licenseName}} \xD7 {{perUnit}}",
1890
2294
  creditUsageCompanyGrant: "{{amount}} company grant",
1891
2295
  creditUsageRenewsOn: "Renews on the {{day}}.",
2296
+ planManagerLoading: "Loading your plan",
2297
+ planManagerError: "There was a problem retrieving your plan.",
2298
+ planManagerUnavailable: "Your plan is not available for this account.",
2299
+ planManagerTrialEndsIn: "Trial ends in {{amount}} {{units}}",
2300
+ planManagerTrialEndsSoon: "Trial ends in less than a minute",
2301
+ planManagerTrialEnded: "Your trial has ended",
2302
+ // The trial countdown's units, looked up by the bare key with `{ count }`.
2303
+ planManagerDays: "days",
2304
+ planManagerDays_one: "day",
2305
+ planManagerDays_other: "days",
2306
+ planManagerHours: "hours",
2307
+ planManagerHours_one: "hour",
2308
+ planManagerHours_other: "hours",
2309
+ planManagerMinutes: "minutes",
2310
+ planManagerMinutes_one: "minute",
2311
+ planManagerMinutes_other: "minutes",
2312
+ planManagerCanceled: "Subscription canceled",
2313
+ planManagerAccessEnds: "Access to {{plan}} will end on {{date}}.",
2314
+ planManagerPlanFallback: "plan",
2315
+ planManagerCustomAwaiting: "Pay to activate {{plan}}",
2316
+ planManagerCustomAwaitingDescription: "Pay the invoice to activate your custom plan. Due by {{date}}.",
2317
+ planManagerCustomDue: "Pay by {{date}} to keep {{plan}}",
2318
+ planManagerCustomDueDescription: "Access to {{plan}} will end on {{date}} unless the invoice is paid.",
2319
+ planManagerYourPlan: "your plan",
2320
+ planManagerPayNow: "Pay now",
2321
+ planManagerDowngradeScheduled: "Downgrade to {{plan}} scheduled",
2322
+ planManagerUsageBased: "Usage-based",
2323
+ planManagerFree: "Free",
2324
+ planManagerAddOns: "Add-ons",
2325
+ planManagerAdditional: "Additional",
2326
+ planManagerTierBased: "Tier-based",
2327
+ planManagerCreditsInPlan: "Credits in plan",
2328
+ planManagerCreditsError: "There was a problem retrieving your credits.",
2329
+ planManagerCreditsLoading: "Loading your credits",
2330
+ planManagerTopUps: "Top-ups",
2331
+ planManagerCreditBundles: "Credit bundles",
2332
+ planManagerPromotionalCredits: "Promotional credits",
2333
+ planManagerChangePlan: "Change plan",
2334
+ planManagerCredits: "{{amount}} {{creditName}}",
2335
+ planManagerCreditsPerPeriod: "{{amount}} {{creditName}} per {{period}}",
2336
+ planManagerCreditsPerLicense: "{{amount}} {{creditName}} per {{licenseName}}",
2337
+ planManagerCreditsPlusPerPeriod: "+ {{amount}} {{creditName}} per {{period}}",
2338
+ planManagerLicensesTimesCredits: "{{quantity}} {{licenseName}} \xD7 {{perUnit}} = {{total}} {{creditName}}/{{period}}",
2339
+ planManagerLicensesTimesCreditsPlusCompany: "{{quantity}} {{licenseName}} \xD7 {{perUnit}} + {{fixed}} = {{total}} {{creditName}}/{{period}}",
2340
+ planManagerUsed: "{{amount}} used",
2341
+ planManagerAutoTopup: "Auto top-up",
2342
+ planManagerAutoTopupDisabled: "Auto top-up disabled for {{unit}}",
2343
+ planManagerAutoTopupAdds: "Adds {{amount}} {{unit}} when {{threshold}} remaining in balance",
2344
+ planManagerAutoTopupTip: "When credit balance reaches {{threshold}} remaining, an auto top-up of {{amount}} credits will be processed.",
2345
+ planManagerEdit: "Edit",
2346
+ planManagerSeeAll: "See all ({{total}})",
2347
+ planManagerHideAll: "Hide all",
2348
+ unsubscribeButton: "Unsubscribe",
2349
+ unsubscribeTitle: "Cancel subscription",
2350
+ unsubscribeAccessUntil: "You will retain access to your plan until the end of the billing period, on {{date}}",
2351
+ unsubscribeNotReady: "Not ready to cancel?",
2352
+ unsubscribeManagePlan: "Manage plan",
2353
+ unsubscribePlan: "Plan",
2354
+ unsubscribeAddOns: "Add-ons",
2355
+ unsubscribeMonthlyTotal: "Monthly total:",
2356
+ unsubscribeQuarterlyTotal: "Quarterly total:",
2357
+ unsubscribeYearlyTotal: "Yearly total:",
2358
+ unsubscribeConfirm: "Cancel subscription",
2359
+ unsubscribeFailed: "Unsubscribe failed",
2360
+ unsubscribeClose: "Close",
2361
+ unsubscribeError: "There was a problem retrieving your subscription.",
2362
+ unsubscribeUnavailable: "Your subscription is not available for this account.",
1892
2363
  usageByUserHeader: "Usage by user",
1893
2364
  usageByUserTotal: "{{amount}} used by your team this period",
1894
2365
  usageByUserError: "There was a problem retrieving usage by user.",
@@ -1924,7 +2395,12 @@ var DEFAULT_STRINGS = {
1924
2395
  usageTiersGraduated: "Tiers apply progressively as quantity increases.",
1925
2396
  periodMonthShort: "mo",
1926
2397
  periodQuarterShort: "qtr",
1927
- periodYearShort: "yr"
2398
+ periodYearShort: "yr",
2399
+ periodDay: "day",
2400
+ periodWeek: "week",
2401
+ periodMonth: "month",
2402
+ periodQuarter: "quarter",
2403
+ periodYear: "year"
1928
2404
  };
1929
2405
  var MISSING_STRING = "\0schematic:missing";
1930
2406
  function interpolate(template, vars) {
@@ -1955,6 +2431,45 @@ function defaultString(key, vars) {
1955
2431
  return lookup(DEFAULT_STRINGS, key, vars) ?? DEFAULT_STRINGS[key] ?? key;
1956
2432
  }
1957
2433
 
2434
+ // src/elements/styles/card-group.ts
2435
+ var cardGroupCss = `
2436
+ .schematic-card-group {
2437
+ background: var(--schematic-background);
2438
+ border-radius: var(--schematic-radius);
2439
+ box-shadow: var(--schematic-shadow);
2440
+ color: var(--schematic-text);
2441
+ display: flex;
2442
+ flex-direction: column;
2443
+ overflow: clip;
2444
+ }
2445
+
2446
+ .schematic-card-group .schematic-card,
2447
+ .schematic-card-group .schematic-element[data-state="pending"],
2448
+ .schematic-card-group .schematic-element[data-state="error"],
2449
+ .schematic-card-group .schematic-plan-manager {
2450
+ background: none;
2451
+ border-radius: 0;
2452
+ box-shadow: none;
2453
+ }
2454
+
2455
+ .schematic-card-group .schematic-metered-features__list,
2456
+ .schematic-card-group .schematic-credit-usage__credits,
2457
+ .schematic-card-group .schematic-plan-manager {
2458
+ gap: 0;
2459
+ }
2460
+
2461
+ .schematic-card-group > .schematic-element + .schematic-element,
2462
+ .schematic-card-group .schematic-card + .schematic-card {
2463
+ border-top: 1px solid var(--schematic-card-divider);
2464
+ }
2465
+
2466
+ .schematic-card-group .schematic-element:not(.schematic-card) > .schematic-header {
2467
+ margin: 0;
2468
+ padding: calc(var(--schematic-card-padding) * 0.75)
2469
+ var(--schematic-card-padding) 0;
2470
+ }
2471
+ `;
2472
+
1958
2473
  // src/elements/styles/credit-usage.ts
1959
2474
  var creditUsageCss = `
1960
2475
  .schematic-credit-usage__credits {
@@ -1963,8 +2478,6 @@ var creditUsageCss = `
1963
2478
  gap: var(--schematic-space);
1964
2479
  }
1965
2480
 
1966
- /* Each credit draws its own card, so the root draws one only while pending
1967
- or failed. */
1968
2481
  .schematic-credit-usage[data-state="pending"],
1969
2482
  .schematic-credit-usage[data-state="error"] {
1970
2483
  background: var(--schematic-background);
@@ -1985,7 +2498,6 @@ var creditUsageCss = `
1985
2498
  gap: calc(var(--schematic-space) * 1.5);
1986
2499
  }
1987
2500
 
1988
- /* Held even without a glyph, as the embed does, so names line up. */
1989
2501
  .schematic-credit-usage__icon {
1990
2502
  align-items: center;
1991
2503
  background: var(--schematic-surface);
@@ -2002,8 +2514,6 @@ var creditUsageCss = `
2002
2514
  color: var(--schematic-accent);
2003
2515
  }
2004
2516
 
2005
- /* The embed's spacing: the balance well clear of the name, the composition
2006
- tucked close under the balance. */
2007
2517
  .schematic-credit-usage__body {
2008
2518
  display: flex;
2009
2519
  flex-direction: column;
@@ -2059,7 +2569,6 @@ var creditUsageCss = `
2059
2569
  margin-inline-start: -0.333rem;
2060
2570
  }
2061
2571
 
2062
- /* Opens above its toggle, as in the embed. */
2063
2572
  .schematic-credit-usage__grants {
2064
2573
  background: var(--schematic-inset);
2065
2574
  border-radius: calc(var(--schematic-radius) * 0.8);
@@ -2079,8 +2588,6 @@ var creditUsageCss = `
2079
2588
  padding: 0;
2080
2589
  }
2081
2590
 
2082
- /* Where the grant and its date do not fit on one line, the date wraps
2083
- rather than overflowing the panel. */
2084
2591
  .schematic-credit-usage__grant {
2085
2592
  display: flex;
2086
2593
  flex-wrap: wrap;
@@ -2111,7 +2618,6 @@ var creditUsageCss = `
2111
2618
 
2112
2619
  // src/elements/styles/dialog.ts
2113
2620
  var dialogCss = `
2114
- /* Up to 768px wide, with a tighter radius than a card. */
2115
2621
  .schematic-dialog {
2116
2622
  background: var(--schematic-background);
2117
2623
  border: 0;
@@ -2122,16 +2628,10 @@ var dialogCss = `
2122
2628
  margin: auto;
2123
2629
  max-height: calc(100vh - 2 * var(--schematic-space));
2124
2630
  max-width: none;
2125
- /* No padding of its own: a click on the backdrop lands on the dialog
2126
- itself, and one inside lands on the header or body. */
2127
2631
  padding: 0;
2128
- /* Never wider than the screen, whatever it holds. */
2129
2632
  width: min(48rem, calc(100vw - 2 * var(--schematic-space)));
2130
2633
  }
2131
2634
 
2132
- /* Centred by vw on a phone: a host page wider than the screen widens the
2133
- layout viewport, and auto margins would centre the dialog half off the
2134
- screen. Desktop keeps auto margins, as vw counts the scrollbar there. */
2135
2635
  @media (max-width: 52rem) {
2136
2636
  .schematic-dialog {
2137
2637
  inset-inline: 0 auto;
@@ -2148,8 +2648,6 @@ var dialogCss = `
2148
2648
  background: var(--schematic-backdrop);
2149
2649
  }
2150
2650
 
2151
- /* Narrow on the right, where the close control's own hit area makes up the
2152
- rest. */
2153
2651
  .schematic-dialog__header {
2154
2652
  align-items: center;
2155
2653
  border-bottom: 1px solid
@@ -2166,7 +2664,6 @@ var dialogCss = `
2166
2664
  }
2167
2665
  }
2168
2666
 
2169
- /* Body text at 18px, not a heading face. */
2170
2667
  .schematic-dialog__title {
2171
2668
  font-family: var(--schematic-font-body);
2172
2669
  font-size: 1.125rem;
@@ -2631,15 +3128,12 @@ var includedFeaturesCss = `
2631
3128
  padding: 0;
2632
3129
  }
2633
3130
 
2634
- /* Icon, name and details; the usage drops beneath on a narrow card. */
2635
3131
  .schematic-included-features__row {
2636
3132
  column-gap: 0.5rem;
2637
3133
  display: grid;
2638
3134
  grid-template-columns: min-content 1fr;
2639
3135
  }
2640
3136
 
2641
- /* Two classes: the icon font's own rule comes later in the sheet and sets
2642
- display, which would leave the glyph in the circle's corner. */
2643
3137
  .schematic-included-features .schematic-included-features__icon {
2644
3138
  align-items: center;
2645
3139
  background: var(--schematic-surface);
@@ -2661,7 +3155,6 @@ var includedFeaturesCss = `
2661
3155
  grid-column: 2;
2662
3156
  }
2663
3157
 
2664
- /* An item name, as add-ons and plan lines elsewhere. */
2665
3158
  .schematic-included-features__name {
2666
3159
  font-family: var(--schematic-font-heading);
2667
3160
  font-size: 1.125rem;
@@ -2684,10 +3177,8 @@ var includedFeaturesCss = `
2684
3177
  }
2685
3178
 
2686
3179
  @container (min-width: 23.4375rem) {
2687
- /* The usage takes the room it needs and wraps only when the name leaves
2688
- it none. */
2689
3180
  .schematic-included-features__row {
2690
- grid-template-columns: min-content 1fr auto;
3181
+ grid-template-columns: min-content 1fr 1fr;
2691
3182
  }
2692
3183
 
2693
3184
  .schematic-included-features__usage {
@@ -2759,7 +3250,6 @@ var invoicesCss = `
2759
3250
  .schematic-invoices__amount {
2760
3251
  cursor: help;
2761
3252
  font-variant-numeric: tabular-nums;
2762
- /* Keeps a lone amount at the end when the date is hidden. */
2763
3253
  margin-inline-start: auto;
2764
3254
  text-align: end;
2765
3255
  }
@@ -2777,7 +3267,6 @@ var invoicesCss = `
2777
3267
  gap: calc(var(--schematic-space) / 2);
2778
3268
  }
2779
3269
 
2780
- /* Cancels the glyph's side bearing, so the chevron sits flush. */
2781
3270
  .schematic-invoices__chevron {
2782
3271
  margin-inline-start: -0.333rem;
2783
3272
  }
@@ -2806,7 +3295,6 @@ var meteredFeaturesCss = `
2806
3295
  padding: 0;
2807
3296
  }
2808
3297
 
2809
- /* Each feature is a card; while pending or failed, the root is the card. */
2810
3298
  .schematic-metered-features[data-state="pending"],
2811
3299
  .schematic-metered-features[data-state="error"] {
2812
3300
  background: var(--schematic-background);
@@ -2829,7 +3317,6 @@ var meteredFeaturesCss = `
2829
3317
  gap: calc(var(--schematic-space) * 1.5);
2830
3318
  }
2831
3319
 
2832
- /* Kept without a glyph, as in the embed, so names line up. */
2833
3320
  .schematic-metered-features__icon {
2834
3321
  align-items: center;
2835
3322
  background: var(--schematic-surface);
@@ -2843,8 +3330,6 @@ var meteredFeaturesCss = `
2843
3330
  width: 2.75rem;
2844
3331
  }
2845
3332
 
2846
- /* The glyph takes the base text colour rather than inheriting, so the accent
2847
- is set on it too. */
2848
3333
  .schematic-metered-features__icon .schematic-icon {
2849
3334
  color: var(--schematic-accent);
2850
3335
  }
@@ -2878,8 +3363,6 @@ var meteredFeaturesCss = `
2878
3363
  margin: 0;
2879
3364
  }
2880
3365
 
2881
- /* Beside the title when both fit, otherwise beneath it as in the embed,
2882
- rather than wrapping in a narrow column. */
2883
3366
  .schematic-metered-features__figures {
2884
3367
  display: flex;
2885
3368
  flex: 0 0 auto;
@@ -2902,7 +3385,6 @@ var meteredFeaturesCss = `
2902
3385
  text-align: start;
2903
3386
  }
2904
3387
 
2905
- /* Too narrow to keep "1,300 GB of storage used" on one line. */
2906
3388
  .schematic-metered-features__headline {
2907
3389
  white-space: normal;
2908
3390
  }
@@ -2917,7 +3399,6 @@ var meteredFeaturesCss = `
2917
3399
  white-space: nowrap;
2918
3400
  }
2919
3401
 
2920
- /* Negative margins undo the card's padding so the footer bleeds to its edges. */
2921
3402
  .schematic-metered-features__price-details {
2922
3403
  align-items: center;
2923
3404
  background: var(--schematic-surface);
@@ -2930,6 +3411,10 @@ var meteredFeaturesCss = `
2930
3411
  var(--schematic-card-padding);
2931
3412
  }
2932
3413
 
3414
+ .schematic-metered-features__price-cost {
3415
+ text-align: end;
3416
+ }
3417
+
2933
3418
  .schematic-metered-features .schematic-skeleton__cell[data-column="name"] {
2934
3419
  width: 10rem;
2935
3420
  }
@@ -2953,7 +3438,6 @@ var meteredFeaturesCss = `
2953
3438
  background: color-mix(in srgb, var(--schematic-accent) 50%, transparent);
2954
3439
  }
2955
3440
 
2956
- /* Past the soft limit, the fill is the included share over a warning track. */
2957
3441
  .schematic-meter--overage {
2958
3442
  background: var(--schematic-warning);
2959
3443
  }
@@ -3045,7 +3529,6 @@ var paymentMethodsCss = `
3045
3529
  white-space: nowrap;
3046
3530
  }
3047
3531
 
3048
- /* The pill: the default method on the left, Edit or Add on the right. */
3049
3532
  .schematic-payment-methods__current {
3050
3533
  align-items: center;
3051
3534
  background: var(--schematic-surface);
@@ -3056,8 +3539,6 @@ var paymentMethodsCss = `
3056
3539
  padding: calc(var(--schematic-space) / 2.25) var(--schematic-space);
3057
3540
  }
3058
3541
 
3059
- /* One line: a label too long for the space truncates rather than wrapping
3060
- "Card ending in" away from its digits or widening the dialog. */
3061
3542
  .schematic-payment-methods__method {
3062
3543
  align-items: center;
3063
3544
  display: inline-flex;
@@ -3073,7 +3554,6 @@ var paymentMethodsCss = `
3073
3554
  white-space: nowrap;
3074
3555
  }
3075
3556
 
3076
- /* The brand's mark before the label, in the label's colour. */
3077
3557
  .schematic-payment-methods__icon {
3078
3558
  color: currentColor;
3079
3559
  flex-shrink: 0;
@@ -3096,15 +3576,10 @@ var paymentMethodsCss = `
3096
3576
  white-space: nowrap;
3097
3577
  }
3098
3578
 
3099
- /* The toggle that reveals the other methods. Its chevron is a glyph per
3100
- state, down while folded and up while unfolded, and the hover underline
3101
- goes on the label alone, as on every toggle. */
3102
3579
  .schematic-payment-methods__choose {
3103
3580
  align-items: center;
3104
3581
  align-self: flex-start;
3105
3582
  display: inline-flex;
3106
- /* A button centres its text; a label that wraps on a phone keeps to the
3107
- start. */
3108
3583
  text-align: start;
3109
3584
  gap: calc(var(--schematic-space) / 2);
3110
3585
  }
@@ -3117,9 +3592,6 @@ var paymentMethodsCss = `
3117
3592
  text-decoration: underline;
3118
3593
  }
3119
3594
 
3120
-
3121
- /* A faintly tinted panel, roomier than the shared dialog body, with its
3122
- parts spaced further apart. */
3123
3595
  .schematic-payment-methods__dialog .schematic-dialog__body {
3124
3596
  background: color-mix(in srgb, var(--schematic-text) 2.5%, transparent);
3125
3597
  gap: calc(var(--schematic-space) * 2);
@@ -3132,9 +3604,6 @@ var paymentMethodsCss = `
3132
3604
  }
3133
3605
  }
3134
3606
 
3135
- /* The list tucks up under its toggle, the heading sits a card's gap above
3136
- the pill, and a failed write sits close under what it failed
3137
- on. */
3138
3607
  .schematic-payment-methods__dialog .schematic-payment-methods__list,
3139
3608
  .schematic-payment-methods__dialog .schematic-payment-methods__current,
3140
3609
  .schematic-payment-methods__dialog .schematic-payment-methods__error {
@@ -3149,8 +3618,6 @@ var paymentMethodsCss = `
3149
3618
  padding: 0;
3150
3619
  }
3151
3620
 
3152
- /* The name on the left, the expiry and actions on the right; a narrow
3153
- dialog wraps the actions under the name. */
3154
3621
  .schematic-payment-methods__row {
3155
3622
  align-items: center;
3156
3623
  border-bottom: 1px solid var(--schematic-card-divider);
@@ -3160,8 +3627,6 @@ var paymentMethodsCss = `
3160
3627
  padding: calc(var(--schematic-space) / 2) 0;
3161
3628
  }
3162
3629
 
3163
- /* The name takes the line's room first; the actions wrap under it before
3164
- the name is cut short. */
3165
3630
  .schematic-payment-methods__row .schematic-payment-methods__method {
3166
3631
  flex: 1 1 10rem;
3167
3632
  }
@@ -3214,7 +3679,6 @@ var paymentMethodsCss = `
3214
3679
  width: 100%;
3215
3680
  }
3216
3681
 
3217
- /* Larger than the shared CTA: taller, with bigger type and radius. */
3218
3682
  .schematic-payment-methods__add-new {
3219
3683
  border-radius: 0.625rem;
3220
3684
  font-size: 1.1875rem;
@@ -3226,7 +3690,6 @@ var paymentMethodsCss = `
3226
3690
  align-self: flex-start;
3227
3691
  }
3228
3692
 
3229
- /* The failed write and its retry sit on one line at the foot of the dialog. */
3230
3693
  .schematic-payment-methods__error {
3231
3694
  align-items: center;
3232
3695
  display: flex;
@@ -3239,8 +3702,6 @@ var paymentMethodsCss = `
3239
3702
  white-space: nowrap;
3240
3703
  }
3241
3704
 
3242
- /* Spaced as the embed's form: 24px between parts, and a wider break before
3243
- Save under the address. */
3244
3705
  .schematic-payment-methods__form {
3245
3706
  display: flex;
3246
3707
  flex-direction: column;
@@ -3251,8 +3712,6 @@ var paymentMethodsCss = `
3251
3712
  margin-bottom: calc(var(--schematic-space) * 2);
3252
3713
  }
3253
3714
 
3254
- /* The fields the checkout settings add beside Stripe's own, labelled as
3255
- Stripe's are. */
3256
3715
  .schematic-payment-methods__field {
3257
3716
  display: flex;
3258
3717
  flex-direction: column;
@@ -3262,7 +3721,6 @@ var paymentMethodsCss = `
3262
3721
  .schematic-payment-methods__input {
3263
3722
  background: var(--schematic-background);
3264
3723
  border: 1px solid var(--schematic-border);
3265
- /* The embed's 8px at the default radius; Stripe's fields take the same. */
3266
3724
  border-radius: calc(var(--schematic-radius) * 0.8);
3267
3725
  box-sizing: border-box;
3268
3726
  color: var(--schematic-text);
@@ -3291,109 +3749,364 @@ var paymentMethodsCss = `
3291
3749
  }
3292
3750
  `;
3293
3751
 
3294
- // src/elements/styles/index.tsx
3295
- init_tokens();
3296
-
3297
- // src/elements/styles/tooltip.ts
3298
- var tooltipCss = `
3299
- .schematic-tooltip {
3300
- display: inline-block;
3301
- margin-inline-start: 0.25rem;
3302
- position: relative;
3303
- vertical-align: middle;
3304
- }
3305
-
3306
- .schematic-tooltip__trigger {
3307
- background: none;
3308
- border: 0;
3309
- color: var(--schematic-muted);
3310
- cursor: help;
3311
- /* A button keeps the browser's control font; the glyph is the embed's
3312
- 24px. */
3313
- font-size: 1.5rem;
3314
- line-height: 0;
3315
- padding: 0;
3752
+ // src/elements/styles/plan-manager.ts
3753
+ var planManagerCss = `
3754
+ .schematic-plan-manager {
3755
+ display: flex;
3756
+ flex-direction: column;
3757
+ gap: var(--schematic-space);
3316
3758
  }
3317
3759
 
3318
- .schematic-tooltip__trigger:focus-visible {
3319
- outline: 2px solid var(--schematic-accent);
3320
- outline-offset: 2px;
3760
+ .schematic-plan-manager[data-state="pending"],
3761
+ .schematic-plan-manager[data-state="error"] {
3762
+ background: var(--schematic-background);
3763
+ border-radius: var(--schematic-radius);
3764
+ box-shadow: var(--schematic-shadow);
3765
+ padding: calc(var(--schematic-card-padding) * 0.75)
3766
+ var(--schematic-card-padding);
3321
3767
  }
3322
3768
 
3323
- .schematic-tooltip__content {
3769
+ .schematic-plan-manager:has(.schematic-plan-manager__notice) {
3324
3770
  background: var(--schematic-background);
3325
- border: 1px solid var(--schematic-border);
3326
- border-radius: calc(var(--schematic-radius) / 2);
3327
- bottom: calc(100% + 0.5rem);
3771
+ border-radius: var(--schematic-radius);
3328
3772
  box-shadow: var(--schematic-shadow);
3329
- color: var(--schematic-text);
3330
- font-size: 0.875rem;
3331
- inset-inline-end: 0;
3332
- padding: 0.5rem 0.75rem;
3333
- pointer-events: none;
3334
- position: absolute;
3335
- text-align: start;
3336
- visibility: hidden;
3337
- white-space: nowrap;
3338
- z-index: 1;
3773
+ gap: 0;
3774
+ overflow: hidden;
3339
3775
  }
3340
3776
 
3341
- .schematic-tooltip:hover .schematic-tooltip__content,
3342
- .schematic-tooltip:focus-within .schematic-tooltip__content {
3343
- visibility: visible;
3777
+ .schematic-plan-manager:has(.schematic-plan-manager__notice)
3778
+ .schematic-plan-manager__card {
3779
+ border-radius: 0;
3780
+ box-shadow: none;
3344
3781
  }
3345
3782
 
3346
- .schematic-tiers {
3783
+ .schematic-plan-manager__notice {
3784
+ align-items: center;
3785
+ background: var(--schematic-inset);
3347
3786
  display: flex;
3348
3787
  flex-direction: column;
3349
3788
  gap: 0.5rem;
3789
+ padding: calc(var(--schematic-space) * 1.5);
3790
+ text-align: center;
3350
3791
  }
3351
3792
 
3352
- .schematic-tiers__list {
3353
- margin: 0;
3354
- }
3355
-
3356
- .schematic-tiers__tier {
3357
- display: flex;
3358
- gap: var(--schematic-space);
3359
- justify-content: space-between;
3360
- padding: 0.25rem 0;
3361
- }
3362
-
3363
- .schematic-tiers__price {
3793
+ .schematic-plan-manager__notice-title {
3794
+ font-family: var(--schematic-font-heading);
3795
+ font-size: 1.25rem;
3796
+ font-weight: 600;
3797
+ line-height: var(--schematic-line-height-heading);
3364
3798
  margin: 0;
3365
3799
  }
3366
3800
 
3367
- .schematic-tiers__mode {
3368
- border-top: 1px solid var(--schematic-border);
3369
- padding-top: 0.5rem;
3370
- white-space: normal;
3801
+ .schematic-plan-manager__notice-body {
3802
+ font-size: 0.8125rem;
3371
3803
  }
3372
- `;
3373
3804
 
3374
- // src/elements/styles/upcoming-bill.ts
3375
- var upcomingBillCss = `
3376
- .schematic-upcoming-bill {
3805
+ .schematic-plan-manager__card {
3377
3806
  display: flex;
3378
3807
  flex-direction: column;
3379
- gap: var(--schematic-space);
3808
+ gap: calc(var(--schematic-space) * 2);
3380
3809
  }
3381
3810
 
3382
- .schematic-upcoming-bill .schematic-header {
3383
- margin-bottom: 0;
3811
+ .schematic-plan-manager__plan {
3812
+ align-items: center;
3813
+ display: flex;
3814
+ gap: var(--schematic-space);
3815
+ justify-content: space-between;
3384
3816
  }
3385
3817
 
3386
- .schematic-upcoming-bill__amount {
3387
- align-items: flex-start;
3818
+ .schematic-plan-manager__title {
3388
3819
  display: flex;
3820
+ flex-direction: column;
3389
3821
  gap: var(--schematic-space);
3390
- justify-content: space-between;
3391
3822
  }
3392
3823
 
3393
- .schematic-upcoming-bill__total {
3824
+ .schematic-plan-manager__name {
3394
3825
  font-family: var(--schematic-font-heading);
3395
3826
  font-size: 2.3125rem;
3396
- font-variant-numeric: tabular-nums;
3827
+ font-weight: 800;
3828
+ line-height: 1;
3829
+ margin: 0;
3830
+ }
3831
+
3832
+ .schematic-plan-manager__price {
3833
+ font-family: var(--schematic-font-heading);
3834
+ font-size: 1.25rem;
3835
+ font-weight: 600;
3836
+ white-space: nowrap;
3837
+ }
3838
+
3839
+ .schematic-plan-manager__section {
3840
+ display: flex;
3841
+ flex-direction: column;
3842
+ gap: 0.5rem;
3843
+ }
3844
+
3845
+ .schematic-plan-manager__label {
3846
+ line-height: 1;
3847
+ }
3848
+
3849
+ .schematic-plan-manager__rows {
3850
+ display: flex;
3851
+ flex-direction: column;
3852
+ gap: var(--schematic-space);
3853
+ list-style: none;
3854
+ margin: 0;
3855
+ padding: 0;
3856
+ }
3857
+
3858
+ .schematic-plan-manager__row,
3859
+ .schematic-plan-manager__row-main {
3860
+ align-items: center;
3861
+ display: flex;
3862
+ flex-wrap: wrap;
3863
+ gap: var(--schematic-space);
3864
+ justify-content: space-between;
3865
+ }
3866
+
3867
+ .schematic-plan-manager__row-main {
3868
+ align-items: baseline;
3869
+ gap: 0.5rem;
3870
+ }
3871
+
3872
+ .schematic-plan-manager__row--stacked {
3873
+ align-items: stretch;
3874
+ flex-direction: column;
3875
+ gap: 0.25rem;
3876
+ }
3877
+
3878
+ .schematic-plan-manager__item {
3879
+ font-family: var(--schematic-font-heading);
3880
+ font-size: 1.125rem;
3881
+ font-weight: 800;
3882
+ }
3883
+
3884
+ .schematic-plan-manager__detail,
3885
+ .schematic-plan-manager__used {
3886
+ align-items: center;
3887
+ display: inline-flex;
3888
+ gap: 0.25rem;
3889
+ }
3890
+
3891
+ .schematic-plan-manager__see-all {
3892
+ align-items: center;
3893
+ align-self: flex-start;
3894
+ display: inline-flex;
3895
+ gap: 0.25rem;
3896
+ margin-top: 0.5rem;
3897
+ }
3898
+
3899
+ .schematic-plan-manager__see-all .schematic-chevron {
3900
+ margin-inline-start: -0.333rem;
3901
+ }
3902
+
3903
+ .schematic-plan-manager__auto-topup {
3904
+ align-items: center;
3905
+ background: var(--schematic-inset);
3906
+ border-radius: calc(var(--schematic-radius) * 0.8);
3907
+ display: flex;
3908
+ gap: 0.5rem;
3909
+ justify-content: space-between;
3910
+ padding: calc(var(--schematic-space) * 1.5);
3911
+ }
3912
+
3913
+ .schematic-plan-manager__auto-topup-lines {
3914
+ display: flex;
3915
+ flex-direction: column;
3916
+ gap: 0.5rem;
3917
+ line-height: 1.25;
3918
+ }
3919
+
3920
+ .schematic-plan-manager__change-plan {
3921
+ width: 100%;
3922
+ }
3923
+
3924
+ .schematic-plan-manager .schematic-skeleton__cell[data-column="name"] {
3925
+ width: 10rem;
3926
+ }
3927
+
3928
+ .schematic-plan-manager .schematic-skeleton__cell[data-column="price"] {
3929
+ width: 6rem;
3930
+ }
3931
+ `;
3932
+
3933
+ // src/elements/styles/index.tsx
3934
+ init_tokens();
3935
+
3936
+ // src/elements/styles/tooltip.ts
3937
+ var tooltipCss = `
3938
+ .schematic-tooltip {
3939
+ display: inline-block;
3940
+ margin-inline-start: 0.25rem;
3941
+ position: relative;
3942
+ vertical-align: middle;
3943
+ }
3944
+
3945
+ .schematic-tooltip__trigger {
3946
+ background: none;
3947
+ border: 0;
3948
+ color: var(--schematic-muted);
3949
+ cursor: help;
3950
+ font-size: 1.5rem;
3951
+ line-height: 0;
3952
+ padding: 0;
3953
+ }
3954
+
3955
+ .schematic-tooltip__trigger:focus-visible {
3956
+ outline: 2px solid var(--schematic-accent);
3957
+ outline-offset: 2px;
3958
+ }
3959
+
3960
+ .schematic-tooltip__content {
3961
+ background: var(--schematic-background);
3962
+ border: 1px solid var(--schematic-border);
3963
+ border-radius: calc(var(--schematic-radius) / 2);
3964
+ bottom: calc(100% + 0.5rem);
3965
+ box-shadow: var(--schematic-shadow);
3966
+ color: var(--schematic-text);
3967
+ font-size: 0.875rem;
3968
+ inset-inline-end: 0;
3969
+ padding: 0.5rem 0.75rem;
3970
+ pointer-events: none;
3971
+ position: absolute;
3972
+ text-align: start;
3973
+ visibility: hidden;
3974
+ white-space: nowrap;
3975
+ z-index: 1;
3976
+ }
3977
+
3978
+ .schematic-tooltip:hover .schematic-tooltip__content,
3979
+ .schematic-tooltip:focus-within .schematic-tooltip__content {
3980
+ visibility: visible;
3981
+ }
3982
+
3983
+ .schematic-tiers {
3984
+ display: flex;
3985
+ flex-direction: column;
3986
+ gap: 0.5rem;
3987
+ }
3988
+
3989
+ .schematic-tiers__list {
3990
+ margin: 0;
3991
+ }
3992
+
3993
+ .schematic-tiers__tier {
3994
+ display: flex;
3995
+ gap: var(--schematic-space);
3996
+ justify-content: space-between;
3997
+ padding: 0.25rem 0;
3998
+ }
3999
+
4000
+ .schematic-tiers__price {
4001
+ margin: 0;
4002
+ }
4003
+
4004
+ .schematic-tiers__mode {
4005
+ border-top: 1px solid var(--schematic-border);
4006
+ padding-top: 0.5rem;
4007
+ white-space: normal;
4008
+ }
4009
+ `;
4010
+
4011
+ // src/elements/styles/unsubscribe.ts
4012
+ var unsubscribeCss = `
4013
+ .schematic-unsubscribe {
4014
+ display: flex;
4015
+ justify-content: center;
4016
+ }
4017
+
4018
+ .schematic-unsubscribe__open {
4019
+ width: 100%;
4020
+ }
4021
+
4022
+ .schematic-unsubscribe__columns {
4023
+ display: flex;
4024
+ flex-wrap: wrap;
4025
+ gap: calc(var(--schematic-space) * 2);
4026
+ }
4027
+
4028
+ .schematic-unsubscribe__summary {
4029
+ display: flex;
4030
+ flex: 1 1 18rem;
4031
+ flex-direction: column;
4032
+ gap: calc(var(--schematic-space) * 2);
4033
+ }
4034
+
4035
+ .schematic-unsubscribe__manage {
4036
+ display: flex;
4037
+ flex-direction: column;
4038
+ gap: 0.5rem;
4039
+ }
4040
+
4041
+ .schematic-unsubscribe__manage-plan {
4042
+ align-self: flex-start;
4043
+ color: var(--schematic-accent);
4044
+ }
4045
+
4046
+ .schematic-unsubscribe__sidebar {
4047
+ background: var(--schematic-inset);
4048
+ border-radius: calc(var(--schematic-radius) * 0.8);
4049
+ display: flex;
4050
+ flex: 1 1 16rem;
4051
+ flex-direction: column;
4052
+ gap: calc(var(--schematic-space) * 1.5);
4053
+ padding: calc(var(--schematic-space) * 1.5);
4054
+ }
4055
+
4056
+ .schematic-unsubscribe__group {
4057
+ display: flex;
4058
+ flex-direction: column;
4059
+ gap: 0.125rem;
4060
+ }
4061
+
4062
+ .schematic-unsubscribe__line {
4063
+ align-items: baseline;
4064
+ display: flex;
4065
+ gap: var(--schematic-space);
4066
+ justify-content: space-between;
4067
+ white-space: nowrap;
4068
+ }
4069
+
4070
+ .schematic-unsubscribe__name {
4071
+ font-family: var(--schematic-font-heading);
4072
+ font-size: 1.125rem;
4073
+ font-weight: 800;
4074
+ white-space: normal;
4075
+ }
4076
+
4077
+ .schematic-unsubscribe__total {
4078
+ border-top: 1px solid var(--schematic-card-divider);
4079
+ padding-top: calc(var(--schematic-space) * 1.5);
4080
+ }
4081
+
4082
+ .schematic-unsubscribe__confirm {
4083
+ width: 100%;
4084
+ }
4085
+ `;
4086
+
4087
+ // src/elements/styles/upcoming-bill.ts
4088
+ var upcomingBillCss = `
4089
+ .schematic-upcoming-bill {
4090
+ display: flex;
4091
+ flex-direction: column;
4092
+ gap: var(--schematic-space);
4093
+ }
4094
+
4095
+ .schematic-upcoming-bill .schematic-header {
4096
+ margin-bottom: 0;
4097
+ }
4098
+
4099
+ .schematic-upcoming-bill__amount {
4100
+ align-items: flex-start;
4101
+ display: flex;
4102
+ gap: var(--schematic-space);
4103
+ justify-content: space-between;
4104
+ }
4105
+
4106
+ .schematic-upcoming-bill__total {
4107
+ font-family: var(--schematic-font-heading);
4108
+ font-size: 2.3125rem;
4109
+ font-variant-numeric: tabular-nums;
3397
4110
  font-weight: 800;
3398
4111
  line-height: 1;
3399
4112
  }
@@ -3425,7 +4138,7 @@ var upcomingBillCss = `
3425
4138
  }
3426
4139
 
3427
4140
  .schematic-upcoming-bill__discount {
3428
- align-items: center;
4141
+ align-items: start;
3429
4142
  display: inline-flex;
3430
4143
  gap: calc(var(--schematic-space) / 2);
3431
4144
  }
@@ -3453,6 +4166,7 @@ var rulesCss = `
3453
4166
  color: var(--schematic-text);
3454
4167
  font-family: var(--schematic-font-body);
3455
4168
  line-height: var(--schematic-line-height);
4169
+ text-wrap: balance;
3456
4170
  }
3457
4171
 
3458
4172
  :where([class^="schematic-"]) *,
@@ -3465,7 +4179,6 @@ var rulesCss = `
3465
4179
  margin: 0;
3466
4180
  }
3467
4181
 
3468
- /* Unit suffixes ("/mo", "/seat") sit on the baseline, as in the embed. */
3469
4182
  :where([class^="schematic-"]) sub,
3470
4183
  :where([class^="schematic-"]) sup {
3471
4184
  line-height: 1;
@@ -3503,13 +4216,11 @@ var rulesCss = `
3503
4216
  gap: var(--schematic-space);
3504
4217
  }
3505
4218
 
3506
- /* The message may run long; the action beside it stays one line. */
3507
4219
  .schematic-status__retry {
3508
4220
  flex-shrink: 0;
3509
4221
  white-space: nowrap;
3510
4222
  }
3511
4223
 
3512
- /* Visually hidden, still read by assistive technology. */
3513
4224
  .schematic-hidden {
3514
4225
  border: 0;
3515
4226
  clip-path: inset(50%);
@@ -3638,7 +4349,6 @@ var rulesCss = `
3638
4349
  border-color: var(--schematic-primary);
3639
4350
  }
3640
4351
 
3641
- /* The embed's small button: 15px type, 40px tall. */
3642
4352
  .schematic-cta--small {
3643
4353
  border-radius: 0.375rem;
3644
4354
  font-size: 0.9375rem;
@@ -3646,7 +4356,6 @@ var rulesCss = `
3646
4356
  padding: 0.4375rem 1.25rem;
3647
4357
  }
3648
4358
 
3649
- /* The embed's ghost button, for secondary actions such as Try again. */
3650
4359
  .schematic-cta--ghost {
3651
4360
  background: transparent;
3652
4361
  border-color: color-mix(in srgb, var(--schematic-text) 20%, transparent);
@@ -3674,19 +4383,15 @@ var rulesCss = `
3674
4383
  text-decoration: underline;
3675
4384
  }
3676
4385
 
3677
- /* Every toggle's chevron: the 24px glyph, muted. */
3678
4386
  .schematic-chevron {
3679
4387
  color: var(--schematic-muted);
3680
4388
  font-size: 1.5rem;
3681
4389
  }
3682
4390
 
3683
- /* A toggle underlines its label alone: a flex container hands its underline
3684
- to every item, the chevron included, and an item cannot take it off. */
3685
4391
  .schematic-link-button:has(.schematic-link-button__label):hover {
3686
4392
  text-decoration: none;
3687
4393
  }
3688
4394
 
3689
- /* The reset colours every schematic- element; the label keeps the link's. */
3690
4395
  .schematic-link-button__label {
3691
4396
  color: inherit;
3692
4397
  }
@@ -3787,7 +4492,6 @@ var rulesCss = `
3787
4492
  margin: 0;
3788
4493
  }
3789
4494
 
3790
- /* A label on the left, its value on the right. */
3791
4495
  .schematic-row {
3792
4496
  align-items: flex-start;
3793
4497
  display: flex;
@@ -3996,6 +4700,9 @@ ${tooltipCss}
3996
4700
  ${includedFeaturesCss}
3997
4701
  ${meteredFeaturesCss}
3998
4702
  ${creditUsageCss}
4703
+ ${planManagerCss}
4704
+ ${unsubscribeCss}
4705
+ ${cardGroupCss}
3999
4706
  `;
4000
4707
  var schematicStylesCss = withTokenDefaults(rulesCss) + iconsCss;
4001
4708
  var SchematicStyles = () => /* @__PURE__ */ jsx("style", { "data-schematic-styles": "", children: schematicStylesCss });
@@ -4112,8 +4819,9 @@ var StatusFrame = ({
4112
4819
  skeleton = /* @__PURE__ */ jsx2("div", { className: "schematic-skeleton" })
4113
4820
  }) => {
4114
4821
  useReportHiddenError(error, errorMessage);
4822
+ const root = cx("schematic-element", className);
4115
4823
  if (error !== void 0 && !hasData) {
4116
- return /* @__PURE__ */ jsx2("div", { className, "data-state": "error", children: /* @__PURE__ */ jsxs("div", { className: "schematic-status", role: "alert", children: [
4824
+ return /* @__PURE__ */ jsx2("div", { className: root, "data-state": "error", children: /* @__PURE__ */ jsxs("div", { className: "schematic-status", role: "alert", children: [
4117
4825
  /* @__PURE__ */ jsx2("span", { className: "schematic-error schematic-status__message", children: errorMessage ?? error.message }),
4118
4826
  onRetry !== void 0 && /* @__PURE__ */ jsx2(
4119
4827
  "button",
@@ -4127,12 +4835,12 @@ var StatusFrame = ({
4127
4835
  ] }) });
4128
4836
  }
4129
4837
  if (isPending && !hasData) {
4130
- return /* @__PURE__ */ jsxs("div", { "aria-busy": "true", className, "data-state": "pending", children: [
4838
+ return /* @__PURE__ */ jsxs("div", { "aria-busy": "true", className: root, "data-state": "pending", children: [
4131
4839
  /* @__PURE__ */ jsx2("span", { className: "schematic-hidden", children: loadingLabel }),
4132
4840
  skeleton
4133
4841
  ] });
4134
4842
  }
4135
- return /* @__PURE__ */ jsxs("div", { className, "data-state": "ready", children: [
4843
+ return /* @__PURE__ */ jsxs("div", { className: root, "data-state": "ready", children: [
4136
4844
  children,
4137
4845
  error !== void 0 && /* @__PURE__ */ jsx2("p", { className: "schematic-status-note schematic-error", role: "alert", children: errorMessage ?? error.message })
4138
4846
  ] });
@@ -5316,7 +6024,7 @@ function PriceDetails({
5316
6024
  const period = details.period === null ? void 0 : shortPeriod(details.period, t);
5317
6025
  if (details.kind === "overage") {
5318
6026
  return /* @__PURE__ */ jsxs6("div", { className: "schematic-metered-features__price-details", children: [
5319
- /* @__PURE__ */ jsxs6("span", { children: [
6027
+ /* @__PURE__ */ jsxs6("span", { className: "schematic-metered-features__price-label", children: [
5320
6028
  t("meteredFeaturesAdditional"),
5321
6029
  ": ",
5322
6030
  details.unitPrice,
@@ -5327,7 +6035,7 @@ function PriceDetails({
5327
6035
  period !== void 0 && `/${period}`
5328
6036
  ] })
5329
6037
  ] }),
5330
- /* @__PURE__ */ jsxs6("span", { children: [
6038
+ /* @__PURE__ */ jsxs6("span", { className: "schematic-metered-features__price-cost", children: [
5331
6039
  details.overage.amount,
5332
6040
  " ",
5333
6041
  details.overage.units,
@@ -5341,7 +6049,7 @@ function PriceDetails({
5341
6049
  ] });
5342
6050
  }
5343
6051
  return /* @__PURE__ */ jsxs6("div", { className: "schematic-metered-features__price-details", children: [
5344
- /* @__PURE__ */ jsxs6("span", { children: [
6052
+ /* @__PURE__ */ jsxs6("span", { className: "schematic-metered-features__price-label", children: [
5345
6053
  t("meteredFeaturesTier"),
5346
6054
  ": ",
5347
6055
  details.from,
@@ -5359,7 +6067,7 @@ function PriceDetails({
5359
6067
  }
5360
6068
  ) })
5361
6069
  ] }),
5362
- details.cost !== null && /* @__PURE__ */ jsxs6("span", { children: [
6070
+ details.cost !== null && /* @__PURE__ */ jsxs6("span", { className: "schematic-metered-features__price-cost", children: [
5363
6071
  details.cost,
5364
6072
  period !== void 0 && /* @__PURE__ */ jsxs6("sub", { children: [
5365
6073
  "/",
@@ -5803,24 +6511,792 @@ function FormSkeleton({ label }) {
5803
6511
  }
5804
6512
  PaymentMethods.resources = ["paymentMethods"];
5805
6513
 
5806
- // src/elements/UpcomingBill.tsx
5807
- import { useUpcomingInvoice } from "@schematichq/schematic-react";
5808
- import { useMemo as useMemo7 } from "react";
6514
+ // src/elements/PlanManager.tsx
6515
+ import {
6516
+ useCompany,
6517
+ useCreditBalances as useCreditBalances2,
6518
+ useFeatureUsage as useFeatureUsage3
6519
+ } from "@schematichq/schematic-react";
6520
+ import { useMemo as useMemo7, useState as useState7 } from "react";
5809
6521
  import { Fragment as Fragment4, jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
5810
- function UpcomingBill({
6522
+ var VISIBLE_CREDIT_COUNT = 3;
6523
+ var UNIT_KEY = {
6524
+ day: "planManagerDays",
6525
+ hour: "planManagerHours",
6526
+ minute: "planManagerMinutes"
6527
+ };
6528
+ var PERIOD_KEY = {
6529
+ day: "periodDay",
6530
+ month: "periodMonth",
6531
+ quarter: "periodQuarter",
6532
+ week: "periodWeek",
6533
+ year: "periodYear"
6534
+ };
6535
+ function PlanManager({
6536
+ changePlanTarget,
6537
+ changePlanUrl,
5811
6538
  className,
6539
+ editAutoTopupTarget,
6540
+ editAutoTopupUrl,
5812
6541
  headingLevel = 2,
5813
6542
  locale: localeProp,
5814
- showAmount = true,
5815
- showBalance = true,
5816
- showDiscounts = true,
6543
+ onChangePlan,
6544
+ onEditAutoTopup,
6545
+ showAddOns = true,
6546
+ showCredits = true,
6547
+ showDescription = true,
6548
+ showHardLimit = false,
6549
+ showHeader = true,
6550
+ showLabels = true,
6551
+ showNotice = true,
6552
+ showPrice = true,
6553
+ showUsageBased = true,
6554
+ showWarningThresholdAsLimit = false,
6555
+ showZeroPriceAsFree = false,
6556
+ strings
6557
+ }) {
6558
+ const company = useCompany();
6559
+ const usage = useFeatureUsage3();
6560
+ const credits = useCreditBalances2();
6561
+ const locale = useResolvedLocale(localeProp);
6562
+ const t = useTranslator(strings, localeProp);
6563
+ const creditsFailed = credits.data === void 0 && credits.error !== void 0;
6564
+ const [creditsHaveFailed, setCreditsHaveFailed] = useState7(false);
6565
+ if (creditsFailed && !creditsHaveFailed) {
6566
+ setCreditsHaveFailed(true);
6567
+ } else if (!creditsFailed && creditsHaveFailed && (credits.data !== void 0 || company.data === void 0 || usage.data === void 0)) {
6568
+ setCreditsHaveFailed(false);
6569
+ }
6570
+ const creditsSettled = !showCredits || credits.data !== void 0 || creditsHaveFailed;
6571
+ const view = useMemo7(
6572
+ () => company.data === void 0 || usage.data === void 0 || !creditsSettled ? void 0 : derivePlanManager(
6573
+ {
6574
+ company: company.data,
6575
+ creditBalances: credits.data ?? [],
6576
+ featureUsage: usage.data
6577
+ },
6578
+ {
6579
+ locale,
6580
+ showCredits,
6581
+ showWarningThresholdAsLimit,
6582
+ showZeroPriceAsFree
6583
+ }
6584
+ ),
6585
+ [
6586
+ company.data,
6587
+ credits.data,
6588
+ creditsSettled,
6589
+ locale,
6590
+ showCredits,
6591
+ showWarningThresholdAsLimit,
6592
+ showZeroPriceAsFree,
6593
+ usage.data
6594
+ ]
6595
+ );
6596
+ const creditsRefetchError = showCredits && credits.data !== void 0 ? credits.error : void 0;
6597
+ const cardError = company.error ?? usage.error;
6598
+ const error = cardError ?? creditsRefetchError;
6599
+ const unavailable = view === void 0 && httpStatus(error) === 404;
6600
+ const errorMessage = error === void 0 ? void 0 : unavailable ? t("planManagerUnavailable") : cardError === void 0 ? t("planManagerCreditsError") : t("planManagerError");
6601
+ const retry = () => {
6602
+ for (const handle of showCredits ? [company, usage, credits] : [company, usage]) {
6603
+ if (handle.error !== void 0) {
6604
+ handle.refetch();
6605
+ }
6606
+ }
6607
+ };
6608
+ const Heading = `h${headingLevel}`;
6609
+ return /* @__PURE__ */ jsx10(
6610
+ StatusFrame,
6611
+ {
6612
+ className: cx("schematic-plan-manager", className),
6613
+ error,
6614
+ errorMessage,
6615
+ hasData: view !== void 0,
6616
+ isPending: company.isPending || usage.isPending || credits.isPending,
6617
+ loadingLabel: t("planManagerLoading"),
6618
+ onRetry: retry,
6619
+ retryText: t("retry"),
6620
+ skeleton: /* @__PURE__ */ jsx10(PlanManagerSkeleton, {}),
6621
+ children: view !== void 0 && /* @__PURE__ */ jsxs9(Fragment4, { children: [
6622
+ showNotice && view.notice !== null && /* @__PURE__ */ jsx10(Notice, { locale, notice: view.notice, t }),
6623
+ /* @__PURE__ */ jsxs9("div", { className: "schematic-card schematic-plan-manager__card", children: [
6624
+ showHeader && view.plan !== null && /* @__PURE__ */ jsxs9("div", { className: "schematic-plan-manager__plan", children: [
6625
+ /* @__PURE__ */ jsxs9("div", { className: "schematic-plan-manager__title", children: [
6626
+ /* @__PURE__ */ jsx10(Heading, { className: "schematic-plan-manager__name", children: view.plan.name }),
6627
+ showDescription && view.plan.description !== null && /* @__PURE__ */ jsx10("p", { className: "schematic-plan-manager__description", children: view.plan.description })
6628
+ ] }),
6629
+ showPrice && view.plan.price !== null && /* @__PURE__ */ jsx10(Price, { price: view.plan.price, t })
6630
+ ] }),
6631
+ showAddOns && view.addOns.length > 0 && /* @__PURE__ */ jsx10(Section, { label: t("planManagerAddOns"), showLabel: showLabels, children: view.addOns.map((addOn) => /* @__PURE__ */ jsxs9("li", { className: "schematic-plan-manager__row", children: [
6632
+ /* @__PURE__ */ jsx10("span", { className: "schematic-plan-manager__item", children: addOn.name }),
6633
+ addOn.price !== null && /* @__PURE__ */ jsxs9("span", { className: "schematic-plan-manager__price-value", children: [
6634
+ addOn.price.amount,
6635
+ /* @__PURE__ */ jsx10(PeriodSuffix, { period: addOn.price.period, t })
6636
+ ] })
6637
+ ] }, addOn.id)) }),
6638
+ showUsageBased && view.usageBased.length > 0 && /* @__PURE__ */ jsx10(
6639
+ Section,
6640
+ {
6641
+ label: t("planManagerUsageBased"),
6642
+ showLabel: showLabels,
6643
+ children: view.usageBased.map((row) => /* @__PURE__ */ jsx10(
6644
+ UsageBasedItem,
6645
+ {
6646
+ locale,
6647
+ row,
6648
+ showHardLimit,
6649
+ t
6650
+ },
6651
+ row.featureId
6652
+ ))
6653
+ }
6654
+ ),
6655
+ showCredits && credits.data === void 0 && creditsHaveFailed && (credits.error !== void 0 || credits.isPending) && /* @__PURE__ */ jsx10(
6656
+ StatusFrame,
6657
+ {
6658
+ className: "schematic-plan-manager__section",
6659
+ error: credits.error,
6660
+ errorMessage: t("planManagerCreditsError"),
6661
+ hasData: false,
6662
+ isPending: credits.isPending,
6663
+ loadingLabel: t("planManagerCreditsLoading"),
6664
+ onRetry: credits.refetch,
6665
+ retryText: t("retry"),
6666
+ children: null
6667
+ }
6668
+ ),
6669
+ showCredits && view.planCredits.length > 0 && /* @__PURE__ */ jsx10(
6670
+ Truncated,
6671
+ {
6672
+ locale,
6673
+ after: view.autoTopup !== null && /* @__PURE__ */ jsx10(
6674
+ AutoTopupBox,
6675
+ {
6676
+ lines: view.autoTopup.lines,
6677
+ onEdit: onEditAutoTopup,
6678
+ t,
6679
+ target: editAutoTopupTarget,
6680
+ url: editAutoTopupUrl
6681
+ }
6682
+ ),
6683
+ label: t("planManagerCreditsInPlan"),
6684
+ rows: view.planCredits,
6685
+ showLabel: showLabels,
6686
+ t,
6687
+ children: (row) => /* @__PURE__ */ jsx10(PlanCreditItem, { row, t }, row.creditId)
6688
+ }
6689
+ ),
6690
+ showCredits && view.topUps.length > 0 && /* @__PURE__ */ jsx10(
6691
+ Truncated,
6692
+ {
6693
+ locale,
6694
+ label: t("planManagerTopUps"),
6695
+ rows: view.topUps,
6696
+ showLabel: showLabels,
6697
+ t,
6698
+ children: (row) => /* @__PURE__ */ jsx10(CreditGroupItem, { countAlways: true, row, t }, row.key)
6699
+ }
6700
+ ),
6701
+ showCredits && view.bundles.length > 0 && /* @__PURE__ */ jsx10(
6702
+ Truncated,
6703
+ {
6704
+ locale,
6705
+ label: t("planManagerCreditBundles"),
6706
+ rows: view.bundles,
6707
+ showLabel: showLabels,
6708
+ t,
6709
+ children: (row) => /* @__PURE__ */ jsx10(CreditGroupItem, { row, t }, row.key)
6710
+ }
6711
+ ),
6712
+ showCredits && view.promotional.length > 0 && /* @__PURE__ */ jsx10(
6713
+ Truncated,
6714
+ {
6715
+ locale,
6716
+ label: t("planManagerPromotionalCredits"),
6717
+ rows: view.promotional,
6718
+ showLabel: showLabels,
6719
+ t,
6720
+ children: (row) => /* @__PURE__ */ jsx10(CreditGroupItem, { plain: true, row, t }, row.key)
6721
+ }
6722
+ ),
6723
+ view.canChangePlan && /* @__PURE__ */ jsx10(
6724
+ Cta,
6725
+ {
6726
+ className: "schematic-cta schematic-plan-manager__change-plan",
6727
+ label: t("planManagerChangePlan"),
6728
+ onClick: onChangePlan,
6729
+ target: changePlanTarget,
6730
+ url: changePlanUrl
6731
+ }
6732
+ )
6733
+ ] })
6734
+ ] })
6735
+ }
6736
+ );
6737
+ }
6738
+ function Notice({
6739
+ locale,
6740
+ notice: notice2,
6741
+ t
6742
+ }) {
6743
+ let title = null;
6744
+ let body = null;
6745
+ let payUrl = null;
6746
+ switch (notice2.kind) {
6747
+ case "trial":
6748
+ title = notice2.endsIn === null ? null : notice2.endsIn === "soon" ? t("planManagerTrialEndsSoon") : notice2.endsIn === "ended" ? t("planManagerTrialEnded") : t("planManagerTrialEndsIn", {
6749
+ amount: formatNumber(notice2.endsIn.amount, locale),
6750
+ units: t(UNIT_KEY[notice2.endsIn.unit], {
6751
+ count: notice2.endsIn.amount
6752
+ })
6753
+ });
6754
+ break;
6755
+ case "canceled":
6756
+ title = t("planManagerCanceled");
6757
+ body = notice2.date === null ? null : t("planManagerAccessEnds", {
6758
+ date: notice2.date,
6759
+ plan: notice2.planName ?? t("planManagerPlanFallback")
6760
+ });
6761
+ break;
6762
+ case "customPlanBilling": {
6763
+ const plan = notice2.planName ?? t("planManagerYourPlan");
6764
+ title = notice2.awaitingActivation ? t("planManagerCustomAwaiting", { plan }) : t("planManagerCustomDue", { date: notice2.date, plan });
6765
+ body = notice2.awaitingActivation ? t("planManagerCustomAwaitingDescription", { date: notice2.date }) : t("planManagerCustomDueDescription", { date: notice2.date, plan });
6766
+ payUrl = notice2.invoiceUrl;
6767
+ break;
6768
+ }
6769
+ case "scheduledDowngrade":
6770
+ title = t("planManagerDowngradeScheduled", { plan: notice2.toPlanName });
6771
+ body = notice2.date === null ? null : t("planManagerAccessEnds", {
6772
+ date: notice2.date,
6773
+ plan: notice2.fromPlanName
6774
+ });
6775
+ break;
6776
+ }
6777
+ if (title === null && body === null) {
6778
+ return null;
6779
+ }
6780
+ return /* @__PURE__ */ jsxs9(
6781
+ "div",
6782
+ {
6783
+ className: "schematic-plan-manager__notice",
6784
+ "data-kind": notice2.kind,
6785
+ role: "status",
6786
+ children: [
6787
+ title !== null && /* @__PURE__ */ jsx10("p", { className: "schematic-plan-manager__notice-title", children: title }),
6788
+ body !== null && /* @__PURE__ */ jsx10("p", { className: "schematic-small schematic-plan-manager__notice-body", children: body }),
6789
+ payUrl !== null && /* @__PURE__ */ jsx10(
6790
+ "a",
6791
+ {
6792
+ className: "schematic-cta schematic-plan-manager__pay-now",
6793
+ href: payUrl,
6794
+ rel: "noreferrer",
6795
+ target: "_blank",
6796
+ children: t("planManagerPayNow")
6797
+ }
6798
+ )
6799
+ ]
6800
+ }
6801
+ );
6802
+ }
6803
+ function Price({ price, t }) {
6804
+ return /* @__PURE__ */ jsxs9("div", { className: "schematic-plan-manager__price", children: [
6805
+ price.kind === "usageBased" ? t("planManagerUsageBased") : price.kind === "free" ? t("planManagerFree") : price.amount,
6806
+ price.kind === "amount" && price.period !== null && /* @__PURE__ */ jsx10(PeriodSuffix, { period: price.period, t })
6807
+ ] });
6808
+ }
6809
+ function PeriodSuffix({ period, t }) {
6810
+ const short = shortPeriod(period, t);
6811
+ return short === void 0 ? null : /* @__PURE__ */ jsxs9("sub", { children: [
6812
+ "/",
6813
+ short
6814
+ ] });
6815
+ }
6816
+ function Section({
6817
+ children,
6818
+ label,
6819
+ showLabel
6820
+ }) {
6821
+ return /* @__PURE__ */ jsxs9("section", { "aria-label": label, className: "schematic-plan-manager__section", children: [
6822
+ showLabel && /* @__PURE__ */ jsx10("span", { className: "schematic-muted schematic-plan-manager__label", children: label }),
6823
+ /* @__PURE__ */ jsx10("ul", { className: "schematic-plan-manager__rows", children })
6824
+ ] });
6825
+ }
6826
+ function Truncated({
6827
+ after,
6828
+ children,
6829
+ label,
6830
+ locale,
6831
+ rows,
6832
+ showLabel,
6833
+ t
6834
+ }) {
6835
+ const [expanded, setExpanded] = useState7(false);
6836
+ const shown = expanded ? rows : rows.slice(0, VISIBLE_CREDIT_COUNT);
6837
+ return /* @__PURE__ */ jsxs9("section", { "aria-label": label, className: "schematic-plan-manager__section", children: [
6838
+ showLabel && /* @__PURE__ */ jsx10("span", { className: "schematic-muted schematic-plan-manager__label", children: label }),
6839
+ /* @__PURE__ */ jsx10("ul", { className: "schematic-plan-manager__rows", children: shown.map(children) }),
6840
+ rows.length > VISIBLE_CREDIT_COUNT && /* @__PURE__ */ jsxs9(
6841
+ "button",
6842
+ {
6843
+ "aria-expanded": expanded,
6844
+ className: "schematic-link-button schematic-plan-manager__see-all",
6845
+ type: "button",
6846
+ onClick: () => setExpanded((value) => !value),
6847
+ children: [
6848
+ /* @__PURE__ */ jsx10(
6849
+ "i",
6850
+ {
6851
+ "aria-hidden": "true",
6852
+ className: `schematic-icon schematic-icon--${expanded ? "chevron-up" : "chevron-down"} schematic-chevron`
6853
+ }
6854
+ ),
6855
+ /* @__PURE__ */ jsx10("span", { className: "schematic-link-button__label", children: expanded ? t("planManagerHideAll") : t("planManagerSeeAll", {
6856
+ total: formatNumber(rows.length, locale)
6857
+ }) })
6858
+ ]
6859
+ }
6860
+ ),
6861
+ after
6862
+ ] });
6863
+ }
6864
+ function UsageBasedItem({
6865
+ locale,
6866
+ row,
6867
+ showHardLimit,
6868
+ t
6869
+ }) {
6870
+ const details = [];
6871
+ if (row.additional) {
6872
+ details.push(`${t("planManagerAdditional")}: `);
6873
+ }
6874
+ if (row.tierBased) {
6875
+ details.push(t("planManagerTierBased"));
6876
+ }
6877
+ if (row.unitPrice !== null) {
6878
+ const short = row.unitPrice.period === null ? void 0 : shortPeriod(row.unitPrice.period, t);
6879
+ details.push(
6880
+ /* @__PURE__ */ jsxs9("span", { children: [
6881
+ row.unitPrice.cost,
6882
+ /* @__PURE__ */ jsxs9("sub", { children: [
6883
+ "/",
6884
+ row.unitPrice.packageSize !== null && `${row.unitPrice.packageSize} `,
6885
+ row.unitPrice.units,
6886
+ short !== void 0 && `/${short}`
6887
+ ] })
6888
+ ] }, "price")
6889
+ );
6890
+ }
6891
+ if (row.perUse !== null) {
6892
+ details.push(
6893
+ t("usagePerUse", { amount: row.perUse.amount, units: row.perUse.units })
6894
+ );
6895
+ }
6896
+ const costPeriod = row.cost?.period === null || row.cost === null ? void 0 : shortPeriod(row.cost.period, t);
6897
+ return /* @__PURE__ */ jsxs9(
6898
+ "li",
6899
+ {
6900
+ className: "schematic-plan-manager__row",
6901
+ "data-testid": "schematic-usage-based",
6902
+ children: [
6903
+ /* @__PURE__ */ jsx10("span", { className: "schematic-plan-manager__item", children: row.quantity === null ? row.name : `${row.quantity.amount} ${row.quantity.units}` }),
6904
+ /* @__PURE__ */ jsxs9("span", { className: "schematic-plan-manager__detail", children: [
6905
+ details.length > 0 && /* @__PURE__ */ jsx10("span", { className: "schematic-muted schematic-small", children: details }),
6906
+ row.cost !== null && /* @__PURE__ */ jsxs9("span", { children: [
6907
+ row.cost.amount,
6908
+ costPeriod !== void 0 && /* @__PURE__ */ jsxs9("sub", { children: [
6909
+ "/",
6910
+ costPeriod
6911
+ ] })
6912
+ ] }),
6913
+ row.tiers !== null && row.tiers.ranges.length > 0 && /* @__PURE__ */ jsx10(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ jsx10(
6914
+ PriceTiers,
6915
+ {
6916
+ currency: row.tiers.currency,
6917
+ locale,
6918
+ mode: row.tiers.mode,
6919
+ period: row.tiers.period,
6920
+ ranges: row.tiers.ranges,
6921
+ t,
6922
+ unit: row.tiers.unit
6923
+ }
6924
+ ) }),
6925
+ showHardLimit && row.hardLimit !== null && /* @__PURE__ */ jsx10(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
6926
+ amount: row.hardLimit.amount,
6927
+ units: row.hardLimit.units
6928
+ }) })
6929
+ ] })
6930
+ ]
6931
+ }
6932
+ );
6933
+ }
6934
+ function PlanCreditItem({ row, t }) {
6935
+ const text = row.text;
6936
+ const composition = row.composition;
6937
+ return /* @__PURE__ */ jsxs9(
6938
+ "li",
6939
+ {
6940
+ className: "schematic-plan-manager__row schematic-plan-manager__row--stacked",
6941
+ "data-testid": "schematic-plan-credit",
6942
+ children: [
6943
+ /* @__PURE__ */ jsxs9("div", { className: "schematic-plan-manager__row-main", children: [
6944
+ /* @__PURE__ */ jsx10("span", { className: "schematic-plan-manager__item", children: text.kind === "perLicense" ? /* @__PURE__ */ jsxs9(Fragment4, { children: [
6945
+ t("planManagerCreditsPerLicense", {
6946
+ amount: text.amount,
6947
+ creditName: text.creditName,
6948
+ licenseName: text.licenseName
6949
+ }),
6950
+ text.plus !== null && ` ${t("planManagerCreditsPlusPerPeriod", {
6951
+ amount: text.plus.amount,
6952
+ creditName: text.plus.creditName,
6953
+ period: periodWord(text.plus.period, t)
6954
+ })}`
6955
+ ] }) : text.period === null ? t("planManagerCredits", {
6956
+ amount: text.amount,
6957
+ creditName: text.creditName
6958
+ }) : t("planManagerCreditsPerPeriod", {
6959
+ amount: text.amount,
6960
+ creditName: text.creditName,
6961
+ period: periodWord(text.period, t)
6962
+ }) }),
6963
+ row.used !== null && /* @__PURE__ */ jsxs9("span", { className: "schematic-muted schematic-small schematic-plan-manager__used", children: [
6964
+ t("planManagerUsed", { amount: row.used }),
6965
+ row.autoTopup !== null && /* @__PURE__ */ jsx10(Tooltip, { label: t("planManagerAutoTopup"), children: t("planManagerAutoTopupTip", {
6966
+ amount: row.autoTopup.amount,
6967
+ threshold: row.autoTopup.threshold
6968
+ }) })
6969
+ ] })
6970
+ ] }),
6971
+ composition !== null && /* @__PURE__ */ jsx10("span", { className: "schematic-muted schematic-small", children: t(
6972
+ composition.fixed === null ? "planManagerLicensesTimesCredits" : "planManagerLicensesTimesCreditsPlusCompany",
6973
+ {
6974
+ creditName: composition.creditName,
6975
+ fixed: composition.fixed ?? void 0,
6976
+ licenseName: composition.licenseName,
6977
+ period: shortPeriod(composition.period, t) ?? periodWord(composition.period, t),
6978
+ perUnit: composition.perUnit,
6979
+ quantity: composition.quantity,
6980
+ total: composition.total
6981
+ }
6982
+ ) })
6983
+ ]
6984
+ }
6985
+ );
6986
+ }
6987
+ function CreditGroupItem({
6988
+ countAlways = false,
6989
+ plain = false,
6990
+ row,
6991
+ t
6992
+ }) {
6993
+ const named = !plain && row.bundleName !== null;
6994
+ const showCount = !plain && row.count > 1 && (named || countAlways);
6995
+ const amount = `${row.quantity} ${row.creditName}`;
6996
+ return /* @__PURE__ */ jsxs9(
6997
+ "li",
6998
+ {
6999
+ className: "schematic-plan-manager__row",
7000
+ "data-testid": "schematic-credit-group",
7001
+ children: [
7002
+ /* @__PURE__ */ jsxs9("span", { className: "schematic-plan-manager__item", children: [
7003
+ showCount && /* @__PURE__ */ jsxs9("span", { className: "schematic-muted", children: [
7004
+ "(",
7005
+ row.count,
7006
+ ") "
7007
+ ] }),
7008
+ named ? `${row.bundleName} (${amount})` : amount
7009
+ ] }),
7010
+ row.used !== null && /* @__PURE__ */ jsx10("span", { className: "schematic-muted schematic-small schematic-plan-manager__used", children: t("planManagerUsed", { amount: row.used }) })
7011
+ ]
7012
+ }
7013
+ );
7014
+ }
7015
+ function AutoTopupBox({
7016
+ lines,
7017
+ onEdit,
7018
+ t,
7019
+ target,
7020
+ url
7021
+ }) {
7022
+ return /* @__PURE__ */ jsxs9("div", { className: "schematic-plan-manager__auto-topup", children: [
7023
+ /* @__PURE__ */ jsxs9("div", { className: "schematic-plan-manager__auto-topup-lines", children: [
7024
+ /* @__PURE__ */ jsx10("span", { className: "schematic-plan-manager__item", children: t("planManagerAutoTopup") }),
7025
+ lines.map((line) => /* @__PURE__ */ jsx10("span", { children: line.kind === "disabled" ? t("planManagerAutoTopupDisabled", { unit: line.unit }) : t("planManagerAutoTopupAdds", {
7026
+ amount: line.amount,
7027
+ threshold: line.threshold,
7028
+ unit: line.unit
7029
+ }) }, line.creditId))
7030
+ ] }),
7031
+ /* @__PURE__ */ jsx10(
7032
+ Cta,
7033
+ {
7034
+ className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-plan-manager__edit",
7035
+ label: t("planManagerEdit"),
7036
+ onClick: onEdit,
7037
+ target,
7038
+ url
7039
+ }
7040
+ )
7041
+ ] });
7042
+ }
7043
+ function Cta({
7044
+ className,
7045
+ label,
7046
+ onClick,
7047
+ target,
7048
+ url
7049
+ }) {
7050
+ if (onClick !== void 0) {
7051
+ return /* @__PURE__ */ jsx10("button", { className, type: "button", onClick, children: label });
7052
+ }
7053
+ if (url !== void 0) {
7054
+ return /* @__PURE__ */ jsx10("a", { className, href: url, target, children: label });
7055
+ }
7056
+ return null;
7057
+ }
7058
+ function periodWord(period, t) {
7059
+ const key = PERIOD_KEY[period];
7060
+ return key === void 0 ? period : t(key);
7061
+ }
7062
+ function PlanManagerSkeleton() {
7063
+ return /* @__PURE__ */ jsxs9("div", { className: "schematic-skeleton", children: [
7064
+ /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__heading" }),
7065
+ [0, 1].map((index) => /* @__PURE__ */ jsxs9("div", { className: "schematic-skeleton__row", children: [
7066
+ /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
7067
+ /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__cell", "data-column": "price" })
7068
+ ] }, index))
7069
+ ] });
7070
+ }
7071
+ PlanManager.resources = ["company", "featureUsage", "creditBalances"];
7072
+
7073
+ // src/elements/UnsubscribeButton.tsx
7074
+ import {
7075
+ useCompany as useCompany2,
7076
+ useFeatureUsage as useFeatureUsage4,
7077
+ useUnsubscribe
7078
+ } from "@schematichq/schematic-react";
7079
+ import { useMemo as useMemo8, useState as useState8 } from "react";
7080
+ import { jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
7081
+ var TOTAL_KEY = {
7082
+ quarter: "unsubscribeQuarterlyTotal",
7083
+ year: "unsubscribeYearlyTotal"
7084
+ };
7085
+ function UnsubscribeButton({
7086
+ className,
7087
+ locale: localeProp,
7088
+ managePlanTarget,
7089
+ managePlanUrl,
7090
+ onManagePlan,
7091
+ onUnsubscribed,
7092
+ strings
7093
+ }) {
7094
+ const company = useCompany2();
7095
+ const usage = useFeatureUsage4();
7096
+ const { isMutating, unsubscribe } = useUnsubscribe();
7097
+ const locale = useResolvedLocale(localeProp);
7098
+ const t = useTranslator(strings, localeProp);
7099
+ const [open, setOpen] = useState8(false);
7100
+ const [failed, setFailed] = useState8(false);
7101
+ const view = useMemo8(
7102
+ () => company.data === void 0 || usage.data === void 0 ? void 0 : deriveUnsubscribe(company.data, usage.data, { locale }),
7103
+ [company.data, locale, usage.data]
7104
+ );
7105
+ if (view === void 0) {
7106
+ const error = company.error ?? usage.error;
7107
+ if (error === void 0) {
7108
+ return null;
7109
+ }
7110
+ return /* @__PURE__ */ jsx11(
7111
+ StatusFrame,
7112
+ {
7113
+ className: cx("schematic-card", "schematic-unsubscribe", className),
7114
+ error,
7115
+ errorMessage: httpStatus(error) === 404 ? t("unsubscribeUnavailable") : t("unsubscribeError"),
7116
+ hasData: false,
7117
+ isPending: false,
7118
+ loadingLabel: "",
7119
+ onRetry: () => {
7120
+ for (const handle of [company, usage]) {
7121
+ if (handle.error !== void 0) {
7122
+ handle.refetch();
7123
+ }
7124
+ }
7125
+ },
7126
+ retryText: t("retry"),
7127
+ children: null
7128
+ }
7129
+ );
7130
+ }
7131
+ if (!view.canUnsubscribe && !open) {
7132
+ return null;
7133
+ }
7134
+ const close = () => {
7135
+ setOpen(false);
7136
+ setFailed(false);
7137
+ };
7138
+ const confirm = async () => {
7139
+ setFailed(false);
7140
+ try {
7141
+ await unsubscribe();
7142
+ } catch {
7143
+ setFailed(true);
7144
+ return;
7145
+ }
7146
+ setOpen(false);
7147
+ onUnsubscribed?.();
7148
+ };
7149
+ const per = shortPeriod(view.period, t);
7150
+ return /* @__PURE__ */ jsxs10(
7151
+ "div",
7152
+ {
7153
+ className: cx(
7154
+ "schematic-element",
7155
+ "schematic-card",
7156
+ "schematic-unsubscribe",
7157
+ className
7158
+ ),
7159
+ children: [
7160
+ /* @__PURE__ */ jsx11(
7161
+ "button",
7162
+ {
7163
+ className: "schematic-cta schematic-unsubscribe__open",
7164
+ type: "button",
7165
+ onClick: () => {
7166
+ setFailed(false);
7167
+ setOpen(true);
7168
+ },
7169
+ children: t("unsubscribeButton")
7170
+ }
7171
+ ),
7172
+ /* @__PURE__ */ jsx11(
7173
+ Dialog,
7174
+ {
7175
+ className: "schematic-unsubscribe__dialog",
7176
+ closeLabel: t("unsubscribeClose"),
7177
+ open,
7178
+ title: t("unsubscribeTitle"),
7179
+ onClose: close,
7180
+ children: /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__columns", children: [
7181
+ /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__summary", children: [
7182
+ /* @__PURE__ */ jsx11("p", { children: t("unsubscribeAccessUntil", { date: view.accessEndsOn }) }),
7183
+ /* @__PURE__ */ jsx11(
7184
+ ManagePlan,
7185
+ {
7186
+ onClick: onManagePlan,
7187
+ t,
7188
+ target: managePlanTarget,
7189
+ url: managePlanUrl
7190
+ }
7191
+ )
7192
+ ] }),
7193
+ /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__sidebar", children: [
7194
+ view.plan !== null && /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__group", children: [
7195
+ /* @__PURE__ */ jsx11("span", { className: "schematic-muted schematic-small", children: t("unsubscribePlan") }),
7196
+ /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__line", children: [
7197
+ /* @__PURE__ */ jsx11("span", { className: "schematic-unsubscribe__name", children: view.plan.name }),
7198
+ view.plan.price !== null && /* @__PURE__ */ jsxs10("span", { children: [
7199
+ view.plan.price,
7200
+ per !== void 0 && /* @__PURE__ */ jsxs10("sub", { children: [
7201
+ "/",
7202
+ per
7203
+ ] })
7204
+ ] })
7205
+ ] })
7206
+ ] }),
7207
+ view.addOns.length > 0 && /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__group", children: [
7208
+ /* @__PURE__ */ jsx11("span", { className: "schematic-muted schematic-small", children: t("unsubscribeAddOns") }),
7209
+ view.addOns.map((addOn) => /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__line", children: [
7210
+ /* @__PURE__ */ jsx11("span", { className: "schematic-unsubscribe__name", children: addOn.name }),
7211
+ /* @__PURE__ */ jsxs10("span", { children: [
7212
+ addOn.price,
7213
+ !addOn.oneTime && per !== void 0 && /* @__PURE__ */ jsxs10("sub", { children: [
7214
+ "/",
7215
+ per
7216
+ ] })
7217
+ ] })
7218
+ ] }, addOn.id))
7219
+ ] }),
7220
+ /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__line schematic-unsubscribe__total", children: [
7221
+ /* @__PURE__ */ jsx11("span", { className: "schematic-muted", children: t(TOTAL_KEY[view.period] ?? "unsubscribeMonthlyTotal") }),
7222
+ /* @__PURE__ */ jsxs10("span", { children: [
7223
+ view.total,
7224
+ per !== void 0 && /* @__PURE__ */ jsxs10("sub", { children: [
7225
+ "/",
7226
+ per
7227
+ ] })
7228
+ ] })
7229
+ ] }),
7230
+ /* @__PURE__ */ jsx11(
7231
+ "button",
7232
+ {
7233
+ className: "schematic-cta schematic-unsubscribe__confirm",
7234
+ disabled: isMutating,
7235
+ type: "button",
7236
+ onClick: () => void confirm(),
7237
+ children: t("unsubscribeConfirm")
7238
+ }
7239
+ ),
7240
+ failed && /* @__PURE__ */ jsx11("p", { className: "schematic-error", role: "alert", children: t("unsubscribeFailed") })
7241
+ ] })
7242
+ ] })
7243
+ }
7244
+ )
7245
+ ]
7246
+ }
7247
+ );
7248
+ }
7249
+ function ManagePlan({
7250
+ onClick,
7251
+ t,
7252
+ target,
7253
+ url
7254
+ }) {
7255
+ if (onClick === void 0 && url === void 0) {
7256
+ return null;
7257
+ }
7258
+ const label = t("unsubscribeManagePlan");
7259
+ return /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__manage", children: [
7260
+ /* @__PURE__ */ jsx11("p", { children: t("unsubscribeNotReady") }),
7261
+ onClick !== void 0 ? /* @__PURE__ */ jsx11(
7262
+ "button",
7263
+ {
7264
+ className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-unsubscribe__manage-plan",
7265
+ type: "button",
7266
+ onClick,
7267
+ children: label
7268
+ }
7269
+ ) : /* @__PURE__ */ jsx11(
7270
+ "a",
7271
+ {
7272
+ className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-unsubscribe__manage-plan",
7273
+ href: url,
7274
+ target,
7275
+ children: label
7276
+ }
7277
+ )
7278
+ ] });
7279
+ }
7280
+ UnsubscribeButton.resources = ["company", "featureUsage"];
7281
+
7282
+ // src/elements/UpcomingBill.tsx
7283
+ import { useUpcomingInvoice } from "@schematichq/schematic-react";
7284
+ import { useMemo as useMemo9 } from "react";
7285
+ import { Fragment as Fragment5, jsx as jsx12, jsxs as jsxs11 } from "react/jsx-runtime";
7286
+ function UpcomingBill({
7287
+ className,
7288
+ headingLevel = 2,
7289
+ locale: localeProp,
7290
+ showAmount = true,
7291
+ showBalance = true,
7292
+ showDiscounts = true,
5817
7293
  showHeader = true,
5818
7294
  strings
5819
7295
  }) {
5820
7296
  const { data: invoice, error, isPending, refetch } = useUpcomingInvoice();
5821
7297
  const locale = useResolvedLocale(localeProp);
5822
7298
  const t = useTranslator(strings, localeProp);
5823
- const bill = useMemo7(
7299
+ const bill = useMemo9(
5824
7300
  () => invoice === void 0 || invoice === null ? null : deriveUpcomingInvoice(invoice, { locale }),
5825
7301
  [invoice, locale]
5826
7302
  );
@@ -5829,7 +7305,7 @@ function UpcomingBill({
5829
7305
  const discountRow = showDiscounts && bill !== null && bill.discounts.length > 0;
5830
7306
  const unavailable = invoice === void 0 && httpStatus(error) === 404;
5831
7307
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("upcomingBillUnavailable") : t("upcomingBillError");
5832
- return /* @__PURE__ */ jsx10(
7308
+ return /* @__PURE__ */ jsx12(
5833
7309
  StatusFrame,
5834
7310
  {
5835
7311
  className: cx("schematic-card", "schematic-upcoming-bill", className),
@@ -5840,11 +7316,11 @@ function UpcomingBill({
5840
7316
  loadingLabel: t("upcomingBillLoading"),
5841
7317
  onRetry: refetch,
5842
7318
  retryText: t("retry"),
5843
- skeleton: /* @__PURE__ */ jsx10(UpcomingBillSkeleton, { showHeader }),
5844
- children: bill === null ? invoice !== void 0 && /* @__PURE__ */ jsx10("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ jsxs9(Fragment4, { children: [
5845
- showHeader && bill.dueAt !== null && /* @__PURE__ */ jsx10("div", { className: "schematic-header", children: /* @__PURE__ */ jsx10(Heading, { className: "schematic-header__title", children: t("upcomingBillHeader", { date: bill.dueAt.text }) }) }),
5846
- showAmount && /* @__PURE__ */ jsxs9("div", { className: "schematic-upcoming-bill__amount", children: [
5847
- /* @__PURE__ */ jsx10(
7319
+ skeleton: /* @__PURE__ */ jsx12(UpcomingBillSkeleton, { showHeader }),
7320
+ children: bill === null ? invoice !== void 0 && /* @__PURE__ */ jsx12("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ jsxs11(Fragment5, { children: [
7321
+ showHeader && bill.dueAt !== null && /* @__PURE__ */ jsx12("div", { className: "schematic-header", children: /* @__PURE__ */ jsx12(Heading, { className: "schematic-header__title", children: t("upcomingBillHeader", { date: bill.dueAt.text }) }) }),
7322
+ showAmount && /* @__PURE__ */ jsxs11("div", { className: "schematic-upcoming-bill__amount", children: [
7323
+ /* @__PURE__ */ jsx12(
5848
7324
  "span",
5849
7325
  {
5850
7326
  className: "schematic-upcoming-bill__total",
@@ -5852,46 +7328,46 @@ function UpcomingBill({
5852
7328
  children: bill.amountDueText
5853
7329
  }
5854
7330
  ),
5855
- /* @__PURE__ */ jsx10("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
7331
+ /* @__PURE__ */ jsx12("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
5856
7332
  ] }),
5857
- (balanceRows || discountRow) && /* @__PURE__ */ jsxs9("div", { className: "schematic-upcoming-bill__rows", children: [
5858
- balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ jsxs9(
7333
+ (balanceRows || discountRow) && /* @__PURE__ */ jsxs11("div", { className: "schematic-upcoming-bill__rows", children: [
7334
+ balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ jsxs11(
5859
7335
  "div",
5860
7336
  {
5861
7337
  className: "schematic-row schematic-upcoming-bill__balance-applied",
5862
7338
  "data-testid": "schematic-balance-applied",
5863
7339
  children: [
5864
- /* @__PURE__ */ jsx10("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
5865
- /* @__PURE__ */ jsx10("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
7340
+ /* @__PURE__ */ jsx12("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
7341
+ /* @__PURE__ */ jsx12("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
5866
7342
  ]
5867
7343
  }
5868
7344
  ),
5869
- balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ jsxs9(
7345
+ balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ jsxs11(
5870
7346
  "div",
5871
7347
  {
5872
7348
  className: "schematic-row schematic-upcoming-bill__balance-remaining",
5873
7349
  "data-testid": "schematic-balance-remaining",
5874
7350
  children: [
5875
- /* @__PURE__ */ jsx10("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
5876
- /* @__PURE__ */ jsx10("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
7351
+ /* @__PURE__ */ jsx12("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
7352
+ /* @__PURE__ */ jsx12("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
5877
7353
  ]
5878
7354
  }
5879
7355
  ),
5880
- discountRow && /* @__PURE__ */ jsxs9(
7356
+ discountRow && /* @__PURE__ */ jsxs11(
5881
7357
  "div",
5882
7358
  {
5883
7359
  className: "schematic-row schematic-upcoming-bill__discount-row",
5884
7360
  "data-testid": "schematic-discounts",
5885
7361
  children: [
5886
- /* @__PURE__ */ jsx10("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
5887
- /* @__PURE__ */ jsx10("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ jsxs9(
7362
+ /* @__PURE__ */ jsx12("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
7363
+ /* @__PURE__ */ jsx12("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ jsxs11(
5888
7364
  "li",
5889
7365
  {
5890
7366
  className: "schematic-upcoming-bill__discount",
5891
7367
  "data-testid": "schematic-discount",
5892
7368
  children: [
5893
- discount.code !== null && /* @__PURE__ */ jsx10("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
5894
- /* @__PURE__ */ jsx10("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
7369
+ discount.code !== null && /* @__PURE__ */ jsx12("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
7370
+ /* @__PURE__ */ jsx12("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
5895
7371
  ]
5896
7372
  },
5897
7373
  `${discount.couponName}-${index}`
@@ -5905,10 +7381,10 @@ function UpcomingBill({
5905
7381
  );
5906
7382
  }
5907
7383
  function UpcomingBillSkeleton({ showHeader }) {
5908
- return /* @__PURE__ */ jsxs9("div", { className: "schematic-skeleton", children: [
5909
- showHeader && /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__heading" }),
5910
- /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
5911
- /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
7384
+ return /* @__PURE__ */ jsxs11("div", { className: "schematic-skeleton", children: [
7385
+ showHeader && /* @__PURE__ */ jsx12("div", { className: "schematic-skeleton__heading" }),
7386
+ /* @__PURE__ */ jsx12("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx12("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
7387
+ /* @__PURE__ */ jsx12("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx12("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
5912
7388
  ] });
5913
7389
  }
5914
7390
  function discountText(discount, t) {
@@ -5930,10 +7406,12 @@ export {
5930
7406
  Invoices,
5931
7407
  MeteredFeatures,
5932
7408
  PaymentMethods,
7409
+ PlanManager,
5933
7410
  SCHEMATIC_TOKENS,
5934
7411
  SchematicI18nProvider,
5935
7412
  SchematicStyles,
5936
7413
  Tooltip,
7414
+ UnsubscribeButton,
5937
7415
  UpcomingBill,
5938
7416
  billingResources,
5939
7417
  currentTier,
@@ -5942,6 +7420,8 @@ export {
5942
7420
  deriveInvoiceList,
5943
7421
  deriveMeteredFeatures,
5944
7422
  derivePaymentMethods,
7423
+ derivePlanManager,
7424
+ deriveUnsubscribe,
5945
7425
  deriveUpcomingInvoice,
5946
7426
  featureName,
5947
7427
  formatConsumptionRate,
@@ -5964,9 +7444,10 @@ export {
5964
7444
  tierRanges,
5965
7445
  unitPrice,
5966
7446
  usageLimit,
5967
- useCreditBalances2 as useCreditBalances,
7447
+ useCompany3 as useCompany,
7448
+ useCreditBalances3 as useCreditBalances,
5968
7449
  useCreditUserUsage2 as useCreditUserUsage,
5969
- useFeatureUsage3 as useFeatureUsage,
7450
+ useFeatureUsage5 as useFeatureUsage,
5970
7451
  useFeatureUserUsage2 as useFeatureUserUsage,
5971
7452
  useInvalidateBillingData,
5972
7453
  useInvoices2 as useInvoices,
@@ -5978,6 +7459,7 @@ export {
5978
7459
  useSchematicTranslate,
5979
7460
  useSetupIntent2 as useSetupIntent,
5980
7461
  useTranslator,
7462
+ useUnsubscribe2 as useUnsubscribe,
5981
7463
  useUpcomingInvoice2 as useUpcomingInvoice,
5982
7464
  viewerLocale
5983
7465
  };