"use client"; import { useEffect, useState } from "react"; import { motion, AnimatePresence } from "framer-motion"; import Image from "next/image"; import Link from "next/link"; import { X, Minus, Plus, Trash2, ShoppingBag } from "lucide-react"; import { useTranslations, useLocale } from "next-intl"; import { useSaleorCheckoutStore } from "@/stores/saleorCheckoutStore"; import { formatPrice } from "@/lib/saleor"; export default function CartDrawer() { const t = useTranslations("Cart"); const locale = useLocale(); const { checkout, isOpen, isLoading, error, closeCart, removeLine, updateLine, getTotal, getLineCount, getLines, initCheckout, clearError, } = useSaleorCheckoutStore(); const lines = getLines(); const total = getTotal(); const lineCount = getLineCount(); const [initialized, setInitialized] = useState(false); useEffect(() => { if (!initialized) { initCheckout(); setInitialized(true); } }, [initialized]); useEffect(() => { if (isOpen) { document.body.style.overflow = "hidden"; } else { document.body.style.overflow = ""; } return () => { document.body.style.overflow = ""; }; }, [isOpen]); return ( {isOpen && ( <>

{t("yourCart")} ({lineCount})

{error && (

{error}

)}
{lines.length === 0 ? (

{t("yourCartEmpty")}

{t("looksLikeEmpty")}

{t("startShopping")}
) : (
{lines.map((line) => (
{line.variant.product.media[0]?.url ? ( {line.variant.product.name} ) : (
)}

{line.variant.product.name}

{line.variant.name !== "Default" && (

{line.variant.name}

)}

{formatPrice( line.variant.pricing?.price?.gross?.amount || 0, line.variant.pricing?.price?.gross?.currency )}

{line.quantity}
))}
)}
{lines.length > 0 && (
{t("subtotal")} {formatPrice(checkout?.subtotalPrice?.gross?.amount || 0)}
{t("shipping")} {checkout?.shippingPrice?.gross?.amount ? formatPrice(checkout.shippingPrice.gross.amount) : t("calculatedAtCheckout") }
{t("total")} {formatPrice(total)}
{(checkout?.subtotalPrice?.gross?.amount || 0) < 5000 && (

{t("freeShippingOver", { amount: formatPrice(5000) })}

)}
{isLoading ? t("processing") : t("checkout")}
)} )} ); }