import { Outlet } from "react-router-dom";
import { SidebarProvider, SidebarInset } from "@/components/ui/sidebar";
import { DashboardSidebar } from "@/components/admin/DashboardSidebar";
import { ApplicantDashboardSidebar } from "@/components/applicant/DashboardSidebar";
import { DashboardHeader } from "@/components/DashboardHeader";
import { useAuth } from "@/contexts/AuthContext";

export function DashboardLayout() {
  const { hasRole, user } = useAuth();
  const isAdminAccount = Boolean(user?.availableRoles?.includes("admin"));
  const showApplicantSidebar = hasRole("viewer") && !isAdminAccount;

  return (
    <SidebarProvider>
      <div className="flex overflow-hidden h-screen w-full">
        {showApplicantSidebar ? <ApplicantDashboardSidebar /> : <DashboardSidebar />}
        <SidebarInset>
          <DashboardHeader />
          <main className="flex-1 overflow-auto p-6 mt-12">
            <Outlet />
          </main>
        </SidebarInset>
      </div>
    </SidebarProvider>
  );
}
