"use client" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" import { Plan } from "@/lib/stripe" import { Check, Loader2 } from "lucide-react" import { useState } from "react" import { FormError } from "../forms/error" export function PricingCard({ plan, hideButton = false }: { plan: Plan; hideButton?: boolean }) { const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState(null) const handleClick = async () => { setIsLoading(true) setError(null) try { const response = await fetch(`/api/stripe/checkout?code=${plan.code}`, { method: "POST", }) const data = await response.json() if (data.error) { setError(data.error) } else { window.location.href = data.session.url } } catch (error) { setError(error instanceof Error ? error.message : "An unknown error occurred") } finally { setIsLoading(false) } } return (
{plan.name} {plan.description} {plan.price &&
{plan.price}
}
    {plan.benefits.map((benefit, index) => (
  • {benefit}
  • ))}
{!hideButton && ( )} {error && {error}} ) }