@storepecker/storefront-core 2.9.1 → 2.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/address-BdIB6IuI.d.cts +42 -0
  2. package/dist/address-BdIB6IuI.d.ts +42 -0
  3. package/dist/api/index.cjs +36 -32
  4. package/dist/api/index.d.cts +20 -17
  5. package/dist/api/index.d.ts +20 -17
  6. package/dist/api/index.js +4 -4
  7. package/dist/{buy-now-BqVWXyy8.d.cts → buy-now-CDug6LJ_.d.ts} +2 -2
  8. package/dist/{buy-now-DFdnuLjO.d.ts → buy-now-DrKY5_9R.d.cts} +2 -2
  9. package/dist/checkout/index.cjs +163 -76
  10. package/dist/checkout/index.d.cts +37 -26
  11. package/dist/checkout/index.d.ts +37 -26
  12. package/dist/checkout/index.js +50 -64
  13. package/dist/checkout-totals-CbmXM9L7.d.cts +220 -0
  14. package/dist/checkout-totals-DU8l-Wyb.d.ts +220 -0
  15. package/dist/{chunk-IG4BW3ZB.cjs → chunk-32X4SWN4.cjs} +3 -3
  16. package/dist/{chunk-NQZ5GUOG.cjs → chunk-3YPE6UPC.cjs} +24 -16
  17. package/dist/{chunk-RDUT4W3B.cjs → chunk-6APRQ2ED.cjs} +4 -1
  18. package/dist/{chunk-ICKTXS6B.js → chunk-6IXTFZFS.js} +3 -3
  19. package/dist/{chunk-7M5CVYZJ.js → chunk-A7EI7XLU.js} +8 -1
  20. package/dist/chunk-DZPK7GPG.js +601 -0
  21. package/dist/{chunk-TH7OAMGC.js → chunk-E4D4XOAE.js} +24 -16
  22. package/dist/{chunk-NRPK5GCJ.cjs → chunk-EFYAFXIS.cjs} +3 -3
  23. package/dist/{chunk-CBKJ3Y2I.js → chunk-EWZ7TGI7.js} +11 -1
  24. package/dist/{chunk-5XVHYPOC.js → chunk-FF5N7PTB.js} +1 -1
  25. package/dist/{chunk-NOT6VKXA.cjs → chunk-H6UZTS5O.cjs} +67 -23
  26. package/dist/{chunk-XFOUNOKO.cjs → chunk-KNG4OMS5.cjs} +8 -0
  27. package/dist/{chunk-ZAWZ3RB6.js → chunk-NNE42NMP.js} +1 -1
  28. package/dist/chunk-PN6KH5PX.cjs +661 -0
  29. package/dist/{chunk-QQHQTBAM.js → chunk-QSRVMOXT.js} +48 -6
  30. package/dist/{chunk-W6BDMNSU.js → chunk-QVO56X4E.js} +1 -1
  31. package/dist/{chunk-6LS5F4R3.cjs → chunk-SGJUMI3M.cjs} +11 -0
  32. package/dist/{chunk-YLLAP3H2.cjs → chunk-SGKLMS7W.cjs} +2 -2
  33. package/dist/{chunk-ZGMLOLTC.js → chunk-VRZRV2BR.js} +4 -1
  34. package/dist/{chunk-IVKJJLG7.cjs → chunk-WWJAPKRQ.cjs} +8 -8
  35. package/dist/{collections-CXgOv5_G.d.cts → collections-CKNFcE2d.d.cts} +1 -1
  36. package/dist/{collections-CNh2OGbl.d.ts → collections-CtRKsWVx.d.ts} +1 -1
  37. package/dist/components/address-form.cjs +6 -6
  38. package/dist/components/address-form.d.cts +10 -6
  39. package/dist/components/address-form.d.ts +10 -6
  40. package/dist/components/address-form.js +5 -5
  41. package/dist/components/digital-product-download-modal.d.cts +2 -2
  42. package/dist/components/digital-product-download-modal.d.ts +2 -2
  43. package/dist/components/index.cjs +8 -8
  44. package/dist/components/index.d.cts +6 -7
  45. package/dist/components/index.d.ts +6 -7
  46. package/dist/components/index.js +6 -6
  47. package/dist/components/search-dropdown.d.cts +4 -4
  48. package/dist/components/search-dropdown.d.ts +4 -4
  49. package/dist/components/share-button.cjs +3 -3
  50. package/dist/components/share-button.d.cts +1 -1
  51. package/dist/components/share-button.d.ts +1 -1
  52. package/dist/components/share-button.js +2 -2
  53. package/dist/components/theme-data-initializer.d.cts +4 -5
  54. package/dist/components/theme-data-initializer.d.ts +4 -5
  55. package/dist/hooks/index.cjs +672 -44
  56. package/dist/hooks/index.d.cts +239 -13
  57. package/dist/hooks/index.d.ts +239 -13
  58. package/dist/hooks/index.js +630 -11
  59. package/dist/{instagram-DalreBu6.d.cts → instagram-CSzrxk10.d.cts} +8 -2
  60. package/dist/{instagram-BADLnNQ3.d.ts → instagram-CagTLmyq.d.ts} +8 -2
  61. package/dist/models/index.d.cts +8 -8
  62. package/dist/models/index.d.ts +8 -8
  63. package/dist/orders-B6BmHCJN.d.ts +337 -0
  64. package/dist/orders-ZKP0lqRN.d.cts +337 -0
  65. package/dist/pincode-8u7yWLpQ.d.cts +29 -0
  66. package/dist/pincode-8u7yWLpQ.d.ts +29 -0
  67. package/dist/{pixelEvents-LsealscG.d.ts → pixelEvents-DqJ_CEEr.d.ts} +4 -4
  68. package/dist/{pixelEvents-BtEO5QAR.d.cts → pixelEvents-bahgVW4_.d.cts} +4 -4
  69. package/dist/{product-D9liEtl4.d.cts → product-D4kol-Z-.d.cts} +26 -2
  70. package/dist/{product-D9liEtl4.d.ts → product-D4kol-Z-.d.ts} +26 -2
  71. package/dist/store/index.cjs +20 -30
  72. package/dist/store/index.d.cts +21 -7
  73. package/dist/store/index.d.ts +21 -7
  74. package/dist/store/index.js +9 -26
  75. package/dist/{useAddressForm-DGbEn91-.d.cts → useAddressForm-fMOb5Z-a.d.ts} +6 -1
  76. package/dist/{useAddressForm-cO3Au33k.d.ts → useAddressForm-wleIo78M.d.cts} +6 -1
  77. package/dist/utils/index.cjs +60 -56
  78. package/dist/utils/index.d.cts +24 -9
  79. package/dist/utils/index.d.ts +24 -9
  80. package/dist/utils/index.js +4 -4
  81. package/dist/{wishlist-Cj0sQxiY.d.ts → wishlist-L3fM5-ie.d.ts} +1 -1
  82. package/dist/{wishlist-BakHvIFN.d.cts → wishlist-_0x0r1jt.d.cts} +1 -1
  83. package/package.json +1 -1
  84. package/dist/address-DwBZHzbI.d.cts +0 -19
  85. package/dist/address-DwBZHzbI.d.ts +0 -19
  86. package/dist/cart-DZq1ZEnE.d.ts +0 -153
  87. package/dist/cart-DwMFBmpC.d.cts +0 -153
  88. package/dist/chunk-34Y7Y5FU.cjs +0 -246
  89. package/dist/chunk-VPTN4YXD.js +0 -232
  90. package/dist/orders-B3G4CyhH.d.cts +0 -166
  91. package/dist/orders-Bl-Slh72.d.ts +0 -166
