import { CustomerPortal } from "@/components/customer-portal";
import { redirect } from "next/navigation";
import { getCurrentAppUser } from "../../lib/current-user";
import { headers } from "next/headers";
import { verifyRuntimeLicense } from "../../lib/runtime-license";
import { LicenseBlocked } from "../../components/license-blocked";

export const dynamic = "force-dynamic";

export default async function CustomerPage() {
  const requestHeaders = await headers();
  const license = await verifyRuntimeLicense(requestHeaders.get("host") || "localhost");
  if (!license.valid) return <LicenseBlocked reason={license.reason} domain={license.domain} installationId={license.installationId}/>;
  const user = await getCurrentAppUser();
  if (!user) redirect("/login?portal=customer");
  return <CustomerPortal user={{ id: user.id, name: user.name, email: user.email, phone: user.phone, company: user.company, city: user.city, role: user.role }} />;
}
