@schematichq/schematic-components 1.9.0 → 2.0.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.
@@ -4,7 +4,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __commonJS = (cb, mod) => function __require() {
7
+ var __require = /* @__PURE__ */ ((x2) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x2, {
8
+ get: (a2, b2) => (typeof require !== "undefined" ? require : a2)[b2]
9
+ }) : x2)(function(x2) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x2 + '" is not supported');
12
+ });
13
+ var __commonJS = (cb, mod) => function __require2() {
8
14
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
15
  };
10
16
  var __copyProps = (to, from2, except, desc) => {
@@ -83,6 +89,82 @@ var require_void_elements = __commonJS({
83
89
  }
84
90
  });
85
91
 
92
+ // node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js
93
+ var require_use_sync_external_store_shim_development = __commonJS({
94
+ "node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js"(exports) {
95
+ "use strict";
96
+ (function() {
97
+ function is(x2, y2) {
98
+ return x2 === y2 && (0 !== x2 || 1 / x2 === 1 / y2) || x2 !== x2 && y2 !== y2;
99
+ }
100
+ function useSyncExternalStore$2(subscribe, getSnapshot) {
101
+ didWarnOld18Alpha || void 0 === React3.startTransition || (didWarnOld18Alpha = true, console.error(
102
+ "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
103
+ ));
104
+ var value = getSnapshot();
105
+ if (!didWarnUncachedGetSnapshot) {
106
+ var cachedValue = getSnapshot();
107
+ objectIs(value, cachedValue) || (console.error(
108
+ "The result of getSnapshot should be cached to avoid an infinite loop"
109
+ ), didWarnUncachedGetSnapshot = true);
110
+ }
111
+ cachedValue = useState21({
112
+ inst: { value, getSnapshot }
113
+ });
114
+ var inst = cachedValue[0].inst, forceUpdate = cachedValue[1];
115
+ useLayoutEffect6(
116
+ function() {
117
+ inst.value = value;
118
+ inst.getSnapshot = getSnapshot;
119
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
120
+ },
121
+ [subscribe, value, getSnapshot]
122
+ );
123
+ useEffect11(
124
+ function() {
125
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
126
+ return subscribe(function() {
127
+ checkIfSnapshotChanged(inst) && forceUpdate({ inst });
128
+ });
129
+ },
130
+ [subscribe]
131
+ );
132
+ useDebugValue(value);
133
+ return value;
134
+ }
135
+ function checkIfSnapshotChanged(inst) {
136
+ var latestGetSnapshot = inst.getSnapshot;
137
+ inst = inst.value;
138
+ try {
139
+ var nextValue = latestGetSnapshot();
140
+ return !objectIs(inst, nextValue);
141
+ } catch (error) {
142
+ return true;
143
+ }
144
+ }
145
+ function useSyncExternalStore$1(subscribe, getSnapshot) {
146
+ return getSnapshot();
147
+ }
148
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
149
+ var React3 = __require("react"), objectIs = "function" === typeof Object.is ? Object.is : is, useState21 = React3.useState, useEffect11 = React3.useEffect, useLayoutEffect6 = React3.useLayoutEffect, useDebugValue = React3.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
150
+ exports.useSyncExternalStore = void 0 !== React3.useSyncExternalStore ? React3.useSyncExternalStore : shim;
151
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
152
+ })();
153
+ }
154
+ });
155
+
156
+ // node_modules/use-sync-external-store/shim/index.js
157
+ var require_shim = __commonJS({
158
+ "node_modules/use-sync-external-store/shim/index.js"(exports, module) {
159
+ "use strict";
160
+ if (false) {
161
+ module.exports = null;
162
+ } else {
163
+ module.exports = require_use_sync_external_store_shim_development();
164
+ }
165
+ }
166
+ });
167
+
86
168
  // node_modules/lodash/isObject.js
