@schematichq/schematic-components 2.33.0 → 2.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -459,9 +459,10 @@ import {
459
459
  BillingDataProvider,
460
460
  FEATURE_USER_USAGE_LIMIT,
461
461
  SchematicI18nProvider,
462
- useCreditBalances as useCreditBalances2,
462
+ useCompany as useCompany3,
463
+ useCreditBalances as useCreditBalances3,
463
464
  useCreditUserUsage as useCreditUserUsage2,
464
- useFeatureUsage as useFeatureUsage3,
465
+ useFeatureUsage as useFeatureUsage5,
465
466
  useFeatureUserUsage as useFeatureUserUsage2,
466
467
  useInvalidateBillingData,
467
468
  useInvoices as useInvoices2,
@@ -471,6 +472,7 @@ import {
471
472
  useSchematicStrings,
472
473
  useSchematicTranslate,
473
474
  useSetupIntent as useSetupIntent2,
475
+ useUnsubscribe as useUnsubscribe2,
474
476
  useUpcomingInvoice as useUpcomingInvoice2
475
477
  } from "@schematichq/schematic-react";
476
478
 
@@ -1781,6 +1783,416 @@ function isEnglish2(locale) {
1781
1783
  }
1782
1784
  }
1783
1785
 
1786
+ // src/elements/model/planManager.ts
1787
+ var DAY_MS = 24 * 60 * 60 * 1e3;
1788
+ var HOUR_MS = 60 * 60 * 1e3;
1789
+ var MINUTE_MS = 60 * 1e3;
1790
+ function derivePlanManager(data, options) {
1791
+ const { company, creditBalances, featureUsage } = data;
1792
+ const { locale } = options;
1793
+ const subscription = company.subscription ?? null;
1794
+ const currency = subscription?.currency ?? "usd";
1795
+ const planPeriod = subscription?.period ?? company.plan?.period ?? null;
1796
+ const usageBasedSources = featureUsage.filter(
1797
+ (row) => typeof row.priceBehavior === "string"
1798
+ );
1799
+ return {
1800
+ notice: notice(company, options),
1801
+ plan: company.plan === void 0 || company.plan === null ? null : {
1802
+ name: company.plan.name,
1803
+ description: orNull3(company.plan.description),
1804
+ price: planPrice(
1805
+ company.plan.price,
1806
+ planPeriod,
1807
+ currency,
1808
+ usageBasedSources.length > 0,
1809
+ options
1810
+ )
1811
+ },
1812
+ addOns: company.addOns.map((addOn) => {
1813
+ const period = addOn.period === "one-time" ? "one-time" : planPeriod ?? addOn.period ?? null;
1814
+ return {
1815
+ id: addOn.id,
1816
+ name: addOn.name,
1817
+ price: typeof addOn.price === "number" && period !== null ? {
1818
+ amount: formatCurrency(addOn.price, currency, locale),
1819
+ period
1820
+ } : null
1821
+ };
1822
+ }),
1823
+ usageBased: usageBasedSources.flatMap((row) => {
1824
+ const derived = usageBasedRow(row, planPeriod ?? "month", options);
1825
+ return derived === null ? [] : [derived];
1826
+ }),
1827
+ planCredits: planCredits(company, creditBalances, locale),
1828
+ autoTopup: autoTopupBox(company, creditBalances, locale),
1829
+ ...creditGroups(creditBalances, locale),
1830
+ canChangePlan: company.customPlanBilling?.activationStrategy !== "on_payment"
1831
+ };
1832
+ }
1833
+ function notice(company, options) {
1834
+ const { locale } = options;
1835
+ const subscription = company.subscription ?? null;
1836
+ const cancelAt = usableDate(subscription?.cancelAt);
1837
+ const willCancel = cancelAt !== void 0 && subscription?.cancelAtPeriodEnd === true;
1838
+ if (subscription?.status === "trialing" && !willCancel) {
1839
+ const trialEnd = usableDate(subscription.trialEnd);
1840
+ return {
1841
+ kind: "trial",
1842
+ endsIn: trialEnd === void 0 ? null : countdown(
1843
+ trialEnd.getTime() - (options.now ?? /* @__PURE__ */ new Date()).getTime()
1844
+ )
1845
+ };
1846
+ }
1847
+ if (willCancel) {
1848
+ return {
1849
+ kind: "canceled",
1850
+ planName: orNull3(company.plan?.name),
1851
+ date: formatDate(cancelAt, locale)
1852
+ };
1853
+ }
1854
+ const billing = company.customPlanBilling;
1855
+ if (billing !== void 0 && billing !== null) {
1856
+ return {
1857
+ kind: "customPlanBilling",
1858
+ awaitingActivation: billing.activationStrategy === "on_payment",
1859
+ planName: orNull3(billing.planName),
1860
+ date: formatDate(billing.dueAt, locale),
1861
+ invoiceUrl: orNull3(billing.invoiceUrl)
1862
+ };
1863
+ }
1864
+ const downgrade = company.scheduledDowngrade;
1865
+ if (downgrade !== void 0 && downgrade !== null && downgrade.toPlanName !== "") {
1866
+ const periodEnd = usableDate(subscription?.periodEnd);
1867
+ return {
1868
+ kind: "scheduledDowngrade",
1869
+ fromPlanName: downgrade.fromPlanName,
1870
+ toPlanName: downgrade.toPlanName,
1871
+ date: periodEnd === void 0 ? null : formatDate(periodEnd, locale)
1872
+ };
1873
+ }
1874
+ return null;
1875
+ }
1876
+ function countdown(ms) {
1877
+ if (ms >= DAY_MS) {
1878
+ return { amount: Math.floor(ms / DAY_MS), unit: "day" };
1879
+ }
1880
+ if (ms >= HOUR_MS) {
1881
+ return { amount: Math.floor(ms / HOUR_MS), unit: "hour" };
1882
+ }
1883
+ if (ms >= MINUTE_MS) {
1884
+ return { amount: Math.floor(ms / MINUTE_MS), unit: "minute" };
1885
+ }
1886
+ return ms > 0 ? "soon" : "ended";
1887
+ }
1888
+ function planPrice(price, period, currency, hasUsageBased, options) {
1889
+ if (typeof price !== "number") {
1890
+ return null;
1891
+ }
1892
+ const isFree = price === 0;
1893
+ if (isFree && hasUsageBased) {
1894
+ return { kind: "usageBased" };
1895
+ }
1896
+ if (isFree && options.showZeroPriceAsFree === true) {
1897
+ return { kind: "free" };
1898
+ }
1899
+ return {
1900
+ kind: "amount",
1901
+ amount: formatCurrency(price, currency, options.locale),
1902
+ period: isFree ? null : period
1903
+ };
1904
+ }
1905
+ function usageBasedRow(row, period, options) {
1906
+ const { locale } = options;
1907
+ const behavior = row.priceBehavior ?? null;
1908
+ const showCredits = options.showCredits ?? true;
1909
+ if (behavior === "credit_burndown" && !showCredits || row.featureName === "") {
1910
+ return null;
1911
+ }
1912
+ const unit = {
1913
+ name: row.featureName,
1914
+ singularName: row.featureSingularName ?? void 0,
1915
+ pluralName: row.featurePluralName ?? void 0
1916
+ };
1917
+ const isTrait = row.featureType === "trait";
1918
+ const price = row.price ?? void 0;
1919
+ const priceCurrency = price?.currency ?? "usd";
1920
+ const limit = behavior === "credit_burndown" ? null : usageLimit(row, options);
1921
+ let unitPriceText = null;
1922
+ if ((behavior === "pay_as_you_go" || behavior === "overage") && price !== void 0) {
1923
+ const packageSize = price.packageSize ?? 1;
1924
+ const ranges = behavior === "overage" ? tierRanges(price) : [];
1925
+ const lastTier = ranges[ranges.length - 1];
1926
+ const amount = lastTier === void 0 ? unitPrice(price) : lastTier.perUnitPrice ?? price.price;
1927
+ unitPriceText = {
1928
+ cost: formatCurrency(amount, priceCurrency, locale),
1929
+ packageSize: packageSize > 1 ? formatNumber(packageSize, locale) : null,
1930
+ units: featureName(unit, packageSize, locale),
1931
+ period: isTrait ? period : null
1932
+ };
1933
+ }
1934
+ let perUse = null;
1935
+ if (behavior === "credit_burndown" && typeof row.consumptionRate === "number" && row.consumptionRate !== 0 && typeof row.creditName === "string") {
1936
+ perUse = {
1937
+ amount: formatConsumptionRate(row.consumptionRate, locale),
1938
+ units: featureName(
1939
+ {
1940
+ name: row.creditName,
1941
+ singularName: row.creditSingularName,
1942
+ pluralName: row.creditPluralName
1943
+ },
1944
+ row.consumptionRate,
1945
+ locale
1946
+ )
1947
+ };
1948
+ }
1949
+ return {
1950
+ featureId: row.featureId,
1951
+ name: row.featureName,
1952
+ // The bare name, inflected, as the embed counts a limit.
1953
+ quantity: limit === null ? null : {
1954
+ amount: formatNumber(limit, locale),
1955
+ units: featureName({ name: row.featureName }, limit, locale)
1956
+ },
1957
+ additional: behavior === "overage",
1958
+ tierBased: behavior === "tier",
1959
+ unitPrice: unitPriceText,
1960
+ perUse,
1961
+ cost: behavior === "pay_in_advance" ? {
1962
+ amount: formatCurrency(row.currentCost ?? 0, priceCurrency, locale),
1963
+ period: isTrait ? period : null
1964
+ } : null,
1965
+ tiers: behavior === "tier" && isTieredPrice(price) ? {
1966
+ currency: priceCurrency,
1967
+ mode: price?.tiersMode ?? null,
1968
+ period,
1969
+ ranges: tierRanges(price),
1970
+ unit: row.featureSingularName ?? row.featureName
1971
+ } : null,
1972
+ hardLimit: behavior !== null && behavior !== "credit_burndown" && row.valueType === "numeric" && typeof row.allocation === "number" ? {
1973
+ amount: formatNumber(row.allocation, locale),
1974
+ units: featureName(unit, row.allocation, locale)
1975
+ } : null,
1976
+ source: row
1977
+ };
1978
+ }
1979
+ function planCredits(company, balances, locale) {
1980
+ const order = company.plan?.includedCreditIds ?? [];
1981
+ const rank = (creditId) => {
1982
+ const index = order.indexOf(creditId);
1983
+ return index === -1 ? order.length : index;
1984
+ };
1985
+ const subscriptionPeriod = company.subscription?.period ?? null;
1986
+ return balances.flatMap((balance) => {
1987
+ const grants = balance.grants.filter(
1988
+ (grant) => grant.grantReason === "plan"
1989
+ );
1990
+ if (grants.length === 0) {
1991
+ return [];
1992
+ }
1993
+ const unit = creditUnit(balance);
1994
+ const value = sum(grants, (grant) => grant.quantity);
1995
+ const used = sum(grants, (grant) => grant.quantityUsed);
1996
+ const composition = balance.composition ?? null;
1997
+ const autoTopup = balance.autoTopup ?? null;
1998
+ const row = {
1999
+ creditId: balance.creditId,
2000
+ text: composition === null ? {
2001
+ kind: "total",
2002
+ amount: formatCredits(value, locale),
2003
+ creditName: featureName(unit, value, locale),
2004
+ period: subscriptionPeriod
2005
+ } : {
2006
+ kind: "perLicense",
2007
+ amount: formatCredits(composition.perLicenseAmount, locale),
2008
+ creditName: featureName(
2009
+ unit,
2010
+ composition.perLicenseAmount,
2011
+ locale
2012
+ ),
2013
+ licenseName: featureName(licenseUnit(composition), 1, locale),
2014
+ plus: composition.fixedQuantity > 0 ? {
2015
+ amount: formatCredits(
2016
+ composition.fixedQuantity,
2017
+ locale
2018
+ ),
2019
+ creditName: featureName(
2020
+ unit,
2021
+ composition.fixedQuantity,
2022
+ locale
2023
+ ),
2024
+ period: composition.period
2025
+ } : null
2026
+ },
2027
+ used: spent(used, locale),
2028
+ autoTopup: autoTopup !== null && autoTopup.enabled && typeof autoTopup.thresholdCredits === "number" && typeof autoTopup.amount === "number" ? {
2029
+ amount: formatCredits(autoTopup.amount, locale),
2030
+ threshold: formatCredits(autoTopup.thresholdCredits, locale)
2031
+ } : null,
2032
+ composition: composition === null ? null : {
2033
+ quantity: formatNumber(composition.licenseQuantity, locale),
2034
+ licenseName: featureName(
2035
+ licenseUnit(composition),
2036
+ composition.licenseQuantity,
2037
+ locale
2038
+ ),
2039
+ perUnit: formatCredits(composition.perLicenseAmount, locale),
2040
+ fixed: composition.fixedQuantity > 0 ? formatCredits(composition.fixedQuantity, locale) : null,
2041
+ total: formatCredits(composition.total, locale),
2042
+ creditName: featureName(unit, composition.total, locale),
2043
+ period: composition.period
2044
+ }
2045
+ };
2046
+ return [row];
2047
+ }).map((row, index) => ({ row, index })).sort(
2048
+ (a, b) => rank(a.row.creditId) - rank(b.row.creditId) || a.index - b.index
2049
+ ).map(({ row }) => row);
2050
+ }
2051
+ function autoTopupBox(company, balances, locale) {
2052
+ const order = company.plan?.includedCreditIds ?? [];
2053
+ const selfService = order.flatMap((creditId) => {
2054
+ const balance = balances.find((b) => b.creditId === creditId);
2055
+ const autoTopup = balance?.autoTopup ?? null;
2056
+ return balance === void 0 || autoTopup === null || !autoTopup.selfService ? [] : [{ balance, autoTopup }];
2057
+ });
2058
+ if (selfService.length === 0) {
2059
+ return null;
2060
+ }
2061
+ return {
2062
+ lines: selfService.flatMap(({ balance, autoTopup }) => {
2063
+ const unit = creditUnit(balance);
2064
+ if (!autoTopup.enabled) {
2065
+ return [
2066
+ {
2067
+ kind: "disabled",
2068
+ creditId: balance.creditId,
2069
+ unit: featureName(unit, 1, locale)
2070
+ }
2071
+ ];
2072
+ }
2073
+ if (typeof autoTopup.thresholdCredits !== "number" || typeof autoTopup.amount !== "number") {
2074
+ return [];
2075
+ }
2076
+ return [
2077
+ {
2078
+ kind: "adds",
2079
+ creditId: balance.creditId,
2080
+ amount: formatCredits(autoTopup.amount, locale),
2081
+ unit: featureName(unit, autoTopup.amount, locale),
2082
+ threshold: formatCredits(autoTopup.thresholdCredits, locale)
2083
+ }
2084
+ ];
2085
+ })
2086
+ };
2087
+ }
2088
+ function creditGroups(balances, locale) {
2089
+ const groups = /* @__PURE__ */ new Map();
2090
+ for (const balance of balances) {
2091
+ for (const grant of balance.grants) {
2092
+ if (grant.grantReason === "plan") {
2093
+ continue;
2094
+ }
2095
+ const key = `${grant.grantReason}:${grant.bundleId ?? grant.id}`;
2096
+ const group = groups.get(key);
2097
+ if (group === void 0) {
2098
+ groups.set(key, { balance, grants: [grant] });
2099
+ } else {
2100
+ group.grants.push(grant);
2101
+ }
2102
+ }
2103
+ }
2104
+ const rows = Array.from(groups.entries()).map(([key, { balance, grants }]) => {
2105
+ const sorted = [...grants].sort(byRecency);
2106
+ const latest = sorted[0];
2107
+ return {
2108
+ reason: latest.grantReason,
2109
+ createdAt: latest.createdAt,
2110
+ row: {
2111
+ key,
2112
+ count: sorted.length,
2113
+ bundleName: orNull3(latest.bundleName),
2114
+ quantity: formatCredits(latest.quantity, locale),
2115
+ creditName: featureName(creditUnit(balance), latest.quantity, locale),
2116
+ used: spent(
2117
+ sum(sorted, (grant) => grant.quantityUsed),
2118
+ locale
2119
+ )
2120
+ }
2121
+ };
2122
+ }).sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
2123
+ const pick = (reason) => rows.filter((entry) => entry.reason === reason).map((entry) => entry.row);
2124
+ return {
2125
+ bundles: pick("purchased"),
2126
+ promotional: pick("free"),
2127
+ topUps: pick("billing_credit_auto_topup")
2128
+ };
2129
+ }
2130
+ function byRecency(a, b) {
2131
+ return b.createdAt.getTime() - a.createdAt.getTime();
2132
+ }
2133
+ function creditUnit(balance) {
2134
+ return {
2135
+ name: balance.creditName,
2136
+ singularName: balance.creditSingularName ?? void 0,
2137
+ pluralName: balance.creditPluralName ?? void 0
2138
+ };
2139
+ }
2140
+ function licenseUnit(composition) {
2141
+ return {
2142
+ name: composition.licenseName,
2143
+ singularName: composition.licenseSingularName,
2144
+ pluralName: composition.licensePluralName
2145
+ };
2146
+ }
2147
+ function spent(used, locale) {
2148
+ return used > 0 ? formatCredits(used, locale) : null;
2149
+ }
2150
+ function sum(items, value) {
2151
+ return items.reduce((total, item) => total + value(item), 0);
2152
+ }
2153
+ function orNull3(value) {
2154
+ return value === void 0 || value === null || value === "" ? null : value;
2155
+ }
2156
+
2157
+ // src/elements/model/unsubscribe.ts
2158
+ function deriveUnsubscribe(company, featureUsage, options) {
2159
+ const { locale } = options;
2160
+ const subscription = company.subscription ?? null;
2161
+ const currency = subscription?.currency ?? "usd";
2162
+ const cancelAt = usableDate(subscription?.cancelAt);
2163
+ const endsOn = cancelAt ?? usableDate(subscription?.nextBillAt) ?? options.now ?? /* @__PURE__ */ new Date();
2164
+ const money = (amount) => formatCurrency(amount, currency, locale);
2165
+ const addOns = company.addOns.flatMap(
2166
+ (addOn) => typeof addOn.price === "number" ? [
2167
+ {
2168
+ id: addOn.id,
2169
+ name: addOn.name,
2170
+ price: money(addOn.price),
2171
+ oneTime: addOn.period === "one-time"
2172
+ }
2173
+ ] : []
2174
+ );
2175
+ const planPrice2 = company.plan?.price;
2176
+ const total = (typeof planPrice2 === "number" ? planPrice2 : 0) + company.addOns.reduce(
2177
+ (sum2, addOn) => addOn.period !== "one-time" && typeof addOn.price === "number" ? sum2 + addOn.price : sum2,
2178
+ 0
2179
+ ) + featureUsage.reduce(
2180
+ (sum2, row) => row.priceBehavior === "pay_in_advance" ? sum2 + (row.currentCost ?? 0) : sum2,
2181
+ 0
2182
+ );
2183
+ return {
2184
+ canUnsubscribe: subscription !== null && cancelAt === void 0,
2185
+ accessEndsOn: formatDate(endsOn, locale),
2186
+ period: subscription?.period ?? company.plan?.period ?? "month",
2187
+ plan: company.plan === void 0 || company.plan === null ? null : {
2188
+ name: company.plan.name,
2189
+ price: typeof planPrice2 === "number" ? money(planPrice2) : null
2190
+ },
2191
+ addOns,
2192
+ total: money(total)
2193
+ };
2194
+ }
2195
+
1784
2196
  // src/elements/strings.ts
