"use client"; import { Card, CardContent, CardHeader, CardTitle, CardFooter } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { formatCurrency, cn } from "@/lib/utils"; interface MembershipPlan { id: string; name: string; description: string | null; price: number | string; durationMonths: number; courtHours: number | null; discountPercent: number | string | null; benefits: string[] | null; isActive: boolean; subscriberCount: number; benefitsSummary?: { freeHours: number; bookingDiscount: number; extraBenefits: string[]; }; } interface PlanCardProps { plan: MembershipPlan; onEdit?: (plan: MembershipPlan) => void; onDelete?: (plan: MembershipPlan) => void; isAdmin?: boolean; } export function PlanCard({ plan, onEdit, onDelete, isAdmin = false }: PlanCardProps) { const price = typeof plan.price === "string" ? parseFloat(plan.price) : plan.price; const discountPercent = plan.benefitsSummary?.bookingDiscount ?? (plan.discountPercent ? Number(plan.discountPercent) : 0); const freeHours = plan.benefitsSummary?.freeHours ?? plan.courtHours ?? 0; const extraBenefits = plan.benefitsSummary?.extraBenefits ?? plan.benefits ?? []; // Extract store discount from benefits array if present const storeDiscountBenefit = extraBenefits.find(b => b.includes("store discount")); const storeDiscount = storeDiscountBenefit ? parseInt(storeDiscountBenefit.match(/(\d+)%/)?.[1] || "0", 10) : 0; const otherBenefits = extraBenefits.filter(b => !b.includes("store discount")); return (
{plan.name} 0 ? "bg-accent-100 text-accent-700" : "bg-primary-100 text-primary-600" )}> {plan.subscriberCount} {plan.subscriberCount === 1 ? "subscriber" : "subscribers"}
{plan.description && (

{plan.description}

)}
{/* Price */}
{formatCurrency(price)}
/{plan.durationMonths} {plan.durationMonths === 1 ? "month" : "months"}
{/* Key Benefits */}
{/* Free Hours */} {freeHours > 0 && (

{freeHours} free hours

of court time per month

)} {/* Booking Discount */} {discountPercent > 0 && (

{discountPercent}% discount

on additional bookings

)} {/* Store Discount */} {storeDiscount > 0 && (

{storeDiscount}% discount

in store

)} {/* Other Benefits */} {otherBenefits.length > 0 && (

Additional benefits:

    {otherBenefits.map((benefit, index) => (
  • {benefit}
  • ))}
)}
{isAdmin && ( )}
); }