@instockng/storefront-ui 1.0.21 → 1.0.22

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 (130) hide show
  1. package/dist/contexts/CartContext.d.ts +2 -0
  2. package/dist/contexts/CartContext.d.ts.map +1 -1
  3. package/dist/index134.mjs +2 -2
  4. package/dist/index135.mjs +1 -1
  5. package/dist/index136.mjs +6 -6
  6. package/dist/index137.mjs +2 -2
  7. package/dist/index138.mjs +2 -2
  8. package/dist/index140.mjs +2 -2
  9. package/dist/index141.mjs +2 -2
  10. package/dist/index142.mjs +1 -1
  11. package/dist/index144.mjs +8 -8
  12. package/dist/index145.mjs +8 -8
  13. package/dist/index150.mjs +1 -1
  14. package/dist/index151.mjs +1 -1
  15. package/dist/index152.mjs +1 -1
  16. package/dist/index153.mjs +1 -1
  17. package/dist/index154.mjs +1 -1
  18. package/dist/index156.mjs +1 -1
  19. package/dist/index157.mjs +1 -1
  20. package/dist/index159.mjs +2 -2
  21. package/dist/index160.mjs +1 -1
  22. package/dist/index165.mjs +2 -2
  23. package/dist/index167.mjs +1 -1
  24. package/dist/index169.mjs +2 -2
  25. package/dist/index170.mjs +5 -5
  26. package/dist/index173.mjs +1 -1
  27. package/dist/index176.mjs +1 -1
  28. package/dist/index179.mjs +1 -1
  29. package/dist/index180.mjs +1 -1
  30. package/dist/index184.mjs +1 -1
  31. package/dist/index186.mjs +1 -1
  32. package/dist/index190.mjs +1 -1
  33. package/dist/index192.mjs +1 -1
  34. package/dist/index201.mjs +2 -2
  35. package/dist/index203.mjs +1 -1
  36. package/dist/index204.mjs +1 -1
  37. package/dist/index205.mjs +2 -31
  38. package/dist/index206.mjs +2 -11
  39. package/dist/index207.mjs +2 -4
  40. package/dist/index208.mjs +2 -4
  41. package/dist/index209.mjs +2 -13
  42. package/dist/index210.mjs +2 -7
  43. package/dist/index211.mjs +2 -12
  44. package/dist/index212.mjs +2 -5
  45. package/dist/index213.mjs +108 -33
  46. package/dist/index214.mjs +2 -31
  47. package/dist/index215.mjs +2 -28
  48. package/dist/index216.mjs +34 -58
  49. package/dist/index217.mjs +2 -2
  50. package/dist/index218.mjs +244 -2
  51. package/dist/index219.mjs +2 -2
  52. package/dist/index220.mjs +33 -2
  53. package/dist/index221.mjs +65 -2
  54. package/dist/index222.mjs +25 -2
  55. package/dist/index225.mjs +2 -108
  56. package/dist/index226.mjs +2 -2
  57. package/dist/index227.mjs +2 -2
  58. package/dist/index228.mjs +2 -2
  59. package/dist/index229.mjs +2 -37
  60. package/dist/index230.mjs +2 -2
  61. package/dist/index231.mjs +2 -244
  62. package/dist/index232.mjs +2 -2
  63. package/dist/index233.mjs +4 -33
  64. package/dist/index234.mjs +2 -65
  65. package/dist/index235.mjs +2 -25
  66. package/dist/index236.mjs +31 -2
  67. package/dist/index237.mjs +11 -2
  68. package/dist/index238.mjs +4 -2
  69. package/dist/index239.mjs +4 -2
  70. package/dist/index240.mjs +13 -2
  71. package/dist/index241.mjs +7 -2
  72. package/dist/index242.mjs +12 -2
  73. package/dist/index243.mjs +5 -2
  74. package/dist/index244.mjs +33 -2
  75. package/dist/index245.mjs +31 -4
  76. package/dist/index246.mjs +28 -2
  77. package/dist/index247.mjs +61 -2
  78. package/dist/index25.mjs +48 -48
  79. package/dist/index252.mjs +2 -2
  80. package/dist/index253.mjs +2 -2
  81. package/dist/index254.mjs +2 -2
  82. package/dist/index255.mjs +91 -2
  83. package/dist/index256.mjs +2 -91
  84. package/dist/index257.mjs +1 -2
  85. package/dist/index258.mjs +3 -2
  86. package/dist/index259.mjs +2 -2
  87. package/dist/index260.mjs +2 -17
  88. package/dist/index261.mjs +15 -11
  89. package/dist/index262.mjs +13 -6
  90. package/dist/index263.mjs +6 -30
  91. package/dist/index264.mjs +30 -2
  92. package/dist/index3.mjs +133 -102
  93. package/dist/index32.mjs +26 -26
  94. package/dist/index37.mjs +2 -2
  95. package/dist/index38.mjs +2 -2
  96. package/dist/index4.mjs +50 -49
  97. package/dist/index42.mjs +1 -1
  98. package/dist/index47.mjs +17 -17
  99. package/dist/index48.mjs +2 -2
  100. package/dist/index60.mjs +21 -20
  101. package/dist/index61.mjs +2 -24
  102. package/dist/index62.mjs +19 -149
  103. package/dist/index63.mjs +153 -2
  104. package/dist/index66.mjs +2 -2
  105. package/dist/index73.mjs +1 -1
  106. package/dist/index75.mjs +2 -235
  107. package/dist/index76.mjs +233 -4
  108. package/dist/index77.mjs +5 -133
  109. package/dist/index78.mjs +129 -63
  110. package/dist/index79.mjs +67 -86
  111. package/dist/index80.mjs +85 -27
  112. package/dist/index81.mjs +28 -8
  113. package/dist/index82.mjs +8 -74
  114. package/dist/index83.mjs +74 -3
  115. package/dist/index84.mjs +4 -2
  116. package/dist/index85.mjs +2 -83
  117. package/dist/index86.mjs +81 -52
  118. package/dist/index87.mjs +53 -5
  119. package/dist/index88.mjs +5 -4
  120. package/dist/index89.mjs +4 -178
  121. package/dist/index90.mjs +174 -48
  122. package/dist/index91.mjs +51 -67
  123. package/dist/index92.mjs +69 -34
  124. package/dist/index93.mjs +31 -40
  125. package/dist/index94.mjs +43 -2
  126. package/dist/providers/MetaPixelProvider.d.ts +10 -5
  127. package/dist/providers/MetaPixelProvider.d.ts.map +1 -1
  128. package/package.json +4 -4
  129. package/src/contexts/CartContext.tsx +69 -6
  130. package/src/providers/MetaPixelProvider.tsx +24 -16
