@rebuy/rebuy-hydrogen 3.0.0-beta.10 → 3.0.0-beta.3

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.
Files changed (44) hide show
  1. package/dist/components/AddToCartBtn/AddToCartBtn.d.ts.map +1 -1
  2. package/dist/components/AddToCartBtn/HydrogenAddToCartBtn.d.ts.map +1 -1
  3. package/dist/components/AddToCartBtn/HydrogenReactAddToCartBtn.d.ts.map +1 -1
  4. package/dist/components/ProductCard/ProductCard.d.ts.map +1 -1
  5. package/dist/components/ProductPrice/ProductPrice.d.ts +1 -1
  6. package/dist/components/ProductPrice/ProductPrice.d.ts.map +1 -1
  7. package/dist/components/VariantSelect/VariantSelect.d.ts +1 -1
  8. package/dist/components/VariantSelect/VariantSelect.d.ts.map +1 -1
  9. package/dist/hooks/titleLevel.d.ts.map +1 -1
  10. package/dist/index.css +88 -88
  11. package/dist/index.css.map +4 -4
  12. package/dist/index.js +421 -195
  13. package/dist/index.js.map +4 -4
  14. package/dist/index.mjs +430 -196
  15. package/dist/index.mjs.map +4 -4
  16. package/dist/providers/RebuyHydrogenContextProvider.d.ts +1 -1
  17. package/dist/providers/RebuyHydrogenContextProvider.d.ts.map +1 -1
  18. package/dist/providers/RebuyHydrogenReactContextProvider.d.ts.map +1 -1
  19. package/dist/providers/types.d.ts +1 -7
  20. package/dist/providers/types.d.ts.map +1 -1
  21. package/dist/types/rebuyCustom.d.ts +0 -1
  22. package/dist/types/rebuyCustom.d.ts.map +1 -1
  23. package/dist/types/shopify.d.ts.map +1 -1
  24. package/dist/types/widgets.d.ts +1 -1
  25. package/dist/types/widgets.d.ts.map +1 -1
  26. package/dist/utils/convertToRebuyProduct.d.ts.map +1 -1
  27. package/dist/utils/createContextParameters.d.ts.map +1 -1
  28. package/dist/utils/getEncodedAttributes.d.ts.map +1 -1
  29. package/dist/utils/getRebuyConfig.d.ts +1 -1
  30. package/dist/utils/getRebuyConfig.d.ts.map +1 -1
  31. package/dist/widgetContainer/RebuyWidgetContainer.d.ts +1 -1
  32. package/dist/widgetContainer/RebuyWidgetContainer.d.ts.map +1 -1
  33. package/dist/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.d.ts.map +1 -1
  34. package/dist/widgets/RebuyDynamicBundleProducts/BundleImages.d.ts.map +1 -1
  35. package/dist/widgets/RebuyDynamicBundleProducts/BundlePrice.d.ts.map +1 -1
  36. package/dist/widgets/RebuyDynamicBundleProducts/BundleSelection.d.ts +1 -1
  37. package/dist/widgets/RebuyDynamicBundleProducts/BundleSelection.d.ts.map +1 -1
  38. package/dist/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.d.ts.map +1 -1
  39. package/dist/widgets/RebuyDynamicBundleProducts/Select.d.ts.map +1 -1
  40. package/dist/widgets/RebuyProductAddOns/RebuyProductAddOnCard.d.ts.map +1 -1
  41. package/dist/widgets/RebuyProductAddOns/RebuyProductAddOns.d.ts.map +1 -1
  42. package/dist/widgets/RebuyProductAddOns/types.d.ts.map +1 -1
  43. package/dist/widgets/RebuyProductRecommendations/RebuyProductRecommendations.d.ts.map +1 -1
  44. package/package.json +20 -3
package/dist/index.mjs CHANGED
@@ -12,7 +12,12 @@ import * as Utilities from "@rebuy/rebuy/utilities";
12
12
 
13
13
  // src/utils/getEncodedAttributes.ts
14
14
  var getEncodedAttributes = (attributes) => encodeURIComponent(
15
- JSON.stringify(attributes.reduce((merged, { key, value }) => ({ ...merged, [key]: value }), {}))
15
+ JSON.stringify(
16
+ attributes.reduce(
17
+ (merged, { key, value }) => ({ ...merged, [key]: value }),
18
+ {}
19
+ )
20
+ )
16
21
  );
17
22
 
18
23
  // src/utils/createContextParameters.ts