@@ -2,25 +2,28 @@
2
2
 
3
3
  var chunkY46EHRJQ_cjs = require('../chunk-Y46EHRJQ.cjs');
4
4
  var chunk2AHH3XBW_cjs = require('../chunk-2AHH3XBW.cjs');
5
- var chunkNOT6VKXA_cjs = require('../chunk-NOT6VKXA.cjs');
6
- var chunkNRPK5GCJ_cjs = require('../chunk-NRPK5GCJ.cjs');
7
- var chunkNQZ5GUOG_cjs = require('../chunk-NQZ5GUOG.cjs');
8
- var chunk34Y7Y5FU_cjs = require('../chunk-34Y7Y5FU.cjs');
9
- var chunkXFOUNOKO_cjs = require('../chunk-XFOUNOKO.cjs');
5
+ var chunkH6UZTS5O_cjs = require('../chunk-H6UZTS5O.cjs');
6
+ var chunkEFYAFXIS_cjs = require('../chunk-EFYAFXIS.cjs');
7
+ var chunk3YPE6UPC_cjs = require('../chunk-3YPE6UPC.cjs');
8
+ var chunkPN6KH5PX_cjs = require('../chunk-PN6KH5PX.cjs');
9
+ var chunkKNG4OMS5_cjs = require('../chunk-KNG4OMS5.cjs');
10
10
  require('../chunk-NSAHGMS7.cjs');
11
11
  var chunkH6FJYRO3_cjs = require('../chunk-H6FJYRO3.cjs');
12
- var chunkIVKJJLG7_cjs = require('../chunk-IVKJJLG7.cjs');
13
- var chunkRDUT4W3B_cjs = require('../chunk-RDUT4W3B.cjs');
14
- require('../chunk-LJUGNSQQ.cjs');
15
- var chunk6LS5F4R3_cjs = require('../chunk-6LS5F4R3.cjs');
12
+ var chunkWWJAPKRQ_cjs = require('../chunk-WWJAPKRQ.cjs');
13
+ var chunk6APRQ2ED_cjs = require('../chunk-6APRQ2ED.cjs');
14
+ var chunkSGJUMI3M_cjs = require('../chunk-SGJUMI3M.cjs');
16
15
  require('../chunk-BBRB475I.cjs');
17
- require('../chunk-TB72NPRM.cjs');
16
+ var chunkDODFO744_cjs = require('../chunk-DODFO744.cjs');
17
+ var chunkTB72NPRM_cjs = require('../chunk-TB72NPRM.cjs');
18
+ var chunkLJUGNSQQ_cjs = require('../chunk-LJUGNSQQ.cjs');
18
19
  require('../chunk-ECHV2JSY.cjs');
19
20
  require('../chunk-BBRXE57K.cjs');
20
21
  require('../chunk-NE3ZHELZ.cjs');
21
22
  require('../chunk-N3CTXRFT.cjs');
22
23
  var react = require('react');
23
24
  var axios = require('axios');
25
+ var formik = require('formik');
26
+ var libphonenumberJs = require('libphonenumber-js');
24
27
 