1785
2197
  var DEFAULT_STRINGS_LOCALE = "en";
1786
2198
  var DEFAULT_STRINGS = {
@@ -1889,6 +2301,73 @@ var DEFAULT_STRINGS = {
1889
2301
  creditUsagePerLicense: "{{quantity}} {{licenseName}} \xD7 {{perUnit}}",
1890
2302
  creditUsageCompanyGrant: "{{amount}} company grant",
1891
2303
  creditUsageRenewsOn: "Renews on the {{day}}.",
2304
+ planManagerLoading: "Loading your plan",
2305
+ planManagerError: "There was a problem retrieving your plan.",
2306
+ planManagerUnavailable: "Your plan is not available for this account.",
2307
+ planManagerTrialEndsIn: "Trial ends in {{amount}} {{units}}",
2308
+ planManagerTrialEndsSoon: "Trial ends in less than a minute",
2309
+ planManagerTrialEnded: "Your trial has ended",
2310
+ // The trial countdown's units, looked up by the bare key with `{ count }`.
2311
+ planManagerDays: "days",
2312
+ planManagerDays_one: "day",
2313
+ planManagerDays_other: "days",
2314
+ planManagerHours: "hours",
2315
+ planManagerHours_one: "hour",
2316
+ planManagerHours_other: "hours",
2317
+ planManagerMinutes: "minutes",
2318
+ planManagerMinutes_one: "minute",
2319
+ planManagerMinutes_other: "minutes",
2320
+ planManagerCanceled: "Subscription canceled",
2321
+ planManagerAccessEnds: "Access to {{plan}} will end on {{date}}.",
2322
+ planManagerPlanFallback: "plan",
2323
+ planManagerCustomAwaiting: "Pay to activate {{plan}}",
2324
+ planManagerCustomAwaitingDescription: "Pay the invoice to activate your custom plan. Due by {{date}}.",
2325
+ planManagerCustomDue: "Pay by {{date}} to keep {{plan}}",
2326
+ planManagerCustomDueDescription: "Access to {{plan}} will end on {{date}} unless the invoice is paid.",
2327
+ planManagerYourPlan: "your plan",
2328
+ planManagerPayNow: "Pay now",
2329
+ planManagerDowngradeScheduled: "Downgrade to {{plan}} scheduled",
2330
+ planManagerUsageBased: "Usage-based",
2331
+ planManagerFree: "Free",
2332
+ planManagerAddOns: "Add-ons",
2333
+ planManagerAdditional: "Additional",
2334
+ planManagerTierBased: "Tier-based",
2335
+ planManagerCreditsInPlan: "Credits in plan",
2336
+ planManagerCreditsError: "There was a problem retrieving your credits.",
2337
+ planManagerCreditsLoading: "Loading your credits",
2338
+ planManagerTopUps: "Top-ups",
2339
+ planManagerCreditBundles: "Credit bundles",
2340
+ planManagerPromotionalCredits: "Promotional credits",
2341
+ planManagerChangePlan: "Change plan",
2342
+ planManagerCredits: "{{amount}} {{creditName}}",
2343
+ planManagerCreditsPerPeriod: "{{amount}} {{creditName}} per {{period}}",
2344
+ planManagerCreditsPerLicense: "{{amount}} {{creditName}} per {{licenseName}}",
2345
+ planManagerCreditsPlusPerPeriod: "+ {{amount}} {{creditName}} per {{period}}",
2346
+ planManagerLicensesTimesCredits: "{{quantity}} {{licenseName}} \xD7 {{perUnit}} = {{total}} {{creditName}}/{{period}}",
2347
+ planManagerLicensesTimesCreditsPlusCompany: "{{quantity}} {{licenseName}} \xD7 {{perUnit}} + {{fixed}} = {{total}} {{creditName}}/{{period}}",
2348
+ planManagerUsed: "{{amount}} used",
2349
+ planManagerAutoTopup: "Auto top-up",
2350
+ planManagerAutoTopupDisabled: "Auto top-up disabled for {{unit}}",
2351
+ planManagerAutoTopupAdds: "Adds {{amount}} {{unit}} when {{threshold}} remaining in balance",
2352
+ planManagerAutoTopupTip: "When credit balance reaches {{threshold}} remaining, an auto top-up of {{amount}} credits will be processed.",
2353
+ planManagerEdit: "Edit",
2354
+ planManagerSeeAll: "See all ({{total}})",
2355
+ planManagerHideAll: "Hide all",
2356
+ unsubscribeButton: "Unsubscribe",
2357
+ unsubscribeTitle: "Cancel subscription",
2358
+ unsubscribeAccessUntil: "You will retain access to your plan until the end of the billing period, on {{date}}",
2359
+ unsubscribeNotReady: "Not ready to cancel?",
2360
+ unsubscribeManagePlan: "Manage plan",
2361
+ unsubscribePlan: "Plan",
2362
+ unsubscribeAddOns: "Add-ons",
2363
+ unsubscribeMonthlyTotal: "Monthly total:",
2364
+ unsubscribeQuarterlyTotal: "Quarterly total:",
2365
+ unsubscribeYearlyTotal: "Yearly total:",
2366
+ unsubscribeConfirm: "Cancel subscription",
2367
+ unsubscribeFailed: "Unsubscribe failed",
2368
+ unsubscribeClose: "Close",
2369
+ unsubscribeError: "There was a problem retrieving your subscription.",
2370
+ unsubscribeUnavailable: "Your subscription is not available for this account.",
1892
2371
  usageByUserHeader: "Usage by user",
1893
2372
  usageByUserTotal: "{{amount}} used by your team this period",
1894
2373
  usageByUserError: "There was a problem retrieving usage by user.",
@@ -1924,7 +2403,12 @@ var DEFAULT_STRINGS = {
1924
2403
  usageTiersGraduated: "Tiers apply progressively as quantity increases.",
1925
2404
  periodMonthShort: "mo",
1926
2405
  periodQuarterShort: "qtr",
1927
- periodYearShort: "yr"
2406
+ periodYearShort: "yr",
2407
+ periodDay: "day",
2408
+ periodWeek: "week",
2409
+ periodMonth: "month",
2410
+ periodQuarter: "quarter",
2411
+ periodYear: "year"
1928
2412
  };
1929
2413
  var MISSING_STRING = "\0schematic:missing";
1930
2414
  function interpolate(template, vars) {
@@ -3291,146 +3775,408 @@ var paymentMethodsCss = `
3291
3775
  }
3292
3776
  `;
3293
3777
 
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;
3778
+ // src/elements/styles/plan-manager.ts
3779
+ var planManagerCss = `
3780
+ .schematic-plan-manager {
3781
+ display: flex;
3782
+ flex-direction: column;
3783
+ gap: var(--schematic-space);
3316
3784
  }
3317
3785
 
3318
- .schematic-tooltip__trigger:focus-visible {
3319
- outline: 2px solid var(--schematic-accent);
3320
- outline-offset: 2px;
3786
+ /* While loading or failed there is no plan card, so the root draws one. */
3787
+ .schematic-plan-manager[data-state="pending"],
3788
+ .schematic-plan-manager[data-state="error"] {
3789
+ background: var(--schematic-background);
3790
+ border-radius: var(--schematic-radius);
3791
+ box-shadow: var(--schematic-shadow);
3792
+ padding: calc(var(--schematic-card-padding) * 0.75)
3793
+ var(--schematic-card-padding);
3321
3794
  }
3322
3795
 
3323
- .schematic-tooltip__content {
3796
+ /* As in the embed, a notice is a band across the top of the card: the
3797
+ root draws the card and the plan's own card goes flat. */
3798
+ .schematic-plan-manager:has(.schematic-plan-manager__notice) {
3324
3799
  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);
3800
+ border-radius: var(--schematic-radius);
3328
3801
  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;
3802
+ gap: 0;
3803
+ overflow: hidden;
3339
3804
  }
3340
3805
 
3341
- .schematic-tooltip:hover .schematic-tooltip__content,
3342
- .schematic-tooltip:focus-within .schematic-tooltip__content {
3343
- visibility: visible;
3806
+ .schematic-plan-manager:has(.schematic-plan-manager__notice)
3807
+ .schematic-plan-manager__card {
3808
+ border-radius: 0;
3809
+ box-shadow: none;
3344
3810
  }
3345
3811
 
3346
- .schematic-tiers {
3812
+ .schematic-plan-manager__notice {
3813
+ align-items: center;
3814
+ background: var(--schematic-inset);
3347
3815
  display: flex;
3348
3816
  flex-direction: column;
3349
3817
  gap: 0.5rem;
3818
+ padding: calc(var(--schematic-space) * 1.5);
3819
+ text-align: center;
3350
3820
  }
3351
3821
 
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 {
3822
+ .schematic-plan-manager__notice-title {
3823
+ font-family: var(--schematic-font-heading);
3824
+ font-size: 1.25rem;
3825
+ font-weight: 600;
3826
+ line-height: var(--schematic-line-height-heading);
3364
3827
  margin: 0;
3365
3828
  }
3366
3829
 
3367
- .schematic-tiers__mode {
3368
- border-top: 1px solid var(--schematic-border);
3369
- padding-top: 0.5rem;
3370
- white-space: normal;
3830
+ .schematic-plan-manager__notice-body {
3831
+ font-size: 0.8125rem;
3371
3832
  }
3372
- `;
3373
3833
 
3374
- // src/elements/styles/upcoming-bill.ts
3375
- var upcomingBillCss = `
3376
- .schematic-upcoming-bill {
3834
+ .schematic-plan-manager__card {
3377
3835
  display: flex;
3378
3836
  flex-direction: column;
3379
- gap: var(--schematic-space);
3837
+ gap: calc(var(--schematic-space) * 2);
3380
3838
  }
3381
3839
 
3382
- .schematic-upcoming-bill .schematic-header {
3383
- margin-bottom: 0;
3840
+ .schematic-plan-manager__plan {
3841
+ align-items: center;
3842
+ display: flex;
3843
+ gap: var(--schematic-space);
3844
+ justify-content: space-between;
3384
3845
  }
3385
3846
 
3386
- .schematic-upcoming-bill__amount {
3387
- align-items: flex-start;
3847
+ .schematic-plan-manager__title {
3388
3848
  display: flex;
3849
+ flex-direction: column;
3389
3850
  gap: var(--schematic-space);
3390
- justify-content: space-between;
3391
3851
  }
3392
3852
 
3393
- .schematic-upcoming-bill__total {
3853
+ .schematic-plan-manager__name {
3394
3854
  font-family: var(--schematic-font-heading);
3395
3855
  font-size: 2.3125rem;
3396
- font-variant-numeric: tabular-nums;
3397
3856
  font-weight: 800;
3398
3857
  line-height: 1;
3858
+ margin: 0;
3399
3859
  }
3400
3860
 
3401
- .schematic-upcoming-bill__estimate {
3402
- color: var(--schematic-muted);
3403
- max-width: 10rem;
3404
- text-align: end;
3861
+ .schematic-plan-manager__price {
3862
+ font-family: var(--schematic-font-heading);
3863
+ font-size: 1.25rem;
3864
+ font-weight: 600;
3865
+ white-space: nowrap;
3405
3866
  }
3406
3867
 
3407
- .schematic-upcoming-bill__rows {
3868
+ .schematic-plan-manager__section {
3408
3869
  display: flex;
3409
3870
  flex-direction: column;
3410
- gap: var(--schematic-space);
3871
+ gap: 0.5rem;
3411
3872
  }
3412
3873
 
3413
- .schematic-upcoming-bill .schematic-row__value {
3414
- font-variant-numeric: tabular-nums;
3874
+ .schematic-plan-manager__label {
3875
+ line-height: 1;
3415
3876
  }
3416
3877
 
3417
- .schematic-upcoming-bill__discounts {
3418
- align-items: flex-end;
3878
+ .schematic-plan-manager__rows {
3419
3879
  display: flex;
3420
3880
  flex-direction: column;
3421
- gap: calc(var(--schematic-space) / 2);
3881
+ gap: var(--schematic-space);
3422
3882
  list-style: none;
3423
3883
  margin: 0;
3424
3884
  padding: 0;
3425
3885
  }
3426
3886
 
3427
- .schematic-upcoming-bill__discount {
3887
+ /* Centred as in the embed; a plan credit's name and figure share a
3888
+ baseline above the line that explains them. */
3889
+ .schematic-plan-manager__row,
3890
+ .schematic-plan-manager__row-main {
3428
3891
  align-items: center;
3429
- display: inline-flex;
3430
- gap: calc(var(--schematic-space) / 2);
3431
- }
3432
-
3433
- .schematic-upcoming-bill__empty {
3892
+ display: flex;
3893
+ flex-wrap: wrap;
3894
+ gap: var(--schematic-space);
3895
+ justify-content: space-between;
3896
+ }
3897
+
3898
+ .schematic-plan-manager__row-main {
3899
+ align-items: baseline;
3900
+ gap: 0.5rem;
3901
+ }
3902
+
3903
+ .schematic-plan-manager__row--stacked {
3904
+ align-items: stretch;
3905
+ flex-direction: column;
3906
+ gap: 0.25rem;
3907
+ }
3908
+
3909
+ .schematic-plan-manager__item {
3910
+ font-family: var(--schematic-font-heading);
3911
+ font-size: 1.125rem;
3912
+ font-weight: 800;
3913
+ }
3914
+
3915
+ .schematic-plan-manager__detail,
3916
+ .schematic-plan-manager__used {
3917
+ align-items: center;
3918
+ display: inline-flex;
3919
+ gap: 0.25rem;
3920
+ }
3921
+
3922
+ .schematic-plan-manager__see-all {
3923
+ align-items: center;
3924
+ align-self: flex-start;
3925
+ display: inline-flex;
3926
+ gap: 0.25rem;
3927
+ margin-top: 0.5rem;
3928
+ }
3929
+
3930
+ .schematic-plan-manager__see-all .schematic-chevron {
3931
+ margin-inline-start: -0.333rem;
3932
+ }
3933
+
3934
+ .schematic-plan-manager__auto-topup {
3935
+ align-items: center;
3936
+ background: var(--schematic-inset);
3937
+ border-radius: calc(var(--schematic-radius) * 0.8);
3938
+ display: flex;
3939
+ gap: 0.5rem;
3940
+ justify-content: space-between;
3941
+ padding: calc(var(--schematic-space) * 1.5);
3942
+ }
3943
+
3944
+ .schematic-plan-manager__auto-topup-lines {
3945
+ display: flex;
3946
+ flex-direction: column;
3947
+ gap: 0.5rem;
3948
+ line-height: 1.25;
3949
+ }
3950
+
3951
+ .schematic-plan-manager__change-plan {
3952
+ width: 100%;
3953
+ }
3954
+
3955
+ .schematic-plan-manager .schematic-skeleton__cell[data-column="name"] {
3956
+ width: 10rem;
3957
+ }
3958
+
3959
+ .schematic-plan-manager .schematic-skeleton__cell[data-column="price"] {
3960
+ width: 6rem;
3961
+ }
3962
+ `;
3963
+
3964
+ // src/elements/styles/index.tsx
3965
+ init_tokens();
3966
+
3967
+ // src/elements/styles/tooltip.ts
3968
+ var tooltipCss = `
3969
+ .schematic-tooltip {
3970
+ display: inline-block;
3971
+ margin-inline-start: 0.25rem;
3972
+ position: relative;
3973
+ vertical-align: middle;
3974
+ }
3975
+
3976
+ .schematic-tooltip__trigger {
3977
+ background: none;
3978
+ border: 0;
3979
+ color: var(--schematic-muted);
3980
+ cursor: help;
3981
+ /* A button keeps the browser's control font; the glyph is the embed's
3982
+ 24px. */
3983
+ font-size: 1.5rem;
3984
+ line-height: 0;
3985
+ padding: 0;
3986
+ }
3987
+
3988
+ .schematic-tooltip__trigger:focus-visible {
3989
+ outline: 2px solid var(--schematic-accent);
3990
+ outline-offset: 2px;
3991
+ }
3992
+
3993
+ .schematic-tooltip__content {
3994
+ background: var(--schematic-background);
3995
+ border: 1px solid var(--schematic-border);
3996
+ border-radius: calc(var(--schematic-radius) / 2);
3997
+ bottom: calc(100% + 0.5rem);
3998
+ box-shadow: var(--schematic-shadow);
3999
+ color: var(--schematic-text);
4000
+ font-size: 0.875rem;
4001
+ inset-inline-end: 0;
4002
+ padding: 0.5rem 0.75rem;
4003
+ pointer-events: none;
4004
+ position: absolute;
4005
+ text-align: start;
4006
+ visibility: hidden;
4007
+ white-space: nowrap;
4008
+ z-index: 1;
4009
+ }
4010
+
4011
+ .schematic-tooltip:hover .schematic-tooltip__content,
4012
+ .schematic-tooltip:focus-within .schematic-tooltip__content {
4013
+ visibility: visible;
4014
+ }
4015
+
4016
+ .schematic-tiers {
4017
+ display: flex;
4018
+ flex-direction: column;
4019
+ gap: 0.5rem;
4020
+ }
4021
+
4022
+ .schematic-tiers__list {
4023
+ margin: 0;
4024
+ }
4025
+
4026
+ .schematic-tiers__tier {
4027
+ display: flex;
4028
+ gap: var(--schematic-space);
4029
+ justify-content: space-between;
4030
+ padding: 0.25rem 0;
4031
+ }
4032
+
4033
+ .schematic-tiers__price {
4034
+ margin: 0;
4035
+ }
4036
+
4037
+ .schematic-tiers__mode {
4038
+ border-top: 1px solid var(--schematic-border);
4039
+ padding-top: 0.5rem;
4040
+ white-space: normal;
4041
+ }
4042
+ `;
4043
+
4044
+ // src/elements/styles/unsubscribe.ts
4045
+ var unsubscribeCss = `
4046
+ .schematic-unsubscribe {
4047
+ display: flex;
4048
+ justify-content: center;
4049
+ }
4050
+
4051
+ .schematic-unsubscribe__open {
4052
+ width: 100%;
4053
+ }
4054
+
4055
+ .schematic-unsubscribe__columns {
4056
+ display: flex;
4057
+ flex-wrap: wrap;
4058
+ gap: calc(var(--schematic-space) * 2);
4059
+ }
4060
+
4061
+ .schematic-unsubscribe__summary {
4062
+ display: flex;
4063
+ flex: 1 1 18rem;
4064
+ flex-direction: column;
4065
+ gap: calc(var(--schematic-space) * 2);
4066
+ }
4067
+
4068
+ .schematic-unsubscribe__manage {
4069
+ display: flex;
4070
+ flex-direction: column;
4071
+ gap: 0.5rem;
4072
+ }
4073
+
4074
+ .schematic-unsubscribe__manage-plan {
4075
+ align-self: flex-start;
4076
+ color: var(--schematic-accent);
4077
+ }
4078
+
4079
+ .schematic-unsubscribe__sidebar {
4080
+ background: var(--schematic-inset);
4081
+ border-radius: calc(var(--schematic-radius) * 0.8);
4082
+ display: flex;
4083
+ flex: 1 1 16rem;
4084
+ flex-direction: column;
4085
+ gap: calc(var(--schematic-space) * 1.5);
4086
+ padding: calc(var(--schematic-space) * 1.5);
4087
+ }
4088
+
4089
+ .schematic-unsubscribe__group {
4090
+ display: flex;
4091
+ flex-direction: column;
4092
+ gap: 0.125rem;
4093
+ }
4094
+
4095
+ .schematic-unsubscribe__line {
4096
+ align-items: baseline;
4097
+ display: flex;
4098
+ gap: var(--schematic-space);
4099
+ justify-content: space-between;
4100
+ white-space: nowrap;
4101
+ }
4102
+
4103
+ .schematic-unsubscribe__name {
4104
+ font-family: var(--schematic-font-heading);
4105
+ font-size: 1.125rem;
4106
+ font-weight: 800;
4107
+ white-space: normal;
4108
+ }
4109
+
4110
+ .schematic-unsubscribe__total {
4111
+ border-top: 1px solid var(--schematic-card-divider);
4112
+ padding-top: calc(var(--schematic-space) * 1.5);
4113
+ }
4114
+
4115
+ .schematic-unsubscribe__confirm {
4116
+ width: 100%;
4117
+ }
4118
+ `;
4119
+
4120
+ // src/elements/styles/upcoming-bill.ts
4121
+ var upcomingBillCss = `
4122
+ .schematic-upcoming-bill {
4123
+ display: flex;
4124
+ flex-direction: column;
4125
+ gap: var(--schematic-space);
4126
+ }
4127
+
4128
+ .schematic-upcoming-bill .schematic-header {
4129
+ margin-bottom: 0;
4130
+ }
4131
+
4132
+ .schematic-upcoming-bill__amount {
4133
+ align-items: flex-start;
4134
+ display: flex;
4135
+ gap: var(--schematic-space);
4136
+ justify-content: space-between;
4137
+ }
4138
+
4139
+ .schematic-upcoming-bill__total {
4140
+ font-family: var(--schematic-font-heading);
4141
+ font-size: 2.3125rem;
4142
+ font-variant-numeric: tabular-nums;
4143
+ font-weight: 800;
4144
+ line-height: 1;
4145
+ }
4146
+
4147
+ .schematic-upcoming-bill__estimate {
4148
+ color: var(--schematic-muted);
4149
+ max-width: 10rem;
4150
+ text-align: end;
4151
+ }
4152
+
4153
+ .schematic-upcoming-bill__rows {
4154
+ display: flex;
4155
+ flex-direction: column;
4156
+ gap: var(--schematic-space);
4157
+ }
4158
+
4159
+ .schematic-upcoming-bill .schematic-row__value {
4160
+ font-variant-numeric: tabular-nums;
4161
+ }
4162
+
4163
+ .schematic-upcoming-bill__discounts {
4164
+ align-items: flex-end;
4165
+ display: flex;
4166
+ flex-direction: column;
4167
+ gap: calc(var(--schematic-space) / 2);
4168
+ list-style: none;
4169
+ margin: 0;
4170
+ padding: 0;
4171
+ }
4172
+
4173
+ .schematic-upcoming-bill__discount {
4174
+ align-items: center;
4175
+ display: inline-flex;
4176
+ gap: calc(var(--schematic-space) / 2);
4177
+ }
4178
+
4179
+ .schematic-upcoming-bill__empty {
3434
4180
  padding: calc(var(--schematic-space) / 2) 0;
3435
4181
  }
3436
4182
 
@@ -3996,6 +4742,8 @@ ${tooltipCss}
3996
4742
  ${includedFeaturesCss}
3997
4743
  ${meteredFeaturesCss}
3998
4744
  ${creditUsageCss}
4745
+ ${planManagerCss}
4746
+ ${unsubscribeCss}
3999
4747
  `;
4000
4748
  var schematicStylesCss = withTokenDefaults(rulesCss) + iconsCss;
4001
4749
  var SchematicStyles = () => /* @__PURE__ */ jsx("style", { "data-schematic-styles": "", children: schematicStylesCss });
@@ -5803,10 +6551,767 @@ function FormSkeleton({ label }) {
5803
6551
  }
5804
6552
  PaymentMethods.resources = ["paymentMethods"];
5805
6553
 
5806
- // src/elements/UpcomingBill.tsx
5807
- import { useUpcomingInvoice } from "@schematichq/schematic-react";
5808
- import { useMemo as useMemo7 } from "react";
6554
+ // src/elements/PlanManager.tsx
6555
+ import {
6556
+ useCompany,
6557
+ useCreditBalances as useCreditBalances2,
6558
+ useFeatureUsage as useFeatureUsage3
6559
+ } from "@schematichq/schematic-react";
6560
+ import { useMemo as useMemo7, useState as useState7 } from "react";
5809
6561
  import { Fragment as Fragment4, jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
6562
+ var VISIBLE_CREDIT_COUNT = 3;
6563
+ var UNIT_KEY = {
6564
+ day: "planManagerDays",
6565
+ hour: "planManagerHours",
6566
+ minute: "planManagerMinutes"
6567
+ };
6568
+ var PERIOD_KEY = {
6569
+ day: "periodDay",
6570
+ month: "periodMonth",
6571
+ quarter: "periodQuarter",
6572
+ week: "periodWeek",
6573
+ year: "periodYear"
6574
+ };
6575
+ function PlanManager({
6576
+ changePlanTarget,
6577
+ changePlanUrl,
6578
+ className,
6579
+ editAutoTopupTarget,
6580
+ editAutoTopupUrl,
6581
+ headingLevel = 2,
6582
+ locale: localeProp,
6583
+ onChangePlan,
6584
+ onEditAutoTopup,
6585
+ showAddOns = true,
6586
+ showCredits = true,
6587
+ showDescription = true,
6588
+ showHardLimit = false,
6589
+ showHeader = true,
6590
+ showLabels = true,
6591
+ showNotice = true,
6592
+ showPrice = true,
6593
+ showUsageBased = true,
6594
+ showWarningThresholdAsLimit = false,
6595
+ showZeroPriceAsFree = false,
6596
+ strings
6597
+ }) {
6598
+ const company = useCompany();
6599
+ const usage = useFeatureUsage3();
6600
+ const credits = useCreditBalances2();
6601
+ const locale = useResolvedLocale(localeProp);
6602
+ const t = useTranslator(strings, localeProp);
6603
+ const creditsFailed = credits.data === void 0 && credits.error !== void 0;
6604
+ const [creditsHaveFailed, setCreditsHaveFailed] = useState7(false);
6605
+ if (creditsFailed && !creditsHaveFailed) {
6606
+ setCreditsHaveFailed(true);
6607
+ } else if (!creditsFailed && creditsHaveFailed && (credits.data !== void 0 || company.data === void 0 || usage.data === void 0)) {
6608
+ setCreditsHaveFailed(false);
6609
+ }
6610
+ const creditsSettled = !showCredits || credits.data !== void 0 || creditsHaveFailed;
6611
+ const view = useMemo7(
6612
+ () => company.data === void 0 || usage.data === void 0 || !creditsSettled ? void 0 : derivePlanManager(
6613
+ {
6614
+ company: company.data,
6615
+ creditBalances: credits.data ?? [],
6616
+ featureUsage: usage.data
6617
+ },
6618
+ {
6619
+ locale,
6620
+ showCredits,
6621
+ showWarningThresholdAsLimit,
6622
+ showZeroPriceAsFree
6623
+ }
6624
+ ),
6625
+ [
6626
+ company.data,
6627
+ credits.data,
6628
+ creditsSettled,
6629
+ locale,
6630
+ showCredits,
6631
+ showWarningThresholdAsLimit,
6632
+ showZeroPriceAsFree,
6633
+ usage.data
6634
+ ]
6635
+ );
6636
+ const creditsRefetchError = showCredits && credits.data !== void 0 ? credits.error : void 0;
6637
+ const cardError = company.error ?? usage.error;
6638
+ const error = cardError ?? creditsRefetchError;
6639
+ const unavailable = view === void 0 && httpStatus(error) === 404;
6640
+ const errorMessage = error === void 0 ? void 0 : unavailable ? t("planManagerUnavailable") : cardError === void 0 ? t("planManagerCreditsError") : t("planManagerError");
6641
+ const retry = () => {
6642
+ for (const handle of showCredits ? [company, usage, credits] : [company, usage]) {
6643
+ if (handle.error !== void 0) {
6644
+ handle.refetch();
6645
+ }
6646
+ }
6647
+ };
6648
+ const Heading = `h${headingLevel}`;
6649
+ return /* @__PURE__ */ jsx10(
6650
+ StatusFrame,
6651
+ {
6652
+ className: cx("schematic-plan-manager", className),
6653
+ error,
6654
+ errorMessage,
6655
+ hasData: view !== void 0,
6656
+ isPending: company.isPending || usage.isPending || credits.isPending,
6657
+ loadingLabel: t("planManagerLoading"),
6658
+ onRetry: retry,
6659
+ retryText: t("retry"),
6660
+ skeleton: /* @__PURE__ */ jsx10(PlanManagerSkeleton, {}),
6661
+ children: view !== void 0 && /* @__PURE__ */ jsxs9(Fragment4, { children: [
6662
+ showNotice && view.notice !== null && /* @__PURE__ */ jsx10(Notice, { locale, notice: view.notice, t }),
6663
+ /* @__PURE__ */ jsxs9("div", { className: "schematic-card schematic-plan-manager__card", children: [
6664
+ showHeader && view.plan !== null && /* @__PURE__ */ jsxs9("div", { className: "schematic-plan-manager__plan", children: [
6665
+ /* @__PURE__ */ jsxs9("div", { className: "schematic-plan-manager__title", children: [
6666
+ /* @__PURE__ */ jsx10(Heading, { className: "schematic-plan-manager__name", children: view.plan.name }),
6667
+ showDescription && view.plan.description !== null && /* @__PURE__ */ jsx10("p", { className: "schematic-plan-manager__description", children: view.plan.description })
6668
+ ] }),
6669
+ showPrice && view.plan.price !== null && /* @__PURE__ */ jsx10(Price, { price: view.plan.price, t })
6670
+ ] }),
6671
+ 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: [
6672
+ /* @__PURE__ */ jsx10("span", { className: "schematic-plan-manager__item", children: addOn.name }),
6673
+ addOn.price !== null && /* @__PURE__ */ jsxs9("span", { className: "schematic-plan-manager__price-value", children: [
6674
+ addOn.price.amount,
6675
+ /* @__PURE__ */ jsx10(PeriodSuffix, { period: addOn.price.period, t })
6676
+ ] })
6677
+ ] }, addOn.id)) }),
6678
+ showUsageBased && view.usageBased.length > 0 && /* @__PURE__ */ jsx10(
6679
+ Section,
6680
+ {
6681
+ label: t("planManagerUsageBased"),
6682
+ showLabel: showLabels,
6683
+ children: view.usageBased.map((row) => /* @__PURE__ */ jsx10(
6684
+ UsageBasedItem,
6685
+ {
6686
+ locale,
6687
+ row,
6688
+ showHardLimit,
6689
+ t
6690
+ },
6691
+ row.featureId
6692
+ ))
6693
+ }
6694
+ ),
6695
+ showCredits && credits.data === void 0 && creditsHaveFailed && (credits.error !== void 0 || credits.isPending) && /* @__PURE__ */ jsx10(
6696
+ StatusFrame,
6697
+ {
6698
+ className: "schematic-plan-manager__section",
6699
+ error: credits.error,
6700
+ errorMessage: t("planManagerCreditsError"),
6701
+ hasData: false,
6702
+ isPending: credits.isPending,
6703
+ loadingLabel: t("planManagerCreditsLoading"),
6704
+ onRetry: credits.refetch,
6705
+ retryText: t("retry"),
6706
+ children: null
6707
+ }
6708
+ ),
6709
+ showCredits && view.planCredits.length > 0 && /* @__PURE__ */ jsx10(
6710
+ Truncated,
6711
+ {
6712
+ locale,
6713
+ after: view.autoTopup !== null && /* @__PURE__ */ jsx10(
6714
+ AutoTopupBox,
6715
+ {
6716
+ lines: view.autoTopup.lines,
6717
+ onEdit: onEditAutoTopup,
6718
+ t,
6719
+ target: editAutoTopupTarget,
6720
+ url: editAutoTopupUrl
6721
+ }
6722
+ ),
6723
+ label: t("planManagerCreditsInPlan"),
6724
+ rows: view.planCredits,
6725
+ showLabel: showLabels,
6726
+ t,
6727
+ children: (row) => /* @__PURE__ */ jsx10(PlanCreditItem, { row, t }, row.creditId)
6728
+ }
6729
+ ),
6730
+ showCredits && view.topUps.length > 0 && /* @__PURE__ */ jsx10(
6731
+ Truncated,
6732
+ {
6733
+ locale,
6734
+ label: t("planManagerTopUps"),
6735
+ rows: view.topUps,
6736
+ showLabel: showLabels,
6737
+ t,
6738
+ children: (row) => /* @__PURE__ */ jsx10(CreditGroupItem, { countAlways: true, row, t }, row.key)
6739
+ }
6740
+ ),
6741
+ showCredits && view.bundles.length > 0 && /* @__PURE__ */ jsx10(
6742
+ Truncated,
6743
+ {
6744
+ locale,
6745
+ label: t("planManagerCreditBundles"),
6746
+ rows: view.bundles,
6747
+ showLabel: showLabels,
6748
+ t,
6749
+ children: (row) => /* @__PURE__ */ jsx10(CreditGroupItem, { row, t }, row.key)
6750
+ }
6751
+ ),
6752
+ showCredits && view.promotional.length > 0 && /* @__PURE__ */ jsx10(
6753
+ Truncated,
6754
+ {
6755
+ locale,
6756
+ label: t("planManagerPromotionalCredits"),
6757
+ rows: view.promotional,
6758
+ showLabel: showLabels,
6759
+ t,
6760
+ children: (row) => /* @__PURE__ */ jsx10(CreditGroupItem, { plain: true, row, t }, row.key)
6761
+ }
6762
+ ),
6763
+ view.canChangePlan && /* @__PURE__ */ jsx10(
6764
+ Cta,
6765
+ {
6766
+ className: "schematic-cta schematic-plan-manager__change-plan",
6767
+ label: t("planManagerChangePlan"),
6768
+ onClick: onChangePlan,
6769
+ target: changePlanTarget,
6770
+ url: changePlanUrl
6771
+ }
6772
+ )
6773
+ ] })
6774
+ ] })
6775
+ }
6776
+ );
6777
+ }
6778
+ function Notice({
6779
+ locale,
6780
+ notice: notice2,
6781
+ t
6782
+ }) {
6783
+ let title = null;
6784
+ let body = null;
6785
+ let payUrl = null;
6786
+ switch (notice2.kind) {
6787
+ case "trial":
6788
+ title = notice2.endsIn === null ? null : notice2.endsIn === "soon" ? t("planManagerTrialEndsSoon") : notice2.endsIn === "ended" ? t("planManagerTrialEnded") : t("planManagerTrialEndsIn", {
6789
+ amount: formatNumber(notice2.endsIn.amount, locale),
6790
+ units: t(UNIT_KEY[notice2.endsIn.unit], {
6791
+ count: notice2.endsIn.amount
6792
+ })
6793
+ });
6794
+ break;
6795
+ case "canceled":
6796
+ title = t("planManagerCanceled");
6797
+ body = notice2.date === null ? null : t("planManagerAccessEnds", {
6798
+ date: notice2.date,
6799
+ plan: notice2.planName ?? t("planManagerPlanFallback")
6800
+ });
6801
+ break;
6802
+ case "customPlanBilling": {
6803
+ const plan = notice2.planName ?? t("planManagerYourPlan");
6804
+ title = notice2.awaitingActivation ? t("planManagerCustomAwaiting", { plan }) : t("planManagerCustomDue", { date: notice2.date, plan });
6805
+ body = notice2.awaitingActivation ? t("planManagerCustomAwaitingDescription", { date: notice2.date }) : t("planManagerCustomDueDescription", { date: notice2.date, plan });
6806
+ payUrl = notice2.invoiceUrl;
6807
+ break;
6808
+ }
6809
+ case "scheduledDowngrade":
6810
+ title = t("planManagerDowngradeScheduled", { plan: notice2.toPlanName });
6811
+ body = notice2.date === null ? null : t("planManagerAccessEnds", {
6812
+ date: notice2.date,
6813
+ plan: notice2.fromPlanName
6814
+ });
6815
+ break;
6816
+ }
6817
+ if (title === null && body === null) {
6818
+ return null;
6819
+ }
6820
+ return /* @__PURE__ */ jsxs9(
6821
+ "div",
6822
+ {
6823
+ className: "schematic-plan-manager__notice",
6824
+ "data-kind": notice2.kind,
6825
+ role: "status",
6826
+ children: [
6827
+ title !== null && /* @__PURE__ */ jsx10("p", { className: "schematic-plan-manager__notice-title", children: title }),
6828
+ body !== null && /* @__PURE__ */ jsx10("p", { className: "schematic-small schematic-plan-manager__notice-body", children: body }),
6829
+ payUrl !== null && /* @__PURE__ */ jsx10(
6830
+ "a",
6831
+ {
6832
+ className: "schematic-cta schematic-plan-manager__pay-now",
6833
+ href: payUrl,
6834
+ rel: "noreferrer",
6835
+ target: "_blank",
6836
+ children: t("planManagerPayNow")
6837
+ }
6838
+ )
6839
+ ]
6840
+ }
6841
+ );
6842
+ }
6843
+ function Price({ price, t }) {
6844
+ return /* @__PURE__ */ jsxs9("div", { className: "schematic-plan-manager__price", children: [
6845
+ price.kind === "usageBased" ? t("planManagerUsageBased") : price.kind === "free" ? t("planManagerFree") : price.amount,
6846
+ price.kind === "amount" && price.period !== null && /* @__PURE__ */ jsx10(PeriodSuffix, { period: price.period, t })
6847
+ ] });
6848
+ }
6849
+ function PeriodSuffix({ period, t }) {
6850
+ const short = shortPeriod(period, t);
6851
+ return short === void 0 ? null : /* @__PURE__ */ jsxs9("sub", { children: [
6852
+ "/",
6853
+ short
6854
+ ] });
6855
+ }
6856
+ function Section({
6857
+ children,
6858
+ label,
6859
+ showLabel
6860
+ }) {
6861
+ return /* @__PURE__ */ jsxs9("section", { "aria-label": label, className: "schematic-plan-manager__section", children: [
6862
+ showLabel && /* @__PURE__ */ jsx10("span", { className: "schematic-muted schematic-plan-manager__label", children: label }),
6863
+ /* @__PURE__ */ jsx10("ul", { className: "schematic-plan-manager__rows", children })
6864
+ ] });
6865
+ }
6866
+ function Truncated({
6867
+ after,
6868
+ children,
6869
+ label,
6870
+ locale,
6871
+ rows,
6872
+ showLabel,
6873
+ t
6874
+ }) {
6875
+ const [expanded, setExpanded] = useState7(false);
6876
+ const shown = expanded ? rows : rows.slice(0, VISIBLE_CREDIT_COUNT);
6877
+ return /* @__PURE__ */ jsxs9("section", { "aria-label": label, className: "schematic-plan-manager__section", children: [
6878
+ showLabel && /* @__PURE__ */ jsx10("span", { className: "schematic-muted schematic-plan-manager__label", children: label }),
6879
+ /* @__PURE__ */ jsx10("ul", { className: "schematic-plan-manager__rows", children: shown.map(children) }),
6880
+ rows.length > VISIBLE_CREDIT_COUNT && /* @__PURE__ */ jsxs9(
6881
+ "button",
6882
+ {
6883
+ "aria-expanded": expanded,
6884
+ className: "schematic-link-button schematic-plan-manager__see-all",
6885
+ type: "button",
6886
+ onClick: () => setExpanded((value) => !value),
6887
+ children: [
6888
+ /* @__PURE__ */ jsx10(
6889
+ "i",
6890
+ {
6891
+ "aria-hidden": "true",
6892
+ className: `schematic-icon schematic-icon--${expanded ? "chevron-up" : "chevron-down"} schematic-chevron`
6893
+ }
6894
+ ),
6895
+ /* @__PURE__ */ jsx10("span", { className: "schematic-link-button__label", children: expanded ? t("planManagerHideAll") : t("planManagerSeeAll", {
6896
+ total: formatNumber(rows.length, locale)
6897
+ }) })
6898
+ ]
6899
+ }
6900
+ ),
6901
+ after
6902
+ ] });
6903
+ }
6904
+ function UsageBasedItem({
6905
+ locale,
6906
+ row,
6907
+ showHardLimit,
6908
+ t
6909
+ }) {
6910
+ const details = [];
6911
+ if (row.additional) {
6912
+ details.push(`${t("planManagerAdditional")}: `);
6913
+ }
6914
+ if (row.tierBased) {
6915
+ details.push(t("planManagerTierBased"));
6916
+ }
6917
+ if (row.unitPrice !== null) {
6918
+ const short = row.unitPrice.period === null ? void 0 : shortPeriod(row.unitPrice.period, t);
6919
+ details.push(
6920
+ /* @__PURE__ */ jsxs9("span", { children: [
6921
+ row.unitPrice.cost,
6922
+ /* @__PURE__ */ jsxs9("sub", { children: [
6923
+ "/",
6924
+ row.unitPrice.packageSize !== null && `${row.unitPrice.packageSize} `,
6925
+ row.unitPrice.units,
6926
+ short !== void 0 && `/${short}`
6927
+ ] })
6928
+ ] }, "price")
6929
+ );
6930
+ }
6931
+ if (row.perUse !== null) {
6932
+ details.push(
6933
+ t("usagePerUse", { amount: row.perUse.amount, units: row.perUse.units })
6934
+ );
6935
+ }
6936
+ const costPeriod = row.cost?.period === null || row.cost === null ? void 0 : shortPeriod(row.cost.period, t);
6937
+ return /* @__PURE__ */ jsxs9(
6938
+ "li",
6939
+ {
6940
+ className: "schematic-plan-manager__row",
6941
+ "data-testid": "schematic-usage-based",
6942
+ children: [
6943
+ /* @__PURE__ */ jsx10("span", { className: "schematic-plan-manager__item", children: row.quantity === null ? row.name : `${row.quantity.amount} ${row.quantity.units}` }),
6944
+ /* @__PURE__ */ jsxs9("span", { className: "schematic-plan-manager__detail", children: [
6945
+ details.length > 0 && /* @__PURE__ */ jsx10("span", { className: "schematic-muted schematic-small", children: details }),
6946
+ row.cost !== null && /* @__PURE__ */ jsxs9("span", { children: [
6947
+ row.cost.amount,
6948
+ costPeriod !== void 0 && /* @__PURE__ */ jsxs9("sub", { children: [
6949
+ "/",
6950
+ costPeriod
6951
+ ] })
6952
+ ] }),
6953
+ row.tiers !== null && row.tiers.ranges.length > 0 && /* @__PURE__ */ jsx10(Tooltip, { label: t("usageTieredPricingLabel"), children: /* @__PURE__ */ jsx10(
6954
+ PriceTiers,
6955
+ {
6956
+ currency: row.tiers.currency,
6957
+ locale,
6958
+ mode: row.tiers.mode,
6959
+ period: row.tiers.period,
6960
+ ranges: row.tiers.ranges,
6961
+ t,
6962
+ unit: row.tiers.unit
6963
+ }
6964
+ ) }),
6965
+ showHardLimit && row.hardLimit !== null && /* @__PURE__ */ jsx10(Tooltip, { label: t("usageHardLimitLabel"), children: t("usageHardLimit", {
6966
+ amount: row.hardLimit.amount,
6967
+ units: row.hardLimit.units
6968
+ }) })
6969
+ ] })
6970
+ ]
6971
+ }
6972
+ );
6973
+ }
6974
+ function PlanCreditItem({ row, t }) {
6975
+ const text = row.text;
6976
+ const composition = row.composition;
6977
+ return /* @__PURE__ */ jsxs9(
6978
+ "li",
6979
+ {
6980
+ className: "schematic-plan-manager__row schematic-plan-manager__row--stacked",
6981
+ "data-testid": "schematic-plan-credit",
6982
+ children: [
6983
+ /* @__PURE__ */ jsxs9("div", { className: "schematic-plan-manager__row-main", children: [
6984
+ /* @__PURE__ */ jsx10("span", { className: "schematic-plan-manager__item", children: text.kind === "perLicense" ? /* @__PURE__ */ jsxs9(Fragment4, { children: [
6985
+ t("planManagerCreditsPerLicense", {
6986
+ amount: text.amount,
6987
+ creditName: text.creditName,
6988
+ licenseName: text.licenseName
6989
+ }),
6990
+ text.plus !== null && ` ${t("planManagerCreditsPlusPerPeriod", {
6991
+ amount: text.plus.amount,
6992
+ creditName: text.plus.creditName,
6993
+ period: periodWord(text.plus.period, t)
6994
+ })}`
6995
+ ] }) : text.period === null ? t("planManagerCredits", {
6996
+ amount: text.amount,
6997
+ creditName: text.creditName
6998
+ }) : t("planManagerCreditsPerPeriod", {
6999
+ amount: text.amount,
7000
+ creditName: text.creditName,
7001
+ period: periodWord(text.period, t)
7002
+ }) }),
7003
+ row.used !== null && /* @__PURE__ */ jsxs9("span", { className: "schematic-muted schematic-small schematic-plan-manager__used", children: [
7004
+ t("planManagerUsed", { amount: row.used }),
7005
+ row.autoTopup !== null && /* @__PURE__ */ jsx10(Tooltip, { label: t("planManagerAutoTopup"), children: t("planManagerAutoTopupTip", {
7006
+ amount: row.autoTopup.amount,
7007
+ threshold: row.autoTopup.threshold
7008
+ }) })
7009
+ ] })
7010
+ ] }),
7011
+ composition !== null && /* @__PURE__ */ jsx10("span", { className: "schematic-muted schematic-small", children: t(
7012
+ composition.fixed === null ? "planManagerLicensesTimesCredits" : "planManagerLicensesTimesCreditsPlusCompany",
7013
+ {
7014
+ creditName: composition.creditName,
7015
+ fixed: composition.fixed ?? void 0,
7016
+ licenseName: composition.licenseName,
7017
+ period: shortPeriod(composition.period, t) ?? periodWord(composition.period, t),
7018
+ perUnit: composition.perUnit,
7019
+ quantity: composition.quantity,
7020
+ total: composition.total
7021
+ }
7022
+ ) })
7023
+ ]
7024
+ }
7025
+ );
7026
+ }
7027
+ function CreditGroupItem({
7028
+ countAlways = false,
7029
+ plain = false,
7030
+ row,
7031
+ t
7032
+ }) {
7033
+ const named = !plain && row.bundleName !== null;
7034
+ const showCount = !plain && row.count > 1 && (named || countAlways);
7035
+ const amount = `${row.quantity} ${row.creditName}`;
7036
+ return /* @__PURE__ */ jsxs9(
7037
+ "li",
7038
+ {
7039
+ className: "schematic-plan-manager__row",
7040
+ "data-testid": "schematic-credit-group",
7041
+ children: [
7042
+ /* @__PURE__ */ jsxs9("span", { className: "schematic-plan-manager__item", children: [
7043
+ showCount && /* @__PURE__ */ jsxs9("span", { className: "schematic-muted", children: [
7044
+ "(",
7045
+ row.count,
7046
+ ") "
7047
+ ] }),
7048
+ named ? `${row.bundleName} (${amount})` : amount
7049
+ ] }),
7050
+ row.used !== null && /* @__PURE__ */ jsx10("span", { className: "schematic-muted schematic-small schematic-plan-manager__used", children: t("planManagerUsed", { amount: row.used }) })
7051
+ ]
7052
+ }
7053
+ );
7054
+ }
7055
+ function AutoTopupBox({
7056
+ lines,
7057
+ onEdit,
7058
+ t,
7059
+ target,
7060
+ url
7061
+ }) {
7062
+ return /* @__PURE__ */ jsxs9("div", { className: "schematic-plan-manager__auto-topup", children: [
7063
+ /* @__PURE__ */ jsxs9("div", { className: "schematic-plan-manager__auto-topup-lines", children: [
7064
+ /* @__PURE__ */ jsx10("span", { className: "schematic-plan-manager__item", children: t("planManagerAutoTopup") }),
7065
+ lines.map((line) => /* @__PURE__ */ jsx10("span", { children: line.kind === "disabled" ? t("planManagerAutoTopupDisabled", { unit: line.unit }) : t("planManagerAutoTopupAdds", {
7066
+ amount: line.amount,
7067
+ threshold: line.threshold,
7068
+ unit: line.unit
7069
+ }) }, line.creditId))
7070
+ ] }),
7071
+ /* @__PURE__ */ jsx10(
7072
+ Cta,
7073
+ {
7074
+ className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-plan-manager__edit",
7075
+ label: t("planManagerEdit"),
7076
+ onClick: onEdit,
7077
+ target,
7078
+ url
7079
+ }
7080
+ )
7081
+ ] });
7082
+ }
7083
+ function Cta({
7084
+ className,
7085
+ label,
7086
+ onClick,
7087
+ target,
7088
+ url
7089
+ }) {
7090
+ if (onClick !== void 0) {
7091
+ return /* @__PURE__ */ jsx10("button", { className, type: "button", onClick, children: label });
7092
+ }
7093
+ if (url !== void 0) {
7094
+ return /* @__PURE__ */ jsx10("a", { className, href: url, target, children: label });
7095
+ }
7096
+ return null;
7097
+ }
7098
+ function periodWord(period, t) {
7099
+ const key = PERIOD_KEY[period];
7100
+ return key === void 0 ? period : t(key);
7101
+ }
7102
+ function PlanManagerSkeleton() {
7103
+ return /* @__PURE__ */ jsxs9("div", { className: "schematic-skeleton", children: [
7104
+ /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__heading" }),
7105
+ [0, 1].map((index) => /* @__PURE__ */ jsxs9("div", { className: "schematic-skeleton__row", children: [
7106
+ /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__cell", "data-column": "name" }),
7107
+ /* @__PURE__ */ jsx10("div", { className: "schematic-skeleton__cell", "data-column": "price" })
7108
+ ] }, index))
7109
+ ] });
7110
+ }
7111
+ PlanManager.resources = ["company", "featureUsage", "creditBalances"];
7112
+
7113
+ // src/elements/UnsubscribeButton.tsx
7114
+ import {
7115
+ useCompany as useCompany2,
7116
+ useFeatureUsage as useFeatureUsage4,
7117
+ useUnsubscribe
7118
+ } from "@schematichq/schematic-react";
7119
+ import { useMemo as useMemo8, useState as useState8 } from "react";
7120
+ import { jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
7121
+ var TOTAL_KEY = {
7122
+ quarter: "unsubscribeQuarterlyTotal",
7123
+ year: "unsubscribeYearlyTotal"
7124
+ };
7125
+ function UnsubscribeButton({
7126
+ className,
7127
+ locale: localeProp,
7128
+ managePlanTarget,
7129
+ managePlanUrl,
7130
+ onManagePlan,
7131
+ onUnsubscribed,
7132
+ strings
7133
+ }) {
7134
+ const company = useCompany2();
7135
+ const usage = useFeatureUsage4();
7136
+ const { isMutating, unsubscribe } = useUnsubscribe();
7137
+ const locale = useResolvedLocale(localeProp);
7138
+ const t = useTranslator(strings, localeProp);
7139
+ const [open, setOpen] = useState8(false);
7140
+ const [failed, setFailed] = useState8(false);
7141
+ const view = useMemo8(
7142
+ () => company.data === void 0 || usage.data === void 0 ? void 0 : deriveUnsubscribe(company.data, usage.data, { locale }),
7143
+ [company.data, locale, usage.data]
7144
+ );
7145
+ if (view === void 0) {
7146
+ const error = company.error ?? usage.error;
7147
+ if (error === void 0) {
7148
+ return null;
7149
+ }
7150
+ return /* @__PURE__ */ jsx11(
7151
+ StatusFrame,
7152
+ {
7153
+ className: cx("schematic-card", "schematic-unsubscribe", className),
7154
+ error,
7155
+ errorMessage: httpStatus(error) === 404 ? t("unsubscribeUnavailable") : t("unsubscribeError"),
7156
+ hasData: false,
7157
+ isPending: false,
7158
+ loadingLabel: "",
7159
+ onRetry: () => {
7160
+ for (const handle of [company, usage]) {
7161
+ if (handle.error !== void 0) {
7162
+ handle.refetch();
7163
+ }
7164
+ }
7165
+ },
7166
+ retryText: t("retry"),
7167
+ children: null
7168
+ }
7169
+ );
7170
+ }
7171
+ if (!view.canUnsubscribe && !open) {
7172
+ return null;
7173
+ }
7174
+ const close = () => {
7175
+ setOpen(false);
7176
+ setFailed(false);
7177
+ };
7178
+ const confirm = async () => {
7179
+ setFailed(false);
7180
+ try {
7181
+ await unsubscribe();
7182
+ } catch {
7183
+ setFailed(true);
7184
+ return;
7185
+ }
7186
+ setOpen(false);
7187
+ onUnsubscribed?.();
7188
+ };
7189
+ const per = shortPeriod(view.period, t);
7190
+ return /* @__PURE__ */ jsxs10("div", { className: cx("schematic-card", "schematic-unsubscribe", className), children: [
7191
+ /* @__PURE__ */ jsx11(
7192
+ "button",
7193
+ {
7194
+ className: "schematic-cta schematic-unsubscribe__open",
7195
+ type: "button",
7196
+ onClick: () => {
7197
+ setFailed(false);
7198
+ setOpen(true);
7199
+ },
7200
+ children: t("unsubscribeButton")
7201
+ }
7202
+ ),
7203
+ /* @__PURE__ */ jsx11(
7204
+ Dialog,
7205
+ {
7206
+ className: "schematic-unsubscribe__dialog",
7207
+ closeLabel: t("unsubscribeClose"),
7208
+ open,
7209
+ title: t("unsubscribeTitle"),
7210
+ onClose: close,
7211
+ children: /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__columns", children: [
7212
+ /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__summary", children: [
7213
+ /* @__PURE__ */ jsx11("p", { children: t("unsubscribeAccessUntil", { date: view.accessEndsOn }) }),
7214
+ /* @__PURE__ */ jsx11(
7215
+ ManagePlan,
7216
+ {
7217
+ onClick: onManagePlan,
7218
+ t,
7219
+ target: managePlanTarget,
7220
+ url: managePlanUrl
7221
+ }
7222
+ )
7223
+ ] }),
7224
+ /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__sidebar", children: [
7225
+ view.plan !== null && /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__group", children: [
7226
+ /* @__PURE__ */ jsx11("span", { className: "schematic-muted schematic-small", children: t("unsubscribePlan") }),
7227
+ /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__line", children: [
7228
+ /* @__PURE__ */ jsx11("span", { className: "schematic-unsubscribe__name", children: view.plan.name }),
7229
+ view.plan.price !== null && /* @__PURE__ */ jsxs10("span", { children: [
7230
+ view.plan.price,
7231
+ per !== void 0 && /* @__PURE__ */ jsxs10("sub", { children: [
7232
+ "/",
7233
+ per
7234
+ ] })
7235
+ ] })
7236
+ ] })
7237
+ ] }),
7238
+ view.addOns.length > 0 && /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__group", children: [
7239
+ /* @__PURE__ */ jsx11("span", { className: "schematic-muted schematic-small", children: t("unsubscribeAddOns") }),
7240
+ view.addOns.map((addOn) => /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__line", children: [
7241
+ /* @__PURE__ */ jsx11("span", { className: "schematic-unsubscribe__name", children: addOn.name }),
7242
+ /* @__PURE__ */ jsxs10("span", { children: [
7243
+ addOn.price,
7244
+ !addOn.oneTime && per !== void 0 && /* @__PURE__ */ jsxs10("sub", { children: [
7245
+ "/",
7246
+ per
7247
+ ] })
7248
+ ] })
7249
+ ] }, addOn.id))
7250
+ ] }),
7251
+ /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__line schematic-unsubscribe__total", children: [
7252
+ /* @__PURE__ */ jsx11("span", { className: "schematic-muted", children: t(TOTAL_KEY[view.period] ?? "unsubscribeMonthlyTotal") }),
7253
+ /* @__PURE__ */ jsxs10("span", { children: [
7254
+ view.total,
7255
+ per !== void 0 && /* @__PURE__ */ jsxs10("sub", { children: [
7256
+ "/",
7257
+ per
7258
+ ] })
7259
+ ] })
7260
+ ] }),
7261
+ /* @__PURE__ */ jsx11(
7262
+ "button",
7263
+ {
7264
+ className: "schematic-cta schematic-unsubscribe__confirm",
7265
+ disabled: isMutating,
7266
+ type: "button",
7267
+ onClick: () => void confirm(),
7268
+ children: t("unsubscribeConfirm")
7269
+ }
7270
+ ),
7271
+ failed && /* @__PURE__ */ jsx11("p", { className: "schematic-error", role: "alert", children: t("unsubscribeFailed") })
7272
+ ] })
7273
+ ] })
7274
+ }
7275
+ )
7276
+ ] });
7277
+ }
7278
+ function ManagePlan({
7279
+ onClick,
7280
+ t,
7281
+ target,
7282
+ url
7283
+ }) {
7284
+ if (onClick === void 0 && url === void 0) {
7285
+ return null;
7286
+ }
7287
+ const label = t("unsubscribeManagePlan");
7288
+ return /* @__PURE__ */ jsxs10("div", { className: "schematic-unsubscribe__manage", children: [
7289
+ /* @__PURE__ */ jsx11("p", { children: t("unsubscribeNotReady") }),
7290
+ onClick !== void 0 ? /* @__PURE__ */ jsx11(
7291
+ "button",
7292
+ {
7293
+ className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-unsubscribe__manage-plan",
7294
+ type: "button",
7295
+ onClick,
7296
+ children: label
7297
+ }
7298
+ ) : /* @__PURE__ */ jsx11(
7299
+ "a",
7300
+ {
7301
+ className: "schematic-cta schematic-cta--small schematic-cta--ghost schematic-unsubscribe__manage-plan",
7302
+ href: url,
7303
+ target,
7304
+ children: label
7305
+ }
7306
+ )
7307
+ ] });
7308
+ }
7309
+ UnsubscribeButton.resources = ["company", "featureUsage"];
7310
+
7311
+ // src/elements/UpcomingBill.tsx
7312
+ import { useUpcomingInvoice } from "@schematichq/schematic-react";
7313
+ import { useMemo as useMemo9 } from "react";
7314
+ import { Fragment as Fragment5, jsx as jsx12, jsxs as jsxs11 } from "react/jsx-runtime";
5810
7315
  function UpcomingBill({
5811
7316
  className,
5812
7317
  headingLevel = 2,
@@ -5820,7 +7325,7 @@ function UpcomingBill({
5820
7325
  const { data: invoice, error, isPending, refetch } = useUpcomingInvoice();
5821
7326
  const locale = useResolvedLocale(localeProp);
5822
7327
  const t = useTranslator(strings, localeProp);
5823
- const bill = useMemo7(
7328
+ const bill = useMemo9(
5824
7329
  () => invoice === void 0 || invoice === null ? null : deriveUpcomingInvoice(invoice, { locale }),
5825
7330
  [invoice, locale]
5826
7331
  );
@@ -5829,7 +7334,7 @@ function UpcomingBill({
5829
7334
  const discountRow = showDiscounts && bill !== null && bill.discounts.length > 0;
5830
7335
  const unavailable = invoice === void 0 && httpStatus(error) === 404;
5831
7336
  const errorMessage = error === void 0 ? void 0 : unavailable ? t("upcomingBillUnavailable") : t("upcomingBillError");
5832
- return /* @__PURE__ */ jsx10(
7337
+ return /* @__PURE__ */ jsx12(
5833
7338
  StatusFrame,
5834
7339
  {
5835
7340
  className: cx("schematic-card", "schematic-upcoming-bill", className),
@@ -5840,11 +7345,11 @@ function UpcomingBill({
5840
7345
  loadingLabel: t("upcomingBillLoading"),
5841
7346
  onRetry: refetch,
5842
7347
  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(
7348
+ skeleton: /* @__PURE__ */ jsx12(UpcomingBillSkeleton, { showHeader }),
7349
+ children: bill === null ? invoice !== void 0 && /* @__PURE__ */ jsx12("p", { className: "schematic-muted schematic-upcoming-bill__empty", children: t("upcomingBillEmpty") }) : /* @__PURE__ */ jsxs11(Fragment5, { children: [
7350
+ 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 }) }) }),
7351
+ showAmount && /* @__PURE__ */ jsxs11("div", { className: "schematic-upcoming-bill__amount", children: [
7352
+ /* @__PURE__ */ jsx12(
5848
7353
  "span",
5849
7354
  {
5850
7355
  className: "schematic-upcoming-bill__total",
@@ -5852,46 +7357,46 @@ function UpcomingBill({
5852
7357
  children: bill.amountDueText
5853
7358
  }
5854
7359
  ),
5855
- /* @__PURE__ */ jsx10("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
7360
+ /* @__PURE__ */ jsx12("span", { className: "schematic-small schematic-upcoming-bill__estimate", children: t("upcomingBillEstimate") })
5856
7361
  ] }),
5857
- (balanceRows || discountRow) && /* @__PURE__ */ jsxs9("div", { className: "schematic-upcoming-bill__rows", children: [
5858
- balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ jsxs9(
7362
+ (balanceRows || discountRow) && /* @__PURE__ */ jsxs11("div", { className: "schematic-upcoming-bill__rows", children: [
7363
+ balanceRows && bill.balanceApplied !== null && /* @__PURE__ */ jsxs11(
5859
7364
  "div",
5860
7365
  {
5861
7366
  className: "schematic-row schematic-upcoming-bill__balance-applied",
5862
7367
  "data-testid": "schematic-balance-applied",
5863
7368
  children: [
5864
- /* @__PURE__ */ jsx10("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
5865
- /* @__PURE__ */ jsx10("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
7369
+ /* @__PURE__ */ jsx12("span", { className: "schematic-row__label", children: t("upcomingBillBalanceApplied") }),
7370
+ /* @__PURE__ */ jsx12("span", { className: "schematic-row__value", children: bill.balanceApplied.amountText })
5866
7371
  ]
5867
7372
  }
5868
7373
  ),
5869
- balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ jsxs9(
7374
+ balanceRows && bill.balanceRemaining !== null && /* @__PURE__ */ jsxs11(
5870
7375
  "div",
5871
7376
  {
5872
7377
  className: "schematic-row schematic-upcoming-bill__balance-remaining",
5873
7378
  "data-testid": "schematic-balance-remaining",
5874
7379
  children: [
5875
- /* @__PURE__ */ jsx10("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
5876
- /* @__PURE__ */ jsx10("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
7380
+ /* @__PURE__ */ jsx12("span", { className: "schematic-row__label", children: t("upcomingBillBalanceRemaining") }),
7381
+ /* @__PURE__ */ jsx12("span", { className: "schematic-row__value", children: bill.balanceRemaining.amountText })
5877
7382
  ]
5878
7383
  }
5879
7384
  ),
5880
- discountRow && /* @__PURE__ */ jsxs9(
7385
+ discountRow && /* @__PURE__ */ jsxs11(
5881
7386
  "div",
5882
7387
  {
5883
7388
  className: "schematic-row schematic-upcoming-bill__discount-row",
5884
7389
  "data-testid": "schematic-discounts",
5885
7390
  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(
7391
+ /* @__PURE__ */ jsx12("span", { className: "schematic-row__label", children: t("upcomingBillDiscount") }),
7392
+ /* @__PURE__ */ jsx12("ul", { className: "schematic-row__value schematic-upcoming-bill__discounts", children: bill.discounts.map((discount, index) => /* @__PURE__ */ jsxs11(
5888
7393
  "li",
5889
7394
  {
5890
7395
  className: "schematic-upcoming-bill__discount",
5891
7396
  "data-testid": "schematic-discount",
5892
7397
  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) })
7398
+ discount.code !== null && /* @__PURE__ */ jsx12("span", { className: "schematic-chip schematic-upcoming-bill__code", children: discount.code }),
7399
+ /* @__PURE__ */ jsx12("span", { className: "schematic-upcoming-bill__discount-value", children: discountText(discount, t) })
5895
7400
  ]
5896
7401
  },
5897
7402
  `${discount.couponName}-${index}`
@@ -5905,10 +7410,10 @@ function UpcomingBill({
5905
7410
  );
5906
7411
  }
5907
7412
  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" }) })
7413
+ return /* @__PURE__ */ jsxs11("div", { className: "schematic-skeleton", children: [
7414
+ showHeader && /* @__PURE__ */ jsx12("div", { className: "schematic-skeleton__heading" }),
7415
+ /* @__PURE__ */ jsx12("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx12("div", { className: "schematic-skeleton__cell", "data-column": "amount" }) }),
7416
+ /* @__PURE__ */ jsx12("div", { className: "schematic-skeleton__row", children: /* @__PURE__ */ jsx12("div", { className: "schematic-skeleton__cell", "data-column": "row" }) })
5912
7417
  ] });
5913
7418
  }
5914
7419
  function discountText(discount, t) {
@@ -5930,10 +7435,12 @@ export {
5930
7435
  Invoices,
5931
7436
  MeteredFeatures,
5932
7437
  PaymentMethods,
7438
+ PlanManager,
5933
7439
  SCHEMATIC_TOKENS,
5934
7440
  SchematicI18nProvider,
5935
7441
  SchematicStyles,
5936
7442
  Tooltip,
7443
+ UnsubscribeButton,
5937
7444
  UpcomingBill,
5938
7445
  billingResources,
5939
7446
  currentTier,
@@ -5942,6 +7449,8 @@ export {
5942
7449
  deriveInvoiceList,
5943
7450
  deriveMeteredFeatures,
5944
7451
  derivePaymentMethods,
7452
+ derivePlanManager,
7453
+ deriveUnsubscribe,
5945
7454
  deriveUpcomingInvoice,
5946
7455
  featureName,
5947
7456
  formatConsumptionRate,
@@ -5964,9 +7473,10 @@ export {
5964
7473
  tierRanges,
5965
7474
  unitPrice,
5966
7475
  usageLimit,
5967
- useCreditBalances2 as useCreditBalances,
7476
+ useCompany3 as useCompany,
7477
+ useCreditBalances3 as useCreditBalances,
5968
7478
  useCreditUserUsage2 as useCreditUserUsage,
5969
- useFeatureUsage3 as useFeatureUsage,
7479
+ useFeatureUsage5 as useFeatureUsage,
5970
7480
  useFeatureUserUsage2 as useFeatureUserUsage,
5971
7481
  useInvalidateBillingData,
5972
7482
  useInvoices2 as useInvoices,
@@ -5978,6 +7488,7 @@ export {
5978
7488
  useSchematicTranslate,
5979
7489
  useSetupIntent2 as useSetupIntent,
5980
7490
  useTranslator,
7491
+ useUnsubscribe2 as useUnsubscribe,
5981
7492
  useUpcomingInvoice2 as useUpcomingInvoice,
5982
7493
  viewerLocale
5983
7494
  };