'use client'; import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { PricingSection } from '@/components/home/sections/pricing-section'; import { isLocalMode } from '@/lib/config'; import { createPortalSession } from '@/lib/api'; import { useAuth } from '@/components/AuthProvider'; import { Skeleton } from '@/components/ui/skeleton'; import { useSubscription } from '@/hooks/react-query'; type Props = { accountId: string; returnUrl: string; }; export default function AccountBillingStatus({ accountId, returnUrl }: Props) { const { session, isLoading: authLoading } = useAuth(); const [error, setError] = useState(null); const [isManaging, setIsManaging] = useState(false); const { data: subscriptionData, isLoading, error: subscriptionQueryError, } = useSubscription(); const handleManageSubscription = async () => { try { setIsManaging(true); const { url } = await createPortalSession({ return_url: returnUrl }); window.location.href = url; } catch (err) { console.error('Failed to create portal session:', err); setError( err instanceof Error ? err.message : 'Failed to create portal session', ); } finally { setIsManaging(false); } }; // In local development mode, show a simplified component if (isLocalMode()) { return (

Billing Status

Running in local development mode - billing features are disabled

Agent usage limits are not enforced in this environment

); } // Show loading state if (isLoading || authLoading) { return (

Billing Status

); } // Show error state if (error || subscriptionQueryError) { return (

Billing Status

Error loading billing status:{' '} {error || subscriptionQueryError.message}

); } const isPlan = (planId?: string) => { return subscriptionData?.plan_name === planId; }; const planName = isPlan('free') ? 'Free' : isPlan('base') ? 'Pro' : isPlan('extra') ? 'Enterprise' : 'Unknown'; return (

Billing Status

{subscriptionData ? ( <>
Agent Usage This Month ${subscriptionData.current_usage?.toFixed(2) || '0'} /{' '} ${subscriptionData.cost_limit || '0'}
{/* Plans Comparison */}
{/* Manage Subscription Button */} ) : ( <>
Current Plan Free
Agent Usage This Month ${subscriptionData?.current_usage?.toFixed(2) || '0'} /{' '} ${subscriptionData?.cost_limit || '0'}
{/* Plans Comparison */} {/* Action Buttons */}
)}
); }