package/dist/index256.mjs CHANGED
@@ -1,94 +1,5 @@
1
1
  'use client';
2
- import { __module as c } from "./index267.mjs";
3
- var l;
4
- function T() {
5
- return l ? c.exports : (l = 1, (() => {
6
- typeof __nccwpck_require__ < "u" && (__nccwpck_require__.ab = __dirname + "/");
7
- var m = {};
8
- (() => {
9
- var v = m;
10
- /*!
11
- * cookie
12
- * Copyright(c) 2012-2014 Roman Shtylman
13
- * Copyright(c) 2015 Douglas Christopher Wilson
14
- * MIT Licensed
15
- */
16
- v.parse = S, v.serialize = x;
17
- var w = decodeURIComponent, h = encodeURIComponent, y = /; */, f = /^[\u0009\u0020-\u007e\u0080-\u00ff]+$/;
18
- function S(i, n) {
19
- if (typeof i != "string")
20
- throw new TypeError("argument str must be a string");
21
- for (var a = {}, e = n || {}, o = i.split(y), s = e.decode || w, r = 0; r < o.length; r++) {
22
- var t = o[r], p = t.indexOf("=");
23
- if (!(p < 0)) {
24
- var d = t.substr(0, p).trim(), u = t.substr(++p, t.length).trim();
25
- u[0] == '"' && (u = u.slice(1, -1)), a[d] == null && (a[d] = _(u, s));
26
- }
27
- }
28
- return a;
29
- }
30
- function x(i, n, a) {
31
- var e = a || {}, o = e.encode || h;
32
- if (typeof o != "function")
33
- throw new TypeError("option encode is invalid");
34
- if (!f.test(i))
35
- throw new TypeError("argument name is invalid");
36
- var s = o(n);
37
- if (s && !f.test(s))
38
- throw new TypeError("argument val is invalid");
39
- var r = i + "=" + s;
40
- if (e.maxAge != null) {
41
- var t = e.maxAge - 0;
42
- if (isNaN(t) || !isFinite(t))
43
- throw new TypeError("option maxAge is invalid");
44
- r += "; Max-Age=" + Math.floor(t);
45
- }
46
- if (e.domain) {
47
- if (!f.test(e.domain))
48
- throw new TypeError("option domain is invalid");
49
- r += "; Domain=" + e.domain;
50
- }
51
- if (e.path) {
52
- if (!f.test(e.path))
53
- throw new TypeError("option path is invalid");
54
- r += "; Path=" + e.path;
55
- }
56
- if (e.expires) {
57
- if (typeof e.expires.toUTCString != "function")
58
- throw new TypeError("option expires is invalid");
59
- r += "; Expires=" + e.expires.toUTCString();
60
- }
61
- if (e.httpOnly && (r += "; HttpOnly"), e.secure && (r += "; Secure"), e.sameSite) {
62
- var p = typeof e.sameSite == "string" ? e.sameSite.toLowerCase() : e.sameSite;
63
- switch (p) {
64
- case !0:
65
- r += "; SameSite=Strict";
66
- break;
67
- case "lax":
68
- r += "; SameSite=Lax";
69
- break;
70
- case "strict":
71
- r += "; SameSite=Strict";
72
- break;
73
- case "none":
74
- r += "; SameSite=None";
75
- break;
76
- default:
77
- throw new TypeError("option sameSite is invalid");
78
- }
79
- }
80
- return r;
81
- }
82
- function _(i, n) {
83
- try {
84
- return n(i);
85
- } catch {
86
- return i;
87
- }
88
- }
89
- })(), c.exports = m;
90
- })(), c.exports);
91
- }
2
+ var e = {};
92
3
  export {
93
- T as __require
4
+ e as __exports
94
5
  };