@@ -53,11 +58,18 @@ var createContextParameters = ({
53
58
  }
54
59
  if (cartId) {
55
60
  cartContext.token = Utilities.getIdFromGraphUrl(cartId, "Cart");
56
- contextParameters.cart_token = Utilities.getIdFromGraphUrl(cartId, "Cart");
61
+ contextParameters.cart_token = Utilities.getIdFromGraphUrl(
62
+ cartId,
63
+ "Cart"
64
+ );
57
65
  }
58
66
  if (cartSubtotal) {
59
- cartContext.subtotal = Utilities.amountToCents(parseFloat(cartSubtotal));
60
- contextParameters.cart_subtotal = Utilities.amountToCents(parseFloat(cartSubtotal));
67
+ cartContext.subtotal = Utilities.amountToCents(
68
+ parseFloat(cartSubtotal)
69
+ );
70
+ contextParameters.cart_subtotal = Utilities.amountToCents(
71
+ parseFloat(cartSubtotal)
72
+ );
61
73
  }
62
74
  if (cartLinesLength) {
63
75
  const totalLines = cartLinesLength;
@@ -80,10 +92,16 @@ var createContextParameters = ({
80
92
  variant_id: ""
81
93
  };
82
94
  if (cartItem?.merchandise?.product?.id) {
83
- item.product_id = Utilities.getIdFromGraphUrl(cartItem.merchandise.product.id, "Product");
95
+ item.product_id = Utilities.getIdFromGraphUrl(
96
+ cartItem.merchandise.product.id,
97
+ "Product"
98
+ );
84
99
  }
85
100
  if (cartItem?.merchandise?.id) {
86
- item.variant_id = Utilities.getIdFromGraphUrl(cartItem.merchandise.id, "ProductVariant");
101
+ item.variant_id = Utilities.getIdFromGraphUrl(
102
+ cartItem.merchandise.id,
103
+ "ProductVariant"
104
+ );
87
105
  }
88
106
  if (cartItem?.attributes?.length) {
89
107
  const validAttributes = cartItem.attributes.filter(
@@ -109,18 +127,20 @@ var createContextParameters = ({
109
127
 
110
128
  // src/utils/getRebuyConfig.ts
111
129
  import { RebuyClient } from "@rebuy/rebuy";
112
- var getRebuyConfig = async (storeDomain) => {
130
+ var getRebuyConfig = async (rebuyKey, storeDomain) => {
113
131
  try {
114
132
  const request = {
115
133
  parameters: { shop: storeDomain },
116
134
  url: `/api/v1/user/config`
117
135
  };
118
- const { data: rebuy, ...response } = await new RebuyClient(void 0, void 0, storeDomain).getShieldedAsset(
119
- request.url,
120
- request.parameters
121
- );
136
+ const { data: rebuy, ...response } = await new RebuyClient(
137
+ rebuyKey
138
+ ).getShieldedAsset(request.url, request.parameters);
122
139
  if (!rebuy?.shop) {
123
- throw new Error("Rebuy configuration is not properly set up - missing shop", { cause: response });
140
+ throw new Error(
141
+ "Rebuy configuration is not properly set up - missing shop",
142
+ { cause: response }
143
+ );
124
144
  }
125
145
  return rebuy;
126
146
  } catch (error) {
@@ -134,30 +154,30 @@ var getRebuyConfig = async (storeDomain) => {
134
154
  // src/providers/RebuyHydrogenContextProvider.tsx
135
155
  import { jsx } from "react/jsx-runtime";
136
156
  var RebuyHydrogenContext = ({
137
- apiKey,
138
157
  cartAttributes,
139
158
  cartCost,
140
159
  cartId,
141
160
  cartLines,
142
161
  cartNote,
143
162
  cartQuantity,
144
- children,
145
- publicStoreDomain,
146
- shop
163
+ children
147
164
  }) => {
165
+ const primaryDomain = import.meta.env.PRIMARY_DOMAIN;
166
+ const rebuyKey = import.meta.env.PUBLIC_REBUY_API_KEY;
167
+ const storeDomain = import.meta.env.PUBLIC_STORE_DOMAIN;
148
168
  const [rebuyConfig, setRebuyConfig] = useState(null);
149
169
  const location = useLocation();
150
170
  const queryObject = Utilities2.queryStringToObject(location.search);
151
- const windowUrl = `${shop}${location.pathname}${location.search}`;
171
+ const windowUrl = `${primaryDomain}${location.pathname}${location.search}`;
152
172
  useEffect(() => {
153
173
  const initConfig = async () => {
154
- const config = await getRebuyConfig(publicStoreDomain);
174
+ const config = await getRebuyConfig(rebuyKey, storeDomain);
155
175
  setRebuyConfig(config);
156
176
  };
157
177
  if (!rebuyConfig?.shop) {
158
178
  initConfig();
159
179
  }
160
- }, [rebuyConfig]);
180
+ }, [rebuyConfig, rebuyKey, storeDomain]);
161
181
  const contextParameters = useMemo(
162
182
  () => createContextParameters({
163
183
  cacheKey: rebuyConfig?.shop?.cache_key,
@@ -172,7 +192,17 @@ var RebuyHydrogenContext = ({
172
192
  queryObject,
173
193
  windowUrl
174
194
  }),
175
- [rebuyConfig, windowUrl, queryObject, cartAttributes, cartCost, cartId, cartLines, cartQuantity, cartNote]
195
+ [
196
+ rebuyConfig,
197
+ windowUrl,
198
+ queryObject,
199
+ cartAttributes,
200
+ cartCost,
201
+ cartId,
202
+ cartLines,
203
+ cartQuantity,
204
+ cartNote
205
+ ]
176
206
  );
177
207
  const contextParametersJSON = JSON.stringify(contextParameters);
178
208
  const contextValue = useMemo(
@@ -182,26 +212,20 @@ var RebuyHydrogenContext = ({
182
212
  return /* @__PURE__ */ jsx(RebuyContext.Provider, { value: contextValue, children });
183
213
  };
184
214
  var RebuyHydrogenContextProvider = ({
185
- apiKey,
186
215
  cart,
187
- children,
188
- publicStoreDomain,
189
- shop
216
+ children
190
217
  }) => {
191
218
  return /* @__PURE__ */ jsx(Await, { resolve: cart, children: (resolvedCart) => {
192
219
  const cart2 = resolvedCart;
193
220
  return /* @__PURE__ */ jsx(
194
221
  RebuyHydrogenContext,
195
222
  {
196
- apiKey,
197
223
  cartAttributes: cart2?.attributes,
198
224
  cartCost: cart2?.cost?.subtotalAmount?.amount,
199
225
  cartId: cart2?.id,
200
226
  cartLines: cart2?.lines?.nodes,
201
227
  cartNote: cart2?.note,
202
228
  cartQuantity: cart2?.totalQuantity,
203
- publicStoreDomain,
204
- shop,
205
229
  children
206
230
  }
207
231
  );
@@ -211,7 +235,11 @@ var RebuyHydrogenContextProvider = ({
211
235
  // src/providers/RebuyHydrogenReactContextProvider.tsx
212
236
  import * as Utilities3 from "@rebuy/rebuy/utilities";
213
237
  import { useLocation as useLocation2 } from "@remix-run/react";
214
- import { CartProvider, ShopifyProvider, useCart } from "@shopify/hydrogen-react";
238
+ import {
239
+ CartProvider,
240
+ ShopifyProvider,
241
+ useCart
242
+ } from "@shopify/hydrogen-react";
215
243
  import { useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
216
244
 
217
245
  // src/queries/cart.queries.ts
@@ -677,26 +705,24 @@ var CART_FRAGMENT = `#graphql
677
705
 
678
706
  // src/providers/RebuyHydrogenReactContextProvider.tsx
679
707
  import { jsx as jsx2 } from "react/jsx-runtime";
680
- var PUBLIC_PRIMARY_DOMAIN = import.meta.env.PUBLIC_PRIMARY_DOMAIN;
681
- var PUBLIC_REBUY_API_KEY = import.meta.env.PUBLIC_REBUY_API_KEY;
682
- var PUBLIC_STORE_DOMAIN = import.meta.env.PUBLIC_STORE_DOMAIN;
683
- var PUBLIC_STOREFRONT_ID = import.meta.env.PUBLIC_STOREFRONT_ID;
684
- var PUBLIC_STOREFRONT_API_TOKEN = import.meta.env.PUBLIC_STOREFRONT_API_TOKEN || "";
685
708
  var RebuyHydrogenReactContext = ({ children }) => {
709
+ const primaryDomain = import.meta.env.PRIMARY_DOMAIN;
710
+ const rebuyKey = import.meta.env.PUBLIC_REBUY_API_KEY;
711
+ const storeDomain = import.meta.env.PUBLIC_STORE_DOMAIN;
686
712
  const [rebuyConfig, setRebuyConfig] = useState2(null);
687
713
  const location = useLocation2();
688
714
  const queryObject = Utilities3.queryStringToObject(location.search);
689
- const windowUrl = `${PUBLIC_PRIMARY_DOMAIN}${location.pathname}${location.search}`;
715
+ const windowUrl = `${primaryDomain}${location.pathname}${location.search}`;
690
716
  const cart = useCart();
691
717
  useEffect2(() => {
692
718
  const initConfig = async () => {
693
- const config = await getRebuyConfig(PUBLIC_STORE_DOMAIN);
719
+ const config = await getRebuyConfig(rebuyKey, storeDomain);
694
720
  setRebuyConfig(config);
695
721
  };
696
722
  if (!rebuyConfig?.shop) {
697
723
  initConfig();
698
724
  }
699
- }, [rebuyConfig, PUBLIC_STORE_DOMAIN]);
725
+ }, [rebuyConfig, rebuyKey, storeDomain]);
700
726
  const contextParameters = useMemo2(
701
727
  () => createContextParameters({
702
728
  cacheKey: rebuyConfig?.shop?.cache_key,
@@ -745,6 +771,9 @@ var RebuyHydrogenReactContextProvider = ({
745
771
  onNoteUpdateComplete,
746
772
  storefrontApiVersion = "2025-01"
747
773
  }) => {
774
+ const publicStoreDomain = import.meta.env.PUBLIC_STORE_DOMAIN;
775
+ const storefrontId = import.meta.env.PUBLIC_STOREFRONT_ID;
776
+ const storefrontToken = import.meta.env.PUBLIC_STOREFRONT_API_TOKEN || "";
748
777
  const adapted = {
749
778
  onAttributesUpdate: onAttributesUpdate ? () => onAttributesUpdate() : void 0,
750
779
  onAttributesUpdateComplete: onAttributesUpdateComplete ? () => onAttributesUpdateComplete() : void 0,
@@ -768,10 +797,10 @@ var RebuyHydrogenReactContextProvider = ({
768
797
  {
769
798
  countryIsoCode,
770
799
  languageIsoCode,
771
- storeDomain: PUBLIC_STORE_DOMAIN,
800
+ storeDomain: publicStoreDomain,
772
801
  storefrontApiVersion,
773
- storefrontId: PUBLIC_STOREFRONT_ID,
774
- storefrontToken: PUBLIC_STOREFRONT_API_TOKEN,
802
+ storefrontId,
803
+ storefrontToken,
775
804
  children: /* @__PURE__ */ jsx2(
776
805
  CartProvider,
777
806
  {
@@ -808,9 +837,27 @@ var RebuyHydrogenReactContextProvider = ({
808
837
  import { RebuyClient as RebuyClient2 } from "@rebuy/rebuy";
809
838
  import * as Utilities4 from "@rebuy/rebuy/utilities";
810
839
  import { flattenConnection } from "@shopify/hydrogen";
811
- import React, { useContext, useEffect as useEffect3, useMemo as useMemo3, useState as useState3 } from "react";
812
- var RebuyWidgetContainerBase = ({ children, ...props }) => {
813
- const { apiKey, collection, collectionId, dataSource, limit, options, product, productId, variant, variantId } = props;
840
+ import React, {
841
+ useContext,
842
+ useEffect as useEffect3,
843
+ useMemo as useMemo3,
844
+ useState as useState3
845
+ } from "react";
846
+ var RebuyWidgetContainerBase = ({
847
+ children,
848
+ ...props
849
+ }) => {
850
+ const {
851
+ collection,
852
+ collectionId,
853
+ dataSource,
854
+ limit,
855
+ options,
856
+ product,
857
+ productId,
858
+ variant,
859
+ variantId
860
+ } = props;
814
861
  const contextParameters = useContext(RebuyContext);
815
862
  const [Rebuy, setRebuy] = useState3(null);
816
863
  const [initialized, setInitialized] = useState3(false);
@@ -819,9 +866,10 @@ var RebuyWidgetContainerBase = ({ children, ...props }) => {
819
866
  const shopifyCollectionId = collection?.id ?? collectionId ?? null;
820
867
  const [products, setProducts] = useState3([]);
821
868
  const [metadata, setMetadata] = useState3();
869
+ const REBUY_API_KEY = import.meta.env.PUBLIC_REBUY_API_KEY;
822
870
  useEffect3(() => {
823
871
  if (!Rebuy) {
824
- const client = new RebuyClient2(apiKey);
872
+ const client = new RebuyClient2(REBUY_API_KEY);
825
873
  client.setContextParameters(
826
874
  contextParameters
827
875
  // TODO: fix this type when @rebuy/rebuy is moved to typescript
@@ -832,7 +880,7 @@ var RebuyWidgetContainerBase = ({ children, ...props }) => {
832
880
  setRebuy(client);
833
881
  setInitialized(true);
834
882
  }
835
- }, [apiKey, Rebuy, contextParameters, options]);
883
+ }, [REBUY_API_KEY, Rebuy, contextParameters, options]);
836
884
  useEffect3(() => {
837
885
  if (!Rebuy) return;
838
886
  Rebuy.setContextParameters(
@@ -847,27 +895,48 @@ var RebuyWidgetContainerBase = ({ children, ...props }) => {
847
895
  // Keeping this object generic to allow for custom endpoints
848
896
  };
849
897
  if (shopifyProductId) {
850
- request2.params.shopify_product_ids = Utilities4.getIdFromGraphUrl(shopifyProductId, "Product");
898
+ request2.params.shopify_product_ids = Utilities4.getIdFromGraphUrl(
899
+ shopifyProductId,
900
+ "Product"
901
+ );
851
902
  }
852
903
  if (shopifyProductId) {
853
- request2.params.shopify_product_ids = Utilities4.getIdFromGraphUrl(shopifyProductId, "Product");
904
+ request2.params.shopify_product_ids = Utilities4.getIdFromGraphUrl(
905
+ shopifyProductId,
906
+ "Product"
907
+ );
854
908
  }
855
909
  if (shopifyVariantId) {
856
- request2.params.shopify_variant_ids = Utilities4.getIdFromGraphUrl(shopifyVariantId, "ProductVariant");
910
+ request2.params.shopify_variant_ids = Utilities4.getIdFromGraphUrl(
911
+ shopifyVariantId,
912
+ "ProductVariant"
913
+ );
857
914
  }
858
915
  if (shopifyCollectionId) {
859
- request2.params.shopify_collection_ids = Utilities4.getIdFromGraphUrl(shopifyCollectionId, "Collection");
916
+ request2.params.shopify_collection_ids = Utilities4.getIdFromGraphUrl(
917
+ shopifyCollectionId,
918
+ "Collection"
919
+ );
860
920
  }
861
921
  if (limit) {
862
922
  request2.params.limit = limit;
863
923
  }
864
924
  return request2;
865
- }, [dataSource, shopifyProductId, shopifyVariantId, shopifyCollectionId, limit]);
925
+ }, [
926
+ dataSource,
927
+ shopifyProductId,
928
+ shopifyVariantId,
929
+ shopifyCollectionId,
930
+ limit
931
+ ]);
866
932
  useEffect3(() => {
867
933
  let isMounted = true;
868
934
  if (!Rebuy || !initialized) return;
869
935
  const fetchData = async () => {
870
- const { data, metadata: metadata2 } = await Rebuy.getStorefrontData(request.endpoint, request.params);
936
+ const { data, metadata: metadata2 } = await Rebuy.getStorefrontData(
937
+ request.endpoint,
938
+ request.params
939
+ );
871
940
  if (isMounted) {
872
941
  setProducts(
873
942
  Array.isArray(data) ? data.map((product2) => ({
@@ -900,11 +969,24 @@ var RebuyWidgetContainerBase = ({ children, ...props }) => {
900
969
  };
901
970
  var RebuyWidgetContainer = RebuyWidgetContainerBase;
902
971
 
972
+ // src/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.module.css
973
+ var RebuyCompleteTheLook_default = {
974
+ container: "RebuyCompleteTheLook_container",
975
+ productGrid: "RebuyCompleteTheLook_productGrid",
976
+ productItem: "RebuyCompleteTheLook_productItem"
977
+ };
978
+
903
979
  // src/components/ProductCard/ProductCard.tsx
904
980
  import { Link } from "@remix-run/react";
905
981
  import { Image } from "@shopify/hydrogen";
906
982
  import { useState as useState4 } from "react";
907
983
 
984
+ // src/components/ProductCard/ProductCard.module.css
985
+ var ProductCard_default = {
986
+ container: "ProductCard_container",
987
+ productInfo: "ProductCard_productInfo"
988
+ };
989
+
908
990
  // src/components/AddToCartBtn/HydrogenAddToCartBtn.tsx
909
991
  import { CartForm, Money } from "@shopify/hydrogen";
910
992
 
@@ -965,13 +1047,22 @@ var HydrogenReactAddToCartBtn = ({
965
1047
  linesAdd(linesToAdd);
966
1048
  addToCartCallback?.();
967
1049
  };
968
- return /* @__PURE__ */ jsxs2("button", { className: AddToCartBtn_default.button, disabled, onClick: handleAddToCart, type: "button", children: [
969
- addToCartBtnText,
970
- moneyData && /* @__PURE__ */ jsxs2(Fragment2, { children: [
971
- /* @__PURE__ */ jsx4("span", { children: " | " }),
972
- /* @__PURE__ */ jsx4(Money2, { data: moneyData, withoutTrailingZeros: true })
973
- ] })
974
- ] });
1050
+ return /* @__PURE__ */ jsxs2(
1051
+ "button",
1052
+ {
1053
+ className: AddToCartBtn_default.button,
1054
+ disabled,
1055
+ onClick: handleAddToCart,
1056
+ type: "button",
1057
+ children: [
1058
+ addToCartBtnText,
1059
+ moneyData && /* @__PURE__ */ jsxs2(Fragment2, { children: [
1060
+ /* @__PURE__ */ jsx4("span", { children: " | " }),
1061
+ /* @__PURE__ */ jsx4(Money2, { data: moneyData, withoutTrailingZeros: true })
1062
+ ] })
1063
+ ]
1064
+ }
1065
+ );
975
1066
  };
976
1067
 
977
1068
  // src/components/AddToCartBtn/AddToCartBtn.tsx
@@ -1028,12 +1119,24 @@ var ProductPrice_default = {
1028
1119
 
1029
1120
  // src/components/ProductPrice/ProductPrice.tsx
1030
1121
  import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
1031
- var RebuyProductPrice = ({ selectedVariant }) => {
1122
+ var RebuyProductPrice = ({
1123
+ selectedVariant
1124
+ }) => {
1032
1125
  if (!selectedVariant) return null;
1033
1126
  const { compareAtPriceV2: compareAtPrice, priceV2: price } = selectedVariant;
1034
1127
  const isDiscounted = (price2, compareAtPrice2) => Number(compareAtPrice2?.amount) > Number(price2?.amount);
1035
- const CompareAtPrice = ({ data: compareAtPrice2 }) => {
1036
- return compareAtPrice2 && /* @__PURE__ */ jsx6(Money3, { as: "span", className: ProductPrice_default.compareAtPrice, data: compareAtPrice2, withoutTrailingZeros: true });
1128
+ const CompareAtPrice = ({
1129
+ data: compareAtPrice2
1130
+ }) => {
1131
+ return compareAtPrice2 && /* @__PURE__ */ jsx6(
1132
+ Money3,
1133
+ {
1134
+ as: "span",
1135
+ className: ProductPrice_default.compareAtPrice,
1136
+ data: compareAtPrice2,
1137
+ withoutTrailingZeros: true
1138
+ }
1139
+ );
1037
1140
  };
1038
1141
  return price && /* @__PURE__ */ jsxs3("div", { className: ProductPrice_default.priceContainer, children: [
1039
1142
  /* @__PURE__ */ jsx6(Money3, { data: price, withoutTrailingZeros: true }),
@@ -1068,12 +1171,17 @@ var VariantSelect_default = {
1068
1171
 
1069
1172
  // src/components/VariantSelect/VariantSelect.tsx
1070
1173
  import { jsx as jsx8 } from "react/jsx-runtime";
1071
- var VariantSelect = ({ handleSelectedVariant, product }) => {
1174
+ var VariantSelect = ({
1175
+ handleSelectedVariant,
1176
+ product
1177
+ }) => {
1072
1178
  const getOptionsLabel = (product2) => {
1073
1179
  const options = product2.variants.nodes[0].selectedOptions;
1074
1180
  const optionsFromKeys = options ? Object.keys(options[0]) : [];
1075
1181
  const optionsFromValues = options ? options.map((option) => option.name) : [];
1076
- const useValues = optionsFromKeys.every((key) => ["name", "value"].includes(key));
1182
+ const useValues = optionsFromKeys.every(
1183
+ (key) => ["name", "value"].includes(key)
1184
+ );
1077
1185
  return (useValues ? optionsFromValues : optionsFromKeys).join(" / ");
1078
1186
  };
1079
1187
  return product?.variants.nodes.length > 1 && /* @__PURE__ */ jsx8("div", { children: /* @__PURE__ */ jsx8(
@@ -1087,12 +1195,6 @@ var VariantSelect = ({ handleSelectedVariant, product }) => {
1087
1195
  ) });
1088
1196
  };
1089
1197
 
1090
- // src/components/ProductCard/ProductCard.module.css
1091
- var ProductCard_default = {
1092
- container: "ProductCard_container",
1093
- productInfo: "ProductCard_productInfo"
1094
- };
1095
-
1096
1198
  // src/components/ProductCard/ProductCard.tsx
1097
1199
  import { jsx as jsx9, jsxs as jsxs4 } from "react/jsx-runtime";
1098
1200
  var ProductCard = ({
@@ -1102,10 +1204,14 @@ var ProductCard = ({
1102
1204
  product,
1103
1205
  productCardTitleLevel
1104
1206
  }) => {
1105
- const [selectedVariant, setSelectedVariant] = useState4(product.variants.nodes[0]);
1207
+ const [selectedVariant, setSelectedVariant] = useState4(
1208
+ product.variants.nodes[0]
1209
+ );
1106
1210
  const { image } = selectedVariant;
1107
1211
  const handleSelectedVariant = (product2, variant_id) => {
1108
- const updatedVariant = product2.variants.nodes.find((variant) => variant.id === variant_id);
1212
+ const updatedVariant = product2.variants.nodes.find(
1213
+ (variant) => variant.id === variant_id
1214
+ );
1109
1215
  if (updatedVariant) {
1110
1216
  setSelectedVariant(updatedVariant);
1111
1217
  }
@@ -1121,9 +1227,21 @@ var ProductCard = ({
1121
1227
  }
1122
1228
  ) }),
1123
1229
  /* @__PURE__ */ jsxs4("div", { className: ProductCard_default.productInfo, children: [
1124
- /* @__PURE__ */ jsx9(Link, { to: `/products/${product.handle}`, children: /* @__PURE__ */ jsx9(Title, { level: productCardTitleLevel, text: product.title }) }),
1230
+ /* @__PURE__ */ jsx9(Link, { to: `/products/${product.handle}`, children: /* @__PURE__ */ jsx9(
1231
+ Title,
1232
+ {
1233
+ level: productCardTitleLevel,
1234
+ text: product.title
1235
+ }
1236
+ ) }),
1125
1237
  /* @__PURE__ */ jsx9(RebuyProductPrice, { selectedVariant }),
1126
- /* @__PURE__ */ jsx9(VariantSelect, { handleSelectedVariant, product })
1238
+ /* @__PURE__ */ jsx9(
1239
+ VariantSelect,
1240
+ {
1241
+ handleSelectedVariant,
1242
+ product
1243
+ }
1244
+ )
1127
1245
  ] })
1128
1246
  ] }),
1129
1247
  /* @__PURE__ */ jsx9(
@@ -1176,13 +1294,6 @@ var getTitleLevel = (level, decreaseLevel = false) => {
1176
1294
  }
1177
1295
  };
1178
1296
 
1179
- // src/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.module.css
1180
- var RebuyCompleteTheLook_default = {
1181
- container: "RebuyCompleteTheLook_container",
1182
- productGrid: "RebuyCompleteTheLook_productGrid",
1183
- productItem: "RebuyCompleteTheLook_productItem"
1184
- };
1185
-
1186
1297
  // src/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.tsx
1187
1298
  import { jsx as jsx10, jsxs as jsxs5 } from "react/jsx-runtime";
1188
1299
  var RebuyCompleteTheLook = (props) => {
@@ -1199,7 +1310,14 @@ var RebuyCompleteTheLook = (props) => {
1199
1310
  return null;
1200
1311
  }
1201
1312
  return /* @__PURE__ */ jsxs5("section", { className: RebuyCompleteTheLook_default.container, children: [
1202
- /* @__PURE__ */ jsx10(Title, { level: getTitleLevel(customTitleLevel), style: customTitleStyle, text: customTitle }),
1313
+ /* @__PURE__ */ jsx10(
1314
+ Title,
1315
+ {
1316
+ level: getTitleLevel(customTitleLevel),
1317
+ style: customTitleStyle,
1318
+ text: customTitle
1319
+ }
1320
+ ),
1203
1321
  /* @__PURE__ */ jsx10("ul", { className: RebuyCompleteTheLook_default.productGrid, children: products.map((product) => /* @__PURE__ */ jsx10("li", { className: RebuyCompleteTheLook_default.productItem, children: /* @__PURE__ */ jsx10(
1204
1322
  ProductCard,
1205
1323
  {
@@ -1207,7 +1325,10 @@ var RebuyCompleteTheLook = (props) => {
1207
1325
  addToCartCallback,
1208
1326
  isHydrogenReact: props.isHydrogenReact,
1209
1327
  product,
1210
- productCardTitleLevel: getTitleLevel(customTitleLevel, true)
1328
+ productCardTitleLevel: getTitleLevel(
1329
+ customTitleLevel,
1330
+ true
1331
+ )
1211
1332
  }
1212
1333
  ) }, product.id)) })
1213
1334
  ] });
@@ -1216,6 +1337,84 @@ var RebuyCompleteTheLook = (props) => {
1216
1337
  // src/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.tsx
1217
1338
  import { useCallback, useEffect as useEffect4, useState as useState5 } from "react";
1218
1339
 
1340
+ // src/widgets/RebuyDynamicBundleProducts/BundlePrice.tsx
1341
+ import { Money as Money4 } from "@shopify/hydrogen";
1342
+
1343
+ // src/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.module.css
1344
+ var RebuyDynamicBundleProducts_default = {
1345
+ container: "RebuyDynamicBundleProducts_container",
1346
+ addCartBtnContainer: "RebuyDynamicBundleProducts_addCartBtnContainer",
1347
+ bundleContainer: "RebuyDynamicBundleProducts_bundleContainer",
1348
+ select: "RebuyDynamicBundleProducts_select",
1349
+ bundleItemRowContainer: "RebuyDynamicBundleProducts_bundleItemRowContainer",
1350
+ unselected: "RebuyDynamicBundleProducts_unselected",
1351
+ bundleItemRow: "RebuyDynamicBundleProducts_bundleItemRow",
1352
+ bundleItemInput: "RebuyDynamicBundleProducts_bundleItemInput",
1353
+ bundleItemLabel: "RebuyDynamicBundleProducts_bundleItemLabel",
1354
+ bundleImages: "RebuyDynamicBundleProducts_bundleImages",
1355
+ bundleImage: "RebuyDynamicBundleProducts_bundleImage",
1356
+ fadeIn: "RebuyDynamicBundleProducts_fadeIn",
1357
+ bundleImageDelimiter: "RebuyDynamicBundleProducts_bundleImageDelimiter",
1358
+ compareAtPrice: "RebuyDynamicBundleProducts_compareAtPrice"
1359
+ };
1360
+
1361
+ // src/widgets/RebuyDynamicBundleProducts/BundlePrice.tsx
1362
+ import { jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
1363
+ var BundlePrice = ({ products }) => {
1364
+ const isDisabled = products.filter((product) => product.selected).length < 1;
1365
+ const totalBundlePrice = () => {
1366
+ let total = 0;
1367
+ let currencyCode = "USD";
1368
+ for (const product of products) {
1369
+ if (product.selected && product.selectedVariant) {
1370
+ const { priceV2: price2 } = product.selectedVariant;
1371
+ total += Number(price2?.amount);
1372
+ currencyCode = price2?.currencyCode || "USD";
1373
+ }
1374
+ }
1375
+ return {
1376
+ amount: String(total),
1377
+ currencyCode
1378
+ };
1379
+ };
1380
+ const totalBundleCompareAtPrice = () => {
1381
+ let compareAtTotal = 0;
1382
+ let currencyCode = "USD";
1383
+ for (const product of products) {
1384
+ if (product.selected && product.selectedVariant) {
1385
+ const { compareAtPriceV2: compareAtPrice2, priceV2: price2 } = product.selectedVariant;
1386
+ currencyCode = price2?.currencyCode || "USD";
1387
+ compareAtTotal += Number((compareAtPrice2 || price2)?.amount);
1388
+ }
1389
+ }
1390
+ return {
1391
+ amount: String(compareAtTotal),
1392
+ currencyCode
1393
+ };
1394
+ };
1395
+ const isDiscounted = (price2, compareAtPrice2) => Number(compareAtPrice2?.amount) > Number(price2?.amount);
1396
+ const price = totalBundlePrice();
1397
+ const compareAtPrice = totalBundleCompareAtPrice();
1398
+ const CompareAtPrice = ({
1399
+ data: compareAtPrice2
1400
+ }) => {
1401
+ return compareAtPrice2 && /* @__PURE__ */ jsx11(
1402
+ Money4,
1403
+ {
1404
+ as: "span",
1405
+ className: RebuyDynamicBundleProducts_default.compareAtPrice,
1406
+ data: compareAtPrice2,
1407
+ withoutTrailingZeros: true
1408
+ }
1409
+ );
1410
+ };
1411
+ return products.length > 0 && /* @__PURE__ */ jsx11("div", { className: "flex items-center flex-col", children: !isDisabled && /* @__PURE__ */ jsxs6("p", { className: "flex items-center gap-2 mb-2", children: [
1412
+ /* @__PURE__ */ jsx11("span", { children: "Total Price:" }),
1413
+ /* @__PURE__ */ jsx11(Money4, { as: "span", data: price, withoutTrailingZeros: true }),
1414
+ isDiscounted(price, compareAtPrice) && /* @__PURE__ */ jsx11(CompareAtPrice, { data: compareAtPrice })
1415
+ ] }) });
1416
+ };
1417
+
1219
1418
  // src/utils/convertToRebuyProduct.tsx
1220
1419
  var convertToRebuyProduct = (isHydrogenReact, product) => {
1221
1420
  const mainProductVariants = isHydrogenReact ? product?.variants?.nodes?.map((variant) => {
@@ -1275,7 +1474,9 @@ var convertToRebuyProduct = (isHydrogenReact, product) => {
1275
1474
  },
1276
1475
  handle: product?.handle || "",
1277
1476
  id: product?.id || "",
1278
- images: [{ altText: "", height: 100, id: "", url: "", width: 100 }],
1477
+ images: [
1478
+ { altText: "", height: 100, id: "", url: "", width: 100 }
1479
+ ],
1279
1480
  media: [],
1280
1481
  metafields: [],
1281
1482
  options: [],
@@ -1284,9 +1485,12 @@ var convertToRebuyProduct = (isHydrogenReact, product) => {
1284
1485
  minVariantPrice: { amount: "0", currencyCode: "USD" }
1285
1486
  },
1286
1487
  selected: true,
1287
- selectedOptions: product?.selectedVariant?.selectedOptions?.reduce((acc, option) => {
1288
- return { ...acc, [option.name]: option.value };
1289
- }, {}) || {},
1488
+ selectedOptions: product?.selectedVariant?.selectedOptions?.reduce(
1489
+ (acc, option) => {
1490
+ return { ...acc, [option.name]: option.value };
1491
+ },
1492
+ {}
1493
+ ) || {},
1290
1494
  selectedSellingPlan: {},
1291
1495
  selectedSellingPlanAllocation: {},
1292
1496
  selectedVariant: {
@@ -1363,9 +1567,12 @@ var convertToRebuyProduct = (isHydrogenReact, product) => {
1363
1567
  minVariantPrice: { amount: "0", currencyCode: "USD" }
1364
1568
  },
1365
1569
  selected: true,
1366
- selectedOptions: product?.selectedOrFirstAvailableVariant?.selectedOptions?.reduce((acc, option) => {
1367
- return { ...acc, [option.name]: option.value };
1368
- }, {}) || {},
1570
+ selectedOptions: product?.selectedOrFirstAvailableVariant?.selectedOptions?.reduce(
1571
+ (acc, option) => {
1572
+ return { ...acc, [option.name]: option.value };
1573
+ },
1574
+ {}
1575
+ ) || {},
1369
1576
  selectedSellingPlan: {},
1370
1577
  selectedSellingPlanAllocation: {},
1371
1578
  selectedVariant: {
@@ -1443,32 +1650,12 @@ var convertToRebuyProduct = (isHydrogenReact, product) => {
1443
1650
  import { Link as Link2 } from "@remix-run/react";
1444
1651
  import { Image as Image2 } from "@shopify/hydrogen";
1445
1652
  import { Fragment as Fragment3 } from "react";
1446
-
1447
- // src/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.module.css
1448
- var RebuyDynamicBundleProducts_default = {
1449
- container: "RebuyDynamicBundleProducts_container",
1450
- addCartBtnContainer: "RebuyDynamicBundleProducts_addCartBtnContainer",
1451
- bundleContainer: "RebuyDynamicBundleProducts_bundleContainer",
1452
- select: "RebuyDynamicBundleProducts_select",
1453
- bundleItemRowContainer: "RebuyDynamicBundleProducts_bundleItemRowContainer",
1454
- unselected: "RebuyDynamicBundleProducts_unselected",
1455
- bundleItemRow: "RebuyDynamicBundleProducts_bundleItemRow",
1456
- bundleItemInput: "RebuyDynamicBundleProducts_bundleItemInput",
1457
- bundleItemLabel: "RebuyDynamicBundleProducts_bundleItemLabel",
1458
- bundleImages: "RebuyDynamicBundleProducts_bundleImages",
1459
- bundleImage: "RebuyDynamicBundleProducts_bundleImage",
1460
- "fade-in": "RebuyDynamicBundleProducts_fade-in",
1461
- bundleImageDelimiter: "RebuyDynamicBundleProducts_bundleImageDelimiter",
1462
- compareAtPrice: "RebuyDynamicBundleProducts_compareAtPrice"
1463
- };
1464
-
1465
- // src/widgets/RebuyDynamicBundleProducts/BundleImages.tsx
1466
- import { Fragment as Fragment4, jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
1653
+ import { Fragment as Fragment4, jsx as jsx12, jsxs as jsxs7 } from "react/jsx-runtime";
1467
1654
  var BundleImages = ({ products }) => {
1468
1655
  const selected = products.filter((product) => product.selected);
1469
- return /* @__PURE__ */ jsx11("ul", { className: RebuyDynamicBundleProducts_default.bundleImages, children: products.map((product, index) => {
1656
+ return /* @__PURE__ */ jsx12("ul", { className: RebuyDynamicBundleProducts_default.bundleImages, children: products.map((product, index) => {
1470
1657
  const image = product.selectedVariant?.image;
1471
- const productImage = image ? /* @__PURE__ */ jsx11(
1658
+ const productImage = image ? /* @__PURE__ */ jsx12(
1472
1659
  Image2,
1473
1660
  {
1474
1661
  alt: image.altText || `Picture of ${product.title}`,
@@ -1483,53 +1670,66 @@ var BundleImages = ({ products }) => {
1483
1670
  product.title
1484
1671
  );
1485
1672
  const showDelimiter = selected[0]?.id !== product.id;
1486
- return /* @__PURE__ */ jsx11(Fragment3, { children: product.selected && /* @__PURE__ */ jsxs6(Fragment4, { children: [
1487
- showDelimiter && /* @__PURE__ */ jsx11("li", { className: RebuyDynamicBundleProducts_default.bundleImageDelimiter, children: /* @__PURE__ */ jsx11("span", { children: "+" }) }),
1488
- /* @__PURE__ */ jsx11("li", { className: "flex items-center", children: product.default ? (
1673
+ return /* @__PURE__ */ jsx12(Fragment3, { children: product.selected && /* @__PURE__ */ jsxs7(Fragment4, { children: [
1674
+ showDelimiter && /* @__PURE__ */ jsx12("li", { className: RebuyDynamicBundleProducts_default.bundleImageDelimiter, children: /* @__PURE__ */ jsx12("span", { children: "+" }) }),
1675
+ /* @__PURE__ */ jsx12("li", { className: "flex items-center", children: product.default ? (
1489
1676
  // Already on product page
1490
1677
  productImage
1491
1678
  ) : (
1492
1679
  // Link to product
1493
- /* @__PURE__ */ jsx11(Link2, { title: product.title, to: `/products/${product.handle}`, children: productImage })
1680
+ /* @__PURE__ */ jsx12(
1681
+ Link2,
1682
+ {
1683
+ title: product.title,
1684
+ to: `/products/${product.handle}`,
1685
+ children: productImage
1686
+ }
1687
+ )
1494
1688
  ) })
1495
1689
  ] }) }, product.id + "-BundleImages-" + index);
1496
1690
  }) });
1497
1691
  };
1498
1692
 
1499
1693
  // src/widgets/RebuyDynamicBundleProducts/Select.tsx
1500
- import { jsx as jsx12 } from "react/jsx-runtime";
1694
+ import { jsx as jsx13 } from "react/jsx-runtime";
1501
1695
  var Select = ({ onSelectVariant, product }) => {
1502
1696
  const getOptionsLabel = (product2) => {
1503
1697
  const options = product2.variants.nodes[0].selectedOptions;
1504
1698
  const optionsFromKeys = options ? Object.keys(options[0]) : [];
1505
1699
  const optionsFromValues = options ? options.map((option) => option.name) : [];
1506
- const useValues = optionsFromKeys.every((key) => ["name", "value"].includes(key));
1700
+ const useValues = optionsFromKeys.every(
1701
+ (key) => ["name", "value"].includes(key)
1702
+ );
1507
1703
  return (useValues ? optionsFromValues : optionsFromKeys).join(" / ");
1508
1704
  };
1509
- return product && /* @__PURE__ */ jsx12(
1705
+ return product && /* @__PURE__ */ jsx13(
1510
1706
  "select",
1511
1707
  {
1512
1708
  "aria-label": "select variant",
1513
1709
  className: RebuyDynamicBundleProducts_default.select,
1514
1710
  onChange: (e) => onSelectVariant(product, e.target.value),
1515
1711
  value: product.selectedVariant.id,
1516
- children: /* @__PURE__ */ jsx12("optgroup", { label: getOptionsLabel(product), children: product.variants.nodes.map(({ id, title }) => /* @__PURE__ */ jsx12("option", { value: id, children: title }, id + "-BundleVariant")) })
1712
+ children: /* @__PURE__ */ jsx13("optgroup", { label: getOptionsLabel(product), children: product.variants.nodes.map(({ id, title }) => /* @__PURE__ */ jsx13("option", { value: id, children: title }, id + "-BundleVariant")) })
1517
1713
  }
1518
1714
  );
1519
1715
  };
1520
1716
 
1521
1717
  // src/widgets/RebuyDynamicBundleProducts/BundleSelection.tsx
1522
- import { jsx as jsx13, jsxs as jsxs7 } from "react/jsx-runtime";
1523
- var BundleSelection = ({ onSelectVariant, onToggleBundleItem, products }) => {
1524
- return /* @__PURE__ */ jsx13("ul", { children: products.map((product, index) => {
1718
+ import { jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
1719
+ var BundleSelection = ({
1720
+ onSelectVariant,
1721
+ onToggleBundleItem,
1722
+ products
1723
+ }) => {
1724
+ return /* @__PURE__ */ jsx14("ul", { children: products.map((product, index) => {
1525
1725
  const { availableForSale } = product.selectedVariant;
1526
1726
  const isOutOfStock = !availableForSale;
1527
- return /* @__PURE__ */ jsx13(
1727
+ return /* @__PURE__ */ jsx14(
1528
1728
  "li",
1529
1729
  {
1530
1730
  className: `${RebuyDynamicBundleProducts_default.bundleItemRowContainer} ${!product.selected && RebuyDynamicBundleProducts_default.unselected}`,
1531
- children: /* @__PURE__ */ jsxs7("div", { className: RebuyDynamicBundleProducts_default.bundleItemRow, children: [
1532
- /* @__PURE__ */ jsx13(
1731
+ children: /* @__PURE__ */ jsxs8("div", { className: RebuyDynamicBundleProducts_default.bundleItemRow, children: [
1732
+ /* @__PURE__ */ jsx14(
1533
1733
  "input",
1534
1734
  {
1535
1735
  checked: product.selected && availableForSale,
@@ -1541,14 +1741,32 @@ var BundleSelection = ({ onSelectVariant, onToggleBundleItem, products }) => {
1541
1741
  value: product.id
1542
1742
  }
1543
1743
  ),
1544
- /* @__PURE__ */ jsxs7("div", { className: RebuyDynamicBundleProducts_default.bundleItemInput, children: [
1545
- /* @__PURE__ */ jsxs7("label", { className: RebuyDynamicBundleProducts_default.bundleItemLabel, htmlFor: `${product.id}-toggle`, children: [
1546
- isOutOfStock && /* @__PURE__ */ jsx13("b", { children: "SOLD OUT" }),
1547
- product.default && /* @__PURE__ */ jsx13("b", { children: "This item:" }),
1548
- product.title,
1549
- /* @__PURE__ */ jsx13(RebuyProductPrice, { selectedVariant: product.selectedVariant })
1550
- ] }),
1551
- product.variants.nodes.length > 1 && /* @__PURE__ */ jsx13(Select, { onSelectVariant, product })
1744
+ /* @__PURE__ */ jsxs8("div", { className: RebuyDynamicBundleProducts_default.bundleItemInput, children: [
1745
+ /* @__PURE__ */ jsxs8(
1746
+ "label",
1747
+ {
1748
+ className: RebuyDynamicBundleProducts_default.bundleItemLabel,
1749
+ htmlFor: `${product.id}-toggle`,
1750
+ children: [
1751
+ isOutOfStock && /* @__PURE__ */ jsx14("b", { children: "SOLD OUT" }),
1752
+ product.default && /* @__PURE__ */ jsx14("b", { children: "This item:" }),
1753
+ product.title,
1754
+ /* @__PURE__ */ jsx14(
1755
+ RebuyProductPrice,
1756
+ {
1757
+ selectedVariant: product.selectedVariant
1758
+ }
1759
+ )
1760
+ ]
1761
+ }
1762
+ ),
1763
+ product.variants.nodes.length > 1 && /* @__PURE__ */ jsx14(
1764
+ Select,
1765
+ {
1766
+ onSelectVariant,
1767
+ product
1768
+ }
1769
+ )
1552
1770
  ] })
1553
1771
  ] })
1554
1772
  },
@@ -1557,54 +1775,6 @@ var BundleSelection = ({ onSelectVariant, onToggleBundleItem, products }) => {
1557
1775
  }) });
1558
1776
  };
1559
1777
 
1560
- // src/widgets/RebuyDynamicBundleProducts/BundlePrice.tsx
1561
- import { Money as Money4 } from "@shopify/hydrogen";
1562
- import { jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
1563
- var BundlePrice = ({ products }) => {
1564
- const isDisabled = products.filter((product) => product.selected).length < 1;
1565
- const totalBundlePrice = () => {
1566
- let total = 0;
1567
- let currencyCode = "USD";
1568
- for (const product of products) {
1569
- if (product.selected && product.selectedVariant) {
1570
- const { priceV2: price2 } = product.selectedVariant;
1571
- total += Number(price2?.amount);
1572
- currencyCode = price2?.currencyCode || "USD";
1573
- }
1574
- }
1575
- return {
1576
- amount: String(total),
1577
- currencyCode
1578
- };
1579
- };
1580
- const totalBundleCompareAtPrice = () => {
1581
- let compareAtTotal = 0;
1582
- let currencyCode = "USD";
1583
- for (const product of products) {
1584
- if (product.selected && product.selectedVariant) {
1585
- const { compareAtPriceV2: compareAtPrice2, priceV2: price2 } = product.selectedVariant;
1586
- currencyCode = price2?.currencyCode || "USD";
1587
- compareAtTotal += Number((compareAtPrice2 || price2)?.amount);
1588
- }
1589
- }
1590
- return {
1591
- amount: String(compareAtTotal),
1592
- currencyCode
1593
- };
1594
- };
1595
- const isDiscounted = (price2, compareAtPrice2) => Number(compareAtPrice2?.amount) > Number(price2?.amount);
1596
- const price = totalBundlePrice();
1597
- const compareAtPrice = totalBundleCompareAtPrice();
1598
- const CompareAtPrice = ({ data: compareAtPrice2 }) => {
1599
- return compareAtPrice2 && /* @__PURE__ */ jsx14(Money4, { as: "span", className: RebuyDynamicBundleProducts_default.compareAtPrice, data: compareAtPrice2, withoutTrailingZeros: true });
1600
- };
1601
- return products.length > 0 && /* @__PURE__ */ jsx14("div", { className: "flex items-center flex-col", children: !isDisabled && /* @__PURE__ */ jsxs8("p", { className: "flex items-center gap-2 mb-2", children: [
1602
- /* @__PURE__ */ jsx14("span", { children: "Total Price:" }),
1603
- /* @__PURE__ */ jsx14(Money4, { as: "span", data: price, withoutTrailingZeros: true }),
1604
- isDiscounted(price, compareAtPrice) && /* @__PURE__ */ jsx14(CompareAtPrice, { data: compareAtPrice })
1605
- ] }) });
1606
- };
1607
-
1608
1778
  // src/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.tsx
1609
1779
  import { jsx as jsx15, jsxs as jsxs9 } from "react/jsx-runtime";
1610
1780
  var RebuyDynamicBundleProducts = (props) => {
@@ -1620,7 +1790,10 @@ var RebuyDynamicBundleProducts = (props) => {
1620
1790
  } = props;
1621
1791
  const [bundleProducts, setBundleProducts] = useState5([]);
1622
1792
  useEffect4(() => {
1623
- const mainProduct = convertToRebuyProduct(isHydrogenReact || false, product);
1793
+ const mainProduct = convertToRebuyProduct(
1794
+ isHydrogenReact || false,
1795
+ product
1796
+ );
1624
1797
  const formattedProducts = products.map((product2) => {
1625
1798
  return {
1626
1799
  ...product2,
@@ -1639,7 +1812,9 @@ var RebuyDynamicBundleProducts = (props) => {
1639
1812
  );
1640
1813
  const onSelectVariant = useCallback(
1641
1814
  (product2, variant_id) => {
1642
- const variant = product2.variants.nodes.find(({ id }) => id === variant_id);
1815
+ const variant = product2.variants.nodes.find(
1816
+ ({ id }) => id === variant_id
1817
+ );
1643
1818
  if (variant) {
1644
1819
  product2.selectedVariant = variant;
1645
1820
  product2.selected = variant.availableForSale || false;
@@ -1653,7 +1828,14 @@ var RebuyDynamicBundleProducts = (props) => {
1653
1828
  return null;
1654
1829
  }
1655
1830
  return /* @__PURE__ */ jsxs9("section", { className: RebuyDynamicBundleProducts_default.container, children: [
1656
- /* @__PURE__ */ jsx15(Title, { level: getTitleLevel(customTitleLevel), style: customTitleStyle, text: customTitle }),
1831
+ /* @__PURE__ */ jsx15(
1832
+ Title,
1833
+ {
1834
+ level: getTitleLevel(customTitleLevel),
1835
+ style: customTitleStyle,
1836
+ text: customTitle
1837
+ }
1838
+ ),
1657
1839
  /* @__PURE__ */ jsxs9("div", { className: RebuyDynamicBundleProducts_default.bundleContainer, children: [
1658
1840
  /* @__PURE__ */ jsx15(BundleImages, { products: bundleProducts }),
1659
1841
  /* @__PURE__ */ jsx15(BundlePrice, { products: bundleProducts }),
@@ -1740,8 +1922,20 @@ var RebuyProductAddOnCard = ({
1740
1922
  /* @__PURE__ */ jsxs10("div", { className: RebuyProductAddOns_default.addOnCardTextContent, children: [
1741
1923
  !availableForSale && /* @__PURE__ */ jsx16("p", { className: RebuyProductAddOns_default.addOnCardOutOfStock, children: outOfStockText }),
1742
1924
  /* @__PURE__ */ jsx16(Title, { level: titleLevel, text: product.title }),
1743
- /* @__PURE__ */ jsx16(RebuyProductPrice, { selectedVariant: product.selectedVariant }),
1744
- /* @__PURE__ */ jsx16(Link3, { className: RebuyProductAddOns_default.addOnCardLearnMore, to: `/products/${product.handle}`, children: learnMoreText })
1925
+ /* @__PURE__ */ jsx16(
1926
+ RebuyProductPrice,
1927
+ {
1928
+ selectedVariant: product.selectedVariant
1929
+ }
1930
+ ),
1931
+ /* @__PURE__ */ jsx16(
1932
+ Link3,
1933
+ {
1934
+ className: RebuyProductAddOns_default.addOnCardLearnMore,
1935
+ to: `/products/${product.handle}`,
1936
+ children: learnMoreText
1937
+ }
1938
+ )
1745
1939
  ] })
1746
1940
  ] }) });
1747
1941
  };
@@ -1792,7 +1986,10 @@ var RebuyProductAddOns = (props) => {
1792
1986
  });
1793
1987
  setAddedItems(products);
1794
1988
  if (includeMainProduct) {
1795
- setAddedItems([convertToRebuyProduct(isHydrogenReact || false, product), ...products]);
1989
+ setAddedItems([
1990
+ convertToRebuyProduct(isHydrogenReact || false, product),
1991
+ ...products
1992
+ ]);
1796
1993
  } else {
1797
1994
  setAddedItems(products);
1798
1995
  }
@@ -1800,7 +1997,9 @@ var RebuyProductAddOns = (props) => {
1800
1997
  const handleChange = useCallback2(
1801
1998
  (event, product2) => {
1802
1999
  const newProducts = [...products];
1803
- const productIndex = newProducts.findIndex((p) => p.id === product2.id);
2000
+ const productIndex = newProducts.findIndex(
2001
+ (p) => p.id === product2.id
2002
+ );
1804
2003
  if (productIndex !== -1) {
1805
2004
  newProducts[productIndex] = {
1806
2005
  ...newProducts[productIndex],
@@ -1810,7 +2009,9 @@ var RebuyProductAddOns = (props) => {
1810
2009
  if (event.target.checked) {
1811
2010
  setAddedItems((prev) => [...prev, product2]);
1812
2011
  } else {
1813
- setAddedItems((prev) => prev.filter((item) => item.id !== product2.id));
2012
+ setAddedItems(
2013
+ (prev) => prev.filter((item) => item.id !== product2.id)
2014
+ );
1814
2015
  }
1815
2016
  }
1816
2017
  },
@@ -1843,7 +2044,14 @@ var RebuyProductAddOns = (props) => {
1843
2044
  return null;
1844
2045
  }
1845
2046
  return /* @__PURE__ */ jsxs11("div", { className: RebuyProductAddOns_default.container, children: [
1846
- /* @__PURE__ */ jsx17(Title, { level: getTitleLevel(customTitleLevel), style: customTitleStyle, text: customTitle }),
2047
+ /* @__PURE__ */ jsx17(
2048
+ Title,
2049
+ {
2050
+ level: getTitleLevel(customTitleLevel),
2051
+ style: customTitleStyle,
2052
+ text: customTitle
2053
+ }
2054
+ ),
1847
2055
  /* @__PURE__ */ jsx17("ul", { className: RebuyProductAddOns_default.productAddOnsList, children: products.map((product2) => /* @__PURE__ */ jsx17("li", { children: /* @__PURE__ */ jsx17(
1848
2056
  RebuyProductAddOnCard,
1849
2057
  {
@@ -1857,11 +2065,23 @@ var RebuyProductAddOns = (props) => {
1857
2065
  /* @__PURE__ */ jsxs11("div", { className: RebuyProductAddOns_default.productAddOnsFooter, children: [
1858
2066
  /* @__PURE__ */ jsxs11("div", { className: RebuyProductAddOns_default.moneyContainer, children: [
1859
2067
  subtotalText,
1860
- subtotalWithOutProduct && /* @__PURE__ */ jsx17(Money5, { data: subtotalWithOutProduct, withoutTrailingZeros: true })
2068
+ subtotalWithOutProduct && /* @__PURE__ */ jsx17(
2069
+ Money5,
2070
+ {
2071
+ data: subtotalWithOutProduct,
2072
+ withoutTrailingZeros: true
2073
+ }
2074
+ )
1861
2075
  ] }),
1862
2076
  includeMainProduct && /* @__PURE__ */ jsxs11("div", { className: RebuyProductAddOns_default.moneyContainer, children: [
1863
2077
  withProductText,
1864
- subtotalWithProduct && /* @__PURE__ */ jsx17(Money5, { data: subtotalWithProduct, withoutTrailingZeros: true })
2078
+ subtotalWithProduct && /* @__PURE__ */ jsx17(
2079
+ Money5,
2080
+ {
2081
+ data: subtotalWithProduct,
2082
+ withoutTrailingZeros: true
2083
+ }
2084
+ )
1865
2085
  ] }),
1866
2086
  /* @__PURE__ */ jsx17("div", { className: RebuyProductAddOns_default.addCartBtnContainer, children: includeMainProduct ? /* @__PURE__ */ jsx17(
1867
2087
  AddToCartBtn,
@@ -1871,7 +2091,9 @@ var RebuyProductAddOns = (props) => {
1871
2091
  disabled: addedItems.length === 0,
1872
2092
  isHydrogenReact,
1873
2093
  moneyData: subtotalWithProduct,
1874
- selectedVariants: addedItems.map((item) => item.selectedVariant)
2094
+ selectedVariants: addedItems.map(
2095
+ (item) => item.selectedVariant
2096
+ )
1875
2097
  }
1876
2098
  ) : /* @__PURE__ */ jsx17(
1877
2099
  AddToCartBtn,
@@ -1881,7 +2103,9 @@ var RebuyProductAddOns = (props) => {
1881
2103
  disabled: addedItems.length === 0,
1882
2104
  isHydrogenReact,
1883
2105
  moneyData: subtotalWithOutProduct,
1884
- selectedVariants: addedItems.map((item) => item.selectedVariant)
2106
+ selectedVariants: addedItems.map(
2107
+ (item) => item.selectedVariant
2108
+ )
1885
2109
  }
1886
2110
  ) })
1887
2111
  ] })
@@ -1910,7 +2134,14 @@ var RebuyProductRecommendations = (props) => {
1910
2134
  return null;
1911
2135
  }
1912
2136
  return /* @__PURE__ */ jsxs12("section", { className: RebuyProductRecommendations_default.container, children: [
1913
- /* @__PURE__ */ jsx18(Title, { level: getTitleLevel(customTitleLevel), style: customTitleStyle, text: customTitle }),
2137
+ /* @__PURE__ */ jsx18(
2138
+ Title,
2139
+ {
2140
+ level: getTitleLevel(customTitleLevel),
2141
+ style: customTitleStyle,
2142
+ text: customTitle
2143
+ }
2144
+ ),
1914
2145
  /* @__PURE__ */ jsx18("ul", { className: RebuyProductRecommendations_default.productGrid, children: products.map((product) => /* @__PURE__ */ jsx18("li", { className: RebuyProductRecommendations_default.productItem, children: /* @__PURE__ */ jsx18(
1915
2146
  ProductCard,
1916
2147
  {
@@ -1918,7 +2149,10 @@ var RebuyProductRecommendations = (props) => {
1918
2149
  addToCartCallback,
1919
2150
  isHydrogenReact: props.isHydrogenReact,
1920
2151
  product,
1921
- productCardTitleLevel: getTitleLevel(customTitleLevel, true)
2152
+ productCardTitleLevel: getTitleLevel(
2153
+ customTitleLevel,
2154
+ true
2155
+ )
1922
2156
  }
1923
2157
  ) }, product.id)) })
1924
2158
  ] });