87
169
  var require_isObject = __commonJS({
88
170
  "node_modules/lodash/isObject.js"(exports, module) {
@@ -2546,15 +2628,7 @@ function getFeatureName(feature, count = 0) {
2546
2628
  return pluralize(name, count);
2547
2629
  }
2548
2630
 
2549
- // src/utils/api/hydrate.ts
2550
- function isCheckoutData(data) {
2551
- return typeof data === "object" && data !== null && "company" in data;
2552
- }
2553
-
2554
2631
  // src/utils/api/plan.ts
2555
- function isHydratedPlan(plan) {
2556
- return typeof plan !== "undefined" && "current" in plan;
2557
- }
2558
2632
  function entitlementCountsReducer(acc, plan) {
2559
2633
  acc[plan.id] = {
2560
2634
  size: plan.entitlements.length,
@@ -4109,20 +4183,12 @@ var St = "__sc-".concat(f, "__");
4109
4183
 
4110
4184
  // src/utils/style.ts
4111
4185
  function attr(key, value) {
4112
- return typeof value !== "undefined" && lt`
4186
+ if (typeof value !== "undefined") {
4187
+ return lt`
4113
4188
  ${key}: ${value};
4114
4189
  `;
4190
+ }
4115
4191
  }
4116
- attr.px = function propAsPx(key, value) {
4117
- return typeof value !== "undefined" && lt`
4118
- ${key}: ${typeof value === "number" ? `${value}px` : value};
4119
- `;
4120
- };
4121
- attr.rem = function propAsRem(key, value) {
4122
- return typeof value !== "undefined" && lt`
4123
- ${key}: ${typeof value === "number" ? `${value / TEXT_BASE_SIZE}rem` : value};
4124
- `;
4125
- };
4126
4192
 
4127
4193
  // src/hooks/useAvailablePlans.ts
4128
4194
  function useAvailablePlans(activePeriod, options = { useSelectedPeriod: true }) {
@@ -4155,11 +4221,16 @@ function useAvailablePlans(activePeriod, options = { useSelectedPeriod: true })
4155
4221
  addOns: getActivePlans(data?.activeAddOns || []),
4156
4222
  periods: getAvailablePeriods()
4157
4223
  };
4158
- }, [data, getAvailablePeriods, getActivePlans]);
4224
+ }, [
4225
+ data?.activePlans,
4226
+ data?.activeAddOns,
4227
+ getActivePlans,
4228
+ getAvailablePeriods
4229
+ ]);
4159
4230
  }
4160
4231
 
4161
4232
  // src/hooks/useEmbed.ts
4162
- import { useContext as useContext4 } from "react";
4233
+ import { useContext as useContext5 } from "react";
4163
4234
 
4164
4235
  // src/context/embedState.ts
4165
4236
  var defaultTheme = {
@@ -6620,17 +6691,485 @@ var ReportNamespaces = class {
6620
6691
  }
6621
6692
  };
6622
6693
 
6694
+ // node_modules/react-i18next/dist/es/IcuTrans.js
6695
+ import { useContext as useContext2 } from "react";
6696
+
6697
+ // node_modules/react-i18next/dist/es/IcuTransWithoutContext.js
6698
+ import React2 from "react";
6699
+
6700
+ // node_modules/react-i18next/dist/es/IcuTransUtils/TranslationParserError.js
6701
+ var TranslationParserError = class _TranslationParserError extends Error {
6702
+ constructor(message, position2, translationString) {
6703
+ super(message);
6704
+ this.name = "TranslationParserError";
6705
+ this.position = position2;
6706
+ this.translationString = translationString;
6707
+ if (Error.captureStackTrace) {
6708
+ Error.captureStackTrace(this, _TranslationParserError);
6709
+ }
6710
+ }
6711
+ };
6712
+
6713
+ // node_modules/react-i18next/dist/es/IcuTransUtils/htmlEntityDecoder.js
6714
+ var commonEntities = {
6715
+ " ": "\xA0",
6716
+ "&": "&",
6717
+ "&lt;": "<",
6718
+ "&gt;": ">",
6719
+ "&quot;": '"',
6720
+ "&apos;": "'",
6721
+ "&copy;": "\xA9",
6722
+ "&reg;": "\xAE",
6723
+ "&trade;": "\u2122",
6724
+ "&hellip;": "\u2026",
6725
+ "&ndash;": "\u2013",
6726
+ "&mdash;": "\u2014",
6727
+ "&lsquo;": "\u2018",
6728
+ "&rsquo;": "\u2019",
6729
+ "&sbquo;": "\u201A",
6730
+ "&ldquo;": "\u201C",
6731
+ "&rdquo;": "\u201D",
6732
+ "&bdquo;": "\u201E",
6733
+ "&dagger;": "\u2020",
6734
+ "&Dagger;": "\u2021",
6735
+ "&bull;": "\u2022",
6736
+ "&prime;": "\u2032",
6737
+ "&Prime;": "\u2033",
6738
+ "&lsaquo;": "\u2039",
6739
+ "&rsaquo;": "\u203A",
6740
+ "&sect;": "\xA7",
6741
+ "&para;": "\xB6",
6742
+ "&middot;": "\xB7",
6743
+ "&ensp;": "\u2002",
6744
+ "&emsp;": "\u2003",
6745
+ "&thinsp;": "\u2009",
6746
+ "&euro;": "\u20AC",
6747
+ "&pound;": "\xA3",
6748
+ "&yen;": "\xA5",
6749
+ "&cent;": "\xA2",
6750
+ "&curren;": "\xA4",
6751
+ "&times;": "\xD7",
6752
+ "&divide;": "\xF7",
6753
+ "&minus;": "\u2212",
6754
+ "&plusmn;": "\xB1",
6755
+ "&ne;": "\u2260",
6756
+ "&le;": "\u2264",
6757
+ "&ge;": "\u2265",
6758
+ "&asymp;": "\u2248",
6759
+ "&equiv;": "\u2261",
6760
+ "&infin;": "\u221E",
6761
+ "&int;": "\u222B",
6762
+ "&sum;": "\u2211",
6763
+ "&prod;": "\u220F",
6764
+ "&radic;": "\u221A",
6765
+ "&part;": "\u2202",
6766
+ "&permil;": "\u2030",
6767
+ "&deg;": "\xB0",
6768
+ "&micro;": "\xB5",
6769
+ "&larr;": "\u2190",
6770
+ "&uarr;": "\u2191",
6771
+ "&rarr;": "\u2192",
6772
+ "&darr;": "\u2193",
6773
+ "&harr;": "\u2194",
6774
+ "&crarr;": "\u21B5",
6775
+ "&lArr;": "\u21D0",
6776
+ "&uArr;": "\u21D1",
6777
+ "&rArr;": "\u21D2",
6778
+ "&dArr;": "\u21D3",
6779
+ "&hArr;": "\u21D4",
6780
+ "&alpha;": "\u03B1",
6781
+ "&beta;": "\u03B2",
6782
+ "&gamma;": "\u03B3",
6783
+ "&delta;": "\u03B4",
6784
+ "&epsilon;": "\u03B5",
6785
+ "&zeta;": "\u03B6",
6786
+ "&eta;": "\u03B7",
6787
+ "&theta;": "\u03B8",
6788
+ "&iota;": "\u03B9",
6789
+ "&kappa;": "\u03BA",
6790
+ "&lambda;": "\u03BB",
6791
+ "&mu;": "\u03BC",
6792
+ "&nu;": "\u03BD",
6793
+ "&xi;": "\u03BE",
6794
+ "&omicron;": "\u03BF",
6795
+ "&pi;": "\u03C0",
6796
+ "&rho;": "\u03C1",
6797
+ "&sigma;": "\u03C3",
6798
+ "&tau;": "\u03C4",
6799
+ "&upsilon;": "\u03C5",
6800
+ "&phi;": "\u03C6",
6801
+ "&chi;": "\u03C7",
6802
+ "&psi;": "\u03C8",
6803
+ "&omega;": "\u03C9",
6804
+ "&Alpha;": "\u0391",
6805
+ "&Beta;": "\u0392",
6806
+ "&Gamma;": "\u0393",
6807
+ "&Delta;": "\u0394",
6808
+ "&Epsilon;": "\u0395",
6809
+ "&Zeta;": "\u0396",
6810
+ "&Eta;": "\u0397",
6811
+ "&Theta;": "\u0398",
6812
+ "&Iota;": "\u0399",
6813
+ "&Kappa;": "\u039A",
6814
+ "&Lambda;": "\u039B",
6815
+ "&Mu;": "\u039C",
6816
+ "&Nu;": "\u039D",
6817
+ "&Xi;": "\u039E",
6818
+ "&Omicron;": "\u039F",
6819
+ "&Pi;": "\u03A0",
6820
+ "&Rho;": "\u03A1",
6821
+ "&Sigma;": "\u03A3",
6822
+ "&Tau;": "\u03A4",
6823
+ "&Upsilon;": "\u03A5",
6824
+ "&Phi;": "\u03A6",
6825
+ "&Chi;": "\u03A7",
6826
+ "&Psi;": "\u03A8",
6827
+ "&Omega;": "\u03A9",
6828
+ "&Agrave;": "\xC0",
6829
+ "&Aacute;": "\xC1",
6830
+ "&Acirc;": "\xC2",
6831
+ "&Atilde;": "\xC3",
6832
+ "&Auml;": "\xC4",
6833
+ "&Aring;": "\xC5",
6834
+ "&AElig;": "\xC6",
6835
+ "&Ccedil;": "\xC7",
6836
+ "&Egrave;": "\xC8",
6837
+ "&Eacute;": "\xC9",
6838
+ "&Ecirc;": "\xCA",
6839
+ "&Euml;": "\xCB",
6840
+ "&Igrave;": "\xCC",
6841
+ "&Iacute;": "\xCD",
6842
+ "&Icirc;": "\xCE",
6843
+ "&Iuml;": "\xCF",
6844
+ "&ETH;": "\xD0",
6845
+ "&Ntilde;": "\xD1",
6846
+ "&Ograve;": "\xD2",
6847
+ "&Oacute;": "\xD3",
6848
+ "&Ocirc;": "\xD4",
6849
+ "&Otilde;": "\xD5",
6850
+ "&Ouml;": "\xD6",
6851
+ "&Oslash;": "\xD8",
6852
+ "&Ugrave;": "\xD9",
6853
+ "&Uacute;": "\xDA",
6854
+ "&Ucirc;": "\xDB",
6855
+ "&Uuml;": "\xDC",
6856
+ "&Yacute;": "\xDD",
6857
+ "&THORN;": "\xDE",
6858
+ "&szlig;": "\xDF",
6859
+ "&agrave;": "\xE0",
6860
+ "&aacute;": "\xE1",
6861
+ "&acirc;": "\xE2",
6862
+ "&atilde;": "\xE3",
6863
+ "&auml;": "\xE4",
6864
+ "&aring;": "\xE5",
6865
+ "&aelig;": "\xE6",
6866
+ "&ccedil;": "\xE7",
6867
+ "&egrave;": "\xE8",
6868
+ "&eacute;": "\xE9",
6869
+ "&ecirc;": "\xEA",
6870
+ "&euml;": "\xEB",
6871
+ "&igrave;": "\xEC",
6872
+ "&iacute;": "\xED",
6873
+ "&icirc;": "\xEE",
6874
+ "&iuml;": "\xEF",
6875
+ "&eth;": "\xF0",
6876
+ "&ntilde;": "\xF1",
6877
+ "&ograve;": "\xF2",
6878
+ "&oacute;": "\xF3",
6879
+ "&ocirc;": "\xF4",
6880
+ "&otilde;": "\xF5",
6881
+ "&ouml;": "\xF6",
6882
+ "&oslash;": "\xF8",
6883
+ "&ugrave;": "\xF9",
6884
+ "&uacute;": "\xFA",
6885
+ "&ucirc;": "\xFB",
6886
+ "&uuml;": "\xFC",
6887
+ "&yacute;": "\xFD",
6888
+ "&thorn;": "\xFE",
6889
+ "&yuml;": "\xFF",
6890
+ "&iexcl;": "\xA1",
6891
+ "&iquest;": "\xBF",
6892
+ "&fnof;": "\u0192",
6893
+ "&circ;": "\u02C6",
6894
+ "&tilde;": "\u02DC",
6895
+ "&OElig;": "\u0152",
6896
+ "&oelig;": "\u0153",
6897
+ "&Scaron;": "\u0160",
6898
+ "&scaron;": "\u0161",
6899
+ "&Yuml;": "\u0178",
6900
+ "&ordf;": "\xAA",
6901
+ "&ordm;": "\xBA",
6902
+ "&macr;": "\xAF",
6903
+ "&acute;": "\xB4",
6904
+ "&cedil;": "\xB8",
6905
+ "&sup1;": "\xB9",
6906
+ "&sup2;": "\xB2",
6907
+ "&sup3;": "\xB3",
6908
+ "&frac14;": "\xBC",
6909
+ "&frac12;": "\xBD",
6910
+ "&frac34;": "\xBE",
6911
+ "&spades;": "\u2660",
6912
+ "&clubs;": "\u2663",
6913
+ "&hearts;": "\u2665",
6914
+ "&diams;": "\u2666",
6915
+ "&loz;": "\u25CA",
6916
+ "&oline;": "\u203E",
6917
+ "&frasl;": "\u2044",
6918
+ "&weierp;": "\u2118",
6919
+ "&image;": "\u2111",
6920
+ "&real;": "\u211C",
6921
+ "&alefsym;": "\u2135"
6922
+ };
6923
+ var entityPattern = new RegExp(Object.keys(commonEntities).map((entity) => entity.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"), "g");
6924
+ var decodeHtmlEntities = (text) => text.replace(entityPattern, (match2) => commonEntities[match2]).replace(/&#(\d+);/g, (_2, num) => String.fromCharCode(parseInt(num, 10))).replace(/&#x([0-9a-fA-F]+);/g, (_2, hex) => String.fromCharCode(parseInt(hex, 16)));
6925
+
6926
+ // node_modules/react-i18next/dist/es/IcuTransUtils/tokenizer.js
6927
+ var tokenize2 = (translation) => {
6928
+ const tokens = [];
6929
+ let position2 = 0;
6930
+ let currentText = "";
6931
+ const flushText = () => {
6932
+ if (currentText) {
6933
+ tokens.push({
6934
+ type: "Text",
6935
+ value: currentText,
6936
+ position: position2 - currentText.length
6937
+ });
6938
+ currentText = "";
6939
+ }
6940
+ };
6941
+ while (position2 < translation.length) {
6942
+ const char2 = translation[position2];
6943
+ if (char2 === "<") {
6944
+ const tagMatch = translation.slice(position2).match(/^<(\d+)>/);
6945
+ if (tagMatch) {
6946
+ flushText();
6947
+ tokens.push({
6948
+ type: "TagOpen",
6949
+ value: tagMatch[0],
6950
+ position: position2,
6951
+ tagNumber: parseInt(tagMatch[1], 10)
6952
+ });
6953
+ position2 += tagMatch[0].length;
6954
+ } else {
6955
+ const closeTagMatch = translation.slice(position2).match(/^<\/(\d+)>/);
6956
+ if (closeTagMatch) {
6957
+ flushText();
6958
+ tokens.push({
6959
+ type: "TagClose",
6960
+ value: closeTagMatch[0],
6961
+ position: position2,
6962
+ tagNumber: parseInt(closeTagMatch[1], 10)
6963
+ });
6964
+ position2 += closeTagMatch[0].length;
6965
+ } else {
6966
+ currentText += char2;
6967
+ position2 += 1;
6968
+ }
6969
+ }
6970
+ } else {
6971
+ currentText += char2;
6972
+ position2 += 1;
6973
+ }
6974
+ }
6975
+ flushText();
6976
+ return tokens;
6977
+ };
6978
+
6979
+ // node_modules/react-i18next/dist/es/IcuTransUtils/renderTranslation.js
6980
+ import React from "react";
6981
+ var renderDeclarationNode = (declaration2, children, childDeclarations) => {
6982
+ const {
6983
+ type,
6984
+ props = {}
6985
+ } = declaration2;
6986
+ if (props.children && Array.isArray(props.children) && childDeclarations) {
6987
+ const {
6988
+ children: _childrenToRemove,
6989
+ ...propsWithoutChildren
6990
+ } = props;
6991
+ return React.createElement(type, propsWithoutChildren, ...children);
6992
+ }
6993
+ if (children.length === 0) {
6994
+ return React.createElement(type, props);
6995
+ }
6996
+ if (children.length === 1) {
6997
+ return React.createElement(type, props, children[0]);
6998
+ }
6999
+ return React.createElement(type, props, ...children);
7000
+ };
7001
+ var renderTranslation = (translation, declarations = []) => {
7002
+ if (!translation) {
7003
+ return [];
7004
+ }
7005
+ const tokens = tokenize2(translation);
7006
+ const result = [];
7007
+ const stack = [];
7008
+ const literalTagNumbers = /* @__PURE__ */ new Set();
7009
+ const getCurrentDeclarations = () => {
7010
+ if (stack.length === 0) {
7011
+ return declarations;
7012
+ }
7013
+ const parentFrame = stack[stack.length - 1];
7014
+ if (parentFrame.declaration.props?.children && Array.isArray(parentFrame.declaration.props.children)) {
7015
+ return parentFrame.declaration.props.children;
7016
+ }
7017
+ return parentFrame.declarations;
7018
+ };
7019
+ tokens.forEach((token2) => {
7020
+ switch (token2.type) {
7021
+ case "Text":
7022
+ {
7023
+ const decoded = decodeHtmlEntities(token2.value);
7024
+ const targetArray = stack.length > 0 ? stack[stack.length - 1].children : result;
7025
+ targetArray.push(decoded);
7026
+ }
7027
+ break;
7028
+ case "TagOpen":
7029
+ {
7030
+ const {
7031
+ tagNumber
7032
+ } = token2;
7033
+ const currentDeclarations = getCurrentDeclarations();
7034
+ const declaration2 = currentDeclarations[tagNumber];
7035
+ if (!declaration2) {
7036
+ literalTagNumbers.add(tagNumber);
7037
+ const literalText = `<${tagNumber}>`;
7038
+ const targetArray = stack.length > 0 ? stack[stack.length - 1].children : result;
7039
+ targetArray.push(literalText);
7040
+ break;
7041
+ }
7042
+ stack.push({
7043
+ tagNumber,
7044
+ children: [],
7045
+ position: token2.position,
7046
+ declaration: declaration2,
7047
+ declarations: currentDeclarations
7048
+ });
7049
+ }
7050
+ break;
7051
+ case "TagClose":
7052
+ {
7053
+ const {
7054
+ tagNumber
7055
+ } = token2;
7056
+ if (literalTagNumbers.has(tagNumber)) {
7057
+ const literalText = `</${tagNumber}>`;
7058
+ const literalTargetArray = stack.length > 0 ? stack[stack.length - 1].children : result;
7059
+ literalTargetArray.push(literalText);
7060
+ literalTagNumbers.delete(tagNumber);
7061
+ break;
7062
+ }
7063
+ if (stack.length === 0) {
7064
+ throw new TranslationParserError(`Unexpected closing tag </${tagNumber}> at position ${token2.position}`, token2.position, translation);
7065
+ }
7066
+ const frame = stack.pop();
7067
+ if (frame.tagNumber !== tagNumber) {
7068
+ throw new TranslationParserError(`Mismatched tags: expected </${frame.tagNumber}> but got </${tagNumber}> at position ${token2.position}`, token2.position, translation);
7069
+ }
7070
+ const element = renderDeclarationNode(frame.declaration, frame.children, frame.declarations);
7071
+ const elementTargetArray = stack.length > 0 ? stack[stack.length - 1].children : result;
7072
+ elementTargetArray.push(element);
7073
+ }
7074
+ break;
7075
+ }
7076
+ });
7077
+ if (stack.length > 0) {
7078
+ const unclosed = stack[stack.length - 1];
7079
+ throw new TranslationParserError(`Unclosed tag <${unclosed.tagNumber}> at position ${unclosed.position}`, unclosed.position, translation);
7080
+ }
7081
+ return result;
7082
+ };
7083
+
7084
+ // node_modules/react-i18next/dist/es/IcuTransWithoutContext.js
7085
+ function IcuTransWithoutContext({
7086
+ i18nKey,
7087
+ defaultTranslation,
7088
+ content,
7089
+ ns,
7090
+ values = {},
7091
+ i18n: i18nFromProps,
7092
+ t: tFromProps
7093
+ }) {
7094
+ const i18n = i18nFromProps || getI18n();
7095
+ if (!i18n) {
7096
+ warnOnce(i18n, "NO_I18NEXT_INSTANCE", `IcuTrans: You need to pass in an i18next instance using i18nextReactModule`, {
7097
+ i18nKey
7098
+ });
7099
+ return React2.createElement(React2.Fragment, {}, defaultTranslation);
7100
+ }
7101
+ const t2 = tFromProps || i18n.t?.bind(i18n) || ((k2) => k2);
7102
+ let namespaces = ns || t2.ns || i18n.options?.defaultNS;
7103
+ namespaces = isString2(namespaces) ? [namespaces] : namespaces || ["translation"];
7104
+ let mergedValues = values;
7105
+ if (i18n.options?.interpolation?.defaultVariables) {
7106
+ mergedValues = values && Object.keys(values).length > 0 ? {
7107
+ ...values,
7108
+ ...i18n.options.interpolation.defaultVariables
7109
+ } : {
7110
+ ...i18n.options.interpolation.defaultVariables
7111
+ };
7112
+ }
7113
+ const translation = t2(i18nKey, {
7114
+ defaultValue: defaultTranslation,
7115
+ ...mergedValues,
7116
+ ns: namespaces
7117
+ });
7118
+ try {
7119
+ const rendered = renderTranslation(translation, content);
7120
+ return React2.createElement(React2.Fragment, {}, ...rendered);
7121
+ } catch (error) {
7122
+ warn(i18n, "ICU_TRANS_RENDER_ERROR", `IcuTrans component error for key "${i18nKey}": ${error.message}`, {
7123
+ i18nKey,
7124
+ error
7125
+ });
7126
+ return React2.createElement(React2.Fragment, {}, translation);
7127
+ }
7128
+ }
7129
+ IcuTransWithoutContext.displayName = "IcuTransWithoutContext";
7130
+
7131
+ // node_modules/react-i18next/dist/es/IcuTrans.js
7132
+ function IcuTrans({
7133
+ i18nKey,
7134
+ defaultTranslation,
7135
+ content,
7136
+ ns,
7137
+ values = {},
7138
+ i18n: i18nFromProps,
7139
+ t: tFromProps
7140
+ }) {
7141
+ const {
7142
+ i18n: i18nFromContext,
7143
+ defaultNS: defaultNSFromContext
7144
+ } = useContext2(I18nContext) || {};
7145
+ const i18n = i18nFromProps || i18nFromContext || getI18n();
7146
+ const t2 = tFromProps || i18n?.t.bind(i18n);
7147
+ return IcuTransWithoutContext({
7148
+ i18nKey,
7149
+ defaultTranslation,
7150
+ content,
7151
+ ns: ns || t2?.ns || defaultNSFromContext || i18n?.options?.defaultNS,
7152
+ values,
7153
+ i18n,
7154
+ t: tFromProps
7155
+ });
7156
+ }
7157
+ IcuTrans.displayName = "IcuTrans";
7158
+
6623
7159
  // node_modules/react-i18next/dist/es/useTranslation.js
6624
- import { useState, useEffect, useContext as useContext2, useRef, useCallback as useCallback2 } from "react";
6625
- var usePrevious = (value, ignore) => {
6626
- const ref = useRef();
6627
- useEffect(() => {
6628
- ref.current = ignore ? ref.current : value;
6629
- }, [value, ignore]);
6630
- return ref.current;
7160
+ var import_shim = __toESM(require_shim(), 1);
7161
+ import { useContext as useContext3, useCallback as useCallback2, useMemo as useMemo2, useEffect, useRef, useState } from "react";
7162
+ var notReadyT = (k2, optsOrDefaultValue) => {
7163
+ if (isString2(optsOrDefaultValue)) return optsOrDefaultValue;
7164
+ if (isObject(optsOrDefaultValue) && isString2(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
7165
+ return Array.isArray(k2) ? k2[k2.length - 1] : k2;
7166
+ };
7167
+ var notReadySnapshot = {
7168
+ t: notReadyT,
7169
+ ready: false
7170
+ };
7171
+ var dummySubscribe = () => () => {
6631
7172
  };
6632
- var alwaysNewT = (i18n, language, namespace, keyPrefix) => i18n.getFixedT(language, namespace, keyPrefix);
6633
- var useMemoizedT = (i18n, language, namespace, keyPrefix) => useCallback2(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
6634
7173
  var useTranslation = (ns, props = {}) => {
6635
7174
  const {
6636
7175
  i18n: i18nFromProps
@@ -6638,106 +7177,106 @@ var useTranslation = (ns, props = {}) => {
6638
7177
  const {
6639
7178
  i18n: i18nFromContext,
6640
7179
  defaultNS: defaultNSFromContext
6641
- } = useContext2(I18nContext) || {};
7180
+ } = useContext3(I18nContext) || {};
6642
7181
  const i18n = i18nFromProps || i18nFromContext || getI18n();
6643
7182
  if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
6644
7183
  if (!i18n) {
6645
7184
  warnOnce(i18n, "NO_I18NEXT_INSTANCE", "useTranslation: You will need to pass in an i18next instance by using initReactI18next");
6646
- const notReadyT = (k2, optsOrDefaultValue) => {
6647
- if (isString2(optsOrDefaultValue)) return optsOrDefaultValue;
6648
- if (isObject(optsOrDefaultValue) && isString2(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
6649
- return Array.isArray(k2) ? k2[k2.length - 1] : k2;
6650
- };
6651
- const retNotReady = [notReadyT, {}, false];
6652
- retNotReady.t = notReadyT;
6653
- retNotReady.i18n = {};
6654
- retNotReady.ready = false;
6655
- return retNotReady;
6656
- }
6657
- if (i18n.options.react?.wait) warnOnce(i18n, "DEPRECATED_OPTION", "useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");
6658
- const i18nOptions = {
7185
+ }
7186
+ const i18nOptions = useMemo2(() => ({
6659
7187
  ...getDefaults(),
6660
- ...i18n.options.react,
7188
+ ...i18n?.options?.react,
6661
7189
  ...props
6662
- };
7190
+ }), [i18n, props]);
6663
7191
  const {
6664
7192
  useSuspense,
6665
7193
  keyPrefix
6666
7194
  } = i18nOptions;
6667
- let namespaces = ns || defaultNSFromContext || i18n.options?.defaultNS;
6668
- namespaces = isString2(namespaces) ? [namespaces] : namespaces || ["translation"];
6669
- i18n.reportNamespaces.addUsedNamespaces?.(namespaces);
6670
- const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every((n) => hasLoadedNamespace2(n, i18n, i18nOptions));
6671
- const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
6672
- const getT = () => memoGetT;
6673
- const getNewT = () => alwaysNewT(i18n, props.lng || null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
6674
- const [t2, setT] = useState(getT);
6675
- let joinedNS = namespaces.join();
6676
- if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
6677
- const previousJoinedNS = usePrevious(joinedNS);
6678
- const isMounted = useRef(true);
6679
- useEffect(() => {
7195
+ const namespaces = useMemo2(() => {
7196
+ const nsOrContext = ns || defaultNSFromContext || i18n?.options?.defaultNS;
7197
+ return isString2(nsOrContext) ? [nsOrContext] : nsOrContext || ["translation"];
7198
+ }, [ns, defaultNSFromContext, i18n]);
7199
+ i18n?.reportNamespaces?.addUsedNamespaces?.(namespaces);
7200
+ const subscribe = useCallback2((callback) => {
7201
+ if (!i18n) return dummySubscribe;
6680
7202
  const {
6681
7203
  bindI18n,
6682
7204
  bindI18nStore
6683
7205
  } = i18nOptions;
6684
- isMounted.current = true;
6685
- if (!ready && !useSuspense) {
6686
- if (props.lng) {
6687
- loadLanguages2(i18n, props.lng, namespaces, () => {
6688
- if (isMounted.current) setT(getNewT);
6689
- });
6690
- } else {
6691
- loadNamespaces2(i18n, namespaces, () => {
6692
- if (isMounted.current) setT(getNewT);
6693
- });
6694
- }
6695
- }
6696
- if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
6697
- setT(getNewT);
6698
- }
6699
- const boundReset = () => {
6700
- if (isMounted.current) setT(getNewT);
6701
- };
6702
- if (bindI18n) i18n?.on(bindI18n, boundReset);
6703
- if (bindI18nStore) i18n?.store.on(bindI18nStore, boundReset);
7206
+ if (bindI18n) i18n.on(bindI18n, callback);
7207
+ if (bindI18nStore) i18n.store.on(bindI18nStore, callback);
6704
7208
  return () => {
6705
- isMounted.current = false;
6706
- if (i18n && bindI18n) bindI18n?.split(" ").forEach((e2) => i18n.off(e2, boundReset));
6707
- if (bindI18nStore && i18n) bindI18nStore.split(" ").forEach((e2) => i18n.store.off(e2, boundReset));
7209
+ if (bindI18n) bindI18n.split(" ").forEach((e2) => i18n.off(e2, callback));
7210
+ if (bindI18nStore) bindI18nStore.split(" ").forEach((e2) => i18n.store.off(e2, callback));
7211
+ };
7212
+ }, [i18n, i18nOptions]);
7213
+ const snapshotRef = useRef();
7214
+ const getSnapshot = useCallback2(() => {
7215
+ if (!i18n) {
7216
+ return notReadySnapshot;
7217
+ }
7218
+ const calculatedReady = !!(i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every((n) => hasLoadedNamespace2(n, i18n, i18nOptions));
7219
+ const calculatedT = i18n.getFixedT(props.lng || i18n.language, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
7220
+ const lastSnapshot = snapshotRef.current;
7221
+ if (lastSnapshot && lastSnapshot.ready === calculatedReady && lastSnapshot.lng === (props.lng || i18n.language) && lastSnapshot.keyPrefix === keyPrefix) {
7222
+ return lastSnapshot;
7223
+ }
7224
+ const newSnapshot = {
7225
+ t: calculatedT,
7226
+ ready: calculatedReady,
7227
+ lng: props.lng || i18n.language,
7228
+ keyPrefix
6708
7229
  };
6709
- }, [i18n, joinedNS]);
7230
+ snapshotRef.current = newSnapshot;
7231
+ return newSnapshot;
7232
+ }, [i18n, namespaces, keyPrefix, i18nOptions, props.lng]);
7233
+ const [loadCount, setLoadCount] = useState(0);
7234
+ const {
7235
+ t: t2,
7236
+ ready
7237
+ } = (0, import_shim.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
6710
7238
  useEffect(() => {
6711
- if (isMounted.current && ready) {
6712
- setT(getT);
6713
- }
6714
- }, [i18n, keyPrefix, ready]);
6715
- const ret = [t2, i18n, ready];
6716
- ret.t = t2;
6717
- ret.i18n = i18n;
6718
- ret.ready = ready;
6719
- if (ready) return ret;
6720
- if (!ready && !useSuspense) return ret;
6721
- throw new Promise((resolve) => {
6722
- if (props.lng) {
6723
- loadLanguages2(i18n, props.lng, namespaces, () => resolve());
6724
- } else {
6725
- loadNamespaces2(i18n, namespaces, () => resolve());
6726
- }
6727
- });
7239
+ if (i18n && !ready && !useSuspense) {
7240
+ const onLoaded = () => setLoadCount((c2) => c2 + 1);
7241
+ if (props.lng) {
7242
+ loadLanguages2(i18n, props.lng, namespaces, onLoaded);
7243
+ } else {
7244
+ loadNamespaces2(i18n, namespaces, onLoaded);
7245
+ }
7246
+ }
7247
+ }, [i18n, props.lng, namespaces, ready, useSuspense, loadCount]);
7248
+ const finalI18n = i18n || {};
7249
+ const ret = useMemo2(() => {
7250
+ const arr = [t2, finalI18n, ready];
7251
+ arr.t = t2;
7252
+ arr.i18n = finalI18n;
7253
+ arr.ready = ready;
7254
+ return arr;
7255
+ }, [t2, finalI18n, ready]);
7256
+ if (i18n && useSuspense && !ready) {
7257
+ throw new Promise((resolve) => {
7258
+ const onLoaded = () => resolve();
7259
+ if (props.lng) {
7260
+ loadLanguages2(i18n, props.lng, namespaces, onLoaded);
7261
+ } else {
7262
+ loadNamespaces2(i18n, namespaces, onLoaded);
7263
+ }
7264
+ });
7265
+ }
7266
+ return ret;
6728
7267
  };
6729
7268
 
6730
7269
  // node_modules/react-i18next/dist/es/withTranslation.js
6731
7270
  import { createElement as createElement2, forwardRef as forwardRefReact } from "react";
6732
7271
 
6733
7272
  // node_modules/react-i18next/dist/es/I18nextProvider.js
6734
- import { createElement as createElement3, useMemo as useMemo2 } from "react";
7273
+ import { createElement as createElement3, useMemo as useMemo3 } from "react";
6735
7274
 
6736
7275
  // node_modules/react-i18next/dist/es/withSSR.js
6737
7276
  import { createElement as createElement4 } from "react";
6738
7277
 
6739
7278
  // node_modules/react-i18next/dist/es/useSSR.js
6740
- import { useContext as useContext3 } from "react";
7279
+ import { useContext as useContext4 } from "react";
6741
7280
 
6742
7281
  // src/localization/en.json
6743
7282
  var en_default = {
@@ -6747,7 +7286,7 @@ var en_default = {
6747
7286
  Active: "Active",
6748
7287
  Add: "Add",
6749
7288
  "Add new payment method": "Add new payment method",
6750
- "Add Seats": "Add More",
7289
+ "Add More": "Add More",
6751
7290
  "Add-ons": "Add-ons",
6752
7291
  "Add-ons Quantity": "Add-ons Quantity",
6753
7292
  Additional: "Additional",
@@ -7083,12 +7622,12 @@ var Icon = ({ name, className = "", ...rest }) => {
7083
7622
  };
7084
7623
 
7085
7624
  // src/context/EmbedProvider.tsx
7086
- var import_debounce = __toESM(require_debounce());
7087
- var import_merge2 = __toESM(require_merge());
7625
+ var import_debounce = __toESM(require_debounce(), 1);
7626
+ var import_merge2 = __toESM(require_merge(), 1);
7088
7627
  import {
7089
7628
  useCallback as useCallback3,
7090
7629
  useEffect as useEffect2,
7091
- useMemo as useMemo3,
7630
+ useMemo as useMemo4,
7092
7631
  useReducer,
7093
7632
  useRef as useRef2,
7094
7633
  useState as useState2
@@ -10573,7 +11112,7 @@ var ComponentspublicApi = class extends BaseAPI2 {
10573
11112
  };
10574
11113
 
10575
11114
  // src/context/embedReducer.ts
10576
- var import_merge = __toESM(require_merge());
11115
+ var import_merge = __toESM(require_merge(), 1);
10577
11116
  var dispatchPlanChangedEvent = (detail) => {
10578
11117
  const event = new CustomEvent("plan-changed", {
10579
11118
  bubbles: true,
@@ -10581,6 +11120,33 @@ var dispatchPlanChangedEvent = (detail) => {
10581
11120
  });
10582
11121
  window.dispatchEvent(event);
10583
11122
  };
11123
+ function normalize(data) {
11124
+ return (0, import_merge.default)({}, data, {
11125
+ activePlans: data?.activePlans.map((plan) => ({
11126
+ companyCanTrial: false,
11127
+ current: false,
11128
+ valid: true,
11129
+ usageViolations: [],
11130
+ ...plan
11131
+ })),
11132
+ activeAddOns: data?.activeAddOns.map((plan) => ({
11133
+ companyCanTrial: false,
11134
+ current: false,
11135
+ valid: true,
11136
+ usageViolations: [],
11137
+ ...plan
11138
+ })),
11139
+ activeUsageBasedEntitlements: [],
11140
+ checkoutSettings: {
11141
+ collectAddress: false,
11142
+ collectEmail: false,
11143
+ collectPhone: false,
11144
+ taxCollectionEnabled: false
11145
+ },
11146
+ creditBundles: [],
11147
+ creditGrants: []
11148
+ });
11149
+ }
10584
11150
  var reducer = (state, action) => {
10585
11151
  switch (action.type) {
10586
11152
  case "SET_ACCESS_TOKEN": {
@@ -10596,7 +11162,15 @@ var reducer = (state, action) => {
10596
11162
  isPending: true
10597
11163
  };
10598
11164
  }
10599
- case "HYDRATE_PUBLIC":
11165
+ case "HYDRATE_PUBLIC": {
11166
+ return {
11167
+ ...state,
11168
+ data: normalize(action.data),
11169
+ error: void 0,
11170
+ isPending: false,
11171
+ stale: false
11172
+ };
11173
+ }
10600
11174
  case "HYDRATE":
10601
11175
  case "HYDRATE_COMPONENT":
10602
11176
  case "HYDRATE_EXTERNAL": {
@@ -10617,44 +11191,38 @@ var reducer = (state, action) => {
10617
11191
  };
10618
11192
  }
10619
11193
  case "UPDATE_PAYMENT_METHOD": {
10620
- if (!isCheckoutData(state.data)) {
10621
- return state;
10622
- }
10623
- const data = { ...state.data };
10624
- if (data.subscription) {
10625
- data.subscription.paymentMethod = action.paymentMethod;
11194
+ const updated = normalize(state.data);
11195
+ if (updated.subscription) {
11196
+ updated.subscription.paymentMethod = action.paymentMethod;
10626
11197
  }
10627
- if (data.company) {
10628
- const updatedPaymentMethods = data.company.paymentMethods.filter(
11198
+ if (updated.company) {
11199
+ const updatedPaymentMethods = updated.company.paymentMethods.filter(
10629
11200
  (paymentMethod) => paymentMethod.id !== action.paymentMethod.id
10630
11201
  );
10631
- data.company.paymentMethods = [
11202
+ updated.company.paymentMethods = [
10632
11203
  action.paymentMethod,
10633
11204
  ...updatedPaymentMethods
10634
11205
  ];
10635
- if (!data.subscription) {
10636
- data.company.defaultPaymentMethod = action.paymentMethod;
11206
+ if (!updated.subscription) {
11207
+ updated.company.defaultPaymentMethod = action.paymentMethod;
10637
11208
  }
10638
11209
  }
10639
11210
  return {
10640
11211
  ...state,
10641
- data
11212
+ data: updated
10642
11213
  };
10643
11214
  }
10644
11215
  case "DELETE_PAYMENT_METHOD": {
10645
- if (!isCheckoutData(state.data)) {
10646
- return state;
10647
- }
10648
- const data = { ...state.data };
10649
- if (data.company) {
10650
- const paymentMethods = [...data.company.paymentMethods];
10651
- data.company.paymentMethods = paymentMethods.filter(
11216
+ const updated = normalize(state.data);
11217
+ if (updated.company) {
11218
+ const paymentMethods = [...updated.company.paymentMethods];
11219
+ updated.company.paymentMethods = paymentMethods.filter(
10652
11220
  (paymentMethod) => paymentMethod.id !== action.paymentMethodId
10653
11221
  );
10654
11222
  }
10655
11223
  return {
10656
11224
  ...state,
10657
- data
11225
+ data: updated
10658
11226
  };
10659
11227
  }
10660
11228
  case "RESET": {
@@ -10701,6 +11269,10 @@ var reducer = (state, action) => {
10701
11269
 
10702
11270
  // src/context/EmbedProvider.tsx
10703
11271
  import { jsx, jsxs } from "react/jsx-runtime";
11272
+ var getCustomHeaders = (sessionId) => ({
11273
+ "X-Schematic-Components-Version": "2.0.0",
11274
+ "X-Schematic-Session-ID": sessionId
11275
+ });
10704
11276
  var EmbedProvider = ({
10705
11277
  children,
10706
11278
  apiKey,
@@ -10714,13 +11286,6 @@ var EmbedProvider = ({
10714
11286
  const resolvedState = (0, import_merge2.default)({}, initialState, providedState);
10715
11287
  return resolvedState;
10716
11288
  });
10717
- const customHeaders = useMemo3(
10718
- () => ({
10719
- "X-Schematic-Components-Version": "1.9.0",
10720
- "X-Schematic-Session-ID": sessionIdRef.current
10721
- }),
10722
- []
10723
- );
10724
11289
  const [api, setApi] = useState2({});
10725
11290
  const debug = useCallback3(
10726
11291
  (message, ...args) => {
@@ -10757,7 +11322,7 @@ var EmbedProvider = ({
10757
11322
  });
10758
11323
  }
10759
11324
  }, [api.public]);
10760
- const debouncedHydratePublic = useMemo3(
11325
+ const debouncedHydratePublic = useMemo4(
10761
11326
  () => (0, import_debounce.default)(
10762
11327
  hydratePublic,
10763
11328
  FETCH_DEBOUNCE_TIMEOUT,
@@ -10783,7 +11348,7 @@ var EmbedProvider = ({
10783
11348
  });
10784
11349
  }
10785
11350
  }, [api.checkout]);
10786
- const debouncedHydrate = useMemo3(
11351
+ const debouncedHydrate = useMemo4(
10787
11352
  () => (0, import_debounce.default)(hydrate, FETCH_DEBOUNCE_TIMEOUT, LEADING_DEBOUNCE_SETTINGS),
10788
11353
  [hydrate]
10789
11354
  );
@@ -10810,7 +11375,7 @@ var EmbedProvider = ({
10810
11375
  },
10811
11376
  [api.checkout]
10812
11377
  );
10813
- const debouncedHydrateComponent = useMemo3(
11378
+ const debouncedHydrateComponent = useMemo4(
10814
11379
  () => (0, import_debounce.default)(
10815
11380
  hydrateComponent,
10816
11381
  FETCH_DEBOUNCE_TIMEOUT,
@@ -10834,7 +11399,7 @@ var EmbedProvider = ({
10834
11399
  });
10835
11400
  }
10836
11401
  }, []);
10837
- const debouncedHydrateExternal = useMemo3(
11402
+ const debouncedHydrateExternal = useMemo4(
10838
11403
  () => (0, import_debounce.default)(
10839
11404
  hydrateExternal,
10840
11405
  FETCH_DEBOUNCE_TIMEOUT,
@@ -10845,7 +11410,7 @@ var EmbedProvider = ({
10845
11410
  const createSetupIntent = useCallback3(async () => {
10846
11411
  return api.checkout?.createSetupIntent();
10847
11412
  }, [api.checkout]);
10848
- const debouncedCreateSetupIntent = useMemo3(
11413
+ const debouncedCreateSetupIntent = useMemo4(
10849
11414
  () => (0, import_debounce.default)(
10850
11415
  createSetupIntent,
10851
11416
  FETCH_DEBOUNCE_TIMEOUT,
@@ -10868,7 +11433,7 @@ var EmbedProvider = ({
10868
11433
  },
10869
11434
  [api.checkout]
10870
11435
  );
10871
- const debouncedUpdatePaymentMethod = useMemo3(
11436
+ const debouncedUpdatePaymentMethod = useMemo4(
10872
11437
  () => (0, import_debounce.default)(
10873
11438
  updatePaymentMethod,
10874
11439
  FETCH_DEBOUNCE_TIMEOUT,
@@ -10891,7 +11456,7 @@ var EmbedProvider = ({
10891
11456
  },
10892
11457
  [api.checkout]
10893
11458
  );
10894
- const debouncedDeletePaymentMethod = useMemo3(
11459
+ const debouncedDeletePaymentMethod = useMemo4(
10895
11460
  () => (0, import_debounce.default)(
10896
11461
  deletePaymentMethod,
10897
11462
  FETCH_DEBOUNCE_TIMEOUT,
@@ -10914,7 +11479,7 @@ var EmbedProvider = ({
10914
11479
  },
10915
11480
  [api.checkout]
10916
11481
  );
10917
- const debouncedCheckout = useMemo3(
11482
+ const debouncedCheckout = useMemo4(
10918
11483
  () => (0, import_debounce.default)(checkout, FETCH_DEBOUNCE_TIMEOUT, LEADING_DEBOUNCE_SETTINGS),
10919
11484
  [checkout]
10920
11485
  );
@@ -10934,7 +11499,7 @@ var EmbedProvider = ({
10934
11499
  }
10935
11500
  return response;
10936
11501
  }, [api.checkout]);
10937
- const debouncedUnsubscribe = useMemo3(
11502
+ const debouncedUnsubscribe = useMemo4(
10938
11503
  () => (0, import_debounce.default)(unsubscribe, FETCH_DEBOUNCE_TIMEOUT, LEADING_DEBOUNCE_SETTINGS),
10939
11504
  [unsubscribe]
10940
11505
  );
@@ -10946,7 +11511,7 @@ var EmbedProvider = ({
10946
11511
  },
10947
11512
  [api.checkout]
10948
11513
  );
10949
- const debouncedGetUpcomingInvoice = useMemo3(
11514
+ const debouncedGetUpcomingInvoice = useMemo4(
10950
11515
  () => (0, import_debounce.default)(
10951
11516
  getUpcomingInvoice,
10952
11517
  FETCH_DEBOUNCE_TIMEOUT,
@@ -10957,7 +11522,7 @@ var EmbedProvider = ({
10957
11522
  const getCustomerBalance = useCallback3(async () => {
10958
11523
  return api.checkout?.fetchCustomerBalance();
10959
11524
  }, [api.checkout]);
10960
- const debouncedGetCustomerBalance = useMemo3(
11525
+ const debouncedGetCustomerBalance = useMemo4(
10961
11526
  () => (0, import_debounce.default)(
10962
11527
  getCustomerBalance,
10963
11528
  FETCH_DEBOUNCE_TIMEOUT,
@@ -10968,7 +11533,7 @@ var EmbedProvider = ({
10968
11533
  const listInvoices = useCallback3(async () => {
10969
11534
  return api.checkout?.listInvoices();
10970
11535
  }, [api.checkout]);
10971
- const debouncedListInvoices = useMemo3(
11536
+ const debouncedListInvoices = useMemo4(
10972
11537
  () => (0, import_debounce.default)(listInvoices, FETCH_DEBOUNCE_TIMEOUT, LEADING_DEBOUNCE_SETTINGS),
10973
11538
  [listInvoices]
10974
11539
  );
@@ -11049,7 +11614,7 @@ var EmbedProvider = ({
11049
11614
  if (apiKey) {
11050
11615
  const configParams = (0, import_merge2.default)({}, apiConfig, {
11051
11616
  apiKey,
11052
- headers: customHeaders
11617
+ headers: getCustomHeaders(sessionIdRef.current)
11053
11618
  });
11054
11619
  const publicApi = new ComponentspublicApi(
11055
11620
  new Configuration2(configParams)
@@ -11059,12 +11624,12 @@ var EmbedProvider = ({
11059
11624
  public: publicApi
11060
11625
  }));
11061
11626
  }
11062
- }, [apiKey, apiConfig, customHeaders]);
11627
+ }, [apiKey, apiConfig]);
11063
11628
  useEffect2(() => {
11064
11629
  if (state.accessToken) {
11065
11630
  const configParams = (0, import_merge2.default)({}, apiConfig, {
11066
11631
  apiKey: state.accessToken,
11067
- headers: customHeaders
11632
+ headers: getCustomHeaders(sessionIdRef.current)
11068
11633
  });
11069
11634
  setApi((prev2) => ({
11070
11635
  ...prev2,
@@ -11073,7 +11638,7 @@ var EmbedProvider = ({
11073
11638
  )
11074
11639
  }));
11075
11640
  }
11076
- }, [state.accessToken, apiConfig, customHeaders]);
11641
+ }, [state.accessToken, apiConfig]);
11077
11642
  useEffect2(() => {
11078
11643
  if (options.settings) {
11079
11644
  updateSettings(options.settings, { update: true });
@@ -11132,13 +11697,13 @@ var EmbedProvider = ({
11132
11697
  };
11133
11698
 
11134
11699
  // src/hooks/useEmbed.ts
11135
- var useEmbed = () => useContext4(EmbedContext);
11700
+ var useEmbed = () => useContext5(EmbedContext);
11136
11701
 
11137
11702
  // src/hooks/useIsLightBackground.ts
11138
- import { useMemo as useMemo4 } from "react";
11703
+ import { useMemo as useMemo5 } from "react";
11139
11704
  function useIsLightBackground() {
11140
11705
  const { settings } = useEmbed();
11141
- const isLightBackground = useMemo4(() => {
11706
+ const isLightBackground = useMemo5(() => {
11142
11707
  return hexToHSL(settings.theme.card.background).l > 50;
11143
11708
  }, [settings.theme.card.background]);
11144
11709
  return isLightBackground;
@@ -11252,18 +11817,8 @@ var usePaymentConfirmation = ({
11252
11817
  };
11253
11818
  };
11254
11819
 
11255
- // src/hooks/usePrevious.ts
11256
- import { useEffect as useEffect4, useRef as useRef4 } from "react";
11257
- function usePrevious2(value) {
11258
- const ref = useRef4(void 0);
11259
- useEffect4(() => {
11260
- ref.current = value;
11261
- }, [value]);
11262
- return ref.current;
11263
- }
11264
-
11265
11820
  // src/hooks/useRequest.ts
11266
- import { useCallback as useCallback5, useMemo as useMemo5, useState as useState4 } from "react";
11821
+ import { useCallback as useCallback5, useMemo as useMemo6, useState as useState4 } from "react";
11267
11822
  function useRequest(fn) {
11268
11823
  const [isLoading, setIsLoading] = useState4(false);
11269
11824
  const [error, setError] = useState4(null);
@@ -11283,7 +11838,7 @@ function useRequest(fn) {
11283
11838
  setIsLoading(false);
11284
11839
  }
11285
11840
  }, [fn]);
11286
- const value = useMemo5(() => {
11841
+ const value = useMemo6(() => {
11287
11842
  const state = { isLoading, error, data };
11288
11843
  return [state, request];
11289
11844
  }, [isLoading, error, data, request]);
@@ -11291,12 +11846,12 @@ function useRequest(fn) {
11291
11846
  }
11292
11847
 
11293
11848
  // src/hooks/useTrialEnd.ts
11294
- import { useMemo as useMemo6 } from "react";
11849
+ import { useMemo as useMemo7 } from "react";
11295
11850
  function useTrialEnd() {
11296
11851
  const { t: t2 } = useTranslation();
11297
11852
  const { data } = useEmbed();
11298
- const { endDate, formatted } = useMemo6(() => {
11299
- const billingSubscription = isCheckoutData(data) ? data.company?.billingSubscription : void 0;
11853
+ const { endDate, formatted } = useMemo7(() => {
11854
+ const billingSubscription = data?.company?.billingSubscription;
11300
11855
  const end = typeof billingSubscription?.trialEnd === "number" ? new Date(billingSubscription.trialEnd * 1e3) : void 0;
11301
11856
  let formatted2;
11302
11857
  if (end) {
@@ -11323,21 +11878,19 @@ function useTrialEnd() {
11323
11878
  });
11324
11879
  }
11325
11880
  return { endDate: end, formatted: formatted2 };
11326
- }, [t2, data]);
11881
+ }, [t2, data?.company?.billingSubscription]);
11327
11882
  return { endDate, formatted };
11328
11883
  }
11329
11884
 
11330
11885
  // src/hooks/useWrapChildren.ts
11331
11886
  import { useLayoutEffect, useState as useState5 } from "react";
11332
- function useWrapChildren(elements) {
11333
- const [shouldWrap, setShouldWrap] = useState5(
11334
- () => new Array(elements.length).fill(false)
11335
- );
11887
+ function useWrapChildren(ref) {
11888
+ const [shouldWrap, setShouldWrap] = useState5([]);
11336
11889
  useLayoutEffect(() => {
11337
11890
  const rowShouldWrap = (parent) => [...parent.children].some(
11338
11891
  (el) => el instanceof HTMLElement && el.previousElementSibling instanceof HTMLElement && el.offsetLeft <= el.previousElementSibling.offsetLeft
11339
11892
  );
11340
- elements.forEach((el, idx) => {
11893
+ ref.current.forEach((el, idx) => {
11341
11894
  new ResizeObserver((entries) => {
11342
11895
  setShouldWrap((prev2) => {
11343
11896
  const next2 = [...prev2];
@@ -11351,12 +11904,12 @@ function useWrapChildren(elements) {
11351
11904
  return next2;
11352
11905
  });
11353
11906
  });
11354
- }, [elements]);
11907
+ }, [ref]);
11355
11908
  return shouldWrap.some((wrap) => wrap);
11356
11909
  }
11357
11910
 
11358
11911
  // src/components/ui/box/styles.ts
11359
- var Box = dt.div((props) => {
11912
+ var Box = dt("div")((props) => {
11360
11913
  function reducer2(acc, [key, value]) {
11361
11914
  if (key.startsWith("$") && !["$viewport"].includes(key)) {
11362
11915
  acc.push(
@@ -11854,7 +12407,7 @@ var Input = dt.input(({ theme, $size = "md", $variant = "filled" }) => {
11854
12407
  });
11855
12408
 
11856
12409
  // src/components/ui/modal/Modal.tsx
11857
- import { useCallback as useCallback6, useLayoutEffect as useLayoutEffect2, useRef as useRef5 } from "react";
12410
+ import { useCallback as useCallback6, useLayoutEffect as useLayoutEffect2, useRef as useRef4 } from "react";
11858
12411
 
11859
12412
  // src/components/ui/modal/styles.ts
11860
12413
  var Overlay = dt(Box)`
@@ -11919,7 +12472,7 @@ var Modal2 = ({
11919
12472
  }) => {
11920
12473
  const { setLayout } = useEmbed();
11921
12474
  const isLightBackground = useIsLightBackground();
11922
- const ref = useRef5(null);
12475
+ const ref = useRef4(null);
11923
12476
  const handleClose = useCallback6(() => {
11924
12477
  setLayout("portal");
11925
12478
  onClose?.();
@@ -12151,8 +12704,8 @@ var Text = dt.span.withConfig({
12151
12704
  );
12152
12705
 
12153
12706
  // src/components/ui/tooltip/Tooltip.tsx
12154
- var import_debounce2 = __toESM(require_debounce());
12155
- import { useCallback as useCallback8, useLayoutEffect as useLayoutEffect3, useRef as useRef6, useState as useState6 } from "react";
12707
+ var import_debounce2 = __toESM(require_debounce(), 1);
12708
+ import { useCallback as useCallback8, useLayoutEffect as useLayoutEffect3, useRef as useRef5, useState as useState6 } from "react";
12156
12709
  import { createPortal } from "react-dom";
12157
12710
 
12158
12711
  // src/components/ui/tooltip/styles.ts
@@ -12302,6 +12855,22 @@ var Content = dt.div.withConfig({
12302
12855
 
12303
12856
  // src/components/ui/tooltip/Tooltip.tsx
12304
12857
  import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
12858
+ var getCoords = (element, { position: position2 }) => {
12859
+ const { top: offsetTop, left: offsetLeft } = document.body.getBoundingClientRect();
12860
+ const rect = element.getBoundingClientRect();
12861
+ let x2 = position2 === "left" ? rect.left : rect.right;
12862
+ if (position2 === "top" || position2 === "bottom") {
12863
+ x2 -= rect.width / 2;
12864
+ }
12865
+ let y2 = position2 === "top" ? rect.top : rect.bottom;
12866
+ if (position2 === "left" || position2 === "right") {
12867
+ y2 -= rect.height / 2;
12868
+ }
12869
+ return {
12870
+ x: Math.round(x2 - offsetLeft),
12871
+ y: Math.round(y2 - offsetTop)
12872
+ };
12873
+ };
12305
12874
  var Tooltip = ({
12306
12875
  trigger,
12307
12876
  content,
@@ -12309,42 +12878,29 @@ var Tooltip = ({
12309
12878
  fullWidth = false,
12310
12879
  ...rest
12311
12880
  }) => {
12312
- const ref = useRef6(null);
12881
+ const ref = useRef5(null);
12313
12882
  const [show, setShow] = useState6(false);
12314
12883
  const [coords2, setCoords] = useState6({ x: 0, y: 0 });
12315
12884
  const updateCoords = useCallback8(() => {
12316
12885
  if (ref.current) {
12317
- const { top: offsetTop, left: offsetLeft } = document.body.getBoundingClientRect();
12318
- const rect = ref.current.getBoundingClientRect();
12319
- let x2 = position2 === "left" ? rect.left : rect.right;
12320
- if (position2 === "top" || position2 === "bottom") {
12321
- x2 -= rect.width / 2;
12322
- }
12323
- let y2 = position2 === "top" ? rect.top : rect.bottom;
12324
- if (position2 === "left" || position2 === "right") {
12325
- y2 -= rect.height / 2;
12326
- }
12327
- setCoords({
12328
- x: Math.round(x2 - offsetLeft),
12329
- y: Math.round(y2 - offsetTop)
12330
- });
12886
+ setCoords(getCoords(ref.current, { position: position2 }));
12331
12887
  }
12332
12888
  }, [position2]);
12333
12889
  useLayoutEffect3(() => {
12334
12890
  const handleResize = (0, import_debounce2.default)(updateCoords, EVENT_DEBOUNCE_TIMEOUT);
12335
12891
  window.addEventListener("resize", handleResize);
12892
+ updateCoords();
12336
12893
  return () => {
12337
12894
  window.removeEventListener("resize", handleResize);
12338
12895
  };
12339
12896
  }, [updateCoords]);
12340
- useLayoutEffect3(() => {
12341
- updateCoords();
12342
- }, [updateCoords, show]);
12343
12897
  return /* @__PURE__ */ jsxs4(Fragment2, { children: [
12344
12898
  /* @__PURE__ */ jsx6(
12345
12899
  Trigger,
12346
12900
  {
12347
12901
  ref,
12902
+ onFocus: () => setShow(true),
12903
+ onBlur: () => setShow(false),
12348
12904
  onPointerEnter: () => setShow(true),
12349
12905
  onPointerLeave: () => setShow(false),
12350
12906
  $fullWidth: fullWidth,
@@ -12490,8 +13046,8 @@ var Root = forwardRef4(
12490
13046
  Root.displayName = "Root";
12491
13047
 
12492
13048
  // src/components/layout/viewport/Viewport.tsx
12493
- var import_debounce3 = __toESM(require_debounce());
12494
- import { forwardRef as forwardRef5, useLayoutEffect as useLayoutEffect5, useMemo as useMemo15, useState as useState13 } from "react";
13049
+ var import_debounce3 = __toESM(require_debounce(), 1);
13050
+ import { forwardRef as forwardRef5, useLayoutEffect as useLayoutEffect5, useMemo as useMemo16, useRef as useRef9, useState as useState13 } from "react";
12495
13051
  import { createPortal as createPortal2 } from "react-dom";
12496
13052
 
12497
13053
  // src/components/shared/billing-threshold-tooltip/BillingThresholdTooltip.tsx
@@ -12526,17 +13082,17 @@ var BillingThresholdTooltip = ({
12526
13082
  // src/components/shared/checkout-dialog/CheckoutDialog.tsx
12527
13083
  import {
12528
13084
  useCallback as useCallback10,
12529
- useEffect as useEffect6,
13085
+ useEffect as useEffect5,
12530
13086
  useLayoutEffect as useLayoutEffect4,
12531
- useMemo as useMemo9,
12532
- useRef as useRef7,
13087
+ useMemo as useMemo10,
13088
+ useRef as useRef6,
12533
13089
  useState as useState10
12534
13090
  } from "react";
12535
13091
 
12536
13092
  // src/components/shared/sidebar/Sidebar.tsx
12537
13093
  import {
12538
13094
  useCallback as useCallback9,
12539
- useMemo as useMemo7
13095
+ useMemo as useMemo8
12540
13096
  } from "react";
12541
13097
 
12542
13098
  // src/components/shared/sidebar/EntitlementRow.tsx
@@ -12657,6 +13213,24 @@ var Proration = ({ currency, charges }) => {
12657
13213
 
12658
13214
  // src/components/shared/sidebar/StageButton.tsx
12659
13215
  import { jsx as jsx13, jsxs as jsxs8 } from "react/jsx-runtime";
13216
+ var NoPaymentRequired = ({
13217
+ isDisabled,
13218
+ isLoading,
13219
+ onClick
13220
+ }) => {
13221
+ const { t: t2 } = useTranslation();
13222
+ return /* @__PURE__ */ jsx13(
13223
+ Button,
13224
+ {
13225
+ type: "button",
13226
+ disabled: isDisabled,
13227
+ onClick,
13228
+ $isLoading: isLoading,
13229
+ $fullWidth: true,
13230
+ children: t2("Subscribe and close")
13231
+ }
13232
+ );
13233
+ };
12660
13234
  var StageButton = ({
12661
13235
  checkout,
12662
13236
  checkoutStage,
@@ -12677,19 +13251,6 @@ var StageButton = ({
12677
13251
  }) => {
12678
13252
  const { t: t2 } = useTranslation();
12679
13253
  const isDisabled = isLoading || !hasPlan || inEditMode;
12680
- const NoPaymentRequired = () => {
12681
- return /* @__PURE__ */ jsx13(
12682
- Button,
12683
- {
12684
- type: "button",
12685
- disabled: isDisabled,
12686
- onClick: checkout,
12687
- $isLoading: isLoading,
12688
- $fullWidth: true,
12689
- children: t2("Subscribe and close")
12690
- }
12691
- );
12692
- };
12693
13254
  if (checkoutStage === "plan") {
12694
13255
  if (isSelectedPlanTrialable && trialPaymentMethodRequired && shouldTrial) {
12695
13256
  return /* @__PURE__ */ jsx13(
@@ -12723,7 +13284,14 @@ var StageButton = ({
12723
13284
  if (!isPaymentMethodRequired && !checkoutStages?.some(
12724
13285
  (stage) => stage.id === "usage" || stage.id === "addons" || stage.id === "credits"
12725
13286
  )) {
12726
- return /* @__PURE__ */ jsx13(NoPaymentRequired, {});
13287
+ return /* @__PURE__ */ jsx13(
13288
+ NoPaymentRequired,
13289
+ {
13290
+ isDisabled,
13291
+ isLoading,
13292
+ onClick: checkout
13293
+ }
13294
+ );
12727
13295
  }
12728
13296
  return /* @__PURE__ */ jsx13(
12729
13297
  Button,
@@ -12751,7 +13319,14 @@ var StageButton = ({
12751
13319
  if (!isPaymentMethodRequired && !checkoutStages?.some(
12752
13320
  (stage) => stage.id === "addons" || stage.id === "credits"
12753
13321
  )) {
12754
- return /* @__PURE__ */ jsx13(NoPaymentRequired, {});
13322
+ return /* @__PURE__ */ jsx13(
13323
+ NoPaymentRequired,
13324
+ {
13325
+ isDisabled,
13326
+ isLoading,
13327
+ onClick: checkout
13328
+ }
13329
+ );
12755
13330
  }
12756
13331
  return /* @__PURE__ */ jsx13(
12757
13332
  Button,
@@ -12792,7 +13367,14 @@ var StageButton = ({
12792
13367
  (stage) => stage.id === "credits"
12793
13368
  );
12794
13369
  if (!isPaymentMethodRequired && !hasAddonsUsageStage && !hasCreditsStage) {
12795
- return /* @__PURE__ */ jsx13(NoPaymentRequired, {});
13370
+ return /* @__PURE__ */ jsx13(
13371
+ NoPaymentRequired,
13372
+ {
13373
+ isDisabled,
13374
+ isLoading,
13375
+ onClick: checkout
13376
+ }
13377
+ );
12796
13378
  }
12797
13379
  return /* @__PURE__ */ jsx13(
12798
13380
  Button,
@@ -12827,7 +13409,14 @@ var StageButton = ({
12827
13409
  }
12828
13410
  if (checkoutStage === "addonsUsage") {
12829
13411
  if (!isPaymentMethodRequired && !checkoutStages?.some((stage) => stage.id === "credits")) {
12830
- return /* @__PURE__ */ jsx13(NoPaymentRequired, {});
13412
+ return /* @__PURE__ */ jsx13(
13413
+ NoPaymentRequired,
13414
+ {
13415
+ isDisabled,
13416
+ isLoading,
13417
+ onClick: checkout
13418
+ }
13419
+ );
12831
13420
  }
12832
13421
  return /* @__PURE__ */ jsx13(
12833
13422
  Button,
@@ -12859,7 +13448,14 @@ var StageButton = ({
12859
13448
  }
12860
13449
  if (checkoutStage === "credits") {
12861
13450
  if (!isPaymentMethodRequired) {
12862
- return /* @__PURE__ */ jsx13(NoPaymentRequired, {});
13451
+ return /* @__PURE__ */ jsx13(
13452
+ NoPaymentRequired,
13453
+ {
13454
+ isDisabled,
13455
+ isLoading,
13456
+ onClick: checkout
13457
+ }
13458
+ );
12863
13459
  }
12864
13460
  return /* @__PURE__ */ jsx13(
12865
13461
  Button,
@@ -12891,7 +13487,14 @@ var StageButton = ({
12891
13487
  }
12892
13488
  if (checkoutStage === "checkout") {
12893
13489
  if (!isPaymentMethodRequired) {
12894
- return /* @__PURE__ */ jsx13(NoPaymentRequired, {});
13490
+ return /* @__PURE__ */ jsx13(
13491
+ NoPaymentRequired,
13492
+ {
13493
+ isDisabled,
13494
+ isLoading,
13495
+ onClick: checkout
13496
+ }
13497
+ );
12895
13498
  }
12896
13499
  return /* @__PURE__ */ jsx13(
12897
13500
  Button,
@@ -12953,33 +13556,30 @@ var Sidebar = ({
12953
13556
  billingSubscription,
12954
13557
  paymentMethod,
12955
13558
  trialPaymentMethodRequired
12956
- } = useMemo7(() => {
12957
- if (isCheckoutData(data)) {
12958
- const currentEntitlements2 = data.featureUsage?.features || [];
12959
- return {
12960
- currentPlan: data.company?.plan,
12961
- currentAddOns: data.company?.addOns || [],
12962
- currentEntitlements: currentEntitlements2,
12963
- currentUsageBasedEntitlements: extractCurrentUsageBasedEntitlements(
12964
- data.featureUsage?.features,
12965
- planPeriod
12966
- ),
12967
- billingSubscription: data.company?.billingSubscription,
12968
- paymentMethod: data.subscription?.paymentMethod,
12969
- trialPaymentMethodRequired: data.trialPaymentMethodRequired === true
12970
- };
12971
- }
13559
+ } = useMemo8(() => {
13560
+ const currentEntitlements2 = data?.featureUsage?.features || [];
12972
13561
  return {
12973
- currentPlan: void 0,
12974
- currentAddOns: [],
12975
- currentEntitlements: [],
12976
- currentUsageBasedEntitlements: [],
12977
- billingSubscription: void 0,
12978
- paymentMethod: void 0,
12979
- trialPaymentMethodRequired: false
13562
+ currentPlan: data?.company?.plan,
13563
+ currentAddOns: data?.company?.addOns || [],
13564
+ currentEntitlements: currentEntitlements2,
13565
+ currentUsageBasedEntitlements: extractCurrentUsageBasedEntitlements(
13566
+ currentEntitlements2,
13567
+ planPeriod
13568
+ ),
13569
+ billingSubscription: data?.company?.billingSubscription,
13570
+ paymentMethod: data?.subscription?.paymentMethod,
13571
+ trialPaymentMethodRequired: data?.trialPaymentMethodRequired === true
12980
13572
  };
12981
- }, [data, planPeriod]);
12982
- const { payInAdvanceEntitlements } = useMemo7(() => {
13573
+ }, [
13574
+ planPeriod,
13575
+ data?.company?.addOns,
13576
+ data?.company?.billingSubscription,
13577
+ data?.company?.plan,
13578
+ data?.featureUsage?.features,
13579
+ data?.subscription?.paymentMethod,
13580
+ data?.trialPaymentMethodRequired
13581
+ ]);
13582
+ const { payInAdvanceEntitlements } = useMemo8(() => {
12983
13583
  const payAsYouGoEntitlements = [];
12984
13584
  const payInAdvanceEntitlements2 = usageBasedEntitlements.filter(
12985
13585
  (entitlement) => {
@@ -12991,7 +13591,7 @@ var Sidebar = ({
12991
13591
  );
12992
13592
  return { payAsYouGoEntitlements, payInAdvanceEntitlements: payInAdvanceEntitlements2 };
12993
13593
  }, [usageBasedEntitlements]);
12994
- const subscriptionPrice = useMemo7(() => {
13594
+ const subscriptionPrice = useMemo8(() => {
12995
13595
  let planPrice;
12996
13596
  let currency;
12997
13597
  if (selectedPlan) {
@@ -13028,7 +13628,7 @@ var Sidebar = ({
13028
13628
  proration,
13029
13629
  taxAmount,
13030
13630
  taxDescription
13031
- } = useMemo7(() => {
13631
+ } = useMemo8(() => {
13032
13632
  return {
13033
13633
  amountOff: charges?.amountOff ?? 0,
13034
13634
  dueNow: charges?.dueNow ?? 0,
@@ -13040,7 +13640,7 @@ var Sidebar = ({
13040
13640
  taxDescription: charges?.taxDisplayName
13041
13641
  };
13042
13642
  }, [charges]);
13043
- const updatedUsageBasedEntitlements = useMemo7(() => {
13643
+ const updatedUsageBasedEntitlements = useMemo8(() => {
13044
13644
  const changedUsageBasedEntitlements = [];
13045
13645
  const addedUsageBasedEntitlements = selectedPlan ? usageBasedEntitlements.reduce(
13046
13646
  (acc, selected) => {
@@ -13091,15 +13691,15 @@ var Sidebar = ({
13091
13691
  currentUsageBasedEntitlements,
13092
13692
  usageBasedEntitlements
13093
13693
  ]);
13094
- const selectedAddOns = useMemo7(
13694
+ const selectedAddOns = useMemo8(
13095
13695
  () => addOns.filter((addOn) => addOn.isSelected),
13096
13696
  [addOns]
13097
13697
  );
13098
- const addedCreditBundles = useMemo7(
13698
+ const addedCreditBundles = useMemo8(
13099
13699
  () => creditBundles.filter((bundle) => bundle.count > 0),
13100
13700
  [creditBundles]
13101
13701
  );
13102
- const discountApplied = useMemo7(
13702
+ const discountApplied = useMemo8(
13103
13703
  () => promoCode && (amountOff > 0 || percentOff > 0),
13104
13704
  [promoCode, amountOff, percentOff]
13105
13705
  );
@@ -13145,7 +13745,7 @@ var Sidebar = ({
13145
13745
  newPlanId: planId,
13146
13746
  newPriceId: priceId,
13147
13747
  addOnIds: addOns.reduce((acc, addOn) => {
13148
- if (addOn.isSelected && isHydratedPlan(selectedPlan) && !selectedPlan.companyCanTrial) {
13748
+ if (addOn.isSelected && !selectedPlan.companyCanTrial) {
13149
13749
  const addOnPriceId = getAddOnPrice(addOn, planPeriod)?.id;
13150
13750
  if (addOnPriceId) {
13151
13751
  acc.push({
@@ -13237,8 +13837,7 @@ var Sidebar = ({
13237
13837
  setError(t2("Unsubscribe failed"));
13238
13838
  }
13239
13839
  }, [t2, unsubscribe, setError, setIsLoading, setLayout]);
13240
- const willPlanChange = isHydratedPlan(selectedPlan) && !selectedPlan.current;
13241
- const { removedAddOns, willAddOnsChange } = useMemo7(() => {
13840
+ const { removedAddOns, willAddOnsChange } = useMemo8(() => {
13242
13841
  const addedAddOns = selectedAddOns.filter(
13243
13842
  (selected) => !currentAddOns.some((current) => selected.id === current.id)
13244
13843
  );
@@ -13252,7 +13851,7 @@ var Sidebar = ({
13252
13851
  willAddOnsChange: willAddOnsChange2
13253
13852
  };
13254
13853
  }, [currentAddOns, selectedAddOns]);
13255
- const isSelectedPlanTrialable = isHydratedPlan(selectedPlan) && selectedPlan?.companyCanTrial === true && selectedPlan?.isTrialable === true;
13854
+ const isSelectedPlanTrialable = selectedPlan?.companyCanTrial === true && selectedPlan?.isTrialable === true;
13256
13855
  const now = /* @__PURE__ */ new Date();
13257
13856
  const trialEndsOn = new Date(now);
13258
13857
  if (isSelectedPlanTrialable && selectedPlan.trialDays) {
@@ -13312,7 +13911,7 @@ var Sidebar = ({
13312
13911
  $justifyContent: "space-between",
13313
13912
  $alignItems: "center",
13314
13913
  $gap: "1rem",
13315
- ...willPlanChange && {
13914
+ ...selectedPlan && !selectedPlan.current && {
13316
13915
  $opacity: "0.625",
13317
13916
  $textDecoration: "line-through",
13318
13917
  $color: settings.theme.typography.heading4.color
@@ -13332,7 +13931,7 @@ var Sidebar = ({
13332
13931
  ]
13333
13932
  }
13334
13933
  ),
13335
- willPlanChange && /* @__PURE__ */ jsxs9(Box, { children: [
13934
+ selectedPlan && !selectedPlan.current && /* @__PURE__ */ jsxs9(Box, { children: [
13336
13935
  /* @__PURE__ */ jsx14(
13337
13936
  Box,
13338
13937
  {
@@ -13834,8 +14433,6 @@ var AddOns = ({ addOns, toggle, isLoading, period }) => {
13834
14433
  $gap: "1rem",
13835
14434
  children: addOns.map((addOn, index) => {
13836
14435
  const { price, currency } = getAddOnPrice(addOn, period) || {};
13837
- const isAddOnValid = isHydratedPlan(addOn) && addOn.valid;
13838
- const isAddOnCurrent = isHydratedPlan(addOn) && addOn.current;
13839
14436
  const displayableEntitlements = addOn.entitlements?.filter(
13840
14437
  (entitlement) => entitlement.valueType === "unlimited" || entitlement.priceBehavior && [
13841
14438
  "pay_as_you_go" /* PayAsYouGo */,
@@ -13906,7 +14503,7 @@ var AddOns = ({ addOns, toggle, isLoading, period }) => {
13906
14503
  }
13907
14504
  )
13908
14505
  ] }) }),
13909
- isAddOnCurrent && /* @__PURE__ */ jsx15(
14506
+ addOn.current && /* @__PURE__ */ jsx15(
13910
14507
  Flex,
13911
14508
  {
13912
14509
  $position: "absolute",
@@ -14026,7 +14623,7 @@ var AddOns = ({ addOns, toggle, isLoading, period }) => {
14026
14623
  Button,
14027
14624
  {
14028
14625
  type: "button",
14029
- disabled: isLoading || !isAddOnValid,
14626
+ disabled: isLoading || !addOn.valid,
14030
14627
  onClick: () => toggle(addOn.id),
14031
14628
  $size: "sm",
14032
14629
  $color: "primary",
@@ -14038,13 +14635,13 @@ var AddOns = ({ addOns, toggle, isLoading, period }) => {
14038
14635
  Button,
14039
14636
  {
14040
14637
  type: "button",
14041
- disabled: isLoading || !isAddOnValid,
14638
+ disabled: isLoading || !addOn.valid,
14042
14639
  onClick: () => toggle(addOn.id),
14043
14640
  $size: "sm",
14044
- $color: isAddOnCurrent ? "danger" : "primary",
14045
- $variant: isAddOnCurrent ? "ghost" : "text",
14641
+ $color: addOn.current ? "danger" : "primary",
14642
+ $variant: addOn.current ? "ghost" : "text",
14046
14643
  $fullWidth: true,
14047
- children: isAddOnCurrent ? t2("Remove add-on") : /* @__PURE__ */ jsxs10(Fragment5, { children: [
14644
+ children: addOn.current ? t2("Remove add-on") : /* @__PURE__ */ jsxs10(Fragment5, { children: [
14048
14645
  /* @__PURE__ */ jsx15(Icon3, { name: "check-rounded", size: "sm" }),
14049
14646
  t2("Selected")
14050
14647
  ] })
@@ -14289,7 +14886,7 @@ var Navigation = ({
14289
14886
  };
14290
14887
 
14291
14888
  // src/components/shared/checkout-dialog/Plan.tsx
14292
- import { Fragment as Fragment8, useEffect as useEffect5, useMemo as useMemo8, useState as useState9 } from "react";
14889
+ import { Fragment as Fragment8, useEffect as useEffect4, useMemo as useMemo9, useState as useState9 } from "react";
14293
14890
 
14294
14891
  // src/components/shared/checkout-dialog/styles.ts
14295
14892
  var FlexWithAlignEnd = dt(Flex)`
@@ -14301,7 +14898,7 @@ import { Fragment as Fragment9, jsx as jsx19, jsxs as jsxs14 } from "react/jsx-r
14301
14898
  var Selected = ({ isCurrent = false, isTrial = false }) => {
14302
14899
  const { t: t2 } = useTranslation();
14303
14900
  const { settings } = useEmbed();
14304
- const text = useMemo8(() => {
14901
+ const text = useMemo9(() => {
14305
14902
  if (isCurrent) {
14306
14903
  return isTrial ? t2("Trial in progress") : t2("Current plan");
14307
14904
  }
@@ -14337,22 +14934,16 @@ var PlanButtonGroup = ({
14337
14934
  }) => {
14338
14935
  const { t: t2 } = useTranslation();
14339
14936
  const { data } = useEmbed();
14340
- const isTrialing = useMemo8(() => {
14341
- return isCheckoutData(data) && data.subscription?.status === "trialing" || false;
14937
+ const isTrialing = useMemo9(() => {
14938
+ return data?.subscription?.status === "trialing" || false;
14342
14939
  }, [data]);
14343
- const { isCurrentPlan, isValidPlan } = useMemo8(() => {
14344
- if (isCheckoutData(data)) {
14345
- return {
14346
- isCurrentPlan: data.company?.plan?.id === plan.id,
14347
- isValidPlan: isHydratedPlan(plan) && plan.valid
14348
- };
14349
- }
14940
+ const { isCurrentPlan, isValidPlan } = useMemo9(() => {
14350
14941
  return {
14351
- isCurrentPlan: false,
14352
- isValidPlan: true
14942
+ isCurrentPlan: data?.company?.plan?.id === plan.id,
14943
+ isValidPlan: plan.valid
14353
14944
  };
14354
- }, [data, plan]);
14355
- if (isHydratedPlan(plan) && plan.companyCanTrial && plan.isTrialable) {
14945
+ }, [plan.id, plan.valid, data?.company?.plan?.id]);
14946
+ if (plan.companyCanTrial && plan.isTrialable) {
14356
14947
  return /* @__PURE__ */ jsxs14(Flex, { $flexDirection: "column", $gap: "1.5rem", children: [
14357
14948
  !isTrialing && /* @__PURE__ */ jsx19(Fragment9, { children: isSelected && shouldTrial ? /* @__PURE__ */ jsx19(Selected, { isCurrent: isCurrentPlan, isTrial: shouldTrial }) : /* @__PURE__ */ jsxs14(Flex, { $flexDirection: "column", $gap: "0.5rem", children: [
14358
14949
  /* @__PURE__ */ jsx19(
@@ -14380,7 +14971,7 @@ var PlanButtonGroup = ({
14380
14971
  children: plan.custom ? plan.customPlanConfig?.ctaText ?? t2("Talk to support") : !isValidPlan ? /* @__PURE__ */ jsx19(Text, { as: Box, $align: "center", children: t2("Over plan limit") }) : t2("Start X day trial", { days: plan.trialDays })
14381
14972
  }
14382
14973
  ),
14383
- isHydratedPlan(plan) && !plan.valid && /* @__PURE__ */ jsx19(UsageViolationText, { violations: plan.usageViolations })
14974
+ !plan.valid && /* @__PURE__ */ jsx19(UsageViolationText, { violations: plan.usageViolations })
14384
14975
  ] }) }),
14385
14976
  !plan.custom && /* @__PURE__ */ jsx19(Fragment9, { children: isSelected && (!shouldTrial || isTrialing) ? /* @__PURE__ */ jsx19(Selected, { isCurrent: isCurrentPlan }) : /* @__PURE__ */ jsxs14(Flex, { $flexDirection: "column", $gap: "0.5rem", children: [
14386
14977
  /* @__PURE__ */ jsx19(
@@ -14398,7 +14989,7 @@ var PlanButtonGroup = ({
14398
14989
  children: !isValidPlan ? /* @__PURE__ */ jsx19(Box, { $textAlign: "center", children: /* @__PURE__ */ jsx19(Text, { as: Box, $align: "center", children: t2("Over plan limit") }) }) : t2("Choose plan")
14399
14990
  }
14400
14991
  ),
14401
- isHydratedPlan(plan) && !plan.valid && /* @__PURE__ */ jsx19(UsageViolationText, { violations: plan.usageViolations })
14992
+ !plan.valid && /* @__PURE__ */ jsx19(UsageViolationText, { violations: plan.usageViolations })
14402
14993
  ] }) })
14403
14994
  ] });
14404
14995
  }
@@ -14425,7 +15016,7 @@ var PlanButtonGroup = ({
14425
15016
  children: plan.custom ? plan.customPlanConfig?.ctaText ?? t2("Talk to support") : !isValidPlan ? /* @__PURE__ */ jsx19(Text, { as: Box, $align: "center", children: t2("Over plan limit") }) : t2("Choose plan")
14426
15017
  }
14427
15018
  ),
14428
- isHydratedPlan(plan) && !plan.valid && /* @__PURE__ */ jsx19(UsageViolationText, { violations: plan.usageViolations })
15019
+ !plan.valid && /* @__PURE__ */ jsx19(UsageViolationText, { violations: plan.usageViolations })
14429
15020
  ] });
14430
15021
  };
14431
15022
  var Plan = ({
@@ -14442,25 +15033,19 @@ var Plan = ({
14442
15033
  const [entitlementCounts, setEntitlementCounts] = useState9(
14443
15034
  () => plans.reduce(entitlementCountsReducer, {})
14444
15035
  );
14445
- const { isTrialing, showCredits, showPeriodToggle, showZeroPriceAsFree } = useMemo8(() => {
14446
- const showCredits2 = data?.showCredits ?? true;
14447
- const showPeriodToggle2 = data?.showPeriodToggle ?? true;
14448
- const showZeroPriceAsFree2 = data?.showZeroPriceAsFree ?? false;
14449
- if (isCheckoutData(data)) {
14450
- return {
14451
- isTrialing: data.subscription?.status === "trialing",
14452
- showCredits: showCredits2,
14453
- showPeriodToggle: showPeriodToggle2,
14454
- showZeroPriceAsFree: showZeroPriceAsFree2
14455
- };
14456
- }
15036
+ const { isTrialing, showCredits, showPeriodToggle, showZeroPriceAsFree } = useMemo9(() => {
14457
15037
  return {
14458
- isTrialing: false,
14459
- showCredits: showCredits2,
14460
- showPeriodToggle: showPeriodToggle2,
14461
- showZeroPriceAsFree: showZeroPriceAsFree2
15038
+ isTrialing: data?.subscription?.status === "trialing",
15039
+ showCredits: data?.showCredits ?? true,
15040
+ showPeriodToggle: data?.showPeriodToggle ?? true,
15041
+ showZeroPriceAsFree: data?.showZeroPriceAsFree ?? false
14462
15042
  };
14463
- }, [data]);
15043
+ }, [
15044
+ data?.showCredits,
15045
+ data?.showPeriodToggle,
15046
+ data?.showZeroPriceAsFree,
15047
+ data?.subscription?.status
15048
+ ]);
14464
15049
  const handleToggleShowAll = (id) => {
14465
15050
  setEntitlementCounts((prev2) => {
14466
15051
  const count = prev2[id] ? { ...prev2[id] } : void 0;
@@ -14476,7 +15061,7 @@ var Plan = ({
14476
15061
  return prev2;
14477
15062
  });
14478
15063
  };
14479
- useEffect5(() => {
15064
+ useEffect4(() => {
14480
15065
  setEntitlementCounts(plans.reduce(entitlementCountsReducer, {}));
14481
15066
  }, [plans]);
14482
15067
  const cardPadding = settings.theme.card.padding / TEXT_BASE_SIZE;
@@ -14606,7 +15191,7 @@ var Plan = ({
14606
15191
  })
14607
15192
  }
14608
15193
  ),
14609
- isHydratedPlan(plan) && plan.current && /* @__PURE__ */ jsx19(
15194
+ plan.current && /* @__PURE__ */ jsx19(
14610
15195
  Flex,
14611
15196
  {
14612
15197
  $position: "absolute",
@@ -14919,7 +15504,7 @@ var Usage = ({ entitlements, updateQuantity, period }) => {
14919
15504
  {
14920
15505
  $size: "lg",
14921
15506
  type: "number",
14922
- value: entitlement.quantity,
15507
+ defaultValue: entitlement.quantity,
14923
15508
  min: 0,
14924
15509
  autoFocus: true,
14925
15510
  onFocus: (event) => {
@@ -15007,8 +15592,8 @@ var createActiveUsageBasedEntitlementsReducer = (entitlements, period) => (acc,
15007
15592
  const featureUsage = entitlements.find(
15008
15593
  (usage2) => usage2.feature?.id === entitlement.feature?.id
15009
15594
  );
15010
- const allocation = featureUsage?.allocation || 0;
15011
- const usage = featureUsage?.usage || 0;
15595
+ const allocation = featureUsage?.allocation ?? entitlement.valueNumeric ?? 0;
15596
+ const usage = featureUsage?.usage ?? 0;
15012
15597
  acc.push({
15013
15598
  ...entitlement,
15014
15599
  allocation,
@@ -15022,15 +15607,13 @@ var CheckoutDialog = ({ top = 0 }) => {
15022
15607
  const { t: t2 } = useTranslation();
15023
15608
  const { data, settings, isPending, checkoutState, previewCheckout } = useEmbed();
15024
15609
  const isLightBackground = useIsLightBackground();
15025
- const contentRef = useRef7(null);
15026
- const checkoutRef = useRef7(null);
15610
+ const contentRef = useRef6(null);
15611
+ const checkoutRef = useRef6(null);
15027
15612
  const [confirmPaymentIntentProps, setConfirmPaymentIntentProps] = useState10(void 0);
15028
15613
  const [charges, setCharges] = useState10();
15029
15614
  const [paymentMethodId, setPaymentMethodId] = useState10(
15030
15615
  () => {
15031
- if (isCheckoutData(data)) {
15032
- return (data.subscription?.paymentMethod || data.company?.defaultPaymentMethod)?.externalId;
15033
- }
15616
+ return data?.subscription?.paymentMethod?.externalId || data?.company?.defaultPaymentMethod?.externalId;
15034
15617
  }
15035
15618
  );
15036
15619
  const [isLoading, setIsLoading] = useState10(false);
@@ -15040,26 +15623,22 @@ var CheckoutDialog = ({ top = 0 }) => {
15040
15623
  currentEntitlements,
15041
15624
  showPeriodToggle,
15042
15625
  trialPaymentMethodRequired
15043
- } = useMemo9(() => {
15044
- const showPeriodToggle2 = data?.showPeriodToggle ?? true;
15045
- if (isCheckoutData(data)) {
15046
- return {
15047
- currentPlanId: data.company?.plan?.id,
15048
- currentEntitlements: data.featureUsage ? data.featureUsage.features : [],
15049
- showPeriodToggle: showPeriodToggle2,
15050
- trialPaymentMethodRequired: data.trialPaymentMethodRequired === true
15051
- };
15052
- }
15626
+ } = useMemo10(() => {
15053
15627
  return {
15054
- currentPlanId: void 0,
15055
- currentEntitlements: [],
15056
- showPeriodToggle: showPeriodToggle2,
15057
- trialPaymentMethodRequired: false
15628
+ currentPlanId: data?.company?.plan?.id,
15629
+ currentEntitlements: data?.featureUsage ? data.featureUsage.features : [],
15630
+ showPeriodToggle: data?.showPeriodToggle ?? true,
15631
+ trialPaymentMethodRequired: data?.trialPaymentMethodRequired === true
15058
15632
  };
15059
- }, [data]);
15060
- const currentPeriod = useMemo9(
15061
- () => checkoutState?.period || isCheckoutData(data) && data.company?.plan?.planPeriod || "month",
15062
- [data, checkoutState?.period]
15633
+ }, [
15634
+ data?.company?.plan?.id,
15635
+ data?.featureUsage,
15636
+ data?.showPeriodToggle,
15637
+ data?.trialPaymentMethodRequired
15638
+ ]);
15639
+ const currentPeriod = useMemo10(
15640
+ () => checkoutState?.period || data?.company?.plan?.planPeriod || "month",
15641
+ [data?.company?.plan?.planPeriod, checkoutState?.period]
15063
15642
  );
15064
15643
  const [planPeriod, setPlanPeriod] = useState10(currentPeriod);
15065
15644
  const {
@@ -15072,30 +15651,24 @@ var CheckoutDialog = ({ top = 0 }) => {
15072
15651
  const [selectedPlan, setSelectedPlan] = useState10(
15073
15652
  () => {
15074
15653
  return availablePlans.find(
15075
- (plan) => checkoutState?.planId ? plan.id === checkoutState.planId : isHydratedPlan(plan) && plan.current
15654
+ (plan) => checkoutState?.planId ? plan.id === checkoutState.planId : plan.current
15076
15655
  );
15077
15656
  }
15078
15657
  );
15079
15658
  const [shouldTrial, setShouldTrial] = useState10(false);
15080
15659
  const [addOns, setAddOns] = useState10(() => {
15081
- if (isCheckoutData(data)) {
15082
- return availableAddOns.map((addOn) => ({
15083
- ...addOn,
15084
- isSelected: typeof checkoutState?.addOnId !== "undefined" ? addOn.id === checkoutState.addOnId : (data.company?.addOns || []).some(
15085
- (currentAddOn) => addOn.id === currentAddOn.id
15086
- )
15087
- }));
15088
- }
15089
- return [];
15660
+ return availableAddOns.map((addOn) => ({
15661
+ ...addOn,
15662
+ isSelected: typeof checkoutState?.addOnId !== "undefined" ? addOn.id === checkoutState.addOnId : (data?.company?.addOns || []).some(
15663
+ (currentAddOn) => addOn.id === currentAddOn.id
15664
+ )
15665
+ }));
15090
15666
  });
15091
15667
  const [creditBundles, setCreditBundles] = useState10(() => {
15092
- if (isCheckoutData(data)) {
15093
- return data.creditBundles.map((bundle) => ({
15094
- ...bundle,
15095
- count: 0
15096
- }));
15097
- }
15098
- return [];
15668
+ return (data?.creditBundles || []).map((bundle) => ({
15669
+ ...bundle,
15670
+ count: 0
15671
+ }));
15099
15672
  });
15100
15673
  const [usageBasedEntitlements, setUsageBasedEntitlements] = useState10(
15101
15674
  () => (selectedPlan?.entitlements || []).reduce(
@@ -15107,9 +15680,7 @@ var CheckoutDialog = ({ top = 0 }) => {
15107
15680
  )
15108
15681
  );
15109
15682
  const [addOnUsageBasedEntitlements, setAddOnUsageBasedEntitlements] = useState10(() => {
15110
- if (!isCheckoutData(data)) return [];
15111
- const currentAddOns = data.company?.addOns || [];
15112
- return currentAddOns.flatMap((currentAddOn) => {
15683
+ return (data?.company?.addOns || []).flatMap((currentAddOn) => {
15113
15684
  const availableAddOn = availableAddOns.find(
15114
15685
  (available) => available.id === currentAddOn.id
15115
15686
  );
@@ -15123,13 +15694,13 @@ var CheckoutDialog = ({ top = 0 }) => {
15123
15694
  );
15124
15695
  });
15125
15696
  });
15126
- const payInAdvanceEntitlements = useMemo9(
15697
+ const payInAdvanceEntitlements = useMemo10(
15127
15698
  () => usageBasedEntitlements.filter(
15128
15699
  (entitlement) => entitlement.priceBehavior === "pay_in_advance" /* PayInAdvance */
15129
15700
  ),
15130
15701
  [usageBasedEntitlements]
15131
15702
  );
15132
- const addOnPayInAdvanceEntitlements = useMemo9(
15703
+ const addOnPayInAdvanceEntitlements = useMemo10(
15133
15704
  () => addOnUsageBasedEntitlements.filter(
15134
15705
  (entitlement) => entitlement.priceBehavior === "pay_in_advance" /* PayInAdvance */
15135
15706
  ),
@@ -15137,12 +15708,12 @@ var CheckoutDialog = ({ top = 0 }) => {
15137
15708
  );
15138
15709
  const [promoCode, setPromoCode] = useState10(null);
15139
15710
  const [isPaymentMethodRequired, setIsPaymentMethodRequired] = useState10(false);
15140
- const willTrialWithoutPaymentMethod = useMemo9(
15711
+ const willTrialWithoutPaymentMethod = useMemo10(
15141
15712
  () => shouldTrial && !trialPaymentMethodRequired,
15142
15713
  [shouldTrial, trialPaymentMethodRequired]
15143
15714
  );
15144
- const isSelectedPlanTrialable = isHydratedPlan(selectedPlan) && selectedPlan.isTrialable && selectedPlan.companyCanTrial;
15145
- const checkoutStages = useMemo9(() => {
15715
+ const isSelectedPlanTrialable = selectedPlan && selectedPlan.isTrialable && selectedPlan.companyCanTrial;
15716
+ const checkoutStages = useMemo10(() => {
15146
15717
  const stages = [];
15147
15718
  if (availablePlans.length > 0) {
15148
15719
  stages.push({
@@ -15355,24 +15926,13 @@ var CheckoutDialog = ({ top = 0 }) => {
15355
15926
  (updates) => {
15356
15927
  const plan = updates.plan;
15357
15928
  const period = updates.period || planPeriod;
15358
- const entitlements = plan.entitlements.reduce(
15359
- (acc, entitlement) => {
15360
- if (entitlement.priceBehavior && (period === "month" && entitlement.meteredMonthlyPrice || period === "year" && entitlement.meteredYearlyPrice)) {
15361
- const allocation = entitlement.valueNumeric || 0;
15362
- acc.push({
15363
- ...entitlement,
15364
- allocation,
15365
- usage: 0,
15366
- quantity: allocation
15367
- });
15368
- }
15369
- return acc;
15370
- },
15929
+ const updatedUsageBasedEntitlements = plan.entitlements.reduce(
15930
+ createActiveUsageBasedEntitlementsReducer(currentEntitlements, period),
15371
15931
  []
15372
15932
  );
15373
15933
  if (plan.id !== selectedPlan?.id) {
15374
15934
  setSelectedPlan(plan);
15375
- setUsageBasedEntitlements(entitlements);
15935
+ setUsageBasedEntitlements(updatedUsageBasedEntitlements);
15376
15936
  }
15377
15937
  const updatedShouldTrial = updates.shouldTrial ?? shouldTrial;
15378
15938
  setShouldTrial(updatedShouldTrial);
@@ -15392,7 +15952,7 @@ var CheckoutDialog = ({ top = 0 }) => {
15392
15952
  addOns: [],
15393
15953
  payInAdvanceEntitlements: []
15394
15954
  } : {
15395
- payInAdvanceEntitlements: entitlements.filter(
15955
+ payInAdvanceEntitlements: updatedUsageBasedEntitlements.filter(
15396
15956
  ({ priceBehavior }) => priceBehavior === "pay_in_advance" /* PayInAdvance */
15397
15957
  )
15398
15958
  }
@@ -15401,6 +15961,7 @@ var CheckoutDialog = ({ top = 0 }) => {
15401
15961
  [
15402
15962
  selectedPlan?.id,
15403
15963
  planPeriod,
15964
+ currentEntitlements,
15404
15965
  shouldTrial,
15405
15966
  willTrialWithoutPaymentMethod,
15406
15967
  handlePreviewCheckout
@@ -15499,12 +16060,18 @@ var CheckoutDialog = ({ top = 0 }) => {
15499
16060
  },
15500
16061
  [handlePreviewCheckout]
15501
16062
  );
15502
- useEffect6(() => {
16063
+ useEffect5(() => {
15503
16064
  if (selectedPlan) {
15504
16065
  selectPlan({ plan: selectedPlan, period: currentPeriod });
15505
16066
  }
15506
16067
  }, []);
15507
- useEffect6(() => {
16068
+ useEffect5(() => {
16069
+ const plan = availablePlans.find(
16070
+ (plan2) => checkoutState?.planId ? plan2.id === checkoutState.planId : plan2.current
16071
+ );
16072
+ setSelectedPlan(plan);
16073
+ }, [availablePlans, checkoutState?.planId]);
16074
+ useEffect5(() => {
15508
16075
  setAddOns((prevAddOns) => {
15509
16076
  return availableAddOns.filter((availAddOn) => {
15510
16077
  if (!selectedPlan) {
@@ -15525,8 +16092,8 @@ var CheckoutDialog = ({ top = 0 }) => {
15525
16092
  };
15526
16093
  });
15527
16094
  });
15528
- }, [availableAddOns, data?.addOnCompatibilities, selectedPlan]);
15529
- useEffect6(() => {
16095
+ }, [data?.addOnCompatibilities, availableAddOns, selectedPlan]);
16096
+ useEffect5(() => {
15530
16097
  if (charges) {
15531
16098
  checkoutRef.current?.scrollTo({
15532
16099
  top: 0,
@@ -15739,11 +16306,11 @@ var CheckoutDialog = ({ top = 0 }) => {
15739
16306
  };
15740
16307
 
15741
16308
  // src/components/shared/payment-dialog/PaymentDialog.tsx
15742
- import { useRef as useRef8 } from "react";
16309
+ import { useRef as useRef7 } from "react";
15743
16310
  import { jsx as jsx22, jsxs as jsxs17 } from "react/jsx-runtime";
15744
16311
  var PaymentDialog = ({ top = 0 }) => {
15745
16312
  const { t: t2 } = useTranslation();
15746
- const contentRef = useRef8(null);
16313
+ const contentRef = useRef7(null);
15747
16314
  return /* @__PURE__ */ jsxs17(Modal2, { size: "md", top, contentRef, children: [
15748
16315
  /* @__PURE__ */ jsx22(ModalHeader, { bordered: true, children: /* @__PURE__ */ jsx22(Text, { $size: 18, children: t2("Edit payment method") }) }),
15749
16316
  /* @__PURE__ */ jsx22(PaymentMethodDetails, {})
@@ -15825,11 +16392,8 @@ var PaymentForm = ({ onConfirm, financeData }) => {
15825
16392
  const [isConfirmed, setIsConfirmed] = useState11(false);
15826
16393
  const [isPaymentComplete, setIsPaymentComplete] = useState11(false);
15827
16394
  const [isAddressComplete, setIsAddressComplete] = useState11(() => {
15828
- if (!isCheckoutData(data)) {
15829
- return true;
15830
- }
15831
16395
  const shouldCollectAddress = shouldCollectBillingAddress(
15832
- data.checkoutSettings.collectAddress,
16396
+ data?.checkoutSettings.collectAddress ?? false,
15833
16397
  financeData
15834
16398
  );
15835
16399
  return !shouldCollectAddress;
@@ -15888,7 +16452,7 @@ var PaymentForm = ({ onConfirm, financeData }) => {
15888
16452
  }
15889
16453
  }
15890
16454
  ) }),
15891
- stripe && isCheckoutData(data) && data.checkoutSettings.collectEmail && /* @__PURE__ */ jsxs18(Box, { "data-field": "name", $marginBottom: "1.5rem", $verticalAlign: "top", children: [
16455
+ stripe && data?.checkoutSettings.collectEmail && /* @__PURE__ */ jsxs18(Box, { "data-field": "name", $marginBottom: "1.5rem", $verticalAlign: "top", children: [
15892
16456
  /* @__PURE__ */ jsx23(Label, { htmlFor: "email", children: "Email" }),
15893
16457
  /* @__PURE__ */ jsx23(
15894
16458
  Input2,
@@ -15902,16 +16466,16 @@ var PaymentForm = ({ onConfirm, financeData }) => {
15902
16466
  }
15903
16467
  )
15904
16468
  ] }),
15905
- isCheckoutData(data) && (shouldCollectBillingAddress(
15906
- data.checkoutSettings.collectAddress,
16469
+ (shouldCollectBillingAddress(
16470
+ data?.checkoutSettings.collectAddress ?? false,
15907
16471
  financeData
15908
- ) || data.checkoutSettings.collectPhone) && /* @__PURE__ */ jsx23(Box, { $marginBottom: "3.5rem", children: /* @__PURE__ */ jsx23(
16472
+ ) || data?.checkoutSettings.collectPhone) && /* @__PURE__ */ jsx23(Box, { $marginBottom: "3.5rem", children: /* @__PURE__ */ jsx23(
15909
16473
  AddressElement,
15910
16474
  {
15911
16475
  options: {
15912
16476
  mode: "billing",
15913
16477
  fields: {
15914
- phone: data.checkoutSettings.collectPhone ? "always" : "never"
16478
+ phone: data?.checkoutSettings.collectPhone ? "always" : "never"
15915
16479
  }
15916
16480
  },
15917
16481
  id: "address-element",
@@ -15939,7 +16503,7 @@ var PaymentForm = ({ onConfirm, financeData }) => {
15939
16503
  };
15940
16504
 
15941
16505
  // src/components/shared/period-toggle/PeriodToggle.tsx
15942
- import { useMemo as useMemo10 } from "react";
16506
+ import { useMemo as useMemo11 } from "react";
15943
16507
  import { jsx as jsx24 } from "react/jsx-runtime";
15944
16508
  var PeriodToggle = ({
15945
16509
  options,
@@ -15950,7 +16514,7 @@ var PeriodToggle = ({
15950
16514
  const { t: t2 } = useTranslation();
15951
16515
  const { settings } = useEmbed();
15952
16516
  const isLightBackground = useIsLightBackground();
15953
- const savingsPercentage = useMemo10(() => {
16517
+ const savingsPercentage = useMemo11(() => {
15954
16518
  if (selectedPlan) {
15955
16519
  const monthlyBillingPrice = getPlanPrice(selectedPlan, "month");
15956
16520
  const yearlyBillingPrice = getPlanPrice(selectedPlan, "year");
@@ -15963,6 +16527,7 @@ var PeriodToggle = ({
15963
16527
  return /* @__PURE__ */ jsx24(
15964
16528
  Flex,
15965
16529
  {
16530
+ "data-testid": "sch-period-toggle",
15966
16531
  $margin: 0,
15967
16532
  $backgroundColor: settings.theme.card.background,
15968
16533
  $borderWidth: "1px",
@@ -15977,9 +16542,11 @@ var PeriodToggle = ({
15977
16542
  },
15978
16543
  children: options.map((option) => {
15979
16544
  const element = /* @__PURE__ */ jsx24(
15980
- Flex,
16545
+ Button,
15981
16546
  {
15982
- tabIndex: 0,
16547
+ "data-testid": "sch-period-toggle-button",
16548
+ $size: "sm",
16549
+ $variant: "text",
15983
16550
  onClick: () => onSelect(option),
15984
16551
  onKeyDown: (event) => {
15985
16552
  if (event.key === "Enter" || event.key === " ") {
@@ -15987,19 +16554,22 @@ var PeriodToggle = ({
15987
16554
  onSelect(option);
15988
16555
  }
15989
16556
  },
15990
- $justifyContent: "center",
15991
- $alignItems: "center",
15992
- $flexBasis: "50%",
15993
- $whiteSpace: "nowrap",
15994
- $padding: "0.75rem 1rem",
15995
- ...option === selectedOption && {
15996
- $backgroundColor: isLightBackground ? "hsla(0, 0%, 0%, 0.125)" : "hsla(0, 0%, 100%, 0.125)"
16557
+ style: {
16558
+ flexBasis: "50%",
16559
+ textDecoration: "none",
16560
+ whiteSpace: "nowrap",
16561
+ borderRadius: "2.5rem",
16562
+ ...option === selectedOption && {
16563
+ backgroundColor: isLightBackground ? "hsla(0, 0%, 0%, 0.125)" : "hsla(0, 0%, 100%, 0.125)"
16564
+ }
15997
16565
  },
15998
- $borderRadius: "2.5rem",
15999
16566
  children: /* @__PURE__ */ jsx24(
16000
16567
  Text,
16001
16568
  {
16002
- style: { flexShrink: 0 },
16569
+ style: {
16570
+ flexShrink: 0,
16571
+ color: settings.theme.typography.text.color
16572
+ },
16003
16573
  $size: 15,
16004
16574
  $weight: option === selectedOption ? 600 : 400,
16005
16575
  children: t2("Billed", { period: adjectify(option) })
@@ -16008,7 +16578,7 @@ var PeriodToggle = ({
16008
16578
  },
16009
16579
  option
16010
16580
  );
16011
- if (option === "year" && savingsPercentage > 0) {
16581
+ if (option === "year") {
16012
16582
  return /* @__PURE__ */ jsx24(
16013
16583
  Tooltip,
16014
16584
  {
@@ -16030,10 +16600,10 @@ var PeriodToggle = ({
16030
16600
  };
16031
16601
 
16032
16602
  // src/components/shared/pricing-tiers-tooltip/PricingTiersTooltip.tsx
16033
- import { useMemo as useMemo12 } from "react";
16603
+ import { useMemo as useMemo13 } from "react";
16034
16604
 
16035
16605
  // src/components/shared/pricing-tiers-tooltip/PriceText.tsx
16036
- import { useMemo as useMemo11 } from "react";
16606
+ import { useMemo as useMemo12 } from "react";
16037
16607
  import { Fragment as Fragment11, jsx as jsx25, jsxs as jsxs19 } from "react/jsx-runtime";
16038
16608
  var PriceText = ({
16039
16609
  feature,
@@ -16043,7 +16613,7 @@ var PriceText = ({
16043
16613
  perUnitPrice = 0
16044
16614
  }) => {
16045
16615
  const { settings } = useEmbed();
16046
- const text = useMemo11(() => {
16616
+ const text = useMemo12(() => {
16047
16617
  if (!flatAmount && perUnitPrice) {
16048
16618
  return /* @__PURE__ */ jsxs19(Fragment11, { children: [
16049
16619
  formatCurrency(perUnitPrice, currency),
@@ -16091,19 +16661,22 @@ var PricingTiersTooltip = ({
16091
16661
  const { t: t2 } = useTranslation();
16092
16662
  const { settings } = useEmbed();
16093
16663
  const isLightBackground = useIsLightBackground();
16094
- const tiers = useMemo12(() => {
16095
- let start = 1;
16096
- return priceTiers.map((tier) => {
16097
- const { upTo, ...rest } = tier;
16098
- const end = upTo ?? Infinity;
16099
- const mapped = {
16100
- ...rest,
16101
- from: start,
16102
- to: end
16103
- };
16104
- start = end + 1;
16105
- return mapped;
16106
- });
16664
+ const { tiers } = useMemo13(() => {
16665
+ return priceTiers.reduce(
16666
+ (acc, tier) => {
16667
+ const end = tier.upTo ?? Infinity;
16668
+ acc.tiers.push({
16669
+ flatAmount: tier.flatAmount ?? void 0,
16670
+ perUnitPrice: tier.perUnitPrice ?? void 0,
16671
+ perUnitPriceDecimal: tier.perUnitPriceDecimal ?? void 0,
16672
+ from: acc.start,
16673
+ to: end
16674
+ });
16675
+ acc.start = end + 1;
16676
+ return acc;
16677
+ },
16678
+ { start: 1, tiers: [] }
16679
+ );
16107
16680
  }, [priceTiers]);
16108
16681
  if (!priceTiers.length) {
16109
16682
  return null;
@@ -16179,13 +16752,13 @@ var PricingTiersTooltip = ({
16179
16752
  };
16180
16753
 
16181
16754
  // src/components/shared/tiered-pricing-details/TieredPricingDetails.tsx
16182
- import { useMemo as useMemo13 } from "react";
16755
+ import { useMemo as useMemo14 } from "react";
16183
16756
  var TieredPricingDetails = ({
16184
16757
  entitlement,
16185
16758
  period
16186
16759
  }) => {
16187
16760
  const { t: t2 } = useTranslation();
16188
- const { currency, flatAmount, perUnitPrice, upTo } = useMemo13(() => {
16761
+ const { currency, flatAmount, perUnitPrice, upTo } = useMemo14(() => {
16189
16762
  const { currency: currency2, priceTier } = getEntitlementPrice(entitlement, period) || {};
16190
16763
  const { flatAmount: flatAmount2, perUnitPrice: perUnitPrice2, perUnitPriceDecimal, upTo: upTo2 } = priceTier?.[0] || {};
16191
16764
  return {
@@ -16233,36 +16806,32 @@ var TieredPricingDetails = ({
16233
16806
  };
16234
16807
 
16235
16808
  // src/components/shared/unsubscribe-dialog/UnsubscribeDialog.tsx
16236
- import { useMemo as useMemo14, useRef as useRef9, useState as useState12 } from "react";
16809
+ import { useMemo as useMemo15, useRef as useRef8, useState as useState12 } from "react";
16237
16810
  import { jsx as jsx27, jsxs as jsxs21 } from "react/jsx-runtime";
16238
16811
  var UnsubscribeDialog = ({ top = 0 }) => {
16239
16812
  const { t: t2 } = useTranslation();
16240
16813
  const { data, setCheckoutState } = useEmbed();
16241
- const contentRef = useRef9(null);
16814
+ const contentRef = useRef8(null);
16242
16815
  const [error, setError] = useState12();
16243
16816
  const [isLoading, setIsLoading] = useState12(false);
16244
- const { planPeriod, currentPlan, currentAddOns, featureUsage, cancelDate } = useMemo14(() => {
16245
- if (isCheckoutData(data)) {
16246
- return {
16247
- planPeriod: data.company?.plan?.planPeriod || "month",
16248
- currentPlan: data.company?.plan,
16249
- currentAddOns: data.company?.addOns || [],
16250
- featureUsage: data.featureUsage,
16251
- cancelDate: new Date(
16252
- data.subscription?.cancelAt || data.upcomingInvoice?.dueDate || Date.now()
16253
- )
16254
- };
16255
- }
16817
+ const { planPeriod, currentPlan, currentAddOns, featureUsage, cancelDate } = useMemo15(() => {
16818
+ const cancelDate2 = data?.subscription?.cancelAt || data?.upcomingInvoice?.dueDate;
16256
16819
  return {
16257
- planPeriod: "month",
16258
- currentPlan: void 0,
16259
- currentAddOns: [],
16260
- featureUsage: void 0,
16261
- cancelDate: /* @__PURE__ */ new Date()
16820
+ planPeriod: data?.company?.plan?.planPeriod || "month",
16821
+ currentPlan: data?.company?.plan,
16822
+ currentAddOns: data?.company?.addOns || [],
16823
+ featureUsage: data?.featureUsage,
16824
+ cancelDate: cancelDate2 ? new Date(cancelDate2) : /* @__PURE__ */ new Date()
16262
16825
  };
16263
- }, [data]);
16826
+ }, [
16827
+ data?.company?.addOns,
16828
+ data?.company?.plan,
16829
+ data?.featureUsage,
16830
+ data?.subscription?.cancelAt,
16831
+ data?.upcomingInvoice?.dueDate
16832
+ ]);
16264
16833
  const { plans: availablePlans, addOns: availableAddOns } = useAvailablePlans(planPeriod);
16265
- const selectedPlan = useMemo14(
16834
+ const selectedPlan = useMemo15(
16266
16835
  () => availablePlans.find((plan) => plan.id === currentPlan?.id),
16267
16836
  [currentPlan?.id, availablePlans]
16268
16837
  );
@@ -16271,7 +16840,7 @@ var UnsubscribeDialog = ({ top = 0 }) => {
16271
16840
  createActiveUsageBasedEntitlementsReducer(currentEntitlements, planPeriod),
16272
16841
  []
16273
16842
  );
16274
- const addOns = useMemo14(
16843
+ const addOns = useMemo15(
16275
16844
  () => availableAddOns.map((available) => ({
16276
16845
  ...available,
16277
16846
  isSelected: currentAddOns.some((current) => available.id === current.id) ?? false
@@ -16537,29 +17106,34 @@ var StyledViewport = dt.div.withConfig({
16537
17106
  import { Fragment as Fragment13, jsx as jsx31, jsxs as jsxs24 } from "react/jsx-runtime";
16538
17107
  var Viewport = forwardRef5(
16539
17108
  ({ children, portal, ...props }, ref) => {
17109
+ const portalRef = useRef9(portal || document.body);
16540
17110
  const { data, layout, settings } = useEmbed();
16541
17111
  const [top, setTop] = useState13(0);
16542
- const { canCheckout, isBadgeVisible } = useMemo15(() => {
17112
+ const { canCheckout, isBadgeVisible } = useMemo16(() => {
16543
17113
  return {
16544
17114
  canCheckout: data?.capabilities?.checkout ?? true,
16545
17115
  isBadgeVisible: !data?.capabilities?.badgeVisibility || settings.badge?.visibility !== "hidden"
16546
17116
  };
16547
- }, [data, settings]);
17117
+ }, [
17118
+ data?.capabilities?.badgeVisibility,
17119
+ data?.capabilities?.checkout,
17120
+ settings.badge?.visibility
17121
+ ]);
16548
17122
  useLayoutEffect5(() => {
16549
- const parent = portal || document.body;
17123
+ const portal2 = portalRef.current;
16550
17124
  const setModalY = (0, import_debounce3.default)(() => {
16551
17125
  const value = Math.abs(
16552
- (parent === document.body ? window.scrollY : parent.scrollTop) ?? 0
17126
+ (portal2 === document.body ? window.scrollY : portal2.scrollTop) ?? 0
16553
17127
  );
16554
17128
  setTop(value);
16555
17129
  }, 250);
16556
- parent.style.overflow = layout === "checkout" || layout === "unsubscribe" || layout === "payment" ? "hidden" : "";
17130
+ portal2.style.overflow = layout === "checkout" || layout === "unsubscribe" || layout === "payment" ? "hidden" : "";
16557
17131
  window.addEventListener("scroll", setModalY);
16558
17132
  return () => {
16559
17133
  window.removeEventListener("scroll", setModalY);
16560
- parent.style.overflow = "";
17134
+ portal2.style.overflow = "";
16561
17135
  };
16562
- }, [portal, layout]);
17136
+ }, [layout]);
16563
17137
  return /* @__PURE__ */ jsxs24(Fragment13, { children: [
16564
17138
  /* @__PURE__ */ jsxs24(StyledViewport, { ref, ...props, children: [
16565
17139
  /* @__PURE__ */ jsx31(RenderLayout, { children }),
@@ -16637,10 +17211,10 @@ var ButtonElement = forwardRef6(({ children, className, ...rest }, ref) => {
16637
17211
  ButtonElement.displayName = "Button";
16638
17212
 
16639
17213
  // src/components/elements/included-features/IncludedFeatures.tsx
16640
- import { forwardRef as forwardRef7, useMemo as useMemo17, useRef as useRef10, useState as useState14 } from "react";
17214
+ import { forwardRef as forwardRef7, useMemo as useMemo18, useRef as useRef10, useState as useState14 } from "react";
16641
17215
 
16642
17216
  // src/components/elements/included-features/UsageDetails.tsx
16643
- import { Fragment as Fragment14, useMemo as useMemo16 } from "react";
17217
+ import { Fragment as Fragment14, useMemo as useMemo17 } from "react";
16644
17218
  import { Fragment as Fragment15, jsx as jsx33, jsxs as jsxs25 } from "react/jsx-runtime";
16645
17219
  var UsageDetails = ({
16646
17220
  entitlement,
@@ -16659,24 +17233,17 @@ var UsageDetails = ({
16659
17233
  } = entitlement;
16660
17234
  const { t: t2 } = useTranslation();
16661
17235
  const { data } = useEmbed();
16662
- const { period, showCredits } = useMemo16(() => {
16663
- const showCredits2 = data?.showCredits ?? true;
16664
- if (isCheckoutData(data)) {
16665
- return {
16666
- period: data.company?.plan?.planPeriod || void 0,
16667
- showCredits: showCredits2
16668
- };
16669
- }
17236
+ const { period, showCredits } = useMemo17(() => {
16670
17237
  return {
16671
- period: void 0,
16672
- showCredits: showCredits2
17238
+ period: data?.company?.plan?.planPeriod || void 0,
17239
+ showCredits: data?.showCredits ?? true
16673
17240
  };
16674
- }, [data]);
16675
- const { billingPrice, cost, currentTier } = useMemo16(
17241
+ }, [data?.company?.plan?.planPeriod, data?.showCredits]);
17242
+ const { billingPrice, cost, currentTier } = useMemo17(
16676
17243
  () => getUsageDetails(entitlement, period),
16677
17244
  [entitlement, period]
16678
17245
  );
16679
- const text = useMemo16(() => {
17246
+ const text = useMemo17(() => {
16680
17247
  if (!feature) {
16681
17248
  return;
16682
17249
  }
@@ -16749,10 +17316,10 @@ var UsageDetails = ({
16749
17316
  priceBehavior,
16750
17317
  softLimit,
16751
17318
  billingPrice,
16752
- currentTier?.to,
17319
+ currentTier,
16753
17320
  showCredits
16754
17321
  ]);
16755
- const usageText = useMemo16(() => {
17322
+ const usageText = useMemo17(() => {
16756
17323
  if (!feature) {
16757
17324
  return;
16758
17325
  }
@@ -16901,36 +17468,34 @@ var IncludedFeatures = forwardRef7(({ className, ...rest }, ref) => {
16901
17468
  const props = resolveDesignProps2(rest);
16902
17469
  const { t: t2 } = useTranslation();
16903
17470
  const { data, settings } = useEmbed();
16904
- const elements = useRef10([]);
16905
- const shouldWrapChildren = useWrapChildren(elements.current);
17471
+ const elementsRef = useRef10([]);
17472
+ const shouldWrapChildren = useWrapChildren(elementsRef);
16906
17473
  const isLightBackground = useIsLightBackground();
16907
17474
  const [showCount, setShowCount] = useState14(VISIBLE_ENTITLEMENT_COUNT);
16908
- const { plan, addOns, featureUsage } = useMemo17(() => {
16909
- if (isCheckoutData(data)) {
16910
- const orderedFeatureUsage = props.visibleFeatures?.reduce(
16911
- (acc, id) => {
16912
- const mappedFeatureUsage = data.featureUsage?.features.find(
16913
- (usage) => usage.feature?.id === id
16914
- );
16915
- if (mappedFeatureUsage) {
16916
- acc.push(mappedFeatureUsage);
16917
- }
16918
- return acc;
16919
- },
16920
- []
16921
- );
16922
- return {
16923
- plan: data.company?.plan,
16924
- addOns: data.company?.addOns || [],
16925
- featureUsage: orderedFeatureUsage || data.featureUsage?.features || []
16926
- };
16927
- }
17475
+ const { plan, addOns, featureUsage } = useMemo18(() => {
17476
+ const orderedFeatureUsage = props.visibleFeatures?.reduce(
17477
+ (acc, id) => {
17478
+ const mappedFeatureUsage = data?.featureUsage?.features.find(
17479
+ (usage) => usage.feature?.id === id
17480
+ );
17481
+ if (mappedFeatureUsage) {
17482
+ acc.push(mappedFeatureUsage);
17483
+ }
17484
+ return acc;
17485
+ },
17486
+ []
17487
+ );
16928
17488
  return {
16929
- plan: void 0,
16930
- addOns: [],
16931
- featureUsage: []
17489
+ plan: data?.company?.plan,
17490
+ addOns: data?.company?.addOns || [],
17491
+ featureUsage: orderedFeatureUsage || data?.featureUsage?.features || []
16932
17492
  };
16933
- }, [props.visibleFeatures, data]);
17493
+ }, [
17494
+ props.visibleFeatures,
17495
+ data?.company?.plan,
17496
+ data?.company?.addOns,
17497
+ data?.featureUsage?.features
17498
+ ]);
16934
17499
  const featureListSize = featureUsage.length;
16935
17500
  const handleToggleShowAll = () => {
16936
17501
  setShowCount(
@@ -16960,7 +17525,7 @@ var IncludedFeatures = forwardRef7(({ className, ...rest }, ref) => {
16960
17525
  {
16961
17526
  ref: (el) => {
16962
17527
  if (el) {
16963
- elements.current.push(el);
17528
+ elementsRef.current.push(el);
16964
17529
  }
16965
17530
  },
16966
17531
  $flexWrap: "wrap",
@@ -17041,7 +17606,7 @@ var IncludedFeatures = forwardRef7(({ className, ...rest }, ref) => {
17041
17606
  IncludedFeatures.displayName = "IncludedFeatures";
17042
17607
 
17043
17608
  // src/components/elements/invoices/Invoices.tsx
17044
- import { forwardRef as forwardRef8, useCallback as useCallback11, useEffect as useEffect7, useState as useState15 } from "react";
17609
+ import { forwardRef as forwardRef8, useCallback as useCallback11, useEffect as useEffect6, useState as useState15 } from "react";
17045
17610
  import { Fragment as Fragment16, jsx as jsx35, jsxs as jsxs27 } from "react/jsx-runtime";
17046
17611
  function resolveDesignProps3(props) {
17047
17612
  return {
@@ -17103,10 +17668,10 @@ var Invoices = forwardRef8(({ className, data, ...rest }, ref) => {
17103
17668
  (prev2) => prev2 !== props.limit.number ? props.limit.number : MAX_VISIBLE_INVOICE_COUNT
17104
17669
  );
17105
17670
  };
17106
- useEffect7(() => {
17671
+ useEffect6(() => {
17107
17672
  getInvoices();
17108
17673
  }, [getInvoices]);
17109
- useEffect7(() => {
17674
+ useEffect6(() => {
17110
17675
  setInvoices(formatInvoices(data));
17111
17676
  }, [data]);
17112
17677
  if (invoices.length === 0) {
@@ -17186,7 +17751,7 @@ var Invoices = forwardRef8(({ className, data, ...rest }, ref) => {
17186
17751
  Invoices.displayName = "Invoices";
17187
17752
 
17188
17753
  // src/components/elements/metered-features/MeteredFeatures.tsx
17189
- import { forwardRef as forwardRef9, useCallback as useCallback12, useMemo as useMemo18, useRef as useRef11, useState as useState16 } from "react";
17754
+ import { forwardRef as forwardRef9, useCallback as useCallback12, useMemo as useMemo19, useRef as useRef11, useState as useState16 } from "react";
17190
17755
 
17191
17756
  // src/components/elements/metered-features/Meter.tsx
17192
17757
  import { jsx as jsx36 } from "react/jsx-runtime";
@@ -17388,45 +17953,31 @@ function resolveDesignProps4(props) {
17388
17953
  }
17389
17954
  var MeteredFeatures = forwardRef9(({ className, ...rest }, ref) => {
17390
17955
  const props = resolveDesignProps4(rest);
17391
- const elements = useRef11([]);
17392
- const shouldWrapChildren = useWrapChildren(elements.current);
17956
+ const elementsRef = useRef11([]);
17957
+ const shouldWrapChildren = useWrapChildren(elementsRef);
17393
17958
  const { t: t2 } = useTranslation();
17394
17959
  const { data, settings, setCheckoutState } = useEmbed();
17395
17960
  const isLightBackground = useIsLightBackground();
17396
- const { period, meteredFeatures, creditGroups, showCredits } = useMemo18(() => {
17397
- const showCredits2 = data?.showCredits ?? true;
17398
- if (isCheckoutData(data)) {
17399
- const period2 = typeof data.company?.plan?.planPeriod === "string" ? data.company?.plan?.planPeriod : void 0;
17400
- const orderedFeatureUsage = props.visibleFeatures?.reduce(
17401
- (acc, id) => {
17402
- const mappedFeatureUsage = data.featureUsage?.features.find(
17403
- (usage) => usage.feature?.id === id
17404
- );
17405
- if (mappedFeatureUsage) {
17406
- acc.push(mappedFeatureUsage);
17407
- }
17408
- return acc;
17409
- },
17410
- []
17411
- );
17412
- return {
17413
- period: period2,
17414
- meteredFeatures: (orderedFeatureUsage || data.featureUsage?.features || []).filter(
17415
- ({ feature }) => feature?.featureType === "event" /* Event */ || feature?.featureType === "trait" /* Trait */
17416
- ),
17417
- creditGroups: groupCreditGrants(data.creditGrants, {
17418
- groupBy: "credit"
17419
- }),
17420
- showCredits: showCredits2
17421
- };
17422
- }
17423
- return {
17424
- period: void 0,
17425
- meteredFeatures: [],
17426
- creditGroups: [],
17427
- showCredits: showCredits2
17428
- };
17429
- }, [props.visibleFeatures, data]);
17961
+ const meteredFeatures = useMemo19(() => {
17962
+ const orderedFeatureUsage = props.visibleFeatures?.reduce(
17963
+ (acc, id) => {
17964
+ const mappedFeatureUsage = data?.featureUsage?.features.find(
17965
+ (usage) => usage.feature?.id === id
17966
+ );
17967
+ if (mappedFeatureUsage) {
17968
+ acc.push(mappedFeatureUsage);
17969
+ }
17970
+ return acc;
17971
+ },
17972
+ []
17973
+ );
17974
+ return (orderedFeatureUsage || data?.featureUsage?.features || []).filter(
17975
+ ({ feature }) => feature?.featureType === "event" /* Event */ || feature?.featureType === "trait" /* Trait */
17976
+ );
17977
+ }, [props.visibleFeatures, data?.featureUsage?.features]);
17978
+ const creditGroups = groupCreditGrants(data?.creditGrants || [], {
17979
+ groupBy: "credit"
17980
+ });
17430
17981
  const [creditVisibility, setCreditVisibility] = useState16(
17431
17982
  creditGroups.map(({ id }) => ({ id, isExpanded: false }))
17432
17983
  );
@@ -17441,6 +17992,9 @@ var MeteredFeatures = forwardRef9(({ className, ...rest }, ref) => {
17441
17992
  if (!shouldShowFeatures) {
17442
17993
  return null;
17443
17994
  }
17995
+ const period = typeof data?.company?.plan?.planPeriod === "string" ? data.company?.plan?.planPeriod : void 0;
17996
+ const canCheckout = data?.capabilities?.checkout ?? false;
17997
+ const showCredits = data?.showCredits ?? true;
17444
17998
  return /* @__PURE__ */ jsxs29(Container2, { ref, className, children: [
17445
17999
  meteredFeatures.reduce((acc, entitlement, index) => {
17446
18000
  if (!entitlement.feature) {
@@ -17467,7 +18021,7 @@ var MeteredFeatures = forwardRef9(({ className, ...rest }, ref) => {
17467
18021
  {
17468
18022
  ref: (el) => {
17469
18023
  if (el) {
17470
- elements.current.push(el);
18024
+ elementsRef.current.push(el);
17471
18025
  }
17472
18026
  },
17473
18027
  $flexWrap: "wrap",
@@ -17518,7 +18072,7 @@ var MeteredFeatures = forwardRef9(({ className, ...rest }, ref) => {
17518
18072
  usageDetails
17519
18073
  }
17520
18074
  ),
17521
- priceBehavior === "pay_in_advance" /* PayInAdvance */ && /* @__PURE__ */ jsx38(
18075
+ canCheckout && priceBehavior === "pay_in_advance" /* PayInAdvance */ && /* @__PURE__ */ jsx38(
17522
18076
  Button,
17523
18077
  {
17524
18078
  type: "button",
@@ -17573,7 +18127,7 @@ var MeteredFeatures = forwardRef9(({ className, ...rest }, ref) => {
17573
18127
  )]
17574
18128
  }
17575
18129
  ),
17576
- /* @__PURE__ */ jsx38(
18130
+ canCheckout && /* @__PURE__ */ jsx38(
17577
18131
  Button,
17578
18132
  {
17579
18133
  type: "button",
@@ -17699,10 +18253,10 @@ var MeteredFeatures = forwardRef9(({ className, ...rest }, ref) => {
17699
18253
  MeteredFeatures.displayName = "MeteredFeatures";
17700
18254
 
17701
18255
  // src/components/elements/payment-method/PaymentMethod.tsx
17702
- import { forwardRef as forwardRef10, useMemo as useMemo20 } from "react";
18256
+ import { forwardRef as forwardRef10, useMemo as useMemo21 } from "react";
17703
18257
 
17704
18258
  // src/components/elements/payment-method/PaymentMethodElement.tsx
17705
- import { useMemo as useMemo19 } from "react";
18259
+ import { useMemo as useMemo20 } from "react";
17706
18260
  import { jsx as jsx39, jsxs as jsxs30 } from "react/jsx-runtime";
17707
18261
  var PaymentElement2 = ({
17708
18262
  iconName,
@@ -17822,7 +18376,7 @@ var PaymentListElement = ({
17822
18376
  }) => {
17823
18377
  const isLightBackground = useIsLightBackground();
17824
18378
  const { iconName, iconTitle, label, paymentLast4 } = getPaymentMethodData(paymentMethod);
17825
- const expirationDate = useMemo19(() => {
18379
+ const expirationDate = useMemo20(() => {
17826
18380
  const { cardExpMonth, cardExpYear } = paymentMethod;
17827
18381
  if (!cardExpMonth || !cardExpYear) {
17828
18382
  return;
@@ -17910,31 +18464,25 @@ var resolveDesignProps5 = (props) => {
17910
18464
  var PaymentMethod = forwardRef10(({ children, className, portal, allowEdit = true, ...rest }, ref) => {
17911
18465
  const props = resolveDesignProps5(rest);
17912
18466
  const { data, setLayout } = useEmbed();
17913
- const { paymentMethod, monthsToExpiration } = useMemo20(() => {
17914
- if (isCheckoutData(data)) {
17915
- const paymentMethod2 = data.subscription?.paymentMethod || data.company?.defaultPaymentMethod;
17916
- let monthsToExpiration2;
17917
- if (typeof paymentMethod2?.cardExpYear === "number" && typeof paymentMethod2?.cardExpMonth === "number") {
17918
- const now = /* @__PURE__ */ new Date();
17919
- const currentYear = now.getFullYear();
17920
- const currentMonth = now.getMonth();
17921
- const timeToExpiration = Math.round(
17922
- +new Date(paymentMethod2.cardExpYear, paymentMethod2.cardExpMonth - 1) - +new Date(currentYear, currentMonth)
17923
- );
17924
- monthsToExpiration2 = Math.round(
17925
- timeToExpiration / (1e3 * 60 * 60 * 24 * 30)
17926
- );
17927
- }
17928
- return {
17929
- paymentMethod: paymentMethod2,
17930
- monthsToExpiration: monthsToExpiration2
17931
- };
18467
+ const { paymentMethod, monthsToExpiration } = useMemo21(() => {
18468
+ const paymentMethod2 = data?.subscription?.paymentMethod || data?.company?.defaultPaymentMethod;
18469
+ let monthsToExpiration2;
18470
+ if (typeof paymentMethod2?.cardExpYear === "number" && typeof paymentMethod2?.cardExpMonth === "number") {
18471
+ const now = /* @__PURE__ */ new Date();
18472
+ const currentYear = now.getFullYear();
18473
+ const currentMonth = now.getMonth();
18474
+ const timeToExpiration = Math.round(
18475
+ +new Date(paymentMethod2.cardExpYear, paymentMethod2.cardExpMonth - 1) - +new Date(currentYear, currentMonth)
18476
+ );
18477
+ monthsToExpiration2 = Math.round(
18478
+ timeToExpiration / (1e3 * 60 * 60 * 24 * 30)
18479
+ );
17932
18480
  }
17933
18481
  return {
17934
- paymentMethod: void 0,
17935
- monthsToExpiration: void 0
18482
+ paymentMethod: paymentMethod2,
18483
+ monthsToExpiration: monthsToExpiration2
17936
18484
  };
17937
- }, [data]);
18485
+ }, [data?.company?.defaultPaymentMethod, data?.subscription?.paymentMethod]);
17938
18486
  return /* @__PURE__ */ jsx40(Element, { ref, className, children: /* @__PURE__ */ jsx40(
17939
18487
  PaymentMethodElement,
17940
18488
  {
@@ -18103,7 +18651,7 @@ var loadStripe = function loadStripe2() {
18103
18651
  };
18104
18652
 
18105
18653
  // src/components/elements/payment-method/PaymentMethodDetails.tsx
18106
- import { useCallback as useCallback13, useEffect as useEffect8, useMemo as useMemo21, useState as useState17 } from "react";
18654
+ import { useCallback as useCallback13, useEffect as useEffect7, useMemo as useMemo22, useState as useState17 } from "react";
18107
18655
  import { jsx as jsx41, jsxs as jsxs31 } from "react/jsx-runtime";
18108
18656
  var resolveDesignProps6 = () => {
18109
18657
  return {
@@ -18132,20 +18680,17 @@ var PaymentMethodDetails = ({
18132
18680
  updatePaymentMethod,
18133
18681
  deletePaymentMethod
18134
18682
  } = useEmbed();
18135
- const { defaultPaymentMethod, paymentMethods, subscription } = useMemo21(() => {
18136
- if (isCheckoutData(data)) {
18137
- return {
18138
- defaultPaymentMethod: data.company?.defaultPaymentMethod,
18139
- paymentMethods: data.company?.paymentMethods || [],
18140
- subscription: data.subscription
18141
- };
18142
- }
18683
+ const { defaultPaymentMethod, paymentMethods, subscription } = useMemo22(() => {
18143
18684
  return {
18144
- defaultPaymentMethod: void 0,
18145
- paymentMethods: [],
18146
- subscription: void 0
18685
+ defaultPaymentMethod: data?.company?.defaultPaymentMethod,
18686
+ paymentMethods: data?.company?.paymentMethods || [],
18687
+ subscription: data?.subscription
18147
18688
  };
18148
- }, [data]);
18689
+ }, [
18690
+ data?.company?.defaultPaymentMethod,
18691
+ data?.company?.paymentMethods,
18692
+ data?.subscription
18693
+ ]);
18149
18694
  const isLightBackground = useIsLightBackground();
18150
18695
  const [isLoading, setIsLoading] = useState17(false);
18151
18696
  const [error, setError] = useState17();
@@ -18166,7 +18711,7 @@ var PaymentMethodDetails = ({
18166
18711
  },
18167
18712
  autoConfirm: true
18168
18713
  });
18169
- const monthsToExpiration = useMemo21(() => {
18714
+ const monthsToExpiration = useMemo22(() => {
18170
18715
  let expiration;
18171
18716
  if (typeof currentPaymentMethod?.cardExpYear === "number" && typeof currentPaymentMethod?.cardExpMonth === "number") {
18172
18717
  const now = /* @__PURE__ */ new Date();
@@ -18240,7 +18785,7 @@ var PaymentMethodDetails = ({
18240
18785
  },
18241
18786
  [t2, deletePaymentMethod]
18242
18787
  );
18243
- useEffect8(() => {
18788
+ useEffect7(() => {
18244
18789
  if (!stripe && setupIntent) {
18245
18790
  let publishableKey = setupIntent.publishableKey || setupIntent.schematicPublishableKey;
18246
18791
  const stripeOptions = {};
@@ -18252,7 +18797,7 @@ var PaymentMethodDetails = ({
18252
18797
  setStripe(stripePromise2);
18253
18798
  }
18254
18799
  }, [stripe, setupIntent]);
18255
- useEffect8(() => {
18800
+ useEffect7(() => {
18256
18801
  if (!setupIntent && (!currentPaymentMethod || showPaymentForm)) {
18257
18802
  initializePaymentMethod();
18258
18803
  }
@@ -18409,7 +18954,7 @@ var PaymentMethodDetails = ({
18409
18954
  };
18410
18955
 
18411
18956
  // src/components/elements/plan-manager/PlanManager.tsx
18412
- import { forwardRef as forwardRef11, useMemo as useMemo23 } from "react";
18957
+ import { forwardRef as forwardRef11, useMemo as useMemo24 } from "react";
18413
18958
 
18414
18959
  // src/components/elements/plan-manager/AddOn.tsx
18415
18960
  import { jsx as jsx42, jsxs as jsxs32 } from "react/jsx-runtime";
@@ -18433,7 +18978,7 @@ var AddOn = ({ addOn, currency, layout }) => {
18433
18978
  };
18434
18979
 
18435
18980
  // src/components/elements/plan-manager/UsageDetails.tsx
18436
- import { Fragment as Fragment19, useMemo as useMemo22 } from "react";
18981
+ import { Fragment as Fragment19, useMemo as useMemo23 } from "react";
18437
18982
  import { Fragment as Fragment20, jsx as jsx43, jsxs as jsxs33 } from "react/jsx-runtime";
18438
18983
  var UsageDetails2 = ({
18439
18984
  entitlement,
@@ -18448,11 +18993,11 @@ var UsageDetails2 = ({
18448
18993
  limit,
18449
18994
  amount = 0,
18450
18995
  cost = 0
18451
- } = useMemo22(
18996
+ } = useMemo23(
18452
18997
  () => getUsageDetails(entitlement, period),
18453
18998
  [entitlement, period]
18454
18999
  );
18455
- const description = useMemo22(() => {
19000
+ const description = useMemo23(() => {
18456
19001
  const acc = [];
18457
19002
  let index = 0;
18458
19003
  if (entitlement.priceBehavior === "overage" /* Overage */) {
@@ -18616,20 +19161,12 @@ var PlanManager = forwardRef11(({ children, className, portal, ...rest }, ref) =
18616
19161
  showCredits,
18617
19162
  showZeroPriceAsFree,
18618
19163
  trialPaymentMethodRequired
18619
- } = useMemo23(() => {
18620
- const showCredits2 = data?.showCredits ?? true;
18621
- const showZeroPriceAsFree2 = data?.showZeroPriceAsFree ?? false;
18622
- if (isCheckoutData(data)) {
18623
- const {
18624
- company,
18625
- creditBundles: creditBundles2,
18626
- creditGrants,
18627
- capabilities,
18628
- postTrialPlan: postTrialPlan2,
18629
- featureUsage: featureUsage2,
18630
- trialPaymentMethodRequired: trialPaymentMethodRequired2
18631
- } = data;
18632
- const creditGroups2 = groupCreditGrants(creditGrants, {
19164
+ } = useMemo24(() => {
19165
+ return {
19166
+ currentPlan: data?.company?.plan,
19167
+ currentAddOns: data?.company?.addOns || [],
19168
+ creditBundles: data?.creditBundles || [],
19169
+ creditGroups: groupCreditGrants(data?.creditGrants || [], {
18633
19170
  groupBy: "bundle"
18634
19171
  }).reduce(
18635
19172
  (acc, grant) => {
@@ -18646,36 +19183,29 @@ var PlanManager = forwardRef11(({ children, className, portal, ...rest }, ref) =
18646
19183
  return acc;
18647
19184
  },
18648
19185
  { plan: [], bundles: [], promotional: [] }
18649
- );
18650
- return {
18651
- currentPlan: company?.plan,
18652
- currentAddOns: company?.addOns || [],
18653
- creditBundles: creditBundles2,
18654
- creditGroups: creditGroups2,
18655
- billingSubscription: company?.billingSubscription,
18656
- canCheckout: capabilities?.checkout ?? true,
18657
- postTrialPlan: postTrialPlan2,
18658
- featureUsage: featureUsage2?.features || [],
18659
- trialPaymentMethodRequired: trialPaymentMethodRequired2,
18660
- showCredits: showCredits2,
18661
- showZeroPriceAsFree: showZeroPriceAsFree2
18662
- };
18663
- }
18664
- return {
18665
- currentPlan: void 0,
18666
- currentAddOns: [],
18667
- creditBundles: [],
18668
- creditGroups: { plan: [], bundles: [], promotional: [] },
18669
- billingSubscription: void 0,
18670
- canCheckout: false,
18671
- postTrialPlan: void 0,
18672
- featureUsage: [],
18673
- trialPaymentMethodRequired: false,
18674
- showCredits: showCredits2,
18675
- showZeroPriceAsFree: showZeroPriceAsFree2
19186
+ ),
19187
+ billingSubscription: data?.company?.billingSubscription,
19188
+ canCheckout: data?.capabilities?.checkout ?? false,
19189
+ postTrialPlan: data?.postTrialPlan,
19190
+ featureUsage: data?.featureUsage?.features || [],
19191
+ trialPaymentMethodRequired: data?.trialPaymentMethodRequired ?? false,
19192
+ showCredits: data?.showCredits ?? true,
19193
+ showZeroPriceAsFree: data?.showZeroPriceAsFree ?? false
18676
19194
  };
18677
- }, [data]);
18678
- const usageBasedEntitlements = useMemo23(
19195
+ }, [
19196
+ data?.capabilities?.checkout,
19197
+ data?.company?.addOns,
19198
+ data?.company?.billingSubscription,
19199
+ data?.company?.plan,
19200
+ data?.creditBundles,
19201
+ data?.creditGrants,
19202
+ data?.featureUsage?.features,
19203
+ data?.postTrialPlan,
19204
+ data?.showCredits,
19205
+ data?.showZeroPriceAsFree,
19206
+ data?.trialPaymentMethodRequired
19207
+ ]);
19208
+ const usageBasedEntitlements = useMemo24(
18679
19209
  () => featureUsage.filter((usage) => typeof usage.priceBehavior === "string"),
18680
19210
  [featureUsage]
18681
19211
  );
@@ -18684,7 +19214,7 @@ var PlanManager = forwardRef11(({ children, className, portal, ...rest }, ref) =
18684
19214
  subscriptionCurrency,
18685
19215
  willSubscriptionCancel,
18686
19216
  isTrialSubscription
18687
- } = useMemo23(() => {
19217
+ } = useMemo24(() => {
18688
19218
  const subscriptionInterval2 = billingSubscription?.interval;
18689
19219
  const subscriptionCurrency2 = billingSubscription?.currency;
18690
19220
  const isTrialSubscription2 = billingSubscription?.status === "trialing";
@@ -19000,46 +19530,111 @@ PlanManager.displayName = "PlanManager";
19000
19530
  import {
19001
19531
  Fragment as Fragment25,
19002
19532
  forwardRef as forwardRef12,
19003
- useEffect as useEffect9,
19004
- useMemo as useMemo26,
19533
+ useCallback as useCallback14,
19534
+ useEffect as useEffect8,
19535
+ useMemo as useMemo27,
19005
19536
  useState as useState18
19006
19537
  } from "react";
19007
19538
 
19008
19539
  // src/components/elements/pricing-table/AddOn.tsx
19009
- import { useMemo as useMemo24 } from "react";
19540
+ import { useMemo as useMemo25 } from "react";
19010
19541
  import { Fragment as Fragment22, jsx as jsx45, jsxs as jsxs35 } from "react/jsx-runtime";
19542
+ function renderMeteredEntitlementPricing2({
19543
+ priceBehavior,
19544
+ softLimit,
19545
+ price,
19546
+ currency,
19547
+ packageSize,
19548
+ feature,
19549
+ featureName,
19550
+ isTiered
19551
+ }) {
19552
+ if (priceBehavior === "overage" /* Overage */ && softLimit) {
19553
+ return /* @__PURE__ */ jsxs35(Fragment22, { children: [
19554
+ "Additional: ",
19555
+ formatCurrency(price, currency),
19556
+ "/",
19557
+ feature ? getFeatureName(
19558
+ feature,
19559
+ packageSize
19560
+ ) : featureName || "unit"
19561
+ ] });
19562
+ }
19563
+ if (priceBehavior === "pay_as_you_go" /* PayAsYouGo */ || priceBehavior === "pay_in_advance" /* PayInAdvance */) {
19564
+ return /* @__PURE__ */ jsxs35(Fragment22, { children: [
19565
+ formatCurrency(price, currency),
19566
+ "/",
19567
+ packageSize > 1 && /* @__PURE__ */ jsxs35(Fragment22, { children: [
19568
+ packageSize,
19569
+ " "
19570
+ ] }),
19571
+ feature ? getFeatureName(
19572
+ feature,
19573
+ packageSize
19574
+ ) : featureName || "unit"
19575
+ ] });
19576
+ }
19577
+ if (isTiered) {
19578
+ return /* @__PURE__ */ jsx45(Fragment22, { children: "Tier-based pricing" });
19579
+ }
19580
+ return null;
19581
+ }
19582
+ function shouldShowUsageBased2(price, displayableEntitlements) {
19583
+ return price < 0.01 && displayableEntitlements.some((ent) => !ent.isUnlimited);
19584
+ }
19011
19585
  var AddOn2 = ({ addOn, sharedProps, selectedPeriod }) => {
19012
19586
  const { layout } = sharedProps;
19013
19587
  const { t: t2 } = useTranslation();
19014
19588
  const { data, settings, setCheckoutState } = useEmbed();
19015
19589
  const isLightBackground = useIsLightBackground();
19016
- const { currentAddOns, canCheckout, isStandalone, showCallToAction } = useMemo24(() => {
19017
- if (isCheckoutData(data)) {
19590
+ const { currentAddOns, canCheckout, isStandalone } = useMemo25(() => {
19591
+ const isStandalone2 = typeof data?.component === "undefined";
19592
+ return {
19593
+ currentAddOns: data?.company?.addOns || [],
19594
+ canCheckout: isStandalone2 || (data?.capabilities?.checkout ?? true),
19595
+ isStandalone: isStandalone2
19596
+ };
19597
+ }, [data?.capabilities?.checkout, data?.company?.addOns, data?.component]);
19598
+ const cardPadding = settings.theme.card.padding / TEXT_BASE_SIZE;
19599
+ const isActiveAddOn = addOn.current && selectedPeriod === currentAddOns.find((currentAddOn) => currentAddOn.id === addOn.id)?.planPeriod;
19600
+ const { price: addOnPrice, currency: addOnCurrency } = getAddOnPrice(addOn, selectedPeriod) || {};
19601
+ const displayableEntitlements = addOn.entitlements?.filter(
19602
+ (entitlement) => entitlement.valueType === "unlimited" || entitlement.priceBehavior && [
19603
+ "pay_as_you_go" /* PayAsYouGo */,
19604
+ "pay_in_advance" /* PayInAdvance */,
19605
+ "overage" /* Overage */,
19606
+ "tier" /* Tiered */
19607
+ ].includes(entitlement.priceBehavior)
19608
+ ).map((entitlement) => {
19609
+ if (entitlement.valueType === "unlimited" && !entitlement.priceBehavior) {
19018
19610
  return {
19019
- currentAddOns: data.company?.addOns || [],
19020
- canCheckout: data.capabilities?.checkout ?? true,
19021
- isStandalone: false,
19022
- showCallToAction: true
19611
+ isUnlimited: true,
19612
+ featureName: entitlement.feature?.name,
19613
+ feature: entitlement.feature
19023
19614
  };
19024
19615
  }
19616
+ const priceData = getEntitlementPrice(entitlement, selectedPeriod);
19025
19617
  return {
19026
- currentAddOns: [],
19027
- canCheckout: true,
19028
- isStandalone: true,
19029
- showCallToAction: typeof layout.callToActionUrl === "string"
19618
+ isUnlimited: false,
19619
+ featureName: entitlement.feature?.name,
19620
+ feature: entitlement.feature,
19621
+ priceBehavior: entitlement.priceBehavior,
19622
+ softLimit: entitlement.softLimit,
19623
+ price: priceData?.price ?? 0,
19624
+ currency: priceData?.currency || addOnCurrency,
19625
+ packageSize: priceData?.packageSize ?? 1,
19626
+ isTiered: entitlement.priceBehavior === "tier" /* Tiered */
19030
19627
  };
19031
- }, [data, layout.callToActionUrl]);
19032
- const cardPadding = settings.theme.card.padding / TEXT_BASE_SIZE;
19033
- const isCurrentAddOn = isHydratedPlan(addOn) && addOn.current;
19034
- const isActiveAddOn = isCurrentAddOn && selectedPeriod === currentAddOns.find((currentAddOn) => currentAddOn.id === addOn.id)?.planPeriod;
19035
- const { price: addOnPrice, currency: addOnCurrency } = getAddOnPrice(addOn, selectedPeriod) || {};
19628
+ }) || [];
19036
19629
  return /* @__PURE__ */ jsxs35(
19037
19630
  Flex,
19038
19631
  {
19632
+ className: "sch-PricingTable_AddOn",
19633
+ "data-testid": "sch-addon",
19634
+ "data-addon-id": addOn.id,
19039
19635
  $position: "relative",
19040
19636
  $flexDirection: "column",
19041
- $gap: "2rem",
19042
- $padding: `${cardPadding}rem`,
19637
+ $padding: `${0.75 * cardPadding}rem 0`,
19043
19638
  $backgroundColor: settings.theme.card.background,
19044
19639
  $borderRadius: `${settings.theme.card.borderRadius / TEXT_BASE_SIZE}rem`,
19045
19640
  $outlineWidth: "2px",
@@ -19049,36 +19644,56 @@ var AddOn2 = ({ addOn, sharedProps, selectedPeriod }) => {
19049
19644
  $boxShadow: cardBoxShadow
19050
19645
  },
19051
19646
  children: [
19052
- /* @__PURE__ */ jsxs35(Flex, { $flexDirection: "column", $gap: "0.75rem", children: [
19053
- /* @__PURE__ */ jsx45(Box, { children: /* @__PURE__ */ jsx45(Text, { display: layout.plans.name.fontStyle, children: addOn.name }) }),
19054
- layout.addOns.showDescription && /* @__PURE__ */ jsx45(Box, { $marginBottom: "0.5rem", children: /* @__PURE__ */ jsx45(Text, { display: layout.plans.description.fontStyle, children: addOn.description }) }),
19055
- /* @__PURE__ */ jsx45(Box, { children: /* @__PURE__ */ jsxs35(Text, { display: layout.plans.name.fontStyle, children: [
19056
- formatCurrency(addOnPrice ?? 0, addOnCurrency),
19057
- /* @__PURE__ */ jsxs35("sub", { children: [
19058
- "/",
19059
- selectedPeriod
19060
- ] })
19061
- ] }) }),
19062
- isActiveAddOn && /* @__PURE__ */ jsx45(
19063
- Flex,
19064
- {
19065
- $position: "absolute",
19066
- $right: "1rem",
19067
- $top: "1rem",
19068
- $backgroundColor: settings.theme.primary,
19069
- $borderRadius: "9999px",
19070
- $padding: "0.125rem 0.85rem",
19071
- children: /* @__PURE__ */ jsx45(
19647
+ /* @__PURE__ */ jsxs35(
19648
+ Flex,
19649
+ {
19650
+ $flexDirection: "column",
19651
+ $gap: "0.75rem",
19652
+ $padding: `0 ${cardPadding}rem ${displayableEntitlements.length > 0 ? 0.75 * cardPadding : 0}rem`,
19653
+ $borderWidth: "0",
19654
+ $borderBottomWidth: displayableEntitlements.length > 0 ? "1px" : "0",
19655
+ $borderStyle: "solid",
19656
+ $borderColor: isLightBackground ? "hsla(0, 0%, 0%, 0.175)" : "hsla(0, 0%, 100%, 0.175)",
19657
+ children: [
19658
+ /* @__PURE__ */ jsx45(Box, { children: /* @__PURE__ */ jsx45(Text, { display: layout.plans.name.fontStyle, children: addOn.name }) }),
19659
+ layout.addOns.showDescription && /* @__PURE__ */ jsx45(Box, { $marginBottom: "0.5rem", children: /* @__PURE__ */ jsx45(Text, { display: layout.plans.description.fontStyle, children: addOn.description }) }),
19660
+ /* @__PURE__ */ jsx45(Box, { children: /* @__PURE__ */ jsx45(
19072
19661
  Text,
19073
19662
  {
19074
- $size: 0.75 * settings.theme.typography.text.fontSize,
19075
- $color: hexToHSL(settings.theme.primary).l > 50 ? "#000000" : "#FFFFFF",
19076
- children: t2("Active")
19663
+ "data-testid": "sch-addon-price",
19664
+ display: layout.plans.name.fontStyle,
19665
+ children: shouldShowUsageBased2(addOnPrice ?? 0, displayableEntitlements) ? t2("Usage-based") : /* @__PURE__ */ jsxs35(Fragment22, { children: [
19666
+ formatCurrency(addOnPrice ?? 0, addOnCurrency),
19667
+ /* @__PURE__ */ jsxs35("sub", { children: [
19668
+ "/",
19669
+ selectedPeriod
19670
+ ] })
19671
+ ] })
19672
+ }
19673
+ ) }),
19674
+ isActiveAddOn && /* @__PURE__ */ jsx45(
19675
+ Flex,
19676
+ {
19677
+ "data-testid": "sch-addon-active",
19678
+ $position: "absolute",
19679
+ $right: "1rem",
19680
+ $top: "1rem",
19681
+ $backgroundColor: settings.theme.primary,
19682
+ $borderRadius: "9999px",
19683
+ $padding: "0.125rem 0.85rem",
19684
+ children: /* @__PURE__ */ jsx45(
19685
+ Text,
19686
+ {
19687
+ $size: 0.75 * settings.theme.typography.text.fontSize,
19688
+ $color: hexToHSL(settings.theme.primary).l > 50 ? "#000000" : "#FFFFFF",
19689
+ children: t2("Active")
19690
+ }
19691
+ )
19077
19692
  }
19078
19693
  )
19079
- }
19080
- )
19081
- ] }),
19694
+ ]
19695
+ }
19696
+ ),
19082
19697
  /* @__PURE__ */ jsxs35(
19083
19698
  Flex,
19084
19699
  {
@@ -19086,24 +19701,19 @@ var AddOn2 = ({ addOn, sharedProps, selectedPeriod }) => {
19086
19701
  $justifyContent: "end",
19087
19702
  $gap: `${cardPadding}rem`,
19088
19703
  $flexGrow: 1,
19704
+ $padding: `${0.75 * cardPadding}rem ${cardPadding}rem 0`,
19089
19705
  children: [
19090
- layout.addOns.showEntitlements && /* @__PURE__ */ jsx45(
19091
- Flex,
19092
- {
19093
- $flexDirection: "column",
19094
- $position: "relative",
19095
- $gap: "1rem",
19096
- $flexGrow: 1,
19097
- children: addOn.entitlements.map((entitlement, entitlementIndex) => {
19098
- const metricPeriodName = getMetricPeriodName(entitlement);
19099
- return /* @__PURE__ */ jsx45(
19100
- Flex,
19101
- {
19102
- $flexWrap: "wrap",
19103
- $justifyContent: "space-between",
19104
- $alignItems: "center",
19105
- $gap: "1rem",
19106
- children: /* @__PURE__ */ jsxs35(Flex, { $gap: "1rem", children: [
19706
+ layout.addOns.showEntitlements && displayableEntitlements.length > 0 && /* @__PURE__ */ jsx45(Flex, { $flexDirection: "column", $gap: "1rem", $flexGrow: 1, children: displayableEntitlements.map((entitlement, idx) => {
19707
+ if (entitlement.isUnlimited) {
19708
+ return /* @__PURE__ */ jsxs35(
19709
+ Flex,
19710
+ {
19711
+ $flexWrap: "wrap",
19712
+ $justifyContent: "space-between",
19713
+ $alignItems: "center",
19714
+ $gap: "1rem",
19715
+ children: [
19716
+ /* @__PURE__ */ jsxs35(Flex, { $gap: "1rem", children: [
19107
19717
  layout.addOns.showFeatureIcons && entitlement.feature?.icon && /* @__PURE__ */ jsx45(
19108
19718
  Icon3,
19109
19719
  {
@@ -19113,57 +19723,82 @@ var AddOn2 = ({ addOn, sharedProps, selectedPeriod }) => {
19113
19723
  rounded: true
19114
19724
  }
19115
19725
  ),
19116
- /* @__PURE__ */ jsxs35(Flex, { $flexDirection: "column", $gap: "0.5rem", children: [
19117
- entitlement.feature?.name && /* @__PURE__ */ jsx45(Flex, { $alignItems: "center", $flexGrow: 1, children: /* @__PURE__ */ jsx45(Text, { children: entitlement.valueType === "numeric" /* Numeric */ || entitlement.valueType === "unlimited" /* Unlimited */ || entitlement.valueType === "trait" /* Trait */ ? /* @__PURE__ */ jsxs35(Fragment22, { children: [
19118
- entitlement.valueType === "unlimited" /* Unlimited */ ? t2("Unlimited", {
19119
- item: getFeatureName(entitlement.feature)
19120
- }) : typeof entitlement.valueNumeric === "number" && /* @__PURE__ */ jsxs35(Fragment22, { children: [
19121
- formatNumber(entitlement.valueNumeric),
19122
- " ",
19123
- getFeatureName(
19124
- entitlement.feature,
19125
- entitlement.valueNumeric
19126
- )
19127
- ] }),
19128
- metricPeriodName && /* @__PURE__ */ jsxs35(Fragment22, { children: [
19129
- " ",
19130
- t2("per"),
19131
- " ",
19132
- t2(metricPeriodName)
19133
- ] })
19134
- ] }) : entitlement.feature.name }) }),
19135
- layout.plans.showFeatureDescriptions && entitlement.feature?.description && /* @__PURE__ */ jsx45(
19136
- Text,
19137
- {
19138
- $size: 0.875 * settings.theme.typography.text.fontSize,
19139
- $color: `color-mix(in oklch, ${settings.theme.typography.text.color}, ${settings.theme.card.background})`,
19140
- children: entitlement.feature.description
19141
- }
19142
- )
19143
- ] })
19144
- ] })
19145
- },
19146
- entitlementIndex
19147
- );
19148
- })
19726
+ entitlement.feature && /* @__PURE__ */ jsx45(
19727
+ Flex,
19728
+ {
19729
+ $flexDirection: "column",
19730
+ $justifyContent: "center",
19731
+ children: /* @__PURE__ */ jsx45(Text, { children: getFeatureName(entitlement.feature) })
19732
+ }
19733
+ )
19734
+ ] }),
19735
+ /* @__PURE__ */ jsx45(
19736
+ Text,
19737
+ {
19738
+ style: { opacity: 0.54 },
19739
+ $size: 0.875 * settings.theme.typography.text.fontSize,
19740
+ $color: settings.theme.typography.text.color,
19741
+ children: "Unlimited"
19742
+ }
19743
+ )
19744
+ ]
19745
+ },
19746
+ idx
19747
+ );
19149
19748
  }
19150
- ),
19151
- showCallToAction && layout.upgrade.isVisible && /* @__PURE__ */ jsx45(
19749
+ const meteredEntitlement = entitlement;
19750
+ return /* @__PURE__ */ jsxs35(
19751
+ Flex,
19752
+ {
19753
+ $flexWrap: "wrap",
19754
+ $justifyContent: "space-between",
19755
+ $alignItems: "center",
19756
+ $gap: "1rem",
19757
+ children: [
19758
+ /* @__PURE__ */ jsxs35(Flex, { $gap: "1rem", children: [
19759
+ meteredEntitlement.feature?.icon && /* @__PURE__ */ jsx45(
19760
+ Icon3,
19761
+ {
19762
+ "data-testid": "sch-feature-icon",
19763
+ name: meteredEntitlement.feature.icon,
19764
+ color: settings.theme.primary,
19765
+ background: isLightBackground ? "hsla(0, 0%, 0%, 0.0625)" : "hsla(0, 0%, 100%, 0.25)",
19766
+ rounded: true
19767
+ }
19768
+ ),
19769
+ /* @__PURE__ */ jsx45(Flex, { $flexDirection: "column", $justifyContent: "center", children: /* @__PURE__ */ jsx45(Text, { children: meteredEntitlement.priceBehavior === "overage" /* Overage */ && meteredEntitlement.softLimit ? `${meteredEntitlement.softLimit} ${getEntitlementFeatureName(meteredEntitlement, "units")}` : getEntitlementFeatureName(meteredEntitlement) }) })
19770
+ ] }),
19771
+ /* @__PURE__ */ jsx45(
19772
+ Text,
19773
+ {
19774
+ style: { opacity: 0.54 },
19775
+ $size: 0.875 * settings.theme.typography.text.fontSize,
19776
+ $color: settings.theme.typography.text.color,
19777
+ children: renderMeteredEntitlementPricing2(meteredEntitlement)
19778
+ }
19779
+ )
19780
+ ]
19781
+ },
19782
+ idx
19783
+ );
19784
+ }) }),
19785
+ sharedProps.showCallToAction && (layout.upgrade.isVisible || layout.downgrade.isVisible) && /* @__PURE__ */ jsx45(Flex, { $flexDirection: "column", $gap: "0.5rem", children: /* @__PURE__ */ jsx45(
19152
19786
  Button,
19153
19787
  {
19154
19788
  type: "button",
19155
- disabled: isHydratedPlan(addOn) && !addOn.valid || !canCheckout,
19789
+ disabled: !addOn.valid || !canCheckout,
19790
+ "data-testid": "sch-addon-cta-button",
19156
19791
  $size: layout.upgrade.buttonSize,
19157
19792
  $color: isActiveAddOn ? "danger" : layout.upgrade.buttonStyle,
19158
- $variant: isActiveAddOn ? "ghost" : isCurrentAddOn ? "outline" : "filled",
19159
- ...layout.callToActionUrl ? {
19793
+ $variant: isActiveAddOn ? "ghost" : addOn.current ? "outline" : "filled",
19794
+ ...sharedProps.callToActionUrl ? {
19160
19795
  as: "a",
19161
- href: layout.callToActionUrl,
19796
+ href: sharedProps.callToActionUrl,
19162
19797
  rel: "noreferrer",
19163
19798
  target: "_blank"
19164
19799
  } : {
19165
19800
  onClick: () => {
19166
- layout.onCallToAction?.(addOn);
19801
+ sharedProps.onCallToAction?.(addOn);
19167
19802
  if (!isStandalone && !addOn.custom) {
19168
19803
  setCheckoutState({
19169
19804
  period: selectedPeriod,
@@ -19174,9 +19809,9 @@ var AddOn2 = ({ addOn, sharedProps, selectedPeriod }) => {
19174
19809
  }
19175
19810
  },
19176
19811
  $fullWidth: true,
19177
- children: isActiveAddOn ? t2("Remove add-on") : isCurrentAddOn ? t2("Change add-on") : t2("Choose add-on")
19812
+ children: isActiveAddOn ? t2("Remove add-on") : addOn.current ? t2("Change add-on") : t2("Choose add-on")
19178
19813
  }
19179
- )
19814
+ ) })
19180
19815
  ]
19181
19816
  }
19182
19817
  )
@@ -19186,16 +19821,16 @@ var AddOn2 = ({ addOn, sharedProps, selectedPeriod }) => {
19186
19821
  };
19187
19822
 
19188
19823
  // src/components/elements/pricing-table/Plan.tsx
19189
- import { useMemo as useMemo25 } from "react";
19824
+ import { useMemo as useMemo26 } from "react";
19190
19825
 
19191
19826
  // src/components/elements/pricing-table/Entitlement.tsx
19192
19827
  import { Fragment as Fragment23, jsx as jsx46, jsxs as jsxs36 } from "react/jsx-runtime";
19193
19828
  var Entitlement = ({
19194
19829
  entitlement,
19830
+ sharedProps,
19831
+ selectedPeriod = "month" /* Month */,
19195
19832
  credits = [],
19196
- selectedPeriod,
19197
- showCredits,
19198
- sharedProps
19833
+ showCredits = true
19199
19834
  }) => {
19200
19835
  const { layout } = sharedProps;
19201
19836
  const { t: t2 } = useTranslation();
@@ -19207,7 +19842,7 @@ var Entitlement = ({
19207
19842
  currency: entitlementCurrency,
19208
19843
  packageSize: entitlementPackageSize = 1
19209
19844
  } = getEntitlementPrice(entitlement, selectedPeriod) || {};
19210
- const limit = entitlement.softLimit ?? entitlement.valueNumeric;
19845
+ const limit = entitlement.softLimit ?? entitlement.valueNumeric ?? void 0;
19211
19846
  const metricPeriodName = getMetricPeriodName(entitlement);
19212
19847
  const creditBasedEntitlementLimit = getCreditBasedEntitlementLimit(
19213
19848
  entitlement,
@@ -19217,6 +19852,7 @@ var Entitlement = ({
19217
19852
  layout.plans.showFeatureIcons && entitlement.feature?.icon && /* @__PURE__ */ jsx46(
19218
19853
  Icon3,
19219
19854
  {
19855
+ "data-testid": "sch-feature-icon",
19220
19856
  name: entitlement.feature.icon,
19221
19857
  color: settings.theme.primary,
19222
19858
  background: `color-mix(in oklch, ${settings.theme.card.background} 87.5%, ${isLightBackground ? "black" : "white"})`,
@@ -19231,7 +19867,7 @@ var Entitlement = ({
19231
19867
  t2("per"),
19232
19868
  " ",
19233
19869
  entitlementPackageSize > 1 && /* @__PURE__ */ jsxs36(Fragment23, { children: [
19234
- entitlementPackageSize,
19870
+ formatNumber(entitlementPackageSize),
19235
19871
  " "
19236
19872
  ] }),
19237
19873
  getFeatureName(entitlement.feature, entitlementPackageSize),
@@ -19247,26 +19883,26 @@ var Entitlement = ({
19247
19883
  entitlement,
19248
19884
  period: selectedPeriod
19249
19885
  }
19250
- ) : showCredits && entitlement.priceBehavior === "credit_burndown" /* Credit */ && entitlement.valueCredit ? /* @__PURE__ */ jsxs36(Fragment23, { children: [
19251
- entitlement.consumptionRate,
19886
+ ) : showCredits && entitlement.priceBehavior === "credit_burndown" /* Credit */ && entitlement.valueCredit && entitlement.consumptionRate ? /* @__PURE__ */ jsxs36(Fragment23, { children: [
19887
+ formatNumber(entitlement.consumptionRate),
19252
19888
  " ",
19253
19889
  getFeatureName(
19254
19890
  entitlement.valueCredit,
19255
- entitlement.consumptionRate || void 0
19891
+ entitlement.consumptionRate
19256
19892
  ),
19257
19893
  " ",
19258
19894
  t2("per"),
19259
19895
  " ",
19260
19896
  getFeatureName(entitlement.feature, 1)
19261
19897
  ] }) : entitlement.priceBehavior === "credit_burndown" /* Credit */ && creditBasedEntitlementLimit ? /* @__PURE__ */ jsx46(Fragment23, { children: creditBasedEntitlementLimit?.period ? t2("Up to X units per period", {
19262
- amount: creditBasedEntitlementLimit.limit,
19898
+ amount: formatNumber(creditBasedEntitlementLimit.limit),
19263
19899
  units: getFeatureName(
19264
19900
  entitlement.feature,
19265
19901
  creditBasedEntitlementLimit.limit
19266
19902
  ),
19267
19903
  period: creditBasedEntitlementLimit.period
19268
19904
  }) : t2("Up to X units", {
19269
- amount: creditBasedEntitlementLimit.limit,
19905
+ amount: formatNumber(creditBasedEntitlementLimit.limit),
19270
19906
  units: getFeatureName(
19271
19907
  entitlement.feature,
19272
19908
  creditBasedEntitlementLimit.limit
@@ -19274,9 +19910,11 @@ var Entitlement = ({
19274
19910
  }) }) : entitlement.valueType === "numeric" /* Numeric */ || entitlement.valueType === "unlimited" /* Unlimited */ || entitlement.valueType === "trait" /* Trait */ ? /* @__PURE__ */ jsxs36(Fragment23, { children: [
19275
19911
  entitlement.valueType === "unlimited" /* Unlimited */ && !entitlement.priceBehavior ? t2("Unlimited", {
19276
19912
  item: getFeatureName(entitlement.feature)
19277
- }) : typeof limit === "number" && /* @__PURE__ */ jsxs36(Fragment23, { children: [
19278
- formatNumber(limit),
19279
- " ",
19913
+ }) : /* @__PURE__ */ jsxs36(Fragment23, { children: [
19914
+ typeof limit === "number" && /* @__PURE__ */ jsxs36(Fragment23, { children: [
19915
+ formatNumber(limit),
19916
+ " "
19917
+ ] }),
19280
19918
  getFeatureName(entitlement.feature, limit)
19281
19919
  ] }),
19282
19920
  metricPeriodName && /* @__PURE__ */ jsxs36(Fragment23, { children: [
@@ -19298,7 +19936,7 @@ var Entitlement = ({
19298
19936
  formatCurrency(entitlementPrice, entitlementCurrency),
19299
19937
  "/",
19300
19938
  entitlementPackageSize > 1 && /* @__PURE__ */ jsxs36(Fragment23, { children: [
19301
- entitlementPackageSize,
19939
+ formatNumber(entitlementPackageSize),
19302
19940
  " "
19303
19941
  ] }),
19304
19942
  getFeatureName(entitlement.feature, entitlementPackageSize),
@@ -19364,9 +20002,6 @@ var Plan2 = ({
19364
20002
  const { data, settings, setCheckoutState } = useEmbed();
19365
20003
  const isLightBackground = useIsLightBackground();
19366
20004
  const trialEnd = useTrialEnd();
19367
- const showCallToAction = useMemo25(() => {
19368
- return typeof sharedProps.callToActionUrl === "string" || typeof sharedProps.onCallToAction === "function";
19369
- }, [sharedProps.callToActionUrl, sharedProps.onCallToAction]);
19370
20005
  const {
19371
20006
  currentPeriod,
19372
20007
  canCheckout,
@@ -19375,53 +20010,29 @@ var Plan2 = ({
19375
20010
  isStandalone,
19376
20011
  showCredits,
19377
20012
  showZeroPriceAsFree
19378
- } = useMemo25(() => {
19379
- const showCredits2 = data?.showCredits ?? true;
19380
- const showZeroPriceAsFree2 = data?.showZeroPriceAsFree ?? false;
19381
- if (isCheckoutData(data)) {
19382
- const billingSubscription = data.company?.billingSubscription;
19383
- const isTrialSubscription2 = billingSubscription?.status === "trialing";
19384
- const willSubscriptionCancel2 = typeof billingSubscription?.cancelAt === "number";
19385
- return {
19386
- currentPeriod: data.company?.plan?.planPeriod || "month",
19387
- canCheckout: data.capabilities?.checkout ?? true,
19388
- isTrialSubscription: isTrialSubscription2,
19389
- willSubscriptionCancel: willSubscriptionCancel2,
19390
- isStandalone: false,
19391
- showCredits: showCredits2,
19392
- showZeroPriceAsFree: showZeroPriceAsFree2
19393
- };
19394
- }
20013
+ } = useMemo26(() => {
20014
+ const isStandalone2 = typeof data?.component === "undefined";
19395
20015
  return {
19396
- currentPeriod: "month",
19397
- canCheckout: true,
19398
- isTrialSubscription: false,
19399
- willSubscriptionCancel: false,
19400
- isStandalone: true,
19401
- showCredits: showCredits2,
19402
- showZeroPriceAsFree: showZeroPriceAsFree2
20016
+ currentPeriod: data?.company?.plan?.planPeriod || "month",
20017
+ canCheckout: isStandalone2 || (data?.capabilities?.checkout ?? true),
20018
+ isTrialSubscription: data?.company?.billingSubscription?.status === "trialing",
20019
+ willSubscriptionCancel: typeof data?.company?.billingSubscription?.cancelAt === "number",
20020
+ isStandalone: isStandalone2,
20021
+ showCredits: data?.showCredits ?? true,
20022
+ showZeroPriceAsFree: data?.showZeroPriceAsFree ?? false
19403
20023
  };
19404
- }, [data]);
19405
- const callToActionTarget = useMemo25(() => {
19406
- if (sharedProps.callToActionTarget) {
19407
- return sharedProps.callToActionTarget;
19408
- }
19409
- if (sharedProps.callToActionUrl) {
19410
- try {
19411
- const ctaUrlOrigin = new URL(sharedProps.callToActionUrl).origin;
19412
- if (ctaUrlOrigin === window.location.hostname) {
19413
- return "_self";
19414
- }
19415
- } catch {
19416
- }
19417
- }
19418
- return "_blank";
19419
- }, [sharedProps.callToActionUrl, sharedProps.callToActionTarget]);
20024
+ }, [
20025
+ data?.capabilities?.checkout,
20026
+ data?.company?.billingSubscription?.cancelAt,
20027
+ data?.company?.billingSubscription?.status,
20028
+ data?.company?.plan?.planPeriod,
20029
+ data?.component,
20030
+ data?.showCredits,
20031
+ data?.showZeroPriceAsFree
20032
+ ]);
19420
20033
  const cardPadding = settings.theme.card.padding / TEXT_BASE_SIZE;
19421
- const currentPlanIndex = plans.findIndex(
19422
- (plan2) => isHydratedPlan(plan2) && plan2.current
19423
- );
19424
- const isActivePlan = isHydratedPlan(plan) && plan.current && currentPeriod === selectedPeriod;
20034
+ const currentPlanIndex = plans.findIndex((plan2) => plan2.current);
20035
+ const isActivePlan = plan.current && currentPeriod === selectedPeriod;
19425
20036
  const { price: planPrice, currency: planCurrency } = getPlanPrice(plan, selectedPeriod) || {};
19426
20037
  const credits = groupPlanCreditGrants(plan.includedCreditGrants);
19427
20038
  const hasUsageBasedEntitlements = plan.entitlements.some(
@@ -19436,6 +20047,7 @@ var Plan2 = ({
19436
20047
  Flex,
19437
20048
  {
19438
20049
  className: "sch-PricingTable_Plan",
20050
+ "data-testid": "sch-plan",
19439
20051
  "data-plan-id": plan.id,
19440
20052
  $position: "relative",
19441
20053
  $flexDirection: "column",
@@ -19465,6 +20077,7 @@ var Plan2 = ({
19465
20077
  /* @__PURE__ */ jsx47(Box, { children: /* @__PURE__ */ jsxs37(
19466
20078
  Text,
19467
20079
  {
20080
+ "data-testid": "sch-plan-price",
19468
20081
  $font: headerPriceFontStyle.fontFamily,
19469
20082
  $size: headerPriceFontStyle.fontSize,
19470
20083
  $weight: headerPriceFontStyle.fontWeight,
@@ -19490,6 +20103,7 @@ var Plan2 = ({
19490
20103
  layout.plans.showFeatureIcons && credit.icon && /* @__PURE__ */ jsx47(
19491
20104
  Icon3,
19492
20105
  {
20106
+ "data-testid": "sch-feature-icon",
19493
20107
  name: credit.icon,
19494
20108
  color: settings.theme.primary,
19495
20109
  background: `color-mix(in oklch, ${settings.theme.card.background} 87.5%, ${isLightBackground ? "black" : "white"})`,
@@ -19522,6 +20136,7 @@ var Plan2 = ({
19522
20136
  isActivePlan && /* @__PURE__ */ jsx47(
19523
20137
  Flex,
19524
20138
  {
20139
+ "data-testid": "sch-plan-active",
19525
20140
  $position: "absolute",
19526
20141
  $right: "1rem",
19527
20142
  $top: "1rem",
@@ -19619,12 +20234,13 @@ var Plan2 = ({
19619
20234
  /* @__PURE__ */ jsx47(Text, { $size: 15, $leading: 1, children: t2("Current plan") })
19620
20235
  ]
19621
20236
  }
19622
- ) : showCallToAction && (layout.upgrade.isVisible || layout.downgrade.isVisible) && /* @__PURE__ */ jsxs37(Flex, { $flexDirection: "column", $gap: "0.5rem", children: [
20237
+ ) : sharedProps.showCallToAction && (layout.upgrade.isVisible || layout.downgrade.isVisible) && /* @__PURE__ */ jsxs37(Flex, { $flexDirection: "column", $gap: "0.5rem", children: [
19623
20238
  /* @__PURE__ */ jsx47(
19624
20239
  Button,
19625
20240
  {
19626
20241
  type: "button",
19627
- disabled: (isHydratedPlan(plan) && !plan.valid || !canCheckout) && !plan.custom,
20242
+ disabled: (!plan.valid || !canCheckout) && !plan.custom,
20243
+ "data-testid": "sch-plan-cta-button",
19628
20244
  ...index > currentPlanIndex ? {
19629
20245
  $size: layout.upgrade.buttonSize,
19630
20246
  $color: layout.upgrade.buttonStyle,
@@ -19642,12 +20258,12 @@ var Plan2 = ({
19642
20258
  } : sharedProps.callToActionUrl ? {
19643
20259
  as: "a",
19644
20260
  href: sharedProps.callToActionUrl,
19645
- target: callToActionTarget,
20261
+ target: sharedProps.callToActionTarget,
19646
20262
  rel: "noreferrer"
19647
20263
  } : {
19648
20264
  onClick: () => {
19649
20265
  sharedProps.onCallToAction?.(plan);
19650
- if (!isStandalone && isHydratedPlan(plan) && !plan.custom) {
20266
+ if (!isStandalone && !plan.custom) {
19651
20267
  setCheckoutState({
19652
20268
  period: selectedPeriod,
19653
20269
  planId: isActivePlan ? null : plan.id,
@@ -19657,10 +20273,10 @@ var Plan2 = ({
19657
20273
  }
19658
20274
  },
19659
20275
  $fullWidth: true,
19660
- children: plan.custom ? plan.customPlanConfig?.ctaText ?? t2("Talk to support") : isHydratedPlan(plan) && !plan.valid ? /* @__PURE__ */ jsx47(Text, { as: Box, $align: "center", children: t2("Over plan limit") }) : isHydratedPlan(plan) && plan.companyCanTrial && plan.isTrialable ? t2("Start X day trial", { days: plan.trialDays }) : t2("Choose plan")
20276
+ children: plan.custom ? plan.customPlanConfig?.ctaText ?? t2("Talk to support") : !plan.valid ? /* @__PURE__ */ jsx47(Text, { as: Box, $align: "center", children: t2("Over plan limit") }) : t2("Choose plan")
19661
20277
  }
19662
20278
  ),
19663
- isHydratedPlan(plan) && !plan.valid && /* @__PURE__ */ jsx47(UsageViolationText, { violations: plan.usageViolations })
20279
+ !plan.valid && /* @__PURE__ */ jsx47(UsageViolationText, { violations: plan.usageViolations })
19664
20280
  ] })
19665
20281
  ]
19666
20282
  }
@@ -19713,193 +20329,211 @@ var resolveDesignProps8 = (props) => {
19713
20329
  }
19714
20330
  };
19715
20331
  };
19716
- var PricingTable = forwardRef12(
19717
- ({ className, callToActionUrl, callToActionTarget, onCallToAction, ...rest }, ref) => {
19718
- const props = resolveDesignProps8(rest);
19719
- const { t: t2 } = useTranslation();
19720
- const { data, settings, isPending, hydratePublic } = useEmbed();
19721
- const { currentPeriod, showPeriodToggle, isStandalone } = useMemo26(() => {
19722
- const showPeriodToggle2 = data?.showPeriodToggle ?? props.showPeriodToggle;
19723
- if (isCheckoutData(data)) {
19724
- const billingSubscription = data.company?.billingSubscription;
19725
- const isTrialSubscription = billingSubscription?.status === "trialing";
19726
- const willSubscriptionCancel = billingSubscription?.cancelAt;
20332
+ var PricingTable = forwardRef12(({ className, ...rest }, ref) => {
20333
+ const props = resolveDesignProps8(rest);
20334
+ const { t: t2 } = useTranslation();
20335
+ const { data, settings, isPending, hydratePublic } = useEmbed();
20336
+ const getCallToActionTarget = useCallback14(
20337
+ (url, target) => {
20338
+ if (target) {
20339
+ return target;
20340
+ }
20341
+ if (url) {
20342
+ try {
20343
+ const ctaUrlOrigin = new URL(url).origin;
20344
+ if (ctaUrlOrigin === window.location.hostname) {
20345
+ return "_self";
20346
+ }
20347
+ } catch {
20348
+ }
20349
+ }
20350
+ return "_blank";
20351
+ },
20352
+ []
20353
+ );
20354
+ const { currentPeriod, isStandalone } = useMemo27(() => {
20355
+ const isStandalone2 = typeof data?.component === "undefined";
20356
+ return {
20357
+ currentPeriod: data?.company?.plan?.planPeriod || "month",
20358
+ currentAddOns: data?.company?.addOns || [],
20359
+ canCheckout: isStandalone2 ?? data?.capabilities?.checkout ?? true,
20360
+ isTrialSubscription: data?.company?.billingSubscription?.status === "trialing",
20361
+ willSubscriptionCancel: data?.company?.billingSubscription?.cancelAt,
20362
+ isStandalone: isStandalone2
20363
+ };
20364
+ }, [
20365
+ data?.capabilities?.checkout,
20366
+ data?.company?.addOns,
20367
+ data?.company?.billingSubscription?.cancelAt,
20368
+ data?.company?.billingSubscription?.status,
20369
+ data?.company?.plan?.planPeriod,
20370
+ data?.component
20371
+ ]);
20372
+ const [selectedPeriod, setSelectedPeriod] = useState18(currentPeriod);
20373
+ const showPeriodToggle = rest.showPeriodToggle ?? data?.showPeriodToggle ?? true;
20374
+ const { plans, addOns, periods } = useAvailablePlans(selectedPeriod, {
20375
+ useSelectedPeriod: showPeriodToggle
20376
+ });
20377
+ const [entitlementCounts, setEntitlementCounts] = useState18(
20378
+ () => plans.reduce(entitlementCountsReducer, {})
20379
+ );
20380
+ const handleToggleShowAll = (id) => {
20381
+ setEntitlementCounts((prev2) => {
20382
+ const count = prev2[id] ? { ...prev2[id] } : void 0;
20383
+ if (count) {
19727
20384
  return {
19728
- currentPeriod: data.company?.plan?.planPeriod || "month",
19729
- currentAddOns: data.company?.addOns || [],
19730
- canCheckout: data.capabilities?.checkout ?? true,
19731
- showPeriodToggle: showPeriodToggle2,
19732
- isTrialSubscription,
19733
- willSubscriptionCancel,
19734
- isStandalone: false
20385
+ ...prev2,
20386
+ [id]: {
20387
+ size: count.size,
20388
+ limit: count.limit > VISIBLE_ENTITLEMENT_COUNT ? VISIBLE_ENTITLEMENT_COUNT : count.size
20389
+ }
19735
20390
  };
19736
20391
  }
19737
- return {
19738
- currentPeriod: "month",
19739
- currentAddOns: [],
19740
- canCheckout: true,
19741
- showPeriodToggle: showPeriodToggle2,
19742
- isTrialSubscription: false,
19743
- willSubscriptionCancel: false,
19744
- isStandalone: true
19745
- };
19746
- }, [props.showPeriodToggle, data]);
19747
- const [selectedPeriod, setSelectedPeriod] = useState18(currentPeriod);
19748
- const { plans, addOns, periods } = useAvailablePlans(selectedPeriod, {
19749
- useSelectedPeriod: showPeriodToggle
20392
+ return prev2;
19750
20393
  });
19751
- const [entitlementCounts, setEntitlementCounts] = useState18(
19752
- () => plans.reduce(entitlementCountsReducer, {})
19753
- );
19754
- const handleToggleShowAll = (id) => {
19755
- setEntitlementCounts((prev2) => {
19756
- const count = prev2[id] ? { ...prev2[id] } : void 0;
19757
- if (count) {
19758
- return {
19759
- ...prev2,
19760
- [id]: {
19761
- size: count.size,
19762
- limit: count.limit > VISIBLE_ENTITLEMENT_COUNT ? VISIBLE_ENTITLEMENT_COUNT : count.size
19763
- }
19764
- };
19765
- }
19766
- return prev2;
19767
- });
19768
- };
19769
- useEffect9(() => {
19770
- if (isStandalone) {
19771
- hydratePublic();
19772
- }
19773
- }, [isStandalone, hydratePublic]);
19774
- useEffect9(() => {
19775
- setEntitlementCounts(plans.reduce(entitlementCountsReducer, {}));
19776
- }, [plans]);
19777
- if (isPending) {
19778
- return /* @__PURE__ */ jsx48(
19779
- Flex,
19780
- {
19781
- $width: "100%",
19782
- $height: "100%",
19783
- $alignItems: "center",
19784
- $justifyContent: "center",
19785
- $padding: `${settings.theme.card.padding / TEXT_BASE_SIZE}rem`,
19786
- children: /* @__PURE__ */ jsx48(Loader, { $size: "2xl" })
19787
- }
19788
- );
20394
+ };
20395
+ useEffect8(() => {
20396
+ if (isStandalone) {
20397
+ hydratePublic();
19789
20398
  }
19790
- const Wrapper = isStandalone ? Container : Fragment25;
19791
- return /* @__PURE__ */ jsx48(Wrapper, { children: /* @__PURE__ */ jsxs38(
19792
- FussyChild,
20399
+ }, [isStandalone, hydratePublic]);
20400
+ useEffect8(() => {
20401
+ setEntitlementCounts(plans.reduce(entitlementCountsReducer, {}));
20402
+ }, [plans]);
20403
+ if (isPending) {
20404
+ return /* @__PURE__ */ jsx48(
20405
+ Flex,
19793
20406
  {
19794
- ref,
19795
- className: `sch-PricingTable ${className}`,
19796
- as: Flex,
19797
- $flexDirection: "column",
19798
- $gap: "2rem",
19799
- children: [
19800
- /* @__PURE__ */ jsxs38(Box, { children: [
19801
- /* @__PURE__ */ jsxs38(
19802
- Flex,
19803
- {
19804
- $flexDirection: "column",
19805
- $justifyContent: "center",
19806
- $alignItems: "center",
19807
- $gap: "1rem",
19808
- $marginBottom: "1rem",
19809
- $viewport: {
19810
- md: {
19811
- $flexDirection: "row",
19812
- $justifyContent: "space-between"
19813
- }
19814
- },
19815
- children: [
19816
- /* @__PURE__ */ jsx48(Text, { display: props.header.fontStyle, children: props.header.isVisible && props.plans.isVisible && plans.length > 0 && t2("Plans") }),
19817
- showPeriodToggle && periods.length > 1 && /* @__PURE__ */ jsx48(
19818
- PeriodToggle,
19819
- {
19820
- options: periods,
19821
- selectedOption: selectedPeriod,
19822
- onSelect: (period) => {
19823
- if (period !== selectedPeriod) {
19824
- setSelectedPeriod(period);
19825
- }
20407
+ $width: "100%",
20408
+ $height: "100%",
20409
+ $alignItems: "center",
20410
+ $justifyContent: "center",
20411
+ $padding: `${settings.theme.card.padding / TEXT_BASE_SIZE}rem`,
20412
+ children: /* @__PURE__ */ jsx48(Loader, { "aria-label": "loading", $size: "2xl" })
20413
+ }
20414
+ );
20415
+ }
20416
+ const showCallToAction = typeof data?.component !== "undefined" || typeof rest.callToActionUrl === "string" || typeof rest.onCallToAction === "function";
20417
+ const callToActionTarget = getCallToActionTarget(
20418
+ rest.callToActionUrl,
20419
+ rest.callToActionTarget
20420
+ );
20421
+ const Wrapper = isStandalone ? Container : Fragment25;
20422
+ return /* @__PURE__ */ jsx48(Wrapper, { children: /* @__PURE__ */ jsxs38(
20423
+ FussyChild,
20424
+ {
20425
+ ref,
20426
+ className: `sch-PricingTable ${className}`,
20427
+ as: Flex,
20428
+ "data-testid": "sch-pricing-table",
20429
+ $flexDirection: "column",
20430
+ $gap: "2rem",
20431
+ children: [
20432
+ /* @__PURE__ */ jsxs38(Box, { children: [
20433
+ /* @__PURE__ */ jsxs38(
20434
+ Flex,
20435
+ {
20436
+ $flexDirection: "column",
20437
+ $justifyContent: "center",
20438
+ $alignItems: "center",
20439
+ $gap: "1rem",
20440
+ $marginBottom: "1rem",
20441
+ $viewport: {
20442
+ md: {
20443
+ $flexDirection: "row",
20444
+ $justifyContent: "space-between"
20445
+ }
20446
+ },
20447
+ children: [
20448
+ /* @__PURE__ */ jsx48(Text, { display: props.header.fontStyle, children: props.header.isVisible && props.plans.isVisible && plans.length > 0 && t2("Plans") }),
20449
+ showPeriodToggle && periods.length > 1 && /* @__PURE__ */ jsx48(
20450
+ PeriodToggle,
20451
+ {
20452
+ options: periods,
20453
+ selectedOption: selectedPeriod,
20454
+ onSelect: (period) => {
20455
+ if (period !== selectedPeriod) {
20456
+ setSelectedPeriod(period);
19826
20457
  }
19827
20458
  }
19828
- )
19829
- ]
19830
- }
19831
- ),
19832
- props.plans.isVisible && plans.length > 0 && /* @__PURE__ */ jsx48(
19833
- Box,
19834
- {
19835
- $display: "grid",
19836
- $gridTemplateColumns: "repeat(auto-fill, minmax(320px, 1fr))",
19837
- $gap: "1rem",
19838
- children: plans.map((plan, index, self2) => {
19839
- const planPeriod = showPeriodToggle ? selectedPeriod : plan.yearlyPrice && !plan.monthlyPrice ? "year" /* Year */ : "month" /* Month */;
19840
- return /* @__PURE__ */ jsx48(
19841
- Plan2,
19842
- {
19843
- plan,
19844
- index,
19845
- sharedProps: {
19846
- layout: props,
19847
- callToActionUrl,
19848
- callToActionTarget,
19849
- onCallToAction
19850
- },
19851
- plans: self2,
19852
- selectedPeriod: planPeriod,
19853
- entitlementCounts,
19854
- handleToggleShowAll
20459
+ }
20460
+ )
20461
+ ]
20462
+ }
20463
+ ),
20464
+ props.plans.isVisible && plans.length > 0 && /* @__PURE__ */ jsx48(
20465
+ Box,
20466
+ {
20467
+ "data-testid": "sch-plans",
20468
+ $display: "grid",
20469
+ $gridTemplateColumns: "repeat(auto-fill, minmax(320px, 1fr))",
20470
+ $gap: "1rem",
20471
+ children: plans.map((plan, index, self2) => {
20472
+ const planPeriod = showPeriodToggle ? selectedPeriod : plan.yearlyPrice && !plan.monthlyPrice ? "year" /* Year */ : "month" /* Month */;
20473
+ return /* @__PURE__ */ jsx48(
20474
+ Plan2,
20475
+ {
20476
+ plan,
20477
+ index,
20478
+ sharedProps: {
20479
+ layout: props,
20480
+ showCallToAction,
20481
+ callToActionUrl: rest.callToActionUrl,
20482
+ callToActionTarget,
20483
+ onCallToAction: rest.onCallToAction
19855
20484
  },
19856
- index
19857
- );
19858
- })
19859
- }
19860
- )
19861
- ] }),
19862
- /* @__PURE__ */ jsx48(Box, { children: props.addOns.isVisible && addOns.length > 0 && /* @__PURE__ */ jsxs38(Fragment26, { children: [
19863
- props.header.isVisible && /* @__PURE__ */ jsx48(
19864
- Flex,
19865
- {
19866
- $justifyContent: "space-between",
19867
- $alignItems: "center",
19868
- $marginBottom: "1rem",
19869
- children: /* @__PURE__ */ jsx48(Text, { display: props.header.fontStyle, children: t2("Add-ons") })
19870
- }
19871
- ),
19872
- /* @__PURE__ */ jsx48(
19873
- Box,
19874
- {
19875
- $display: "grid",
19876
- $gridTemplateColumns: "repeat(auto-fill, minmax(320px, 1fr))",
19877
- $gap: "1rem",
19878
- children: addOns.map((addOn, index) => {
19879
- const addOnPeriod = showPeriodToggle ? selectedPeriod : addOn.yearlyPrice && !addOn.monthlyPrice ? "year" /* Year */ : "month" /* Month */;
19880
- return /* @__PURE__ */ jsx48(
19881
- AddOn2,
19882
- {
19883
- addOn,
19884
- sharedProps: {
19885
- layout: props,
19886
- callToActionUrl,
19887
- callToActionTarget,
19888
- onCallToAction
19889
- },
19890
- selectedPeriod: addOnPeriod
20485
+ plans: self2,
20486
+ selectedPeriod: planPeriod,
20487
+ entitlementCounts,
20488
+ handleToggleShowAll
20489
+ },
20490
+ index
20491
+ );
20492
+ })
20493
+ }
20494
+ )
20495
+ ] }),
20496
+ /* @__PURE__ */ jsx48(Box, { children: props.addOns.isVisible && addOns.length > 0 && /* @__PURE__ */ jsxs38(Fragment26, { children: [
20497
+ props.header.isVisible && /* @__PURE__ */ jsx48(
20498
+ Flex,
20499
+ {
20500
+ $justifyContent: "space-between",
20501
+ $alignItems: "center",
20502
+ $marginBottom: "1rem",
20503
+ children: /* @__PURE__ */ jsx48(Text, { display: props.header.fontStyle, children: t2("Add-ons") })
20504
+ }
20505
+ ),
20506
+ /* @__PURE__ */ jsx48(
20507
+ Box,
20508
+ {
20509
+ $display: "grid",
20510
+ $gridTemplateColumns: "repeat(auto-fill, minmax(320px, 1fr))",
20511
+ $gap: "1rem",
20512
+ children: addOns.map((addOn, index) => {
20513
+ const addOnPeriod = showPeriodToggle ? selectedPeriod : addOn.yearlyPrice && !addOn.monthlyPrice ? "year" /* Year */ : "month" /* Month */;
20514
+ return /* @__PURE__ */ jsx48(
20515
+ AddOn2,
20516
+ {
20517
+ addOn,
20518
+ sharedProps: {
20519
+ layout: props,
20520
+ showCallToAction,
20521
+ callToActionUrl: rest.callToActionUrl,
20522
+ callToActionTarget,
20523
+ onCallToAction: rest.onCallToAction
19891
20524
  },
19892
- index
19893
- );
19894
- })
19895
- }
19896
- )
19897
- ] }) })
19898
- ]
19899
- }
19900
- ) });
19901
- }
19902
- );
20525
+ selectedPeriod: addOnPeriod
20526
+ },
20527
+ index
20528
+ );
20529
+ })
20530
+ }
20531
+ )
20532
+ ] }) })
20533
+ ]
20534
+ }
20535
+ ) });
20536
+ });
19903
20537
  PricingTable.displayName = "PricingTable";
19904
20538
 
19905
20539
  // src/components/elements/text/Text.tsx
@@ -19929,7 +20563,7 @@ var TextElement = forwardRef13(({ children, className, ...rest }, ref) => {
19929
20563
  TextElement.displayName = "Text";
19930
20564
 
19931
20565
  // src/components/elements/unsubscribe-button/UnsubscribeButton.tsx
19932
- import { forwardRef as forwardRef14, useMemo as useMemo27 } from "react";
20566
+ import { forwardRef as forwardRef14, useMemo as useMemo28 } from "react";
19933
20567
  import { jsx as jsx50 } from "react/jsx-runtime";
19934
20568
  var buttonStyles = {
19935
20569
  primary: {
@@ -19960,9 +20594,9 @@ var UnsubscribeButton = forwardRef14(({ children, className, ...rest }, ref) =>
19960
20594
  const props = resolveDesignProps10(rest);
19961
20595
  const { t: t2 } = useTranslation();
19962
20596
  const { data, setLayout } = useEmbed();
19963
- const hasActiveSubscription = useMemo27(() => {
19964
- return isCheckoutData(data) && data.subscription && data.subscription.status !== "cancelled" && !data.subscription.cancelAt;
19965
- }, [data]);
20597
+ const hasActiveSubscription = useMemo28(() => {
20598
+ return data?.subscription && data.subscription.status !== "cancelled" && !data.subscription.cancelAt;
20599
+ }, [data?.subscription]);
19966
20600
  if (!hasActiveSubscription) {
19967
20601
  return null;
19968
20602
  }
@@ -19995,7 +20629,7 @@ var UnsubscribeButton = forwardRef14(({ children, className, ...rest }, ref) =>
19995
20629
  UnsubscribeButton.displayName = "UnsubscribeButton";
19996
20630
 
19997
20631
  // src/components/elements/upcoming-bill/UpcomingBill.tsx
19998
- import { forwardRef as forwardRef15, useCallback as useCallback14, useEffect as useEffect10, useMemo as useMemo28, useState as useState19 } from "react";
20632
+ import { forwardRef as forwardRef15, useCallback as useCallback15, useEffect as useEffect9, useMemo as useMemo29, useState as useState19 } from "react";
19999
20633
  import { jsx as jsx51, jsxs as jsxs39 } from "react/jsx-runtime";
20000
20634
  function resolveDesignProps11(props) {
20001
20635
  return {
@@ -20024,20 +20658,18 @@ var UpcomingBill = forwardRef15(({ className, ...rest }, ref) => {
20024
20658
  const [error, setError] = useState19();
20025
20659
  const [upcomingInvoice, setUpcomingInvoice] = useState19();
20026
20660
  const [balances, setBalances] = useState19([]);
20027
- const discounts = useMemo28(() => {
20028
- return (isCheckoutData(data) && data.subscription?.discounts || []).map(
20029
- (discount) => ({
20030
- couponId: discount.couponId,
20031
- customerFacingCode: discount.customerFacingCode || void 0,
20032
- currency: discount.currency || void 0,
20033
- amountOff: discount.amountOff ?? void 0,
20034
- percentOff: discount.percentOff ?? void 0,
20035
- isActive: discount.isActive
20036
- })
20037
- );
20038
- }, [data]);
20039
- const getInvoice = useCallback14(async () => {
20040
- if (isCheckoutData(data) && data.component?.id && data.subscription && !data.subscription.cancelAt) {
20661
+ const discounts = useMemo29(() => {
20662
+ return (data?.subscription?.discounts || []).map((discount) => ({
20663
+ couponId: discount.couponId,
20664
+ customerFacingCode: discount.customerFacingCode || void 0,
20665
+ currency: discount.currency || void 0,
20666
+ amountOff: discount.amountOff ?? void 0,
20667
+ percentOff: discount.percentOff ?? void 0,
20668
+ isActive: discount.isActive
20669
+ }));
20670
+ }, [data?.subscription?.discounts]);
20671
+ const getInvoice = useCallback15(async () => {
20672
+ if (data?.component?.id && data?.subscription && !data.subscription.cancelAt) {
20041
20673
  try {
20042
20674
  setError(void 0);
20043
20675
  setIsLoading(true);
@@ -20051,8 +20683,8 @@ var UpcomingBill = forwardRef15(({ className, ...rest }, ref) => {
20051
20683
  setIsLoading(false);
20052
20684
  }
20053
20685
  }
20054
- }, [data, getUpcomingInvoice]);
20055
- const getBalances = useCallback14(async () => {
20686
+ }, [data?.component?.id, data?.subscription, getUpcomingInvoice]);
20687
+ const getBalances = useCallback15(async () => {
20056
20688
  try {
20057
20689
  const response = await getCustomerBalance();
20058
20690
  if (response) {
@@ -20062,13 +20694,13 @@ var UpcomingBill = forwardRef15(({ className, ...rest }, ref) => {
20062
20694
  debug("Failed to fetch customer balance.", err2);
20063
20695
  }
20064
20696
  }, [debug, getCustomerBalance]);
20065
- useEffect10(() => {
20697
+ useEffect9(() => {
20066
20698
  getInvoice();
20067
20699
  }, [getInvoice]);
20068
- useEffect10(() => {
20700
+ useEffect9(() => {
20069
20701
  getBalances();
20070
20702
  }, [getBalances]);
20071
- if (!isCheckoutData(data) || !data.subscription || data.subscription.cancelAt) {
20703
+ if (!data?.subscription || data.subscription.cancelAt) {
20072
20704
  return null;
20073
20705
  }
20074
20706
  return /* @__PURE__ */ jsxs39(Element, { ref, className, children: [
@@ -24377,7 +25009,7 @@ var { Inflate, inflate, inflateRaw, ungzip } = inflate_1$1;
24377
25009
  var inflate_1 = inflate;
24378
25010
 
24379
25011
  // src/components/embed/Embed.tsx
24380
- import { useContext as useContext5, useEffect as useEffect11, useState as useState20 } from "react";
25012
+ import { useContext as useContext6, useEffect as useEffect10, useState as useState20 } from "react";
24381
25013
 
24382
25014
  // src/components/embed/renderer.ts
24383
25015
  import { createElement as createElement5 } from "react";
@@ -24457,7 +25089,8 @@ function createRenderer(options) {
24457
25089
  }
24458
25090
 
24459
25091
  // src/components/embed/Embed.tsx
24460
- import { Fragment as Fragment27, jsx as jsx52, jsxs as jsxs40 } from "react/jsx-runtime";
25092
+ import { jsx as jsx52, jsxs as jsxs40 } from "react/jsx-runtime";
25093
+ var renderer = createRenderer();
24461
25094
  var Loading = () => {
24462
25095
  const { settings } = useEmbed();
24463
25096
  return /* @__PURE__ */ jsx52(
@@ -24493,7 +25126,7 @@ var Error2 = ({ message }) => {
24493
25126
  };
24494
25127
  var SchematicEmbed = ({ id, accessToken }) => {
24495
25128
  const [children, setChildren] = useState20(/* @__PURE__ */ jsx52(Loading, {}));
24496
- const theme = useContext5(et);
25129
+ const theme = useContext6(et);
24497
25130
  const {
24498
25131
  data,
24499
25132
  error,
@@ -24504,20 +25137,19 @@ var SchematicEmbed = ({ id, accessToken }) => {
24504
25137
  setAccessToken,
24505
25138
  updateSettings
24506
25139
  } = useEmbed();
24507
- useEffect11(() => {
25140
+ useEffect10(() => {
24508
25141
  if (accessToken) {
24509
25142
  setAccessToken(accessToken);
24510
25143
  }
24511
25144
  }, [accessToken, setAccessToken]);
24512
- useEffect11(() => {
25145
+ useEffect10(() => {
24513
25146
  if (id && stale) {
24514
25147
  hydrateComponent(id);
24515
25148
  }
24516
25149
  }, [id, hydrateComponent, stale]);
24517
- useEffect11(() => {
24518
- const renderer = createRenderer();
25150
+ useEffect10(() => {
24519
25151
  try {
24520
- if (isCheckoutData(data) && data.component?.ast) {
25152
+ if (data?.component?.ast) {
24521
25153
  const nodes = [];
24522
25154
  const compressed = data.component.ast;
24523
25155
  const json = inflate_1(
@@ -24537,7 +25169,7 @@ var SchematicEmbed = ({ id, accessToken }) => {
24537
25169
  } catch (err2) {
24538
25170
  setError(isError(err2) ? err2 : ERROR_UNKNOWN);
24539
25171
  }
24540
- }, [data, setError, updateSettings]);
25172
+ }, [data?.component?.ast, setError, updateSettings]);
24541
25173
  if (!theme) {
24542
25174
  return stub();
24543
25175
  }
@@ -24558,7 +25190,7 @@ var SchematicEmbed = ({ id, accessToken }) => {
24558
25190
  if (isPending) {
24559
25191
  return /* @__PURE__ */ jsx52(Loading, {});
24560
25192
  }
24561
- return /* @__PURE__ */ jsx52(Fragment27, { children });
25193
+ return /* @__PURE__ */ jsx52(Box, { className: "sch-Embed", "data-testid": "sch-embed", children });
24562
25194
  };
24563
25195
  export {
24564
25196
  Box,
@@ -24612,13 +25244,23 @@ export {
24612
25244
  useEmbed,
24613
25245
  useIsLightBackground,
24614
25246
  usePaymentConfirmation,
24615
- usePrevious2 as usePrevious,
24616
25247
  useRequest,
24617
25248
  useTrialEnd,
24618
25249
  useWrapChildren
24619
25250
  };
24620
25251
  /*! Bundled license information:
24621
25252
 
25253
+ use-sync-external-store/cjs/use-sync-external-store-shim.development.js:
25254
+ (**
25255
+ * @license React
25256
+ * use-sync-external-store-shim.development.js
25257
+ *
25258
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
25259
+ *
25260
+ * This source code is licensed under the MIT license found in the
25261
+ * LICENSE file in the root directory of this source tree.
25262
+ *)
25263
+
24622
25264
  pako/dist/pako.esm.mjs:
24623
25265
  (*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) *)
24624
25266
  */