// src/components/PricingTable.tsx import React, { useState, useCallback } from 'react'; import { Loader2, Zap, ExternalLink, Check, X, Sparkles, User, RotateCcw, Building2, Users } from 'lucide-react'; import { CreditInfoButton } from './CreditVisualization'; import { InfoTooltip } from './InfoTooltip'; import { isIOS } from '../utils/platform'; import { Logger } from '@utils/logging'; import type { UseApplePaymentsReturn } from '@hooks/useApplePayments'; import { openUrl } from '@tauri-apps/plugin-opener'; interface PricingTableProps { headline: string; subheadline: string; status: 'loading' | 'plus' | 'pro' | 'max' | 'free' | 'error' | 'enterprise'; /** Tier the org seat grants ('pro' | 'max'), only meaningful when status is 'enterprise'. */ orgTier?: string | null; isButtonLoading: boolean; isAuthenticated?: boolean; error: string | null; onCheckout: () => void; onCheckoutPlus: () => void; onCheckoutMax: () => void; onManageSubscription: () => void; onLogin: () => void; isTriggeredByQuotaError?: boolean; isHalfwayWarning?: boolean; applePayments?: UseApplePaymentsReturn | null; onModalClose?: () => void; } interface FeatureRow { label: string; sparkle?: boolean; free: boolean | string; plus: boolean | string; pro: boolean | string; max: boolean | string; creditInfo?: { free?: number; plus?: number; pro?: number; max?: number }; monthlyCreditInfo?: { free?: number; plus?: number; pro?: number; max?: number }; info?: { free?: string; plus?: string; pro?: string; max?: string }; } interface FeatureGroup { group: string; rows: FeatureRow[]; } const featureGroups: FeatureGroup[] = [ { group: 'Core — Free Forever', rows: [ { label: 'Local Models', free: true, plus: true, pro: true, max: true }, { label: 'Logging & Recording', free: true, plus: true, pro: true, max: true }, { label: 'Discord, Telegram, Email & Pushover', free: true, plus: true, pro: true, max: true }, ], }, { group: 'Cloud inference', rows: [ { label: 'Micro-Agent Builder', sparkle: true, free: '3 agents/day', plus: '3 agents/day', pro: true, max: true, info: { free: 'Building a micro-agent takes ~15 messages with Observer on average, and the free tier gives you 45/day, about 3 full builds. Plenty to design and iterate.', plus: 'Building a micro-agent takes ~15 messages with Observer on average, and the Plus tier gives you 45/day, about 3 full builds. Plenty to design and iterate.', } }, { label: 'Cloud Monitoring', free: '30 min/day · 10 hr/mo', plus: '4 hr/day · 40 hr/mo', pro: '12 hr/day · 100 hr/mo', max: '24 hr/day · 270 hr/mo', creditInfo: { free: 60, plus: 480, pro: 1440, max: 2880 }, monthlyCreditInfo: { free: 1200, plus: 4800, pro: 12000, max: 32400 } }, ], }, { group: 'Notifications', rows: [ { label: 'SMS, Phone & WhatsApp', free: false, plus: false, pro: true, max: true }, ], }, { group: 'Support', rows: [ { label: 'Support', free: 'Limited', plus: 'Limited', pro: 'Better', max: 'Priority' }, ], }, ]; const CheckMark = () => ; const CrossMark = () => ; const renderCell = (value: boolean | string, dailyCredits?: number, tierName?: string, info?: string, monthlyCredits?: number) => { const infoBtn = info && typeof value !== 'string' ? : null; if (value === true) { return ( {infoBtn} ); } if (value === false) return ; const text = ( {value.split(' · ').map((line, i) => ( {line.includes('agents') ? <>{line.split('agents')[0]}{line.split('agents')[1]} : line} ))} ); return ( {info ? {text} : text} {dailyCredits !== undefined && tierName && ( )} {infoBtn} ); }; export const PricingTable: React.FC = ({ headline, subheadline, status, orgTier, isButtonLoading, error, onCheckout, onCheckoutPlus, onCheckoutMax, onManageSubscription, isTriggeredByQuotaError = false, applePayments, onModalClose, }) => { const isAppleDevice = isIOS(); const [internalLoading, setInternalLoading] = useState(false); // No Apple IAP product exists for Plus, so it is only offered outside iOS. const showPlus = !isAppleDevice; const effectiveStatus = status; const handleApplePurchase = useCallback(async (tier: 'pro' | 'max') => { if (!applePayments) return; Logger.info('PRICING_TABLE', `Starting Apple purchase for tier: ${tier}`); setInternalLoading(true); try { const result = await applePayments.purchaseProduct(tier); Logger.info('PRICING_TABLE', 'Purchase result:', result); if (result.success) { if (onModalClose) onModalClose(); window.location.href = '/upgrade-success'; } } catch (err) { Logger.error('PRICING_TABLE', 'Purchase failed:', err); } finally { setInternalLoading(false); } }, [applePayments, onModalClose]); const handleAppleRestore = useCallback(async () => { if (!applePayments) return; Logger.info('PRICING_TABLE', 'Starting Apple restore'); setInternalLoading(true); try { const result = await applePayments.restorePurchases(); Logger.info('PRICING_TABLE', 'Restore result:', result); if (result.success) { if (onModalClose) onModalClose(); window.location.href = '/upgrade-success'; } } catch (err) { Logger.error('PRICING_TABLE', 'Restore failed:', err); } finally { setInternalLoading(false); } }, [applePayments, onModalClose]); const handleManageSubscription = isAppleDevice && applePayments ? () => openUrl('https://apps.apple.com/account/subscriptions') .catch((err: unknown) => Logger.error('PRICING_TABLE', 'openUrl failed:', err)) : onManageSubscription; const handleProCheckout = isAppleDevice && applePayments ? () => handleApplePurchase('pro') : onCheckout; const handleMaxCheckout = isAppleDevice && applePayments ? () => handleApplePurchase('max') : onCheckoutMax; const combinedLoading = isButtonLoading || internalLoading || (applePayments?.isLoading ?? false); const combinedError = error || (applePayments?.error ?? null); // ── table column helpers ────────────────────────────────────────────────── const headerBase = "text-center align-top px-1 md:px-3 pt-2 pb-3 md:pt-3 md:pb-4 text-xs md:text-sm font-bold"; const cellBase = "text-center px-1 md:px-3 py-2 md:py-3"; const getHeaderClass = (tier: 'free' | 'plus' | 'pro' | 'max') => { const current = effectiveStatus === tier; if (tier === 'plus') return `${headerBase} ${current ? 'bg-[#A8631F] text-white dark:bg-[#8A5220]' : 'bg-[#A8631F]/10 text-[#7A4A1C] dark:bg-[#A8631F]/20 dark:text-[#E3B07A]'}`; if (tier === 'pro') return `${headerBase} border-x-2 border-t-2 border-slate-400 dark:border-slate-400/70 ${current ? 'bg-slate-500 text-white dark:bg-slate-600' : 'bg-slate-100 text-slate-800 dark:bg-slate-700/40 dark:text-slate-200'}`; if (tier === 'max') return `${headerBase} ${current ? 'bg-amber-500 text-white dark:bg-amber-600' : 'bg-amber-50 text-amber-900 dark:bg-amber-900/30 dark:text-amber-200'}`; return `${headerBase} bg-gray-50 text-gray-600 dark:bg-gray-900 dark:text-gray-400`; }; const getCellClass = (tier: 'free' | 'plus' | 'pro' | 'max', isLastRow = false) => { const current = effectiveStatus === tier; if (tier === 'plus') return `${cellBase} ${current ? 'bg-[#A8631F]/10 dark:bg-[#A8631F]/15' : ''}`; if (tier === 'pro') return `${cellBase} ${isLastRow ? 'border-b-2' : ''} border-x-2 border-slate-400 dark:border-slate-400/70 ${current ? 'bg-slate-200/70 dark:bg-slate-700/40' : 'bg-slate-100/70 dark:bg-slate-700/20'}`; if (tier === 'max') return `${cellBase} ${current ? 'bg-amber-50/60 dark:bg-amber-900/20' : ''}`; return cellBase; }; // Enterprise seats are billed to the org, not the user — there is no personal // subscription to show or manage, so point them at their team page instead. if (status === 'enterprise') { const tierLabel = orgTier === 'max' ? 'Max' : 'Pro'; return (

