bitsnap-react 1.0.0 → 1.2.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.
package/dist/index.mjs CHANGED
@@ -58,8 +58,7 @@ var PublicApiClient;
58
58
 
59
59
  // src/components/checkout/CartProvider.tsx
60
60
  import { create as create2 } from "@bufbuild/protobuf";
61
- import { createContext, useContext } from "react";
62
- import { QueryClient, QueryClientProvider } from "react-query";
61
+ import { createContext, useContext, useEffect } from "react";
63
62
  import zod from "zod";
64
63
 
65
64
  // src/components/checkout/constants.ts
@@ -100,7 +99,7 @@ function formatCurrency(amount, currency) {
100
99
  import { create } from "zustand";
101
100
  var useCheckoutStore = create((set) => ({
102
101
  isCartVisible: false,
103
- numberOfProductsInCart: 2,
102
+ numberOfProductsInCart: 0,
104
103
  showCart: () => set((state) => ({ ...state, isCartVisible: true })),
105
104
  hideCart: () => set((state) => ({ ...state, isCartVisible: false })),
106
105
  setNumberOfProductsInCart: (numberOfProductsInCart) => set((state) => ({ ...state, numberOfProductsInCart }))
@@ -317,6 +316,7 @@ function mapGooglePayDisplayItems(items, methods, deliveryMethod, couponCode, co
317
316
  }
318
317
 
319
318
  // src/components/checkout/CartProvider.tsx
319
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
320
320
  import { Fragment, jsx } from "react/jsx-runtime";
321
321
  var MARKETING_AGREEMENT_ID = "__m_a";
322
322
  var CartProviderContext = createContext(void 0);
@@ -343,6 +343,9 @@ function getNewHostIfExist() {
343
343
  }
344
344
  var CartProvider = ({ children }) => {
345
345
  const queryClient = new QueryClient();
346
+ useEffect(() => {
347
+ updateNumberOfProductsInCart();
348
+ }, []);
346
349
  const projectID = getProjectID();
347
350
  if (projectID == null) {
348
351
  return /* @__PURE__ */ jsx(Fragment, {});
@@ -455,6 +458,7 @@ function addProducts(products) {
455
458
  metadata: el.metadata
456
459
  })));
457
460
  saveCheckout(checkout);
461
+ updateNumberOfProductsInCart();
458
462
  }
459
463
  function removeProductFromCheckout(ids) {
460
464
  var _a;
@@ -466,6 +470,7 @@ function removeProductFromCheckout(ids) {
466
470
  )
467
471
  };
468
472
  saveCheckout(newCheckout);
473
+ updateNumberOfProductsInCart();
469
474
  }
470
475
  function saveCheckout(model) {
471
476
  localStorage.setItem(checkoutKey, JSON.stringify(model));
@@ -573,6 +578,7 @@ var getCheckoutMethods = (projectID) => {
573
578
  const empty = structuredClone(emptyCheckout);
574
579
  empty.country = (_a = getCheckout()) == null ? void 0 : _a.country;
575
580
  saveCheckout(empty);
581
+ updateNumberOfProductsInCart();
576
582
  },
577
583
  async getAvailableCountries() {
578
584
  const result = await fetch(buildURL(projectID, "/countries"), {
@@ -654,6 +660,7 @@ var getCheckoutMethods = (projectID) => {
654
660
  return product;
655
661
  });
656
662
  saveCheckout(checkout);
663
+ updateNumberOfProductsInCart();
657
664
  },
658
665
  async redirectToNextStep() {
659
666
  const checkout = getCheckout();
@@ -1039,9 +1046,20 @@ function resolveProductDetailsFromSingleProduct(id, product) {
1039
1046
  images: (_d = variant.images) != null ? _d : product.images
1040
1047
  };
1041
1048
  }
1049
+ function updateNumberOfProductsInCart() {
1050
+ var _a, _b;
1051
+ const checkout = getCheckout();
1052
+ let numberOfProductsInCart = 0;
1053
+ if (checkout == null) {
1054
+ useCheckoutStore.setState((state) => ({ ...state, numberOfProductsInCart }));
1055
+ return;
1056
+ }
1057
+ numberOfProductsInCart = (_b = (_a = checkout.products) == null ? void 0 : _a.reduce((acc, product) => acc + product.quantity, 0)) != null ? _b : 0;
1058
+ useCheckoutStore.setState((state) => ({ ...state, numberOfProductsInCart }));
1059
+ }
1042
1060
 
1043
1061
  // src/components/checkout/ApplePay.tsx
1044
- import { useQuery } from "react-query";
1062
+ import { useQuery } from "@tanstack/react-query";
1045
1063
  import { Fragment as Fragment2, jsx as jsx2 } from "react/jsx-runtime";
1046
1064
  function ApplePayButtonComponent({ style, buttonType, colorType, items, onClick }) {
1047
1065
  const {
@@ -1055,7 +1073,10 @@ function ApplePayButtonComponent({ style, buttonType, colorType, items, onClick
1055
1073
  setPostalCode,
1056
1074
  clearCart
1057
1075
  } = useCartProvider();
1058
- const { data: isApplePayAvailable } = useQuery("is-apple-pay-available", checkIfApplePayIsAvailable);
1076
+ const { data: isApplePayAvailable } = useQuery({
1077
+ queryKey: ["is-apple-pay-available"],
1078
+ queryFn: checkIfApplePayIsAvailable
1079
+ });
1059
1080
  if (isApplePayAvailable != true) {
1060
1081
  return null;
1061
1082
  }
@@ -1228,8 +1249,34 @@ var ApplePay_default = Wrapper;
1228
1249
 
1229
1250
  // src/components/checkout/GooglePay.tsx
1230
1251
  import GooglePayButton from "@google-pay/button-react";
1231
- import { useMutation, useQuery as useQuery2 } from "react-query";
1232
- import { Fragment as Fragment3, jsx as jsx3, jsxs } from "react/jsx-runtime";
1252
+
1253
+ // src/ui/spinner.tsx
1254
+ import { Loader2Icon } from "lucide-react";
1255
+
1256
+ // src/lib/utils.ts
1257
+ import { clsx } from "clsx";
1258
+ import { twMerge } from "tailwind-merge";
1259
+ function cn(...inputs) {
1260
+ return twMerge(clsx(inputs));
1261
+ }
1262
+
1263
+ // src/ui/spinner.tsx
1264
+ import { jsx as jsx3 } from "react/jsx-runtime";
1265
+ function Spinner({ className, ...props }) {
1266
+ return /* @__PURE__ */ jsx3(
1267
+ Loader2Icon,
1268
+ {
1269
+ role: "status",
1270
+ "aria-label": "Loading",
1271
+ className: cn("size-4 animate-spin", className),
1272
+ ...props
1273
+ }
1274
+ );
1275
+ }
1276
+
1277
+ // src/components/checkout/GooglePay.tsx
1278
+ import { useQuery as useQuery2, useMutation } from "@tanstack/react-query";
1279
+ import { Fragment as Fragment3, jsx as jsx4, jsxs } from "react/jsx-runtime";
1233
1280
  function GooglePayButtonComponent({ items, style, buttonColor, buttonSizeMode, test }) {
1234
1281
  const {
1235
1282
  getGooglePayConfiguration,
@@ -1241,20 +1288,25 @@ function GooglePayButtonComponent({ items, style, buttonColor, buttonSizeMode, t
1241
1288
  setPostalCode,
1242
1289
  clearCart
1243
1290
  } = useCartProvider();
1244
- const { data: googlePayConfiguration } = useQuery2(["get-google-pay-configuration", items.map((el) => el.id).join(",")], () => getGooglePayConfiguration({
1245
- items: items.map((el) => ({
1246
- ...el,
1247
- id: void 0,
1248
- productID: el.id
1249
- }))
1250
- }));
1251
- const { mutateAsync: completeGooglePayPaymentAsync, isLoading } = useMutation(completeGooglePayPayment);
1291
+ const { data: googlePayConfiguration } = useQuery2({
1292
+ queryKey: ["get-google-pay-configuration", items.map((el) => el.id).join(",")],
1293
+ queryFn: () => getGooglePayConfiguration({
1294
+ items: items.map((el) => ({
1295
+ ...el,
1296
+ id: void 0,
1297
+ productID: el.id
1298
+ }))
1299
+ })
1300
+ });
1301
+ const { mutateAsync: completeGooglePayPaymentAsync, isPending } = useMutation({
1302
+ mutationFn: completeGooglePayPayment
1303
+ });
1252
1304
  if (googlePayConfiguration == null || googlePayConfiguration.isAvailable != true) {
1253
1305
  console.log("google pay configuration is not available", googlePayConfiguration);
1254
1306
  return null;
1255
1307
  }
1256
1308
  return /* @__PURE__ */ jsxs(Fragment3, { children: [
1257
- /* @__PURE__ */ jsx3(
1309
+ /* @__PURE__ */ jsx4(
1258
1310
  GooglePayButton,
1259
1311
  {
1260
1312
  buttonSizeMode,
@@ -1307,16 +1359,16 @@ function GooglePayButtonComponent({ items, style, buttonColor, buttonSizeMode, t
1307
1359
  }
1308
1360
  }
1309
1361
  ),
1310
- isLoading ? "\u0141adowanie..." : null
1362
+ isPending ? /* @__PURE__ */ jsx4(Spinner, {}) : null
1311
1363
  ] });
1312
1364
  }
1313
1365
  function Wrapper2(props) {
1314
- return /* @__PURE__ */ jsx3(Fragment3, { children: /* @__PURE__ */ jsx3(CartProvider_default, { children: /* @__PURE__ */ jsx3(GooglePayButtonComponent, { ...props }) }) });
1366
+ return /* @__PURE__ */ jsx4(Fragment3, { children: /* @__PURE__ */ jsx4(CartProvider_default, { children: /* @__PURE__ */ jsx4(GooglePayButtonComponent, { ...props }) }) });
1315
1367
  }
1316
1368
  var GooglePay_default = Wrapper2;
1317
1369
 
1318
1370
  // src/components/checkout/BitsnapCart.tsx
1319
- import { useEffect as useEffect3 } from "react";
1371
+ import { useEffect as useEffect4 } from "react";
1320
1372
  import zod2 from "zod";
1321
1373
 
1322
1374
  // src/components/checkout/CartComponent.tsx
@@ -1326,12 +1378,11 @@ import { createPortal } from "react-dom";
1326
1378
  // src/components/checkout/CartComponentContent.tsx
1327
1379
  import { useAutoAnimate } from "@formkit/auto-animate/react";
1328
1380
  import React from "react";
1329
- import { useMutation as useMutation2, useQuery as useQuery3 } from "react-query";
1330
1381
 
1331
1382
  // src/components/checkout/CountrySelector.tsx
1332
1383
  import { AnimatePresence, motion } from "framer-motion";
1333
- import { useEffect, useRef, useState } from "react";
1334
- import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
1384
+ import { useEffect as useEffect2, useRef, useState } from "react";
1385
+ import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
1335
1386
  function CountrySelector({
1336
1387
  id,
1337
1388
  open: open2,
@@ -1343,7 +1394,7 @@ function CountrySelector({
1343
1394
  }) {
1344
1395
  var _a;
1345
1396
  const ref = useRef(null);
1346
- useEffect(() => {
1397
+ useEffect2(() => {
1347
1398
  const mutableRef = ref;
1348
1399
  const handleClickOutside = (event) => {
1349
1400
  if (mutableRef.current && // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -1358,13 +1409,13 @@ function CountrySelector({
1358
1409
  document.removeEventListener("mousedown", handleClickOutside);
1359
1410
  };
1360
1411
  }, [ref]);
1361
- useEffect(() => {
1412
+ useEffect2(() => {
1362
1413
  if (selectedValue == null && countries.length > 0) {
1363
1414
  onChange(countries[0].code);
1364
1415
  }
1365
1416
  }, []);
1366
1417
  const [query, setQuery] = useState("");
1367
- return /* @__PURE__ */ jsx4("div", { ref, children: /* @__PURE__ */ jsxs2("div", { className: "relative", children: [
1418
+ return /* @__PURE__ */ jsx5("div", { ref, children: /* @__PURE__ */ jsxs2("div", { className: "relative", children: [
1368
1419
  /* @__PURE__ */ jsxs2(
1369
1420
  "button",
1370
1421
  {
@@ -1377,7 +1428,7 @@ function CountrySelector({
1377
1428
  disabled,
1378
1429
  children: [
1379
1430
  /* @__PURE__ */ jsxs2("span", { className: "truncate flex items-center", children: [
1380
- /* @__PURE__ */ jsx4(
1431
+ /* @__PURE__ */ jsx5(
1381
1432
  "img",
1382
1433
  {
1383
1434
  alt: `${selectedValue}`,
@@ -1387,11 +1438,11 @@ function CountrySelector({
1387
1438
  ),
1388
1439
  (_a = countries.find((el) => el.code === selectedValue)) == null ? void 0 : _a.name
1389
1440
  ] }),
1390
- /* @__PURE__ */ jsx4(
1441
+ /* @__PURE__ */ jsx5(
1391
1442
  "span",
1392
1443
  {
1393
1444
  className: `absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none ${disabled ? "hidden" : ""}`,
1394
- children: /* @__PURE__ */ jsx4(
1445
+ children: /* @__PURE__ */ jsx5(
1395
1446
  "svg",
1396
1447
  {
1397
1448
  className: "h-5 w-5 text-light-purple",
@@ -1399,7 +1450,7 @@ function CountrySelector({
1399
1450
  viewBox: "0 0 20 20",
1400
1451
  fill: "currentColor",
1401
1452
  "aria-hidden": "true",
1402
- children: /* @__PURE__ */ jsx4(
1453
+ children: /* @__PURE__ */ jsx5(
1403
1454
  "path",
1404
1455
  {
1405
1456
  fillRule: "evenodd",
@@ -1414,7 +1465,7 @@ function CountrySelector({
1414
1465
  ]
1415
1466
  }
1416
1467
  ),
1417
- /* @__PURE__ */ jsx4(AnimatePresence, { children: open2 && /* @__PURE__ */ jsxs2(
1468
+ /* @__PURE__ */ jsx5(AnimatePresence, { children: open2 && /* @__PURE__ */ jsxs2(
1418
1469
  motion.ul,
1419
1470
  {
1420
1471
  initial: { opacity: 0 },
@@ -1428,7 +1479,7 @@ function CountrySelector({
1428
1479
  "aria-activedescendant": "listbox-option-3",
1429
1480
  children: [
1430
1481
  /* @__PURE__ */ jsxs2("div", { className: "sticky top-0 z-10 bg-white dark:bg-neutral-800", children: [
1431
- /* @__PURE__ */ jsx4("li", { className: "dark:text-neutral-200 text-neutral-900 cursor-default select-none relative py-2 px-3", children: /* @__PURE__ */ jsx4(
1482
+ /* @__PURE__ */ jsx5("li", { className: "dark:text-neutral-200 text-neutral-900 cursor-default select-none relative py-2 px-3", children: /* @__PURE__ */ jsx5(
1432
1483
  "input",
1433
1484
  {
1434
1485
  type: "search",
@@ -1439,15 +1490,15 @@ function CountrySelector({
1439
1490
  onChange: (e) => setQuery(e.target.value)
1440
1491
  }
1441
1492
  ) }),
1442
- /* @__PURE__ */ jsx4("hr", {})
1493
+ /* @__PURE__ */ jsx5("hr", {})
1443
1494
  ] }),
1444
- /* @__PURE__ */ jsx4(
1495
+ /* @__PURE__ */ jsx5(
1445
1496
  "div",
1446
1497
  {
1447
1498
  className: "max-h-64 scrollbar scrollbar-track-gray-100 scrollbar-thumb-gray-300 hover:scrollbar-thumb-gray-600 scrollbar-thumb-rounded scrollbar-thin overflow-y-scroll",
1448
1499
  children: countries.filter(
1449
1500
  (country) => country.name.toLowerCase().startsWith(query.toLowerCase())
1450
- ).length === 0 ? /* @__PURE__ */ jsx4("li", { className: "text-light-purple cursor-default select-none relative py-2 pl-3 pr-9", children: "No countries found" }) : countries.filter(
1501
+ ).length === 0 ? /* @__PURE__ */ jsx5("li", { className: "text-light-purple cursor-default select-none relative py-2 pl-3 pr-9", children: "No countries found" }) : countries.filter(
1451
1502
  (country) => country.name.toLowerCase().startsWith(query.toLowerCase())
1452
1503
  ).map((value, index) => {
1453
1504
  return /* @__PURE__ */ jsxs2(
@@ -1462,7 +1513,7 @@ function CountrySelector({
1462
1513
  onToggle();
1463
1514
  },
1464
1515
  children: [
1465
- /* @__PURE__ */ jsx4(
1516
+ /* @__PURE__ */ jsx5(
1466
1517
  "img",
1467
1518
  {
1468
1519
  alt: `${value.code}`,
@@ -1470,12 +1521,12 @@ function CountrySelector({
1470
1521
  className: "inline mr-2 h-4 rounded-sm"
1471
1522
  }
1472
1523
  ),
1473
- /* @__PURE__ */ jsx4("span", { className: "font-normal truncate", children: value.name }),
1474
- value.code === selectedValue ? /* @__PURE__ */ jsx4(
1524
+ /* @__PURE__ */ jsx5("span", { className: "font-normal truncate", children: value.name }),
1525
+ value.code === selectedValue ? /* @__PURE__ */ jsx5(
1475
1526
  "span",
1476
1527
  {
1477
1528
  className: "text-blue-600 absolute inset-y-0 right-0 flex items-center pr-8",
1478
- children: /* @__PURE__ */ jsx4(
1529
+ children: /* @__PURE__ */ jsx5(
1479
1530
  "svg",
1480
1531
  {
1481
1532
  className: "h-5 w-5",
@@ -1483,7 +1534,7 @@ function CountrySelector({
1483
1534
  viewBox: "0 0 20 20",
1484
1535
  fill: "currentColor",
1485
1536
  "aria-hidden": "true",
1486
- children: /* @__PURE__ */ jsx4(
1537
+ children: /* @__PURE__ */ jsx5(
1487
1538
  "path",
1488
1539
  {
1489
1540
  fillRule: "evenodd",
@@ -1510,18 +1561,18 @@ function CountrySelector({
1510
1561
  var CountrySelector_default = CountrySelector;
1511
1562
 
1512
1563
  // src/components/checkout/SingleProduct.tsx
1513
- import { useEffect as useEffect2, useState as useState2 } from "react";
1514
- import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
1564
+ import { useEffect as useEffect3, useState as useState2 } from "react";
1565
+ import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
1515
1566
  var SingleProduct = ({ quantity, details, shouldUpdate }) => {
1516
1567
  var _a;
1517
1568
  return /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-3", children: [
1518
- /* @__PURE__ */ jsx5("img", { className: "aspect-auto max-w-[30%] max-w-32 max-h-32", src: (_a = details.image_url) != null ? _a : "", alt: details.name }),
1569
+ /* @__PURE__ */ jsx6("img", { className: "aspect-auto max-w-[30%] max-w-32 max-h-32", src: (_a = details.image_url) != null ? _a : "", alt: details.name }),
1519
1570
  /* @__PURE__ */ jsxs3("div", { className: "flex flex-col", children: [
1520
- /* @__PURE__ */ jsx5("p", { className: "font-medium", children: details.name }),
1521
- /* @__PURE__ */ jsx5("p", { className: "text-sm", children: formatCurrency(details.price, details.currency) }),
1571
+ /* @__PURE__ */ jsx6("p", { className: "font-medium", children: details.name }),
1572
+ /* @__PURE__ */ jsx6("p", { className: "text-sm", children: formatCurrency(details.price, details.currency) }),
1522
1573
  /* @__PURE__ */ jsxs3("div", { className: "flex justify-between", children: [
1523
- /* @__PURE__ */ jsx5(QuantityComponent, { className: "", quantity, shouldUpdate }),
1524
- /* @__PURE__ */ jsx5("button", { className: "text-sm font-medium", onClick: () => shouldUpdate(0), children: "Usu\u0144" })
1574
+ /* @__PURE__ */ jsx6(QuantityComponent, { className: "", quantity, shouldUpdate }),
1575
+ /* @__PURE__ */ jsx6("button", { className: "text-sm font-medium", onClick: () => shouldUpdate(0), children: "Usu\u0144" })
1525
1576
  ] })
1526
1577
  ] })
1527
1578
  ] });
@@ -1534,7 +1585,7 @@ var QuantityComponent = ({
1534
1585
  }) => {
1535
1586
  const [quantityString, setQuantityString] = useState2(quantity.toString());
1536
1587
  const [quantityValue, setQuantityValue] = useState2(quantity);
1537
- useEffect2(() => {
1588
+ useEffect3(() => {
1538
1589
  shouldUpdate(quantityValue);
1539
1590
  }, [quantityValue]);
1540
1591
  function setNewQuantity(newQuantity) {
@@ -1570,8 +1621,8 @@ var QuantityComponent = ({
1570
1621
  setQuantityValue(quantity);
1571
1622
  }
1572
1623
  return /* @__PURE__ */ jsxs3("div", { className: `flex ${className} items-center border dark:border-neutral-400 border-neutral-700 rounded-md my-1`, children: [
1573
- /* @__PURE__ */ jsx5("button", { onClick: decreaseQuantity, className: "px-2 py-1", children: "-" }),
1574
- /* @__PURE__ */ jsx5(
1624
+ /* @__PURE__ */ jsx6("button", { onClick: decreaseQuantity, className: "px-2 py-1", children: "-" }),
1625
+ /* @__PURE__ */ jsx6(
1575
1626
  "input",
1576
1627
  {
1577
1628
  className: "w-8 bg-transparent text-center",
@@ -1582,14 +1633,14 @@ var QuantityComponent = ({
1582
1633
  type: "text"
1583
1634
  }
1584
1635
  ),
1585
- /* @__PURE__ */ jsx5("button", { onClick: increaseQuantity, className: "px-2 py-1", children: "+" })
1636
+ /* @__PURE__ */ jsx6("button", { onClick: increaseQuantity, className: "px-2 py-1", children: "+" })
1586
1637
  ] });
1587
1638
  };
1588
1639
 
1589
1640
  // src/components/checkout/Skeleton.tsx
1590
- import { jsx as jsx6 } from "react/jsx-runtime";
1641
+ import { jsx as jsx7 } from "react/jsx-runtime";
1591
1642
  function Skeleton({ className, ...props }) {
1592
- return /* @__PURE__ */ jsx6(
1643
+ return /* @__PURE__ */ jsx7(
1593
1644
  "div",
1594
1645
  {
1595
1646
  "data-slot": "skeleton",
@@ -1600,32 +1651,47 @@ function Skeleton({ className, ...props }) {
1600
1651
  }
1601
1652
 
1602
1653
  // src/components/checkout/CartComponentContent.tsx
1603
- import { Fragment as Fragment4, jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
1654
+ import { useMutation as useMutation2, useQuery as useQuery3 } from "@tanstack/react-query";
1655
+ import { Fragment as Fragment4, jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
1604
1656
  var CartComponentContent = ({ className }) => {
1605
1657
  var _a, _b, _c, _d, _e;
1606
1658
  const provider = useCartProvider();
1607
- const { mutateAsync: removeProduct } = useMutation2(
1608
- provider.removeProductFromCart
1609
- );
1610
- const { mutateAsync: updateQuantity } = useMutation2(provider.updateQuantity);
1611
- const { mutateAsync: setCountryAsync } = useMutation2(provider.setCountry);
1612
- const { mutateAsync: clearCart } = useMutation2(provider.clearCart);
1659
+ const { mutateAsync: removeProduct } = useMutation2({
1660
+ mutationFn: provider.removeProductFromCart
1661
+ });
1662
+ const { mutateAsync: updateQuantity } = useMutation2({
1663
+ mutationFn: provider.updateQuantity
1664
+ });
1665
+ const { mutateAsync: setCountryAsync } = useMutation2({
1666
+ mutationFn: provider.setCountry
1667
+ });
1668
+ const { mutateAsync: clearCart } = useMutation2({
1669
+ mutationFn: provider.clearCart
1670
+ });
1613
1671
  const [errMsg, setErrMsg] = React.useState("");
1614
1672
  const [isCountryOpen, setIsCountryOpen] = React.useState(false);
1615
1673
  const {
1616
1674
  mutateAsync: continueToCheckoutAsync,
1617
- isLoading: isContinueToCheckoutLoading
1618
- } = useMutation2(provider.redirectToNextStep);
1619
- const { data: availableCountries } = useQuery3(
1620
- "cart-available-countries",
1621
- provider.getAvailableCountries
1622
- );
1623
- const { data: isApplePayAvailable } = useQuery3("cart-one-click-payment", provider.checkIfApplePayIsAvailable);
1624
- const { data, isLoading, refetch } = useQuery3("cart", provider.getProducts);
1625
- const { data: countryData, refetch: refetchCountry } = useQuery3(
1626
- "cart-country",
1627
- provider.getCountry
1628
- );
1675
+ isPending: isContinueToCheckoutLoading
1676
+ } = useMutation2({
1677
+ mutationFn: provider.redirectToNextStep
1678
+ });
1679
+ const { data: availableCountries } = useQuery3({
1680
+ queryKey: ["cart-available-countries"],
1681
+ queryFn: provider.getAvailableCountries
1682
+ });
1683
+ const { data: isApplePayAvailable } = useQuery3({
1684
+ queryKey: ["cart-one-click-payment"],
1685
+ queryFn: provider.checkIfApplePayIsAvailable
1686
+ });
1687
+ const { data, isLoading, refetch } = useQuery3({
1688
+ queryKey: ["cart"],
1689
+ queryFn: provider.getProducts
1690
+ });
1691
+ const { data: countryData, refetch: refetchCountry } = useQuery3({
1692
+ queryKey: ["cart-country"],
1693
+ queryFn: provider.getCountry
1694
+ });
1629
1695
  const [productsParent] = useAutoAnimate(
1630
1696
  /* optional config */
1631
1697
  );
@@ -1674,16 +1740,16 @@ var CartComponentContent = ({ className }) => {
1674
1740
  }
1675
1741
  return /* @__PURE__ */ jsxs4("div", { className: `${className} flex flex-col`, ref: productsParent, children: [
1676
1742
  isLoading && /* @__PURE__ */ jsxs4("div", { className: "relative flex w-full justify-center flex-col gap-4", children: [
1677
- /* @__PURE__ */ jsx7(Skeleton, { className: "w-full h-32" }),
1678
- /* @__PURE__ */ jsx7(Skeleton, { className: "w-full h-32" })
1743
+ /* @__PURE__ */ jsx8(Skeleton, { className: "w-full h-32" }),
1744
+ /* @__PURE__ */ jsx8(Skeleton, { className: "w-full h-32" })
1679
1745
  ] }),
1680
- !isLoading && (products == null || products.length == 0) && /* @__PURE__ */ jsx7("div", { className: "flex flex-col gap-4 p-4", children: /* @__PURE__ */ jsx7("p", { className: "dark:text-neutral-400 text-neutral-700", children: "Brak produkt\xF3w w koszyku." }) }),
1681
- /* @__PURE__ */ jsx7(
1746
+ !isLoading && (products == null || products.length == 0) && /* @__PURE__ */ jsx8("div", { className: "flex flex-col gap-4 p-4", children: /* @__PURE__ */ jsx8("p", { className: "dark:text-neutral-400 text-neutral-700", children: "Brak produkt\xF3w w koszyku." }) }),
1747
+ /* @__PURE__ */ jsx8(
1682
1748
  "div",
1683
1749
  {
1684
1750
  className: "max-h-[70vh] overflow-clip overflow-y-scroll",
1685
- children: products != null && products.length > 0 && /* @__PURE__ */ jsx7("ul", { className: "mt-5", children: products.map((product) => /* @__PURE__ */ jsx7(React.Fragment, { children: product.details != null && /* @__PURE__ */ jsxs4("li", { className: "mb-3", children: [
1686
- /* @__PURE__ */ jsx7(
1751
+ children: products != null && products.length > 0 && /* @__PURE__ */ jsx8("ul", { className: "mt-5", children: products.map((product) => /* @__PURE__ */ jsx8(React.Fragment, { children: product.details != null && /* @__PURE__ */ jsxs4("li", { className: "mb-3", children: [
1752
+ /* @__PURE__ */ jsx8(
1687
1753
  SingleProduct_default,
1688
1754
  {
1689
1755
  quantity: product.quantity,
@@ -1693,18 +1759,18 @@ var CartComponentContent = ({ className }) => {
1693
1759
  }
1694
1760
  }
1695
1761
  ),
1696
- /* @__PURE__ */ jsx7("hr", { className: "h-1 dark:border-neutral-700 border-neutral-400" })
1762
+ /* @__PURE__ */ jsx8("hr", { className: "h-1 dark:border-neutral-700 border-neutral-400" })
1697
1763
  ] }) }, product.id)) })
1698
1764
  }
1699
1765
  ),
1700
- /* @__PURE__ */ jsx7("div", { className: "grow" }),
1766
+ /* @__PURE__ */ jsx8("div", { className: "grow" }),
1701
1767
  sumOfProducts > 0 && currency != null && /* @__PURE__ */ jsxs4(Fragment4, { children: [
1702
- /* @__PURE__ */ jsx7("div", { className: "mx-3 flex flex-col", children: /* @__PURE__ */ jsxs4(
1768
+ /* @__PURE__ */ jsx8("div", { className: "mx-3 flex flex-col", children: /* @__PURE__ */ jsxs4(
1703
1769
  "div",
1704
1770
  {
1705
1771
  className: "flex flex-row justify-between text-lg",
1706
1772
  children: [
1707
- /* @__PURE__ */ jsx7(
1773
+ /* @__PURE__ */ jsx8(
1708
1774
  "p",
1709
1775
  {
1710
1776
  className: "dark:text-neutral-200 text-neutral-800 text-xl",
@@ -1712,27 +1778,27 @@ var CartComponentContent = ({ className }) => {
1712
1778
  }
1713
1779
  ),
1714
1780
  /* @__PURE__ */ jsxs4("div", { className: "flex flex-col items-end", children: [
1715
- /* @__PURE__ */ jsx7(
1781
+ /* @__PURE__ */ jsx8(
1716
1782
  "p",
1717
1783
  {
1718
1784
  className: "dark:text-neutral-200 text-neutral-800 font-medium",
1719
1785
  children: formatCurrency(sumOfProducts, currency)
1720
1786
  }
1721
1787
  ),
1722
- isSomeProductDeliverable && /* @__PURE__ */ jsx7("p", { className: "opacity-70 text-right text-base", children: "+ dostawa" })
1788
+ isSomeProductDeliverable && /* @__PURE__ */ jsx8("p", { className: "opacity-70 text-right text-base", children: "+ dostawa" })
1723
1789
  ] })
1724
1790
  ]
1725
1791
  }
1726
1792
  ) }),
1727
1793
  countries && (countries == null ? void 0 : countries.length) > 1 && /* @__PURE__ */ jsxs4("div", { children: [
1728
- /* @__PURE__ */ jsx7(
1794
+ /* @__PURE__ */ jsx8(
1729
1795
  "h4",
1730
1796
  {
1731
1797
  className: "ml-3 text-sm dark:text-neutral-400 text-neutral-700",
1732
1798
  children: "Wybierz kraj"
1733
1799
  }
1734
1800
  ),
1735
- /* @__PURE__ */ jsx7(
1801
+ /* @__PURE__ */ jsx8(
1736
1802
  CountrySelector_default,
1737
1803
  {
1738
1804
  id: Math.random().toString(),
@@ -1751,7 +1817,7 @@ var CartComponentContent = ({ className }) => {
1751
1817
  )
1752
1818
  ] }),
1753
1819
  /* @__PURE__ */ jsxs4("div", { className: "mb-3 flex flex-col", children: [
1754
- isApplePayAvailable && products != null && products.length > 0 && /* @__PURE__ */ jsx7("div", { className: "w-full px-2", children: /* @__PURE__ */ jsx7(ApplePay_default, { colorType: "white", style: { width: "100%" }, items: products == null ? void 0 : products.map((el) => {
1820
+ isApplePayAvailable && products != null && products.length > 0 && /* @__PURE__ */ jsx8("div", { className: "w-full px-2", children: /* @__PURE__ */ jsx8(ApplePay_default, { colorType: "white", style: { width: "100%" }, items: products == null ? void 0 : products.map((el) => {
1755
1821
  var _a2, _b2, _c2, _d2, _e2, _f;
1756
1822
  return {
1757
1823
  name: (_b2 = (_a2 = el.details) == null ? void 0 : _a2.name) != null ? _b2 : "",
@@ -1762,7 +1828,7 @@ var CartComponentContent = ({ className }) => {
1762
1828
  metadata: el.metadata
1763
1829
  };
1764
1830
  }) }) }),
1765
- products != null && products.length > 0 && /* @__PURE__ */ jsx7("div", { className: "w-full px-2", children: /* @__PURE__ */ jsx7(GooglePay_default, { buttonSizeMode: "fill", buttonColor: "white", style: { width: "100%" }, items: products == null ? void 0 : products.map((el) => {
1831
+ products != null && products.length > 0 && /* @__PURE__ */ jsx8("div", { className: "w-full px-2", children: /* @__PURE__ */ jsx8(GooglePay_default, { buttonSizeMode: "fill", buttonColor: "white", style: { width: "100%" }, items: products == null ? void 0 : products.map((el) => {
1766
1832
  var _a2, _b2, _c2, _d2, _e2, _f;
1767
1833
  return {
1768
1834
  name: (_b2 = (_a2 = el.details) == null ? void 0 : _a2.name) != null ? _b2 : "",
@@ -1773,16 +1839,16 @@ var CartComponentContent = ({ className }) => {
1773
1839
  metadata: el.metadata
1774
1840
  };
1775
1841
  }) }) }),
1776
- /* @__PURE__ */ jsx7(
1842
+ /* @__PURE__ */ jsx8(
1777
1843
  "button",
1778
1844
  {
1779
1845
  onClick: continueToCheckout,
1780
1846
  disabled: isLoading || isContinueToCheckoutLoading || selectedCountry == null,
1781
1847
  className: "px-3 py-2 my-2 mx-2 rounded-md disabled:opacity-40 disabled:cursor-not-allowed dark:bg-neutral-300 dark:hover:bg-neutral-100 dark:text-neutral-800 hover:bg-neutral-900 text-neutral-200 bg-neutral-800 transition font-bold",
1782
- children: isContinueToCheckoutLoading ? "\u0141adowanie..." : "Nast\u0119pny krok"
1848
+ children: isContinueToCheckoutLoading ? /* @__PURE__ */ jsx8(Spinner, {}) : "Nast\u0119pny krok"
1783
1849
  }
1784
1850
  ),
1785
- errMsg.length > 0 && /* @__PURE__ */ jsx7("p", { className: "text-red-500 text-sm text-center", children: errMsg })
1851
+ errMsg.length > 0 && /* @__PURE__ */ jsx8("p", { className: "text-red-500 text-sm text-center", children: errMsg })
1786
1852
  ] })
1787
1853
  ] })
1788
1854
  ] });
@@ -1790,31 +1856,31 @@ var CartComponentContent = ({ className }) => {
1790
1856
  var CartComponentContent_default = CartComponentContent;
1791
1857
 
1792
1858
  // src/components/checkout/CartComponent.tsx
1793
- import { Fragment as Fragment5, jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
1859
+ import { Fragment as Fragment5, jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
1794
1860
  function CartComponent({ isVisible, shouldHide }) {
1795
1861
  const [parent] = useAutoAnimate2(
1796
1862
  /* optional config */
1797
1863
  );
1798
- return /* @__PURE__ */ jsx8("div", { ref: parent, className: "z-[999999]", children: isVisible && /* @__PURE__ */ jsxs5(Fragment5, { children: [
1799
- /* @__PURE__ */ jsx8(
1864
+ return /* @__PURE__ */ jsx9("div", { ref: parent, className: "bitsnap-checkout dark", style: { zIndex: 999999 }, children: isVisible && /* @__PURE__ */ jsxs5(Fragment5, { children: [
1865
+ /* @__PURE__ */ jsx9(
1800
1866
  "div",
1801
1867
  {
1802
- className: "fixed top-0 right-0 left-0 bottom-0 bg-black/30 cursor-pointer",
1868
+ className: "fixed top-0 right-0 left-0 bottom-0 bg-black/30 cursor-pointer z-10",
1803
1869
  onClick: shouldHide
1804
1870
  }
1805
1871
  ),
1806
1872
  /* @__PURE__ */ jsxs5(
1807
1873
  "div",
1808
1874
  {
1809
- className: "fixed top-0 right-0 bottom-0 w-full md:w-[350px] xl:w-[420px] dark:bg-neutral-900 bg-neutral-300 dark:text-neutral-200 text-neutral-900 flex flex-col",
1875
+ className: "fixed z-20 top-0 right-0 bottom-0 w-full md:w-[350px] xl:w-[420px] dark:bg-neutral-900 bg-neutral-300 dark:text-neutral-200 text-neutral-900 flex flex-col",
1810
1876
  children: [
1811
1877
  /* @__PURE__ */ jsxs5(
1812
1878
  "div",
1813
1879
  {
1814
1880
  className: "mx-3 mt-7 flex justify-between items-center",
1815
1881
  children: [
1816
- /* @__PURE__ */ jsx8("h1", { className: "text-2xl font-medium", children: "Koszyk" }),
1817
- /* @__PURE__ */ jsx8(
1882
+ /* @__PURE__ */ jsx9("h1", { className: "text-2xl font-medium", children: "Koszyk" }),
1883
+ /* @__PURE__ */ jsx9(
1818
1884
  "button",
1819
1885
  {
1820
1886
  className: "rounded-full dark:hover:bg-neutral-700 hover:bg-neutral-400 p-2 transition",
@@ -1833,8 +1899,8 @@ function CartComponent({ isVisible, shouldHide }) {
1833
1899
  strokeLinejoin: "round",
1834
1900
  className: "lucide lucide-x",
1835
1901
  children: [
1836
- /* @__PURE__ */ jsx8("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
1837
- /* @__PURE__ */ jsx8("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
1902
+ /* @__PURE__ */ jsx9("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
1903
+ /* @__PURE__ */ jsx9("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
1838
1904
  ]
1839
1905
  }
1840
1906
  )
@@ -1843,7 +1909,7 @@ function CartComponent({ isVisible, shouldHide }) {
1843
1909
  ]
1844
1910
  }
1845
1911
  ),
1846
- /* @__PURE__ */ jsx8(CartComponentContent_default, { className: "grow" })
1912
+ /* @__PURE__ */ jsx9(CartComponentContent_default, { className: "grow" })
1847
1913
  ]
1848
1914
  }
1849
1915
  )
@@ -1854,14 +1920,14 @@ var WrapperCartComponent = (props) => {
1854
1920
  return null;
1855
1921
  }
1856
1922
  return createPortal(
1857
- /* @__PURE__ */ jsx8(CartProvider_default, { children: /* @__PURE__ */ jsx8(CartComponent, { ...props }) }),
1923
+ /* @__PURE__ */ jsx9(CartProvider_default, { children: /* @__PURE__ */ jsx9(CartComponent, { ...props }) }),
1858
1924
  document.body
1859
1925
  );
1860
1926
  };
1861
1927
  var CartComponent_default = WrapperCartComponent;
1862
1928
 
1863
1929
  // src/components/checkout/BitsnapCart.tsx
1864
- import { Fragment as Fragment6, jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
1930
+ import { Fragment as Fragment6, jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
1865
1931
  var cartAddToCartSchema = zod2.object({
1866
1932
  id: zod2.string(),
1867
1933
  isSubscription: zod2.boolean().default(false),
@@ -1872,9 +1938,10 @@ function BitsnapCart({
1872
1938
  projectID,
1873
1939
  children,
1874
1940
  onVisibleChange,
1875
- className
1941
+ className,
1942
+ numberOfProductsInCartOptions
1876
1943
  }) {
1877
- const { isCartVisible, showCart, hideCart } = useCheckoutStore();
1944
+ const { isCartVisible, showCart, hideCart, numberOfProductsInCart } = useCheckoutStore();
1878
1945
  function sentPostMessageToIframe(msg) {
1879
1946
  const iframes = document.querySelectorAll("iframe");
1880
1947
  iframes.forEach((iframe) => {
@@ -1882,13 +1949,13 @@ function BitsnapCart({
1882
1949
  (_a = iframe.contentWindow) == null ? void 0 : _a.postMessage(msg, "*");
1883
1950
  });
1884
1951
  }
1885
- useEffect3(() => {
1952
+ useEffect4(() => {
1886
1953
  onVisibleChange == null ? void 0 : onVisibleChange(isCartVisible);
1887
1954
  }, [isCartVisible]);
1888
- useEffect3(() => {
1955
+ useEffect4(() => {
1889
1956
  setProjectID(projectID);
1890
1957
  }, [projectID]);
1891
- useEffect3(() => {
1958
+ useEffect4(() => {
1892
1959
  if (!("cart" in window)) {
1893
1960
  const projectID2 = getProjectID();
1894
1961
  if (projectID2 == null) {
@@ -1973,7 +2040,7 @@ function BitsnapCart({
1973
2040
  }
1974
2041
  });
1975
2042
  }
1976
- useEffect3(() => {
2043
+ useEffect4(() => {
1977
2044
  var _a;
1978
2045
  setupEventListener();
1979
2046
  if (typeof window !== "undefined") {
@@ -1988,35 +2055,61 @@ function BitsnapCart({
1988
2055
  }
1989
2056
  }
1990
2057
  }, []);
1991
- return /* @__PURE__ */ jsxs6("span", { className: "bitsnap-checkout", children: [
1992
- /* @__PURE__ */ jsx9(
2058
+ return /* @__PURE__ */ jsxs6(Fragment6, { children: [
2059
+ /* @__PURE__ */ jsxs6(
1993
2060
  "button",
1994
2061
  {
1995
2062
  onClick: () => isCartVisible ? hideCart() : showCart(),
1996
- className: className != null ? className : "relative rounded-full hover:bg-neutral-300 transition p-1",
1997
- children: children ? /* @__PURE__ */ jsx9(Fragment6, { children }) : /* @__PURE__ */ jsxs6(
1998
- "svg",
1999
- {
2000
- xmlns: "http://www.w3.org/2000/svg",
2001
- width: "24",
2002
- height: "24",
2003
- viewBox: "0 0 24 24",
2004
- fill: "none",
2005
- stroke: "currentColor",
2006
- strokeWidth: "2",
2007
- strokeLinecap: "round",
2008
- strokeLinejoin: "round",
2009
- className: "lucide lucide-shopping-cart",
2010
- children: [
2011
- /* @__PURE__ */ jsx9("circle", { cx: "8", cy: "21", r: "1" }),
2012
- /* @__PURE__ */ jsx9("circle", { cx: "19", cy: "21", r: "1" }),
2013
- /* @__PURE__ */ jsx9("path", { d: "M2.05 2.05h2l2.66 12.42a2 2 0 0 0 2 1.58h9.78a2 2 0 0 0 1.95-1.57l1.65-7.43H5.12" })
2014
- ]
2015
- }
2016
- )
2063
+ style: { position: "relative" },
2064
+ className: ["bitsnap-checkout", className != null ? className : "rounded-full hover:bg-neutral-300 transition p-1"].join(" "),
2065
+ children: [
2066
+ children ? /* @__PURE__ */ jsx10(Fragment6, { children }) : /* @__PURE__ */ jsxs6(
2067
+ "svg",
2068
+ {
2069
+ xmlns: "http://www.w3.org/2000/svg",
2070
+ width: "24",
2071
+ height: "24",
2072
+ viewBox: "0 0 24 24",
2073
+ fill: "none",
2074
+ stroke: "currentColor",
2075
+ strokeWidth: "2",
2076
+ strokeLinecap: "round",
2077
+ strokeLinejoin: "round",
2078
+ className: "lucide lucide-shopping-cart",
2079
+ children: [
2080
+ /* @__PURE__ */ jsx10("circle", { cx: "8", cy: "21", r: "1" }),
2081
+ /* @__PURE__ */ jsx10("circle", { cx: "19", cy: "21", r: "1" }),
2082
+ /* @__PURE__ */ jsx10("path", { d: "M2.05 2.05h2l2.66 12.42a2 2 0 0 0 2 1.58h9.78a2 2 0 0 0 1.95-1.57l1.65-7.43H5.12" })
2083
+ ]
2084
+ }
2085
+ ),
2086
+ (numberOfProductsInCartOptions == null ? void 0 : numberOfProductsInCartOptions.isVisible) != false && numberOfProductsInCart > 0 && /* @__PURE__ */ jsx10(
2087
+ "div",
2088
+ {
2089
+ style: {
2090
+ position: "absolute",
2091
+ bottom: -5,
2092
+ right: -5,
2093
+ background: "black",
2094
+ color: "white",
2095
+ borderRadius: "50%",
2096
+ width: "22px",
2097
+ height: "22px",
2098
+ display: "flex",
2099
+ alignItems: "center",
2100
+ justifyContent: "center",
2101
+ fontSize: "13px",
2102
+ fontWeight: 600,
2103
+ boxShadow: "0 2px 8px rgba(0, 0, 0, 0.25)",
2104
+ ...numberOfProductsInCartOptions == null ? void 0 : numberOfProductsInCartOptions.style
2105
+ },
2106
+ children: numberOfProductsInCart
2107
+ }
2108
+ )
2109
+ ]
2017
2110
  }
2018
2111
  ),
2019
- /* @__PURE__ */ jsx9(
2112
+ /* @__PURE__ */ jsx10(
2020
2113
  CartComponent_default,
2021
2114
  {
2022
2115
  isVisible: isCartVisible,