package/dist/index257.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  'use client';
2
- import a from "./index205.mjs";
3
- const e = typeof URLSearchParams < "u" ? URLSearchParams : a;
2
+ const e = {};
4
3
  export {
5
4
  e as default
6
5
  };
package/dist/index258.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  'use client';
2
- const a = typeof FormData < "u" ? FormData : null;
2
+ import a from "./index236.mjs";
3
+ const e = typeof URLSearchParams < "u" ? URLSearchParams : a;
3
4
  export {
4
- a as default
5
+ e as default
5
6
  };
package/dist/index259.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- const l = typeof Blob < "u" ? Blob : null;
2
+ const a = typeof FormData < "u" ? FormData : null;
3
3
  export {
4
- l as default
4
+ a as default
5
5
  };
package/dist/index260.mjs CHANGED
@@ -1,20 +1,5 @@
1
1
  'use client';
2
- function y(t, n) {
3
- t = t || 10;
4
- const c = new Array(t), o = new Array(t);
5
- let e = 0, r = 0, i;
6
- return n = n !== void 0 ? n : 1e3, function(h) {
7
- const d = Date.now(), a = o[r];
8
- i || (i = d), c[e] = h, o[e] = d;
9
- let f = r, u = 0;
10
- for (; f !== e; )
11
- u += c[f++], f = f % t;
12
- if (e = (e + 1) % t, e === r && (r = (r + 1) % t), d - i < n)
13
- return;
14
- const w = a && d - a;
15
- return w ? Math.round(u * 1e3 / w) : void 0;
16
- };
17
- }
2
+ const l = typeof Blob < "u" ? Blob : null;
18
3
  export {
19
- y as default
4
+ l as default
20
5
  };
