'use client'; import { Button } from "@/components/ui/Button"; import { Heading, Text } from "@/components/ui/Typography"; import { useAppDispatch, useAppSelector } from "@/lib/redux/hooks"; import { BoxItem, removeFromBox, selectBoxItems, selectBoxTotal, updateQuantity } from "@/lib/redux/slices/boxSlice"; import { Minus, Plus, Trash2 } from "lucide-react"; import Image from "next/image"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { AddBoxToCartClient } from "./AddBoxToCartClient"; export function BuildBoxSidebar() { const dispatch = useAppDispatch(); const items = useAppSelector(selectBoxItems); const boxTotal = useAppSelector(selectBoxTotal); const isEmpty = items.length === 0; const pathname = usePathname(); // Separate box containers from products const boxContainers = items.filter(item => item.variantId === 'box-container'); const products = items.filter(item => item.variantId !== 'box-container'); // Check if we have products for the first step const hasProducts = products.length > 0; // Check if we have a selected box for the second step const hasBoxSelected = boxContainers.length > 0; // Determine which page we're on to show appropriate button text const isCustomizePage = pathname.includes('/customize'); const nextStepUrl = "/build-box/customize"; const nextStepText = "Idući korak"; // Determine if the next step button should be disabled const isNextStepDisabled = isEmpty || (!isCustomizePage && !hasProducts); const handleUpdateQuantity = (id: string, color: string | undefined, newQuantity: number) => { if (newQuantity < 1) return; dispatch(updateQuantity({ id, color, quantity: newQuantity })); }; const handleRemoveItem = (id: string, color: string | undefined) => { dispatch(removeFromBox({ id, color })); }; return (