import { redirect } from "next/navigation";

import { isAuthenticated } from "@/lib/auth-server";
import { DashboardSidebar } from "@/components/dashboard-sidebar";
import { getDashboardRedirectPath } from "@/lib/route-guards";

export default async function DashboardLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  const hasSession = await isAuthenticated();
  const redirectPath = getDashboardRedirectPath(hasSession);

  if (redirectPath) {
    redirect(redirectPath ?? "/");
  }

  return (
    <div className="min-h-dvh bg-background md:flex">
      <DashboardSidebar />
      <div className="min-w-0 flex-1">{children}</div>
    </div>
  );
}
