// src/app/billing-locked/page.tsx — paywall for orgs whose access expired.
// Server page: verifies the session + active org, re-checks the billing
// status (subscribed users are bounced back into the app — never trapped),
// resolves billing-manager rights, then hands plain props to the client UI.
import { headers } from "next/headers";
import { redirect } from "next/navigation";
import { BillingLocked } from "@/components/billing/billing-locked";
import { auth } from "@/lib/auth";
import { isOrgBillingManager } from "@/lib/billing/authorize";
import { getOrgBillingStatus } from "@/lib/billing/status";

export default async function Page() {
  const session = await auth.api.getSession({ headers: await headers() });
  if (!session) {
    redirect("/login");
  }
  const orgId = session.session.activeOrganizationId;
  if (!orgId) {
    redirect("/login");
  }

  const billing = await getOrgBillingStatus(orgId);
  if (billing !== "expired") {
    redirect("/keywords/reservoir");
  }

  const isManager = await isOrgBillingManager(session.user.id, orgId);
  return <BillingLocked orgId={orgId} isManager={isManager} />;
}
