import { getEmployeeSessionAction } from "@/actions/wholesale-auth";
import { getWholesalePickupOrders } from "@/actions/wholesale";
import EmployeePortalClient from "./EmployeePortalClient";

export const dynamic = "force-dynamic";

export default async function EmployeePortalPage() {
  const session = await getEmployeeSessionAction();
  if (!session) {
    // Server-side redirect for unauthenticated visitors. Render a no-op so
    // the client doesn't show a flash of protected content; the layout
    // will swap this for the redirect once it mounts.
    return null;
  }

  const initialOrders = await getWholesalePickupOrders(session.brandId);
  return (
    <EmployeePortalClient
      brandId={session.brandId}
      brandName={session.brandName}
      employeeName={session.name}
      initialOrders={initialOrders}
    />
  );
}