import React, { useState, useEffect } from 'react'; import { Loader2, Check, Zap, Clock } from 'lucide-react'; import { apiJson } from '../lib/api'; import { track } from '../lib/analytics'; import Modal from './ui/Modal'; // Opens when a job hits a 402 (quota exceeded). This is the highest-intent // moment in the product — the user WANTS to clip a video and can't — so it // sells the subscription first (recurring value: minutes, no watermark, // permanent clips) and keeps one-time top-ups as a secondary escape hatch. // // Conversion techniques used (all honest — no fake scarcity or countdowns): // - Goal-gradient: copy centers on finishing THIS video, not abstract quota. // - Compromise effect: all three tiers shown, creator highlighted in the // middle — starter floors the price, pro anchors it, creator reads as the // sensible pick (and matches the pricing page's "most popular"). // - Loss framing: what free actually costs them (watermark, clips deleted // after 7 days) — both real product facts. // - Risk reversal: "cancel anytime" on the CTA. const PLAN_BLURBS = { starter: 'for getting started', creator: 'for daily posting', pro: 'for power users', }; // context: 'wall' (default) = user hit the 402 quota wall mid-task. // 'upsell' = user opened it voluntarily (results banner, header meter) // — different framing: they still HAVE minutes, sell the watermark // removal + permanence instead of "you ran out". export default function TopUpModal({ onClose, required, remaining, context = 'wall' }) { const [plans, setPlans] = useState([]); const [topups, setTopups] = useState([]); const [showTopups, setShowTopups] = useState(false); const [busyPrice, setBusyPrice] = useState(null); const isUpsell = context === 'upsell'; useEffect(() => { track(isUpsell ? 'UpsellModalSeen' : 'QuotaWallSeen', { props: { required: required ?? null, remaining: remaining ?? null } }); apiJson('/api/billing/plans') .then((d) => { const monthly = (d.plans || []).filter((p) => p.interval === 'month'); setPlans(['starter', 'creator', 'pro'] .map((name) => monthly.find((p) => p.plan === name)) .filter(Boolean)); setTopups(d.topups || []); }) .catch(() => {}); }, []); const buy = async (entry, kind) => { setBusyPrice(entry.price_id); track(isUpsell ? 'UpsellModalCheckout' : 'QuotaWallCheckout', { props: { kind, plan: entry.plan || null, minutes: entry.minutes } }); try { const { url } = await apiJson('/api/billing/checkout', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ price_id: entry.price_id }), }); window.location.href = url; } catch (e) { setBusyPrice(null); alert(e?.detail || 'Could not start checkout.'); } }; const fmt = (a, c) => new Intl.NumberFormat('en-US', { style: 'currency', currency: (c || 'usd').toUpperCase(), maximumFractionDigits: 0, }).format((a || 0) / 100); const blockedByLength = typeof required === 'number' && typeof remaining === 'number'; return ( {/* Goal-gradient framing: they're one step from the thing they came for. */}

{isUpsell ? <>Your free clips carry a watermark and are deleted after 7 days. Upgrade to keep them clean, permanent, and with a bigger monthly quota. : blockedByLength ? <>This video needs {required} min and you have{' '} {Math.max(0, Math.round((remaining || 0) * 10) / 10)} min left this month. Upgrade and it starts processing right away. : <>You've used your free minutes for this month. Upgrade and keep clipping right away.}

{plans.map((entry) => { const highlight = entry.plan === 'creator'; return (
{highlight && ( Most popular )}

{entry.plan}

{PLAN_BLURBS[entry.plan] || ''}

{fmt(entry.amount, entry.currency)} /mo
  • {entry.minutes} min every month ({Math.round(entry.minutes / 20)}× your free quota)
  • No watermark on your clips
  • Clips stored forever — free clips delete after 7 days
  • Skips the free queue

cancel anytime.

); })} {plans.length === 0 && (
)}
{/* Secondary escape hatch: one-time packs, deliberately de-emphasized. */}
{!showTopups ? ( ) : (
{topups.map((t) => ( ))} {topups.length === 0 && (
)}
)}
); }