'use client'; import { Button } from "@/components/ui/Button"; import { Heading, Text } from "@/components/ui/Typography"; import { useTranslation } from "@/lib/hooks/useTranslation"; 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"; interface BuildBoxSidebarWithTranslationProps { isMobile?: boolean; } export function BuildBoxSidebarWithTranslation({ isMobile = false }: BuildBoxSidebarWithTranslationProps) { const { t } = useTranslation(); 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 = t('buildBox.sidebar.nextStep'); // 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 (
{/* Fixed header - prikazan samo ako nije mobilni prikaz */} {!isMobile && (
{t('buildBox.sidebar.title')}
)} {/* Scrollable products area */}
{isEmpty ? (
{t('buildBox.sidebar.empty')} {t('buildBox.sidebar.emptySubtext')}
) : (
{/* Show box container if any */} {boxContainers.length > 0 && (
{t('buildBox.sidebar.boxDesign')} {boxContainers.map((box: BoxItem) => (
{box.name}
{box.name}
${box.price}
))}
)} {/* Product items */} {products.length > 0 && ( <> {products.map((item: BoxItem) => (
{item.name}
${item.price}
{item.color && (
Color
)}
{item.quantity}
))} )}
)}
{/* Fixed price and button at bottom */}
{t('buildBox.sidebar.boxPrice')} ${boxTotal.toFixed(2)}
{isCustomizePage ? ( ) : ( )} {!isCustomizePage && !hasProducts && !isEmpty && ( {t('buildBox.sidebar.addProductWarning')} )} {isCustomizePage && !hasBoxSelected && !isEmpty && ( {t('buildBox.sidebar.selectBoxWarning')} )}
); }