import { useEffect, useState } from 'react' import { useSearchParams } from 'react-router-dom' import { Crown, Check, Loader2, ExternalLink, Sparkles, Music, Infinity, Download, Users, Fingerprint, X } from 'lucide-react' import { useAuth } from '../lib/auth' import { createCheckout, createBillingPortal, getBillingStatus } from '../lib/api' interface BillingInfo { is_pro: boolean subscription_status: string | null current_period_end: number | null } interface TierFeature { text: string included: boolean } const freeTierFeatures: TierFeature[] = [ { text: '1 platform sync', included: true }, { text: '5 discoveries per week', included: true }, { text: 'Basic taste profile', included: true }, { text: 'All platforms', included: false }, { text: 'Unlimited discovery', included: false }, { text: 'Full AI insights', included: false }, { text: 'Export playlists', included: false }, ] const premiumTierFeatures: TierFeature[] = [ { text: 'All platform syncs', included: true }, { text: 'Unlimited discovery', included: true }, { text: 'Full taste DNA profile', included: true }, { text: 'Full AI insights & explanations', included: true }, { text: 'Export to any platform', included: true }, { text: 'All discovery modes', included: true }, { text: 'Priority recommendations', included: true }, ] const familyTierFeatures: TierFeature[] = [ { text: 'Everything in Premium', included: true }, { text: 'Up to 5 profiles', included: true }, { text: 'Family taste overlap feature', included: true }, { text: 'Shared discovery feed', included: true }, ] export default function Billing() { const { user, refreshUser } = useAuth() const [searchParams] = useSearchParams() const [billing, setBilling] = useState(null) const [loading, setLoading] = useState(true) const [checkoutLoading, setCheckoutLoading] = useState(false) const [portalLoading, setPortalLoading] = useState(false) const success = searchParams.get('success') === 'true' const canceled = searchParams.get('canceled') === 'true' useEffect(() => { getBillingStatus() .then(setBilling) .catch(() => setBilling({ is_pro: user?.is_pro || false, subscription_status: null, current_period_end: null })) .finally(() => setLoading(false)) }, [user?.is_pro]) useEffect(() => { if (success && refreshUser) { refreshUser() } }, [success, refreshUser]) const handleUpgrade = async () => { setCheckoutLoading(true) try { const { url } = await createCheckout() window.location.href = url } catch { setCheckoutLoading(false) } } const handleManage = async () => { setPortalLoading(true) try { const { url } = await createBillingPortal() window.location.href = url } catch { setPortalLoading(false) } } if (loading) { return (
) } const isPro = billing?.is_pro || false return (

Plans & Pricing

Choose the plan that fits your music discovery journey

{success && (

Welcome to Vynl Premium! Your subscription is now active.

)} {canceled && (

Checkout was canceled. No charges were made.

)} {/* Active subscription banner */} {isPro && billing?.subscription_status && (

Vynl Premium Active

{billing.current_period_end && (

Next billing: {new Date(billing.current_period_end * 1000).toLocaleDateString()}

)}
)} {/* Pricing Cards */}
{/* Free Tier */}

Free

$0 /month

Get started with basic music discovery

    {freeTierFeatures.map((f) => (
  • {f.included ? ( ) : ( )} {f.text}
  • ))}
{isPro ? 'Previous plan' : 'Current plan'}
{/* Premium Tier — Recommended */}
Recommended

Premium

$6.99 /month

Unlock the full power of AI music discovery

    {premiumTierFeatures.map((f) => (
  • {f.text}
  • ))}
{isPro ? (
Your current plan
) : ( )}
{/* Family Tier — Coming Soon */}

Family

Coming Soon
$12.99 /month

Share discovery with up to 5 family members

    {familyTierFeatures.map((f) => (
  • {f.text}
  • ))}
Coming soon
) }