'use client';

import { Product, ProductCustomization } from '@/domain/entities';
import { container } from '@/application/container';
import { useCartStore } from '@/infrastructure/persistence/zustand/cartStore';

/**
 * PRESENTATION — Cart hook: React state + use cases (Clean Architecture boundary)
 */
export function useCart() {
  const items = useCartStore((s) => s.items);
  const summary = container.getCartSummary.execute();

  return {
    items,
    summary,
    addItem: (
      product: Product,
      customization: ProductCustomization,
      customizationLabel: string,
      quantity?: number
    ) => {
      container.addToCart.execute(
        product,
        customization,
        customizationLabel,
        quantity
      );
    },
    removeItem: (id: string) => container.removeFromCart.execute(id),
    updateQuantity: (id: string, quantity: number) =>
      container.updateCartQuantity.execute(id, quantity),
    clearCart: () => container.cartRepository.clearCart(),
    /** @deprecated Use summary.subtotal */
    getTotal: () => summary.subtotal,
    /** @deprecated Use summary.itemCount */
    getItemCount: () => summary.itemCount,
  };
}