25
28
  var useAddress = () => {
26
29
  const [data, setData] = react.useState([]);
@@ -30,7 +33,7 @@ var useAddress = () => {
30
33
  const fetchData = react.useCallback(async () => {
31
34
  try {
32
35
  setIsLoading(true);
33
- const result = await chunkRDUT4W3B_cjs.getAddresses("/store/customer_address/");
36
+ const result = await chunk6APRQ2ED_cjs.getAddresses("/store/customer_address/");
34
37
  setData(result || []);
35
38
  setError(null);
36
39
  } catch (err) {
@@ -56,7 +59,7 @@ var useCart = (addressId) => {
56
59
  async (addrId, shippingId) => {
57
60
  try {
58
61
  setIsLoading(true);
59
- const result = await chunkNRPK5GCJ_cjs.getCart("/customer/cart/", addrId ?? addressId, shippingId);
62
+ const result = await chunkEFYAFXIS_cjs.getCart("/customer/cart/", addrId ?? addressId, shippingId);
60
63
  setData(result);
61
64
  setError(null);
62
65
  } catch (err) {
@@ -128,7 +131,7 @@ function useGetProducts(initialFilter, options) {
128
131
  apiParams[key] = value;
129
132
  }
130
133
  }
131
- const result = await chunkNRPK5GCJ_cjs.getProductList(endpoint, apiParams);
134
+ const result = await chunkEFYAFXIS_cjs.getProductList(endpoint, apiParams);
132
135
  setData(result);
133
136
  if (modeRef.current === "append" && isLoadMoreRef.current) {
134
137
  setProducts((prev) => [...prev, ...result.results || []]);
@@ -196,7 +199,7 @@ var useGetProductDetails = (slug) => {
196
199
  const fetchData = react.useCallback(async () => {
197
200
  try {
198
201
  setIsLoading(true);
199
- const result = await chunkNRPK5GCJ_cjs.getProductDetail("/inventory/products/", slug);
202
+ const result = await chunkEFYAFXIS_cjs.getProductDetail("/inventory/products/", slug);
200
203
  setData(result);
201
204
  } catch (err) {
202
205
  } finally {
@@ -219,7 +222,7 @@ var useGetProductCategories = () => {
219
222
  const fetchData = async () => {
220
223
  try {
221
224
  setIsLoading(true);
222
- const result = await chunkNRPK5GCJ_cjs.getProductCategories("/store/categories");
225
+ const result = await chunkEFYAFXIS_cjs.getProductCategories("/store/categories");
223
226
  setData(result || []);
224
227
  } catch (err) {
225
228
  setError(err);
@@ -264,7 +267,7 @@ var useWishlist = () => {
264
267
  const fetchData = react.useCallback(async () => {
265
268
  try {
266
269
  setIsLoading(true);
267
- const response = await chunkNRPK5GCJ_cjs.getWishlist("/customer/wishlist/");
270
+ const response = await chunkEFYAFXIS_cjs.getWishlist("/customer/wishlist/");
268
271
  if (response.data) setData(response.data);
269
272
  setError(null);
270
273
  } catch (err) {
@@ -322,7 +325,7 @@ function useCheckoutPayment(options) {
322
325
  const [isConfirmingPayment, setIsConfirmingPayment] = react.useState(false);
323
326
  const [showSuccessModal, setShowSuccessModal] = react.useState(false);
324
327
  const [showFailureModal, setShowFailureModal] = react.useState(false);
325
- const resetCartCount = chunkNOT6VKXA_cjs.useCartStore((s) => s.resetCartCount);
328
+ const resetCartCount = chunkH6UZTS5O_cjs.useCartStore((s) => s.resetCartCount);
326
329
  const callbacks = {
327
330
  onSuccess: (order) => {
328
331
  setOrderSummary(order);
@@ -355,7 +358,7 @@ function useCheckoutPayment(options) {
355
358
  );
356
359
  const order = response.data;
357
360
  setOrderSummary(order);
358
- chunk34Y7Y5FU_cjs.processPayment(order, paymentMethod, callbacks);
361
+ chunkPN6KH5PX_cjs.processPayment(order, paymentMethod, callbacks);
359
362
  } catch (error) {
360
363
  if (options.onPlaceOrderError?.(error) === true) return;
361
364
  setShowFailureModal(true);
@@ -636,7 +639,7 @@ function useInlineCheckoutPayment(options) {
636
639
  return;
637
640
  }
638
641
  setOrderSummary(order);
639
- chunk34Y7Y5FU_cjs.processPayment(order, paymentMethod, callbacks, { isPublic });
642
+ chunkPN6KH5PX_cjs.processPayment(order, paymentMethod, callbacks, { isPublic });
640
643
  } catch (error) {
641
644
  if (options.onPlaceOrderError?.(error) === true) return;
642
645
  setShowFailureModal(true);
@@ -724,7 +727,7 @@ function usePublicCheckout() {
724
727
  preview
725
728
  };
726
729
  react.useEffect(() => {
727
- const cart = chunkNQZ5GUOG_cjs.cart_default.get();
730
+ const cart = chunk3YPE6UPC_cjs.cart_default.get();
728
731
  const items = readCartItems(cart);
729
732
  if (Object.keys(items).length === 0) {
730
733
  setIsEmpty(true);
@@ -741,11 +744,11 @@ function usePublicCheckout() {
741
744
  const pricedIds = new Set((priced.product_variants || []).map((v) => v.id));
742
745
  const droppedIds = missingIds.filter((id) => !pricedIds.has(id));
743
746
  if (droppedIds.length === 0) return;
744
- const cart = chunkNQZ5GUOG_cjs.cart_default.get();
747
+ const cart = chunk3YPE6UPC_cjs.cart_default.get();
745
748
  if (cart) {
746
749
  droppedIds.forEach((id) => {
747
750
  const variant = cart.product_variants?.find((v) => v.id === id);
748
- if (variant) chunkNQZ5GUOG_cjs.cart_default.remove(variant);
751
+ if (variant) chunk3YPE6UPC_cjs.cart_default.remove(variant);
749
752
  });
750
753
  }
751
754
  setCartItems((prev) => {
@@ -788,7 +791,7 @@ function usePublicCheckout() {
788
791
  const data = err?.response?.data;
789
792
  const code = data?.error_code;
790
793
  if (code === "CART_EMPTY") {
791
- chunkNQZ5GUOG_cjs.cart_default.clear();
794
+ chunk3YPE6UPC_cjs.cart_default.clear();
792
795
  setCartItems({});
793
796
  setIsEmpty(true);
794
797
  setPreview(null);
@@ -838,7 +841,7 @@ function usePublicCheckout() {
838
841
  const applyCoupon2 = react.useCallback((code) => setCouponCodes([code]), []);
839
842
  const removeCoupon2 = react.useCallback(() => setCouponCodes([]), []);
840
843
  const clearCart = react.useCallback(() => {
841
- chunkNQZ5GUOG_cjs.cart_default.clear();
844
+ chunk3YPE6UPC_cjs.cart_default.clear();
842
845
  setCartItems({});
843
846
  setIsEmpty(true);
844
847
  }, []);
@@ -918,7 +921,7 @@ function useCheckoutCoupon(options) {
918
921
  const refreshCoupons = react.useCallback(async () => {
919
922
  setIsLoading(true);
920
923
  try {
921
- const coupons = await chunk34Y7Y5FU_cjs.fetchAvailableCoupons();
924
+ const coupons = await chunkPN6KH5PX_cjs.fetchAvailableCoupons();
922
925
  setAvailableCoupons(coupons);
923
926
  } catch {
924
927
  } finally {
@@ -930,7 +933,7 @@ function useCheckoutCoupon(options) {
930
933
  setError(null);
931
934
  setIsApplying(true);
932
935
  try {
933
- const coupon = await chunk34Y7Y5FU_cjs.applyCheckoutCoupon(code, callbacks);
936
+ const coupon = await chunkPN6KH5PX_cjs.applyCheckoutCoupon(code, callbacks);
934
937
  setAppliedCoupon(coupon);
935
938
  } catch (err) {
936
939
  setError(err instanceof Error ? err.message : "Failed to apply coupon");
@@ -943,7 +946,7 @@ function useCheckoutCoupon(options) {
943
946
  const removeCouponHandler = react.useCallback(async () => {
944
947
  if (!appliedCoupon) return;
945
948
  try {
946
- await chunk34Y7Y5FU_cjs.removeCheckoutCoupon(appliedCoupon.coupon_code, callbacks);
949
+ await chunkPN6KH5PX_cjs.removeCheckoutCoupon(appliedCoupon.coupon_code, callbacks);
947
950
  setAppliedCoupon(null);
948
951
  setError(null);
949
952
  } catch {
@@ -1042,9 +1045,9 @@ function useVariantSelector(options) {
1042
1045
  }
1043
1046
  function useShopCheckout(options) {
1044
1047
  const { product, onNavigateToCart, onToast, onPreorderRejected } = options;
1045
- const { addToCart, setCart } = chunkNOT6VKXA_cjs.useCartStore();
1046
- const cart = chunkNOT6VKXA_cjs.useCartStore((s) => s.cart);
1047
- const isUserAuthenticated = chunkNOT6VKXA_cjs.useAuthStore((s) => s.isAuthenticated);
1048
+ const { addToCart, setCart } = chunkH6UZTS5O_cjs.useCartStore();
1049
+ const cart = chunkH6UZTS5O_cjs.useCartStore((s) => s.cart);
1050
+ const isUserAuthenticated = chunkH6UZTS5O_cjs.useAuthStore((s) => s.isAuthenticated);
1048
1051
  const [isWishlisted, setIsWishlisted] = react.useState(product.is_wishlisted);
1049
1052
  const [isAddedToCart, setIsAddedToCart] = react.useState(false);
1050
1053
  const [loading, setLoading] = react.useState(false);
@@ -1058,7 +1061,7 @@ function useShopCheckout(options) {
1058
1061
  react.useEffect(() => {
1059
1062
  let inCart;
1060
1063
  if (!isUserAuthenticated) {
1061
- inCart = Number(chunkNQZ5GUOG_cjs.cart_default.get()?.products_quantity?.[product.id]) || 0;
1064
+ inCart = Number(chunk3YPE6UPC_cjs.cart_default.get()?.products_quantity?.[product.id]) || 0;
1062
1065
  } else if (cart) {
1063
1066
  inCart = cart.total_quantity > 0 ? Number(cart.products_quantity?.[product.id]) || 0 : 0;
1064
1067
  } else if (product.cart_quantity !== void 0) {
@@ -1072,7 +1075,7 @@ function useShopCheckout(options) {
1072
1075
  react.useEffect(() => {
1073
1076
  const fetchCategories = async () => {
1074
1077
  try {
1075
- const response = await chunkNRPK5GCJ_cjs.getCategories();
1078
+ const response = await chunkEFYAFXIS_cjs.getCategories();
1076
1079
  setCategories(response.data);
1077
1080
  } catch (error) {
1078
1081
  console.log(error);
@@ -1104,8 +1107,8 @@ function useShopCheckout(options) {
1104
1107
  setLoading(false);
1105
1108
  }
1106
1109
  } else {
1107
- chunkNQZ5GUOG_cjs.cart_default.add(product, quantity);
1108
- const localCartItems = chunkNQZ5GUOG_cjs.cart_default.get();
1110
+ chunk3YPE6UPC_cjs.cart_default.add(product, quantity);
1111
+ const localCartItems = chunk3YPE6UPC_cjs.cart_default.get();
1109
1112
  if (localCartItems) {
1110
1113
  setCart(localCartItems);
1111
1114
  }
@@ -1151,8 +1154,8 @@ function useShopCheckout(options) {
1151
1154
  setLoading(false);
1152
1155
  }
1153
1156
  } else {
1154
- chunkNQZ5GUOG_cjs.cart_default.add(product, quantity);
1155
- const localCartItems = chunkNQZ5GUOG_cjs.cart_default.get();
1157
+ chunk3YPE6UPC_cjs.cart_default.add(product, quantity);
1158
+ const localCartItems = chunk3YPE6UPC_cjs.cart_default.get();
1156
1159
  if (localCartItems) {
1157
1160
  setCart(localCartItems);
1158
1161
  }
@@ -1173,8 +1176,8 @@ function useShopCheckout(options) {
1173
1176
  setQuantity(value);
1174
1177
  }, []);
1175
1178
  const handleShare = react.useCallback(() => {
1176
- chunk6LS5F4R3_cjs.shareLink(
1177
- `Buy ${product.name} at ${chunk6LS5F4R3_cjs.convertToCurrency(
1179
+ chunkSGJUMI3M_cjs.shareLink(
1180
+ `Buy ${product.name} at ${chunkSGJUMI3M_cjs.convertToCurrency(
1178
1181
  Number(product.selling_price)
1179
1182
  )}`,
1180
1183
  product.name
@@ -1192,7 +1195,7 @@ function useShopCheckout(options) {
1192
1195
  const handleNotifyMeFormSubmit = react.useCallback(
1193
1196
  async (values) => {
1194
1197
  try {
1195
- const response = await chunkNRPK5GCJ_cjs.notifyProductStock({
1198
+ const response = await chunkEFYAFXIS_cjs.notifyProductStock({
1196
1199
  ...values,
1197
1200
  variant_slug: product.slug
1198
1201
  });
@@ -1256,7 +1259,7 @@ function useCoupon(options = {}) {
1256
1259
  react.useEffect(() => {
1257
1260
  const fetchCoupons = async () => {
1258
1261
  try {
1259
- const response = await chunkXFOUNOKO_cjs.getCoupons();
1262
+ const response = await chunkKNG4OMS5_cjs.getCoupons();
1260
1263
  if (response.data) {
1261
1264
  setAvailableCoupons(response.data);
1262
1265
  }
@@ -1265,7 +1268,7 @@ function useCoupon(options = {}) {
1265
1268
  };
1266
1269
  const fetchAppliedCoupon2 = async () => {
1267
1270
  try {
1268
- const response = await chunkXFOUNOKO_cjs.getAppliedCoupon();
1271
+ const response = await chunkKNG4OMS5_cjs.getAppliedCoupon();
1269
1272
  if (response.data) {
1270
1273
  setAppliedCoupon(response.data);
1271
1274
  }
@@ -1286,7 +1289,7 @@ function useCoupon(options = {}) {
1286
1289
  try {
1287
1290
  setCouponApplyingLoading(true);
1288
1291
  setCouponApplyingError(null);
1289
- const response = await chunkXFOUNOKO_cjs.applyCoupon(code);
1292
+ const response = await chunkKNG4OMS5_cjs.applyCoupon(code);
1290
1293
  if (response.data) {
1291
1294
  onCouponStatusChange?.(response.data.coupon);
1292
1295
  setAppliedCoupon(response.data.coupon);
@@ -1304,7 +1307,7 @@ function useCoupon(options = {}) {
1304
1307
  const handleRemoveCoupon = react.useCallback(async () => {
1305
1308
  if (!appliedCoupon) return;
1306
1309
  try {
1307
- const response = await chunkXFOUNOKO_cjs.removeCoupon(appliedCoupon.coupon_code);
1310
+ const response = await chunkKNG4OMS5_cjs.removeCoupon(appliedCoupon.coupon_code);
1308
1311
  if (response.data) {
1309
1312
  setAppliedCoupon(null);
1310
1313
  onCouponStatusChange?.(null);
@@ -1326,26 +1329,651 @@ function useCoupon(options = {}) {
1326
1329
  };
1327
1330
  }
1328
1331
 
1332
+ // src/utils/once.ts
1333
+ var store = /* @__PURE__ */ new Map();
1334
+ function once(key, fn) {
1335
+ let promise = store.get(key);
1336
+ if (!promise) {
1337
+ promise = fn().catch((error) => {
1338
+ store.delete(key);
1339
+ throw error;
1340
+ });
1341
+ store.set(key, promise);
1342
+ }
1343
+ return promise;
1344
+ }
1345
+
1346
+ // src/hooks/useCountries.ts
1347
+ var NO_COUNTRIES = [];
1348
+ var NO_STATES = [];
1349
+ function useOnce(key, fetcher) {
1350
+ const [state, setState] = react.useState({ key: null });
1351
+ react.useEffect(() => {
1352
+ if (!key) return;
1353
+ let active = true;
1354
+ once(key, fetcher).then(
1355
+ (data) => active && setState({ key, data }),
1356
+ (error) => active && setState({ key, error })
1357
+ );
1358
+ return () => {
1359
+ active = false;
1360
+ };
1361
+ }, [key]);
1362
+ const current = state.key === key ? state : { data: void 0, error: void 0 };
1363
+ return {
1364
+ data: current.data,
1365
+ error: current.error,
1366
+ isLoading: !!key && current.data === void 0 && current.error === void 0
1367
+ };
1368
+ }
1369
+ var useCountries = () => {
1370
+ const { data, error, isLoading } = useOnce("utils/countries/", async () => (await chunk6APRQ2ED_cjs.getCountries()).data);
1371
+ return { countries: data ?? NO_COUNTRIES, error, isLoading };
1372
+ };
1373
+ var useSubdivisions = (countryId) => {
1374
+ const { data, error, isLoading } = useOnce(
1375
+ countryId ? `utils/subdivisions/:${countryId}` : null,
1376
+ async () => (await chunk6APRQ2ED_cjs.getSubdivisions(countryId)).data.results
1377
+ );
1378
+ return { states: data ?? NO_STATES, error, isLoading };
1379
+ };
1380
+ function useAddressFormat(countryCode) {
1381
+ const [state, setState] = react.useState({});
1382
+ react.useEffect(() => {
1383
+ if (!countryCode) return;
1384
+ let active = true;
1385
+ once(`address-format:${countryCode}`, () => chunkPN6KH5PX_cjs.loadAddressFormat(countryCode)).then(
1386
+ (format) => active && setState({ code: countryCode, format }),
1387
+ (error) => active && setState({ code: countryCode, error })
1388
+ );
1389
+ return () => {
1390
+ active = false;
1391
+ };
1392
+ }, [countryCode]);
1393
+ const fallback = react.useMemo(() => chunkPN6KH5PX_cjs.buildAddressFormat(countryCode ?? "", null), [countryCode]);
1394
+ const current = state.code === countryCode ? state : {};
1395
+ return {
1396
+ format: current.format ?? fallback,
1397
+ error: current.error,
1398
+ isLoading: !!countryCode && !current.format && current.error === void 0
1399
+ };
1400
+ }
1401
+ var NO_ANSWER = { key: "", invalid: false, match: null };
1402
+ var keyFor = (countryCode, pincode) => `${countryCode ?? ""}:${pincode.trim().toUpperCase()}`;
1403
+ function usePincodeLookup({
1404
+ countryCode,
1405
+ pincode,
1406
+ ready,
1407
+ states,
1408
+ stateId,
1409
+ onMatch,
1410
+ enabled: enabledOption
1411
+ }) {
1412
+ const storeEnabled = chunkDODFO744_cjs.useThemeData((s) => !!s.themeData?.pincode_validation_enabled);
1413
+ const enabled = enabledOption ?? storeEnabled;
1414
+ const [answer, setAnswer] = react.useState(NO_ANSWER);
1415
+ const [loading, setLoading] = react.useState(false);
1416
+ const key = keyFor(countryCode, pincode);
1417
+ const current = answer.key === key ? answer : NO_ANSWER;
1418
+ const onMatchRef = react.useRef(onMatch);
1419
+ onMatchRef.current = onMatch;
1420
+ const latest = react.useRef({ pincode, states, stateId });
1421
+ latest.current = { pincode, states, stateId };
1422
+ const requestRef = react.useRef(0);
1423
+ const lookUp = react.useCallback(
1424
+ async (value) => {
1425
+ const request = ++requestRef.current;
1426
+ setLoading(true);
1427
+ const result = await chunkPN6KH5PX_cjs.validatePincode(value, countryCode);
1428
+ if (request === requestRef.current) {
1429
+ setLoading(false);
1430
+ setAnswer({ key: keyFor(countryCode, value), invalid: result.status === "invalid", match: result.match });
1431
+ }
1432
+ return result;
1433
+ },
1434
+ [countryCode]
1435
+ );
1436
+ react.useEffect(() => {
1437
+ if (!enabled || !ready) return;
1438
+ const value = pincode.trim();
1439
+ const timer = setTimeout(() => lookUp(value), chunkPN6KH5PX_cjs.PINCODE_DEBOUNCE_MS);
1440
+ return () => {
1441
+ clearTimeout(timer);
1442
+ requestRef.current += 1;
1443
+ setLoading(false);
1444
+ };
1445
+ }, [enabled, ready, pincode, lookUp]);
1446
+ const { match } = current;
1447
+ react.useEffect(() => {
1448
+ if (match) onMatchRef.current(match, chunkPN6KH5PX_cjs.findSubdivision(states, match));
1449
+ }, [match, states]);
1450
+ const mismatchState = react.useMemo(() => {
1451
+ if (!match || !stateId) return void 0;
1452
+ const pincodeState = chunkPN6KH5PX_cjs.findSubdivision(states, match);
1453
+ return pincodeState && String(pincodeState.id) !== stateId ? pincodeState.name : void 0;
1454
+ }, [match, states, stateId]);
1455
+ const issue = react.useMemo(() => {
1456
+ if (current.serverMessage) return { kind: "server", message: current.serverMessage };
1457
+ if (current.invalid) return { kind: "invalid" };
1458
+ if (mismatchState) return { kind: "mismatch", stateName: mismatchState };
1459
+ return null;
1460
+ }, [current.serverMessage, current.invalid, mismatchState]);
1461
+ const checkNow = react.useCallback(() => {
1462
+ const value = latest.current.pincode.trim();
1463
+ if (enabled && value) lookUp(value);
1464
+ }, [enabled, lookUp]);
1465
+ const verify = react.useCallback(async () => {
1466
+ const value = latest.current.pincode.trim();
1467
+ if (!enabled || !value) return null;
1468
+ const result = await lookUp(value);
1469
+ const { states: currentStates, stateId: currentStateId } = latest.current;
1470
+ if (result.status === "invalid") return { kind: "invalid" };
1471
+ if (result.status === "valid" && currentStateId) {
1472
+ const pincodeState = chunkPN6KH5PX_cjs.findSubdivision(currentStates, result.match);
1473
+ if (pincodeState && String(pincodeState.id) !== currentStateId) {
1474
+ return { kind: "mismatch", stateName: pincodeState.name };
1475
+ }
1476
+ }
1477
+ return null;
1478
+ }, [enabled, lookUp]);
1479
+ const setServerError = react.useCallback(
1480
+ (message) => setAnswer((prev) => {
1481
+ const serverKey = keyFor(countryCode, latest.current.pincode);
1482
+ return { ...prev.key === serverKey ? prev : NO_ANSWER, key: serverKey, serverMessage: message };
1483
+ }),
1484
+ [countryCode]
1485
+ );
1486
+ const areaOptions = react.useMemo(() => chunkPN6KH5PX_cjs.getAreaOptions(match), [match]);
1487
+ return { enabled, loading, issue, areaOptions, checkNow, verify, setServerError };
1488
+ }
1489
+ var INDIA_ID = 105;
1490
+ var EMPTY_ADDRESS_FORM_VALUES = {
1491
+ customer_name: "",
1492
+ customer_email: "",
1493
+ customer_phone: "",
1494
+ customer_country_code: "",
1495
+ country_obj: "",
1496
+ country_name: "",
1497
+ state_obj: "",
1498
+ state_name: "",
1499
+ city: "",
1500
+ pincode: "",
1501
+ address: "",
1502
+ address_line_2: "",
1503
+ is_default: false
1504
+ };
1505
+ function toAddressPayload(values) {
1506
+ const phoneCountry = values.customer_country_code;
1507
+ return {
1508
+ customer_name: values.customer_name.trim(),
1509
+ customer_email: values.customer_email.trim(),
1510
+ customer_phone: chunkPN6KH5PX_cjs.sanitizePhoneInput(values.customer_phone, values.customer_country_code),
1511
+ customer_country_code: phoneCountry ? `+${libphonenumberJs.getCountryCallingCode(phoneCountry)}` : "",
1512
+ address: chunkPN6KH5PX_cjs.joinAddressLines(values.address, values.address_line_2),
1513
+ city: values.city.trim(),
1514
+ state_obj: values.state_obj,
1515
+ state: values.state_name,
1516
+ country_obj: Number(values.country_obj),
1517
+ country: values.country_name,
1518
+ pincode: values.pincode.trim() || chunkPN6KH5PX_cjs.NO_POSTAL_CODE,
1519
+ is_default: values.is_default
1520
+ };
1521
+ }
1522
+ function isPincodeReady(format, value) {
1523
+ const code = value.trim();
1524
+ if (!format.hasPostal || !code || code === chunkPN6KH5PX_cjs.NO_POSTAL_CODE) return false;
1525
+ if (format.postalStrict && format.postalPattern) return format.postalPattern.test(code);
1526
+ return code.length >= chunkPN6KH5PX_cjs.PINCODE_MIN_LENGTH && (!format.postalPattern || format.postalPattern.test(code));
1527
+ }
1528
+ function isPincodeCheckableOnBlur(format, value) {
1529
+ const code = value.trim();
1530
+ if (!format.hasPostal || !code || code === chunkPN6KH5PX_cjs.NO_POSTAL_CODE) return false;
1531
+ if (format.postalStrict || !format.postalPattern) return false;
1532
+ return format.postalPattern.test(code);
1533
+ }
1534
+ function describePincodeIssue(issue, format) {
1535
+ if (!issue) return void 0;
1536
+ const postal = chunkPN6KH5PX_cjs.lowerLabel(format.postalLabel);
1537
+ if (issue.kind === "server") return issue.message;
1538
+ if (issue.kind === "invalid") return `We couldn't find this ${postal}. Check it and try again.`;
1539
+ return `This ${postal} is in ${issue.stateName}. Check the ${postal} or the ${chunkPN6KH5PX_cjs.lowerLabel(format.regionLabel)}.`;
1540
+ }
1541
+ var dialCode = (iso) => `+${libphonenumberJs.getCountryCallingCode(iso)}`;
1542
+ function phoneIsoFromDialCode(dial, addressCountry, countries) {
1543
+ if (!dial) return addressCountry.tld_code;
1544
+ const normalized = dial.startsWith("+") ? dial : `+${dial}`;
1545
+ if (dialCode(addressCountry.tld_code) === normalized) return addressCountry.tld_code;
1546
+ return countries.find((c) => dialCode(c.tld_code) === normalized)?.tld_code ?? addressCountry.tld_code;
1547
+ }
1548
+ function resolveInitialValues(countries, address, draft, defaultCountryId, locationCacheKey) {
1549
+ const byId = (id) => countries.find((c) => c.id === Number(id));
1550
+ const byIso = (iso) => countries.find((c) => c.tld_code === iso);
1551
+ const fallback = byId(defaultCountryId) ?? countries[0];
1552
+ if (address) {
1553
+ const country2 = byId(address.country_obj) ?? countries.find((c) => c.name.toLowerCase() === address.country?.toLowerCase()) ?? fallback;
1554
+ const phoneIso = phoneIsoFromDialCode(address.customer_country_code, country2, countries);
1555
+ return {
1556
+ values: {
1557
+ ...EMPTY_ADDRESS_FORM_VALUES,
1558
+ customer_name: address.customer_name ?? "",
1559
+ customer_email: chunkPN6KH5PX_cjs.usableEmail(address.customer_email),
1560
+ customer_phone: address.customer_phone ?? "",
1561
+ customer_country_code: phoneIso,
1562
+ country_obj: country2.id,
1563
+ country_name: country2.name,
1564
+ state_obj: address.state_obj ? String(address.state_obj) : "",
1565
+ state_name: address.state ?? "",
1566
+ city: address.city ?? "",
1567
+ pincode: address.pincode ?? "",
1568
+ address: address.address ?? "",
1569
+ is_default: !!address.is_default
1570
+ },
1571
+ phoneFollowsCountry: phoneIso === country2.tld_code
1572
+ };
1573
+ }
1574
+ if (draft) {
1575
+ const draftCountry = byId(draft.country_obj) ?? byIso(draft.country_obj);
1576
+ const country2 = draftCountry ?? fallback;
1577
+ const phoneIso = byIso(draft.customer_country_code)?.tld_code ?? country2.tld_code;
1578
+ const text = (value) => typeof value === "string" ? value : value == null ? "" : String(value);
1579
+ const values = {
1580
+ ...EMPTY_ADDRESS_FORM_VALUES,
1581
+ customer_name: text(draft.customer_name),
1582
+ customer_email: text(draft.customer_email),
1583
+ customer_phone: text(draft.customer_phone),
1584
+ customer_country_code: phoneIso,
1585
+ country_obj: country2.id,
1586
+ country_name: country2.name,
1587
+ state_obj: text(draft.state_obj),
1588
+ state_name: text(draft.state_name),
1589
+ city: text(draft.city),
1590
+ pincode: text(draft.pincode),
1591
+ address: text(draft.address),
1592
+ address_line_2: text(draft.address_line_2),
1593
+ is_default: !!draft.is_default
1594
+ };
1595
+ if (!draftCountry) {
1596
+ values.state_obj = "";
1597
+ values.state_name = "";
1598
+ values.pincode = "";
1599
+ }
1600
+ return { values, phoneFollowsCountry: phoneIso === country2.tld_code };
1601
+ }
1602
+ const location = chunkLJUGNSQQ_cjs.getCache(locationCacheKey);
1603
+ const country = byIso(location?.country_code) ?? fallback;
1604
+ return {
1605
+ values: {
1606
+ ...EMPTY_ADDRESS_FORM_VALUES,
1607
+ customer_country_code: country.tld_code,
1608
+ country_obj: country.id,
1609
+ country_name: country.name
1610
+ },
1611
+ phoneFollowsCountry: true
1612
+ };
1613
+ }
1614
+ function useCountryAwareAddressForm({
1615
+ address,
1616
+ loadDraft,
1617
+ onSubmit,
1618
+ profile,
1619
+ pincodeValidationEnabled,
1620
+ defaultCountryId = INDIA_ID,
1621
+ locationCacheKey = chunkTB72NPRM_cjs.IP_API_CACHE_KEY,
1622
+ messages,
1623
+ formatPincodeIssue,
1624
+ onInvalid
1625
+ }) {
1626
+ const { countries: allCountries, error: countriesError } = useCountries();
1627
+ const countries = react.useMemo(
1628
+ () => allCountries.filter((c) => libphonenumberJs.isSupportedCountry(c.tld_code)).sort((a, b) => a.id === defaultCountryId ? -1 : b.id === defaultCountryId ? 1 : 0),
1629
+ [allCountries, defaultCountryId]
1630
+ );
1631
+ const onSubmitRef = react.useRef(onSubmit);
1632
+ onSubmitRef.current = onSubmit;
1633
+ const onInvalidRef = react.useRef(onInvalid);
1634
+ onInvalidRef.current = onInvalid;
1635
+ const formRef = react.useRef(null);
1636
+ const reportInvalid = react.useCallback((errors) => {
1637
+ if (onInvalidRef.current) onInvalidRef.current(errors);
1638
+ else chunkSGJUMI3M_cjs.focusFirstInvalidField(errors, formRef.current);
1639
+ }, []);
1640
+ const loadDraftRef = react.useRef(loadDraft);
1641
+ loadDraftRef.current = loadDraft;
1642
+ const schemaRef = react.useRef();
1643
+ const formik$1 = formik.useFormik({
1644
+ initialValues: EMPTY_ADDRESS_FORM_VALUES,
1645
+ validationSchema: () => schemaRef.current,
1646
+ onSubmit: (values2) => onSubmitRef.current(toAddressPayload(values2), values2)
1647
+ });
1648
+ const { values, setValues, setFieldValue, setTouched, validateForm, resetForm, submitForm } = formik$1;
1649
+ const valuesRef = react.useRef(values);
1650
+ valuesRef.current = values;
1651
+ const touchedRef = react.useRef(formik$1.touched);
1652
+ touchedRef.current = formik$1.touched;
1653
+ const country = react.useMemo(() => countries.find((c) => c.id === Number(values.country_obj)), [countries, values.country_obj]);
1654
+ const countryCode = country?.tld_code;
1655
+ const countryCodeRef = react.useRef(countryCode);
1656
+ countryCodeRef.current = countryCode;
1657
+ const { format, error: formatError } = useAddressFormat(countryCode);
1658
+ const { states, isLoading: statesLoading, error: statesError } = useSubdivisions(country?.id);
1659
+ const statesRef = react.useRef(states);
1660
+ statesRef.current = states;
1661
+ const showState = statesLoading || !!statesError || states.length > 0;
1662
+ const requireState = !statesError && showState;
1663
+ const messagesRef = react.useRef(messages);
1664
+ messagesRef.current = messages;
1665
+ const schema = react.useMemo(
1666
+ () => chunkPN6KH5PX_cjs.buildAddressSchema(format, { requireState, messages: messagesRef.current }),
1667
+ [format, requireState]
1668
+ );
1669
+ schemaRef.current = schema;
1670
+ const phoneFollowsCountryRef = react.useRef(true);
1671
+ const initialPincodeRef = react.useRef("");
1672
+ const initializedFor = react.useRef(null);
1673
+ const initKey = address?.id ?? "new";
1674
+ react.useEffect(() => {
1675
+ if (!countries.length || initializedFor.current === initKey) return;
1676
+ initializedFor.current = initKey;
1677
+ const draft = address ? null : loadDraftRef.current?.() ?? null;
1678
+ const { values: initial, phoneFollowsCountry } = resolveInitialValues(
1679
+ countries,
1680
+ address,
1681
+ draft,
1682
+ defaultCountryId,
1683
+ locationCacheKey
1684
+ );
1685
+ phoneFollowsCountryRef.current = phoneFollowsCountry;
1686
+ initialPincodeRef.current = initial.pincode;
1687
+ resetForm({ values: initial });
1688
+ }, [countries, initKey, resetForm]);
1689
+ const profileAppliedFor = react.useRef(null);
1690
+ react.useEffect(() => {
1691
+ const current = valuesRef.current;
1692
+ if (!profile || address || !current.country_obj || initializedFor.current !== initKey || profileAppliedFor.current === initKey) {
1693
+ return;
1694
+ }
1695
+ profileAppliedFor.current = initKey;
1696
+ const next = { ...current };
1697
+ if (!current.customer_name.trim() && profile.customer_name) next.customer_name = profile.customer_name.trim();
1698
+ if (!current.customer_email.trim()) next.customer_email = chunkPN6KH5PX_cjs.usableEmail(profile.email);
1699
+ if (!current.customer_phone.trim() && profile.phone) {
1700
+ const delivery = countries.find((c) => c.id === Number(current.country_obj));
1701
+ const code = profile.country_code?.trim();
1702
+ const phoneIso = code && /^[A-Za-z]{2}$/.test(code) ? code.toUpperCase() : delivery ? phoneIsoFromDialCode(code, delivery, countries) : current.customer_country_code;
1703
+ next.customer_country_code = phoneIso;
1704
+ next.customer_phone = chunkPN6KH5PX_cjs.sanitizePhoneInput(profile.phone, phoneIso);
1705
+ phoneFollowsCountryRef.current = phoneIso === delivery?.tld_code;
1706
+ }
1707
+ setValues(next, false);
1708
+ }, [profile, initKey, countries, values.country_obj, setValues]);
1709
+ react.useEffect(() => {
1710
+ if (!countryCode) return;
1711
+ const { pincode } = valuesRef.current;
1712
+ if (!format.hasPostal && pincode !== chunkPN6KH5PX_cjs.NO_POSTAL_CODE) setFieldValue("pincode", chunkPN6KH5PX_cjs.NO_POSTAL_CODE, false);
1713
+ else if (format.hasPostal && pincode === chunkPN6KH5PX_cjs.NO_POSTAL_CODE) setFieldValue("pincode", "", false);
1714
+ }, [format, countryCode, setFieldValue]);
1715
+ react.useEffect(() => {
1716
+ const { state_obj, state_name } = valuesRef.current;
1717
+ if (!state_obj || statesLoading || statesError || !states.length) return;
1718
+ const byId = states.find((s) => String(s.id) === state_obj);
1719
+ const state = byId ?? chunkPN6KH5PX_cjs.findStateByName(states, state_obj) ?? chunkPN6KH5PX_cjs.findStateByName(states, state_name);
1720
+ if (state) {
1721
+ if (String(state.id) !== state_obj || state.name !== state_name) {
1722
+ setValues({ ...valuesRef.current, state_obj: String(state.id), state_name: state.name }, false);
1723
+ }
1724
+ } else {
1725
+ setValues({ ...valuesRef.current, state_obj: "", state_name: "" }, false);
1726
+ }
1727
+ }, [states, statesLoading, statesError, values.state_obj, setValues]);
1728
+ const errorsRef = react.useRef(formik$1.errors);
1729
+ errorsRef.current = formik$1.errors;
1730
+ react.useEffect(() => {
1731
+ if (Object.keys(errorsRef.current).length) validateForm();
1732
+ }, [schema, validateForm]);
1733
+ const [autofill, setAutofill] = react.useState({});
1734
+ const autofillRef = react.useRef(autofill);
1735
+ autofillRef.current = autofill;
1736
+ const applyMatch = react.useCallback(
1737
+ (match, state) => {
1738
+ const current = valuesRef.current;
1739
+ const filledBefore = autofillRef.current;
1740
+ const next = {};
1741
+ const filled = {};
1742
+ const city = countryCodeRef.current === "IN" ? match.district || match.city : match.city || match.district;
1743
+ if (city && (!current.city.trim() || current.city === filledBefore.city)) {
1744
+ filled.city = city;
1745
+ if (current.city !== city) next.city = city;
1746
+ }
1747
+ if (state && (!current.state_obj || current.state_obj === filledBefore.state_obj)) {
1748
+ filled.state_obj = String(state.id);
1749
+ if (current.state_obj !== filled.state_obj) {
1750
+ next.state_obj = filled.state_obj;
1751
+ next.state_name = state.name;
1752
+ }
1753
+ }
1754
+ if (Object.keys(next).length) setValues({ ...current, ...next }, true);
1755
+ if (filled.city !== filledBefore.city || filled.state_obj !== filledBefore.state_obj) {
1756
+ setAutofill((prev) => ({ ...prev, ...filled }));
1757
+ }
1758
+ },
1759
+ [setValues]
1760
+ );
1761
+ const pincodeLookup = usePincodeLookup({
1762
+ countryCode,
1763
+ pincode: values.pincode,
1764
+ // Opening a saved address shouldn't re-check a postcode it already has.
1765
+ ready: !!countryCode && values.pincode !== initialPincodeRef.current && isPincodeReady(format, values.pincode),
1766
+ states,
1767
+ stateId: values.state_obj,
1768
+ onMatch: applyMatch,
1769
+ enabled: pincodeValidationEnabled
1770
+ });
1771
+ const { verify: verifyPincode, setServerError: setPincodeServerError, checkNow: checkPincodeNow } = pincodeLookup;
1772
+ const pincodeIssue = pincodeLookup.issue ? (formatPincodeIssue ?? describePincodeIssue)(pincodeLookup.issue, format) : void 0;
1773
+ const changeCountry = react.useCallback(
1774
+ (iso) => {
1775
+ const next = countries.find((c) => c.tld_code === iso);
1776
+ const current = valuesRef.current;
1777
+ if (!next || next.id === current.country_obj) return;
1778
+ const cityWasFilled = !!autofillRef.current.city && current.city === autofillRef.current.city;
1779
+ setValues(
1780
+ {
1781
+ ...current,
1782
+ country_obj: next.id,
1783
+ country_name: next.name,
1784
+ state_obj: "",
1785
+ state_name: "",
1786
+ pincode: "",
1787
+ city: cityWasFilled ? "" : current.city,
1788
+ customer_country_code: phoneFollowsCountryRef.current ? next.tld_code : current.customer_country_code
1789
+ },
1790
+ false
1791
+ );
1792
+ setAutofill({});
1793
+ setTouched({ ...touchedRef.current, state_obj: false, pincode: false, city: false }, false);
1794
+ initialPincodeRef.current = "";
1795
+ },
1796
+ [countries, setValues, setTouched]
1797
+ );
1798
+ const changePhoneCountry = react.useCallback(
1799
+ (iso) => {
1800
+ const current = valuesRef.current;
1801
+ const deliveryIso = countries.find((c) => c.id === current.country_obj)?.tld_code;
1802
+ phoneFollowsCountryRef.current = iso === deliveryIso;
1803
+ setFieldValue("customer_country_code", String(iso));
1804
+ },
1805
+ [countries, setFieldValue]
1806
+ );
1807
+ const changeState = react.useCallback(
1808
+ (e) => {
1809
+ const id = e.target.value;
1810
+ const name = statesRef.current.find((s) => String(s.id) === id)?.name ?? "";
1811
+ setValues({ ...valuesRef.current, state_obj: id, state_name: name }, true);
1812
+ },
1813
+ [setValues]
1814
+ );
1815
+ const formatRef = react.useRef(format);
1816
+ formatRef.current = format;
1817
+ const changePostcode = react.useCallback(
1818
+ (e) => {
1819
+ setFieldValue("pincode", chunkPN6KH5PX_cjs.normalizePostcode(formatRef.current, e.target.value));
1820
+ },
1821
+ [setFieldValue]
1822
+ );
1823
+ const handleBlur = formik$1.handleBlur;
1824
+ const blurPostcode = react.useCallback(
1825
+ (e) => {
1826
+ handleBlur(e);
1827
+ const { pincode } = valuesRef.current;
1828
+ const format2 = formatRef.current;
1829
+ if (pincode !== initialPincodeRef.current && !isPincodeReady(format2, pincode) && isPincodeCheckableOnBlur(format2, pincode)) {
1830
+ checkPincodeNow();
1831
+ }
1832
+ },
1833
+ [handleBlur, checkPincodeNow]
1834
+ );
1835
+ const addArea = react.useCallback(
1836
+ (area) => {
1837
+ const line1 = valuesRef.current.address.trim();
1838
+ if (line1.toLowerCase().includes(area.toLowerCase())) return;
1839
+ setFieldValue("address", line1 ? `${line1}, ${area}` : area);
1840
+ },
1841
+ [setFieldValue]
1842
+ );
1843
+ const showServerPincodeError = react.useCallback(
1844
+ (error) => {
1845
+ const postal = chunkPN6KH5PX_cjs.lowerLabel(formatRef.current.postalLabel);
1846
+ const invalidMessage = formatPincodeIssue?.({ kind: "invalid" }, formatRef.current) ?? `We couldn't find this ${postal}. Check it and try again.`;
1847
+ const message = chunkPN6KH5PX_cjs.getPincodeError(error, invalidMessage);
1848
+ if (!message) return false;
1849
+ setPincodeServerError(message);
1850
+ reportInvalid({ pincode: message });
1851
+ return true;
1852
+ },
1853
+ // formatPincodeIssue is read at call time; a new inline function shouldn't re-create this.
1854
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1855
+ [setPincodeServerError, reportInvalid]
1856
+ );
1857
+ const changePhone = react.useCallback(
1858
+ (e) => {
1859
+ const current = valuesRef.current;
1860
+ const foreign = chunkPN6KH5PX_cjs.detectForeignPhone(e.target.value, current.customer_country_code);
1861
+ if (foreign && countries.some((c) => c.tld_code === foreign.country)) {
1862
+ const deliveryIso = countries.find((c) => c.id === current.country_obj)?.tld_code;
1863
+ phoneFollowsCountryRef.current = foreign.country === deliveryIso;
1864
+ setValues(
1865
+ { ...current, customer_country_code: foreign.country, customer_phone: foreign.nationalNumber },
1866
+ true
1867
+ );
1868
+ return;
1869
+ }
1870
+ setFieldValue("customer_phone", chunkPN6KH5PX_cjs.sanitizePhoneInput(e.target.value, current.customer_country_code));
1871
+ },
1872
+ [countries, setValues, setFieldValue]
1873
+ );
1874
+ const inFlightRef = react.useRef(null);
1875
+ const [submitting, setSubmitting] = react.useState(false);
1876
+ const runSubmit = react.useCallback(async () => {
1877
+ setSubmitting(true);
1878
+ try {
1879
+ const errors = await validateForm();
1880
+ if (Object.keys(errors).length) {
1881
+ const allTouched = Object.fromEntries(Object.keys(valuesRef.current).map((key) => [key, true]));
1882
+ setTouched(allTouched, false);
1883
+ reportInvalid(errors);
1884
+ return false;
1885
+ }
1886
+ const issue = await verifyPincode();
1887
+ if (issue) {
1888
+ reportInvalid({ pincode: true });
1889
+ return false;
1890
+ }
1891
+ await submitForm();
1892
+ return true;
1893
+ } finally {
1894
+ inFlightRef.current = null;
1895
+ setSubmitting(false);
1896
+ }
1897
+ }, [validateForm, setTouched, submitForm, verifyPincode, reportInvalid]);
1898
+ const submit = react.useCallback(() => {
1899
+ if (!inFlightRef.current) inFlightRef.current = runSubmit();
1900
+ return inFlightRef.current;
1901
+ }, [runSubmit]);
1902
+ const countryOptions = react.useMemo(
1903
+ () => countries.map((c) => ({ value: c.tld_code, label: c.name })),
1904
+ [countries]
1905
+ );
1906
+ const phoneOptions = react.useMemo(
1907
+ () => countries.map((c) => {
1908
+ const dial = libphonenumberJs.getCountryCallingCode(c.tld_code);
1909
+ return { value: c.tld_code, label: `${c.name} (+${dial})`, dial };
1910
+ }),
1911
+ [countries]
1912
+ );
1913
+ return {
1914
+ formik: formik$1,
1915
+ formRef,
1916
+ submitting,
1917
+ country,
1918
+ format,
1919
+ formatError,
1920
+ countriesError,
1921
+ countriesLoading: !countries.length && !countriesError,
1922
+ states,
1923
+ statesError,
1924
+ showState,
1925
+ requireState,
1926
+ countryOptions,
1927
+ phoneOptions,
1928
+ cityAutofilled: !!autofill.city && values.city === autofill.city,
1929
+ stateAutofilled: !!autofill.state_obj && values.state_obj === autofill.state_obj,
1930
+ lookupLoading: pincodeLookup.loading,
1931
+ pincodeIssue,
1932
+ areaOptions: pincodeLookup.areaOptions,
1933
+ changeCountry,
1934
+ changePhoneCountry,
1935
+ changeState,
1936
+ changePostcode,
1937
+ blurPostcode,
1938
+ addArea,
1939
+ changePhone,
1940
+ showServerPincodeError,
1941
+ submit
1942
+ };
1943
+ }
1944
+ function useCheckoutTotals(cart, customizationOverride) {
1945
+ return react.useMemo(() => chunkPN6KH5PX_cjs.calculateCartTotals(cart, customizationOverride), [cart, customizationOverride]);
1946
+ }
1947
+
1329
1948
  Object.defineProperty(exports, "useAddressForm", {
1330
1949
  enumerable: true,
1331
- get: function () { return chunkIVKJJLG7_cjs.useAddressForm; }
1950
+ get: function () { return chunkWWJAPKRQ_cjs.useAddressForm; }
1332
1951
  });
1333
1952
  exports.BUY_NOW_PAYLOAD_KEY = BUY_NOW_PAYLOAD_KEY;
1953
+ exports.EMPTY_ADDRESS_FORM_VALUES = EMPTY_ADDRESS_FORM_VALUES;
1954
+ exports.describePincodeIssue = describePincodeIssue;
1955
+ exports.toAddressPayload = toAddressPayload;
1334
1956
  exports.useAddress = useAddress;
1957
+ exports.useAddressFormat = useAddressFormat;
1335
1958
  exports.useBuyNow = useBuyNow;
1336
1959
  exports.useCart = useCart;
1337
1960
  exports.useCheckoutCoupon = useCheckoutCoupon;
1338
1961
  exports.useCheckoutPayment = useCheckoutPayment;
1962
+ exports.useCheckoutTotals = useCheckoutTotals;
1963
+ exports.useCountries = useCountries;
1964
+ exports.useCountryAwareAddressForm = useCountryAwareAddressForm;
1339
1965
  exports.useCoupon = useCoupon;
1340
1966
  exports.useGetProductCategories = useGetProductCategories;
1341
1967
  exports.useGetProductDetails = useGetProductDetails;
1342
1968
  exports.useGetProducts = useGetProducts;
1343
1969
  exports.useInlineCheckoutPayment = useInlineCheckoutPayment;
1344
1970
  exports.useOrders = useOrders;
1971
+ exports.usePincodeLookup = usePincodeLookup;
1345
1972
  exports.useProductDetailModal = useProductDetailModal;
1346
1973
  exports.usePublicCheckout = usePublicCheckout;
1347
1974
  exports.useServiceFormModal = useServiceFormModal;
1348
1975
  exports.useShopCheckout = useShopCheckout;
1976
+ exports.useSubdivisions = useSubdivisions;
1349
1977
  exports.useUserDetails = useUserDetails;
1350
1978
  exports.useVariantSelector = useVariantSelector;
1351
1979
  exports.useWishlist = useWishlist;