package/dist/index261.mjs CHANGED
@@ -1,16 +1,20 @@
1
1
  'use client';
2
- function h(r, a) {
3
- let s = 0, u = 1e3 / a, e, t;
4
- const n = (l, o = Date.now()) => {
5
- s = o, e = null, t && (clearTimeout(t), t = null), r(...l);
2
+ function y(t, n) {
3
+ t = t || 10;
4
+ const c = new Array(t), o = new Array(t);
5
+ let e = 0, r = 0, i;
6
+ return n = n !== void 0 ? n : 1e3, function(h) {
7
+ const d = Date.now(), a = o[r];
8
+ i || (i = d), c[e] = h, o[e] = d;
9
+ let f = r, u = 0;
10
+ for (; f !== e; )
11
+ u += c[f++], f = f % t;
12
+ if (e = (e + 1) % t, e === r && (r = (r + 1) % t), d - i < n)
13
+ return;
14
+ const w = a && d - a;
15
+ return w ? Math.round(u * 1e3 / w) : void 0;
6
16
  };
7
- return [(...l) => {
8
- const o = Date.now(), i = o - s;
9
- i >= u ? n(l, o) : (e = l, t || (t = setTimeout(() => {
10
- t = null, n(e);
11
- }, u - i)));
12
- }, () => e && n(e)];
13
17
  }
14
18
  export {
15
- h as default
19
+ y as default
16
20
  };
package/dist/index262.mjs CHANGED
@@ -1,9 +1,16 @@
1
1
  'use client';
2
- import o from "./index141.mjs";
3
- const n = o.hasStandardBrowserEnv ? /* @__PURE__ */ ((r, e) => (t) => (t = new URL(t, o.origin), r.protocol === t.protocol && r.host === t.host && (e || r.port === t.port)))(
4
- new URL(o.origin),
5
- o.navigator && /(msie|trident)/i.test(o.navigator.userAgent)
6
- ) : () => !0;
2
+ function h(r, a) {
3
+ let s = 0, u = 1e3 / a, e, t;
4
+ const n = (l, o = Date.now()) => {
5
+ s = o, e = null, t && (clearTimeout(t), t = null), r(...l);
6
+ };
7
+ return [(...l) => {
8
+ const o = Date.now(), i = o - s;
9
+ i >= u ? n(l, o) : (e = l, t || (t = setTimeout(() => {
10
+ t = null, n(e);
11
+ }, u - i)));
12
+ }, () => e && n(e)];
13
+ }
7
14
  export {
8
- n as default
15
+ h as default
9
16
  };
package/dist/index263.mjs CHANGED
@@ -1,33 +1,9 @@
1
1
  'use client';
2
- import r from "./index75.mjs";
3
- import c from "./index141.mjs";
4
- const p = c.hasStandardBrowserEnv ? (
5
- // Standard browser envs support document.cookie
6
- {
7
- write(e, t, n, i, s, u) {
8
- const o = [e + "=" + encodeURIComponent(t)];
9
- r.isNumber(n) && o.push("expires=" + new Date(n).toGMTString()), r.isString(i) && o.push("path=" + i), r.isString(s) && o.push("domain=" + s), u === !0 && o.push("secure"), document.cookie = o.join("; ");
10
- },
11
- read(e) {
12
- const t = document.cookie.match(new RegExp("(^|;\\s*)(" + e + ")=([^;]*)"));
13
- return t ? decodeURIComponent(t[3]) : null;
14
- },
15
- remove(e) {
16
- this.write(e, "", Date.now() - 864e5);
17
- }
18
- }
19
- ) : (
20
- // Non-standard browser env (web workers, react-native) lack needed support.
21
- {
22
- write() {
23
- },
24
- read() {
25
- return null;
26
- },
27
- remove() {
28
- }
29
- }
30
- );
2
+ import o from "./index141.mjs";
3
+ const n = o.hasStandardBrowserEnv ? /* @__PURE__ */ ((r, e) => (t) => (t = new URL(t, o.origin), r.protocol === t.protocol && r.host === t.host && (e || r.port === t.port)))(
4
+ new URL(o.origin),
5
+ o.navigator && /(msie|trident)/i.test(o.navigator.userAgent)
6
+ ) : () => !0;
31
7
  export {
32
- p as default
8
+ n as default
33
9
  };
package/dist/index264.mjs CHANGED
@@ -1,5 +1,33 @@
1
1
  'use client';
2
- const e = {};
2
+ import r from "./index76.mjs";
3
+ import c from "./index141.mjs";
4
+ const p = c.hasStandardBrowserEnv ? (
5
+ // Standard browser envs support document.cookie
6
+ {
7
+ write(e, t, n, i, s, u) {
8
+ const o = [e + "=" + encodeURIComponent(t)];
9
+ r.isNumber(n) && o.push("expires=" + new Date(n).toGMTString()), r.isString(i) && o.push("path=" + i), r.isString(s) && o.push("domain=" + s), u === !0 && o.push("secure"), document.cookie = o.join("; ");
10
+ },
11
+ read(e) {
12
+ const t = document.cookie.match(new RegExp("(^|;\\s*)(" + e + ")=([^;]*)"));
13
+ return t ? decodeURIComponent(t[3]) : null;
14
+ },
15
+ remove(e) {
16
+ this.write(e, "", Date.now() - 864e5);
17
+ }
18
+ }
19
+ ) : (
20
+ // Non-standard browser env (web workers, react-native) lack needed support.
21
+ {
22
+ write() {
23
+ },
24
+ read() {
25
+ return null;
26
+ },
27
+ remove() {
28
+ }
29
+ }
30
+ );
3
31
  export {
4
- e as default
32
+ p as default
5
33
  };
package/dist/index3.mjs CHANGED
@@ -1,170 +1,201 @@
1
1
  'use client';
2
- import { jsxs as Q, jsx as V } from "react/jsx-runtime";
3
- import { createContext as W, useState as I, useRef as y, useEffect as m, useCallback as o, useContext as X } from "react";
2
+ import { jsxs as nt, jsx as ct } from "react/jsx-runtime";
3
+ import { createContext as st, useState as k, useRef as _, useCallback as c, useEffect as d, useContext as at } from "react";
4
4
  import "./index20.mjs";
5
- import { useGetCart as Z, useCreateCart as $, useAddCartItem as tt, useUpdateCartItem as et, useRemoveCartItem as rt, useApplyDiscount as ot, useRemoveDiscount as nt, useUpdateCart as st, useCheckoutCart as at } from "./index32.mjs";
5
+ import { useGetCart as ut, useCreateCart as it, useAddCartItem as ft, useUpdateCartItem as mt, useRemoveCartItem as dt, useApplyDiscount as lt, useRemoveDiscount as pt, useUpdateCart as Ct, useCheckoutCart as It } from "./index32.mjs";
6
6
  import "@tanstack/react-query";
7
- import { ShoppingCart as ct } from "./index10.mjs";
8
- import { useMetaPixel as ut } from "./index4.mjs";
9
- const f = "oms_cart_id", N = W(null);
10
- function Ct({ children: l, brandSlug: a, initialCartId: d, shoppingCartProps: P }) {
11
- const [t, c] = I(d || null), [h, v] = I(!1), [g, x] = I(!1), S = y(!1), A = y(!1), p = y(!1), { trackAddToCart: D, trackPurchase: R } = ut();
12
- m(() => {
13
- x(!0);
14
- }, []), m(() => {
15
- if (d || S.current) return;
7
+ import { ShoppingCart as wt } from "./index10.mjs";
8
+ import { useMetaPixel as ht } from "./index4.mjs";
9
+ const l = "oms_cart_id", F = st(null);
10
+ function St({ children: p, brandSlug: i, initialCartId: C, shoppingCartProps: L }) {
11
+ const [t, f] = k(C || null), [g, A] = k(!1), [U, j] = k(!1), S = _(!1), b = _(!1), w = _(!1), { trackAddToCart: h, trackInitiateCheckout: M, trackPurchase: G } = ht(), E = c(() => {
12
+ if (typeof document > "u") return { fbc: void 0, fbp: void 0 };
13
+ const e = (r) => {
14
+ var o;
15
+ const n = `; ${document.cookie}`.split(`; ${r}=`);
16
+ if (n.length === 2) return (o = n.pop()) == null ? void 0 : o.split(";").shift();
17
+ };
18
+ return {
19
+ fbc: e("_fbc"),
20
+ fbp: e("_fbp")
21
+ };
22
+ }, []);
23
+ d(() => {
24
+ j(!0);
25
+ }, []), d(() => {
26
+ if (C || S.current) return;
16
27
  S.current = !0;
17
28
  const r = new URLSearchParams(window.location.search).get("cartId");
18
29
  if (r) {
19
- c(r);
30
+ f(r);
20
31
  return;
21
32
  }
22
- const s = localStorage.getItem(f);
23
- s && c(s);
24
- }, [d]);
25
- const { data: k, isLoading: T, error: w, refetch: n } = Z(t || "", {
33
+ const s = localStorage.getItem(l);
34
+ s && f(s);
35
+ }, [C]);
36
+ const { data: m, isLoading: O, error: I, refetch: a } = ut(t || "", {
26
37
  enabled: !!t,
27
38
  retry: !1
28
39
  // Don't retry on failure - cart might be invalid/expired
29
- }), C = $({
40
+ }), v = it({
30
41
  onSuccess: (e) => {
31
42
  if ("error" in e) {
32
43
  console.error("Failed to create cart:", e.error);
33
44
  return;
34
45
  }
35
- c(e.id);
46
+ f(e.id);
36
47
  },
37
48
  onError: (e) => {
38
49
  console.error("Failed to create cart:", e);
39
50
  },
40
51
  retry: 10
41
52
  });
42
- m(() => {
43
- if (A.current) return;
44
- A.current = !0;
53
+ d(() => {
54
+ if (b.current) return;
55
+ b.current = !0;
45
56
  const e = setTimeout(() => {
46
- !(typeof window < "u" ? localStorage.getItem(f) : null) && !d && C.mutate(a);
57
+ !(typeof window < "u" ? localStorage.getItem(l) : null) && !C && v.mutate(i);
47
58
  }, 150);
48
59
  return () => clearTimeout(e);
49
- }, []), m(() => {
50
- w && t && !p.current && (p.current = !0, console.warn("Cart fetch failed, creating new cart:", w), c(null), typeof window < "u" && localStorage.removeItem(f), setTimeout(() => {
51
- C.mutate(a), p.current = !1;
60
+ }, []), d(() => {
61
+ I && t && !w.current && (w.current = !0, console.warn("Cart fetch failed, creating new cart:", I), f(null), typeof window < "u" && localStorage.removeItem(l), setTimeout(() => {
62
+ v.mutate(i), w.current = !1;
52
63
  }, 100));
53
- }, [w, t, a]);
54
- const _ = tt(t || "", {
55
- onSuccess: () => n()
56
- }), F = et(t || "", {
57
- onSuccess: () => n()
58
- }), U = rt(t || "", {
59
- onSuccess: () => n()
60
- }), L = ot(t || "", {
61
- onSuccess: () => n()
62
- }), j = nt(t || "", {
63
- onSuccess: () => n()
64
- }), G = st(t || "", {
65
- onSuccess: () => n(),
64
+ }, [I, t, i]);
65
+ const q = ft(t || "", {
66
+ onSuccess: () => a()
67
+ }), H = mt(t || "", {
68
+ onSuccess: () => a()
69
+ }), K = dt(t || "", {
70
+ onSuccess: () => a()
71
+ }), Y = lt(t || "", {
72
+ onSuccess: () => a()
73
+ }), z = pt(t || "", {
74
+ onSuccess: () => a()
75
+ }), B = Ct(t || "", {
76
+ onSuccess: () => a(),
66
77
  retry: 3
67
- }), O = at(t || "", {
78
+ }), J = It(t || "", {
68
79
  onSuccess: (e) => {
69
- var s;
80
+ var n;
70
81
  if ("error" in e) return;
71
- const r = ((s = e.items) == null ? void 0 : s.map((u) => {
72
- var i;
82
+ const r = ((n = e.items) == null ? void 0 : n.map((o) => {
83
+ var u;
73
84
  return {
74
- id: ((i = u.variant) == null ? void 0 : i.sku) || "",
75
- quantity: u.quantity,
76
- item_price: Number(u.priceAtPurchase)
85
+ id: ((u = o.variant) == null ? void 0 : u.sku) || "",
86
+ quantity: o.quantity,
87
+ item_price: Number(o.priceAtPurchase)
77
88
  };
78
- })) || [];
79
- R(
89
+ })) || [], s = `order_${e.id}`;
90
+ G(
80
91
  Number(e.totalPrice),
81
92
  "NGN",
82
93
  e.id,
83
- r
94
+ r,
95
+ s
84
96
  );
85
97
  }
86
98
  });
87
- m(() => {
88
- t && typeof window < "u" && localStorage.setItem(f, t);
99
+ d(() => {
100
+ t && typeof window < "u" && localStorage.setItem(l, t);
89
101
  }, [t]);
90
- const b = o(
91
- async (e, r, s, u, i) => {
102
+ const Q = c(
103
+ async (e, r, s, n, o) => {
104
+ var T;
92
105
  if (!t) throw new Error("No cart ID");
93
- await _.mutateAsync({ sku: u, quantity: i }), D(e, r, s, i);
106
+ const { fbc: u, fbp: y } = E(), x = await q.mutateAsync({ sku: n, quantity: o, fbc: u, fbp: y });
107
+ if ("error" in x) return;
108
+ const R = (T = x.items) == null ? void 0 : T.findLast(
109
+ (D) => {
110
+ var $;
111
+ return (($ = D.variant) == null ? void 0 : $.sku) === n;
112
+ }
113
+ );
114
+ if (R) {
115
+ const D = `cart_${t}_item_${R.id}`;
116
+ h(e, r, s, o, D);
117
+ } else
118
+ h(e, r, s, o);
94
119
  },
95
120
  // eslint-disable-next-line react-hooks/exhaustive-deps
96
- [t, D]
97
- ), q = o(
121
+ [t, h, E]
122
+ ), V = c(
98
123
  async (e, r) => {
99
124
  if (!t) throw new Error("No cart ID");
100
- await F.mutateAsync({ itemId: e, quantity: r });
125
+ await H.mutateAsync({ itemId: e, quantity: r });
101
126
  },
102
127
  // eslint-disable-next-line react-hooks/exhaustive-deps
103
128
  [t]
104
- ), H = o(
129
+ ), W = c(
105
130
  async (e) => {
106
131
  if (!t) throw new Error("No cart ID");
107
- await U.mutateAsync(e);
132
+ await K.mutateAsync(e);
108
133
  },
109
134
  // eslint-disable-next-line react-hooks/exhaustive-deps
110
135
  [t]
111
- ), K = o(
136
+ ), X = c(
112
137
  async (e) => {
113
138
  if (!t) throw new Error("No cart ID");
114
- await L.mutateAsync({ code: e });
139
+ await Y.mutateAsync({ code: e });
115
140
  },
116
141
  // eslint-disable-next-line react-hooks/exhaustive-deps
117
142
  [t]
118
- ), Y = o(async () => {
143
+ ), Z = c(async () => {
119
144
  if (!t) throw new Error("No cart ID");
120
- await j.mutateAsync();
121
- }, [t]), M = o(() => {
122
- c(null), typeof window < "u" && localStorage.removeItem(f);
123
- }, []), z = o(() => {
124
- M(), C.mutate(a);
125
- }, [a]), B = o(() => {
126
- v(!0);
127
- }, []), E = o(() => {
128
- v(!1);
129
- }, []), J = {
130
- cart: k || null,
145
+ await z.mutateAsync();
146
+ }, [t]), N = c(() => {
147
+ f(null), typeof window < "u" && localStorage.removeItem(l);
148
+ }, []), tt = c(() => {
149
+ N(), v.mutate(i);
150
+ }, [i]), et = c(() => {
151
+ A(!0);
152
+ }, []), P = c(() => {
153
+ A(!1);
154
+ }, []), rt = c(() => {
155
+ var n, o;
156
+ if (!m || !t) return;
157
+ const e = Number(((n = m.pricing) == null ? void 0 : n.total) || 0), r = ((o = m.items) == null ? void 0 : o.reduce((u, y) => u + y.quantity, 0)) || 0, s = `cart_${t}_checkout`;
158
+ M(e, r, s);
159
+ }, [m, t, M]), ot = {
160
+ cart: m || null,
131
161
  cartId: t,
132
- isLoading: T,
133
- error: w,
134
- updateCartMutation: G,
135
- checkoutMutation: O,
136
- addItem: b,
137
- updateItem: q,
138
- removeItem: H,
139
- applyDiscount: K,
140
- removeDiscount: Y,
141
- clearCart: M,
142
- clearAndCreateNewCart: z,
143
- refetch: n,
144
- isOpen: h,
145
- open: B,
146
- close: E
162
+ isLoading: O,
163
+ error: I,
164
+ updateCartMutation: B,
165
+ checkoutMutation: J,
166
+ addItem: Q,
167
+ updateItem: V,
168
+ removeItem: W,
169
+ applyDiscount: X,
170
+ removeDiscount: Z,
171
+ trackCheckoutInitiated: rt,
172
+ clearCart: N,
173
+ clearAndCreateNewCart: tt,
174
+ refetch: a,
175
+ isOpen: g,
176
+ open: et,
177
+ close: P
147
178
  };
148
- return /* @__PURE__ */ Q(N.Provider, { value: J, children: [
149
- l,
150
- g && /* @__PURE__ */ V(
151
- ct,
179
+ return /* @__PURE__ */ nt(F.Provider, { value: ot, children: [
180
+ p,
181
+ U && /* @__PURE__ */ ct(
182
+ wt,
152
183
  {
153
- isOpen: h,
154
- onClose: E,
155
- ...P
184
+ isOpen: g,
185
+ onClose: P,
186
+ ...L
156
187
  }
157
188
  )
158
189
  ] });
159
190
  }
160
- function It() {
161
- const l = X(N);
162
- if (!l)
191
+ function bt() {
192
+ const p = at(F);
193
+ if (!p)
163
194
  throw new Error("useCart must be used within CartProvider");
164
- return l;
195
+ return p;
165
196
  }
166
197
  export {
167
- N as CartContext,
168
- Ct as CartProvider,
169
- It as useCart
198
+ F as CartContext,
199
+ St as CartProvider,
200
+ bt as useCart
170
201
  };