"use client" import { useState } from "react" import { cn } from "@/lib/utils" export function CheckoutButton({ plan, label, highlight, interval = "month", annualAvailable = false, }: { plan: string label: string highlight?: boolean interval?: "month" | "year" // When true, show a monthly/annual choice. Only pass this for subscription // plans and only when annual billing is actually configured server-side. annualAvailable?: boolean }) { const [loading, setLoading] = useState(false) const [chosenInterval, setChosenInterval] = useState<"month" | "year">(interval) const effectiveInterval = annualAvailable ? chosenInterval : interval async function handleClick() { setLoading(true) const res = await fetch("/api/stripe/checkout", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ plan, interval: effectiveInterval }), }) const data = await res.json() if (data.url) window.location.href = data.url else setLoading(false) } return (