'use client';

import { Button } from '@/components/ui/button';
import { useCartStore } from '@/lib/cart-store';

export function AddToCartButton({
  product,
  available,
  label,
  unavailableLabel
}: {
  product: { id: string; slug: string; sku: string; name: string; image?: string };
  available: boolean;
  label: string;
  unavailableLabel: string;
}) {
  const addItem = useCartStore((s) => s.addItem);

  return (
    <Button
      disabled={!available}
      onClick={() =>
        addItem({
          productId: product.id,
          slug: product.slug,
          sku: product.sku,
          name: product.name,
          image: product.image
        })
      }
    >
      {available ? label : unavailableLabel}
    </Button>
  );
}
