import { useCartStore } from '../../stores/cart';
import { formatCurrency } from '../../lib/utils';

export default function CartSummary() {
  const { items } = useCartStore();
  
  const subtotal = items.reduce((sum, item) => sum + item.price * item.quantity, 0);
  const tax = subtotal * 0.07;
  const shipping = subtotal >= 500 ? 0 : 50;
  const total = subtotal + tax + shipping;

  return (
    <div className="space-y-3">
      <div className="flex justify-between text-sm">
        <span className="text-gray-600">ราคารวม</span>
        <span>{formatCurrency(subtotal)}</span>
      </div>
      <div className="flex justify-between text-sm">
        <span className="text-gray-600">ภาษี VAT (7%)</span>
        <span>{formatCurrency(tax)}</span>
      </div>
      <div className="flex justify-between text-sm">
        <span className="text-gray-600">ค่าจัดส่ง</span>
        <span>{shipping === 0 ? 'ฟรี' : formatCurrency(shipping)}</span>
      </div>
      {shipping === 0 && (
        <p className="text-xs text-green-600">ซื้อขั้นต่ำ 500 บาท จัดส่งฟรี!</p>
      )}
      <div className="border-t pt-3 flex justify-between font-bold text-lg">
        <span>รวมทั้งสิ้น</span>
        <span>{formatCurrency(total)}</span>
      </div>
    </div>
  );
}
