import { createClient } from "@/lib/supabase/server";
import { SubmitButton } from "@/components/ui/submit-button";
import { manageSubscription, getAccountSubscription } from "@/lib/actions/billing";
import { PlanComparison, SUBSCRIPTION_PLANS } from "@/components/billing/plan-comparison";
import { isLocalMode } from "@/lib/config";
type Props = {
accountId: string;
returnUrl: string;
}
export default async function AccountBillingStatus({ accountId, returnUrl }: Props) {
// 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
);
}
const result = await getAccountSubscription(accountId);
// Check if we got an error response or if result is undefined
if (!result || 'message' in result) {
return (
Billing Status
Error loading billing status: {result?.message || 'Unknown error'}
);
}
const { subscription: subscriptionData, usage } = result;
const isPlan = (planId?: string) => {
return subscriptionData?.price_id === planId;
};
const planName = isPlan(SUBSCRIPTION_PLANS.FREE)
? "Free"
: isPlan(SUBSCRIPTION_PLANS.PRO)
? "Pro"
: isPlan(SUBSCRIPTION_PLANS.ENTERPRISE)
? "Enterprise"
: "Unknown";
return (
Billing Status
{subscriptionData ? (
<>
Agent Usage This Month
{usage.display}
{/* Plans Comparison */}
{/* Manage Subscription Button */}
>
) : (
<>
Current Plan
Free
Agent Usage This Month
{usage.display}
{/* Plans Comparison */}
{/* Manage Subscription Button */}
>
)}
)
}