import { supabase } from "@/lib/supabase"; import { getAdminUser } from "@/lib/admin-permissions"; import { getActiveBrandId } from "@/lib/brand-scope"; import { getBillingOverview } from "@/actions/billing/billing-overview"; import AdminAccessDenied from "@/components/admin/AdminAccessDenied"; import BillingClientPage from "./BillingClientPage"; type Props = { params: Promise<{ brandId?: string }>; }; export default async function BillingPage({ params }: Props) { const { brandId: brandIdParam } = await params; const adminUser = await getAdminUser(); if (!adminUser) return ; const activeBrandId = await getActiveBrandId(adminUser, brandIdParam); if (!activeBrandId && adminUser.role !== "platform_admin") { return ; } const effectiveBrandId = activeBrandId ?? ""; const isPlatformAdmin = adminUser.role === "platform_admin"; let resolvedBrandId = effectiveBrandId; if (isPlatformAdmin && !resolvedBrandId) { const { data: firstBrand } = await supabase .from("brands") .select("id") .limit(1) .single(); if (firstBrand?.id) { resolvedBrandId = firstBrand.id; } else { return (

No Brands Found

Create a brand in the database before accessing billing settings.

Back to Admin
); } } if (!resolvedBrandId) return ; // Single source of truth for everything the billing client needs. const overviewRes = await getBillingOverview(resolvedBrandId); if (!overviewRes.success || !overviewRes.data) { return (

Billing Unavailable

{overviewRes.error ?? "Could not load billing information."}

Back to Admin
); } const overview = overviewRes.data; return (
{/* Platform billing header */}

Route Commerce Platform Billing {" — "}Invoiced by Cielo Hermosa, LLC · Manage your platform subscription and add-ons. {" "}Questions? billing@cielohermosa.com

{/* Breadcrumb */}

Billing & Subscription

Manage your Route Commerce subscription for {overview.brandName ?? "your brand"}.

); }