You're on an Enterprise plan

Your seat is provided by your organization and includes all {tierLabel} features, drawing from a shared monthly hours pool quoted for your organization. Billing, seats, and the pool are managed by your team's owner.

View your team {combinedError && (

{combinedError}

)}
); } return (
{/* ── Header ── */}

{headline}

{subheadline}

{isTriggeredByQuotaError && (
🚀 2k+ users • ⭐ 1k+ GitHub stars • ⚡ 100k+ captures/day
)}
{/* ── Comparison Table with pricing + CTA embedded in headers ── */}
{/* Free column */} {/* Plus column (bronze) */} {showPlus && ( )} {/* Pro column (silver) */} {/* Max column */} {featureGroups.map((group, gi) => ( {group.rows.map((row, i) => { const isLastRow = gi === featureGroups.length - 1 && i === group.rows.length - 1; return ( {showPlus && } ); })} ))}
Features
Most Popular
Quick Start
$0 / mo
{effectiveStatus === 'free' ? ( Current ) : ( )}
Most Popular
Plus
$8 / mo
{effectiveStatus === 'plus' ? ( <> Current ) : ( )}
Most Popular
Pro
${isAppleDevice ? '22.99' : '20'} / mo
{effectiveStatus === 'pro' ? ( <> Current ) : ( )}
Most Popular
MAX
${isAppleDevice ? '99.99' : '80'} / mo
{effectiveStatus === 'max' ? ( <> Current ) : ( )}
{group.group} {showPlus && } {/* Pro column highlight runs over the group band */}
{row.sparkle ? ( {row.label} ) : ( {row.label} )} {renderCell(row.free, row.creditInfo?.free, 'Free tier', row.info?.free, row.monthlyCreditInfo?.free)}{renderCell(row.plus, row.creditInfo?.plus, 'Plus tier', row.info?.plus, row.monthlyCreditInfo?.plus)}{renderCell(row.pro, row.creditInfo?.pro, 'Pro tier', row.info?.pro, row.monthlyCreditInfo?.pro)} {renderCell(row.max, row.creditInfo?.max, 'Max tier', row.info?.max, row.monthlyCreditInfo?.max)}
{/* ── Error ── */} {combinedError && (

{combinedError}

)} {/* ── iOS: Restore & Load Products ── */} {isAppleDevice && applePayments && (
{applePayments.loadProducts && ( )}
)} {/* ── Terms (required for App Store) ── */}

By subscribing, you agree to our{' '} {isIOS() ? ( <> {' '}and{' '} ) : ( <> Terms of Service {' '}and{' '} Privacy Policy )} .

); };