'use client'; import { Check, CreditCard } from "lucide-react"; import { Button } from "@/components/ui/button"; import { SubmitButton } from "@/components/ui/submit-button"; import { setupNewSubscription } from "@/lib/actions/billing"; import { createClient } from "@/lib/supabase/client"; import { useEffect, useState } from "react"; export const SUBSCRIPTION_PLANS = { FREE: 'price_1RDQbOG6l1KZGqIrgrYzMbnL', BASIC: 'price_1RC2PYG6l1KZGqIrpbzFB9Lp', // Example price ID PRO: 'price_1RDQWqG6l1KZGqIrChli4Ys4' } as const; const PLAN_DETAILS = { [SUBSCRIPTION_PLANS.FREE]: { name: 'Free', limit: 100, price: 0 }, [SUBSCRIPTION_PLANS.BASIC]: { name: 'Basic', limit: 100, price: 10 }, [SUBSCRIPTION_PLANS.PRO]: { name: 'Pro', limit: 100, price: 50 } } as const; interface PlanComparisonProps { accountId?: string | null; returnUrl?: string; isManaged?: boolean; // If true, uses SubmitButton, if false uses regular Button onPlanSelect?: (planId: string) => void; className?: string; } export function PlanComparison({ accountId, returnUrl = typeof window !== 'undefined' ? window.location.href : '', isManaged = true, onPlanSelect, className = "" }: PlanComparisonProps) { const [currentPlanId, setCurrentPlanId] = useState(); useEffect(() => { async function fetchCurrentPlan() { if (accountId) { const supabase = createClient(); const { data } = await supabase .schema('basejump') .from('billing_subscriptions') .select('price_id') .eq('account_id', accountId) .eq('status', 'active') .single(); // Set to FREE plan if no active subscription found, otherwise use the subscription's plan setCurrentPlanId(data?.price_id || SUBSCRIPTION_PLANS.FREE); } else { // Default to FREE plan if no accountId setCurrentPlanId(SUBSCRIPTION_PLANS.FREE); } } fetchCurrentPlan(); }, [accountId]); return (
{Object.entries(PLAN_DETAILS).map(([planId, plan]) => { const isCurrentPlan = currentPlanId === planId; const isRecommended = planId === SUBSCRIPTION_PLANS.BASIC; return (
{isRecommended && (
Recommended
)} {isCurrentPlan && (
Current Plan
)}

{plan.name}

${plan.price} /mo
{plan.limit} hours/month
{/* Add more features as needed */}
{!isCurrentPlan && accountId && (
{isManaged ? ( {isRecommended ? ( <> Upgrade Now ) : ( 'Select Plan' )} ) : ( )}
)}
); })}
); }