"use client"; import { useState } from "react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { ShoppingCart } from "lucide-react"; import { DEVICE_COST, ORIGINAL_COST, paymentLink } from "@/lib/data"; import { useToast } from "@/components/ui/use-toast"; import Link from "next/link"; const Checkout = () => { const { toast } = useToast(); const [numberOfUnits, setNumberOfUnits] = useState(1); const [productColor, setProductColor] = useState("white"); const incrementUnits = () => { setNumberOfUnits((prev) => prev + 1); }; const decrementUnits = () => { setNumberOfUnits((prev) => Math.max(1, prev - 1)); }; const deviceCost = numberOfUnits * DEVICE_COST; const originalCost = numberOfUnits * ORIGINAL_COST; const totalSavings = originalCost - deviceCost; const freeShipping = deviceCost >= 100; const handleCheckout = async () => { try { const response = await fetch("/api/checkout", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ quantity: numberOfUnits, color: productColor, free_shipping: freeShipping, }), }); if (!response.ok) { throw new Error(); } const { url } = await response.json(); window.location.href = url; } catch (error) { toast({ variant: "destructive", title: "Payment Error", description: "There was an error processing your payment. Please try again or reach out if this persists.", }); } }; return (
${deviceCost}
${originalCost}
Save ${totalSavings.toFixed(0)}
{freeShipping && (

FREE Shipping

)}
{/*
setNumberOfUnits( Math.max(1, parseInt(e.target.value) || 1) ) } className="w-16 text-center border-x bg-white h-10 focus:outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none" min="1" />
*/}
); }; export default Checkout;