"use client";

import { usePathname } from "next/navigation";
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar";
import { AppSidebar } from "@/components/app-sidebar";
import { NotificationSocketProvider } from "@/components/providers/notification-socket-provider";
import { SessionExpiryGuard } from "@/components/providers/session-expiry-guard";
import { BusinessDealFormDialog } from "@/components/deals/business-deal-form-dialog";
import { MoveToLostDialog } from "@/components/deals/move-to-lost-dialog";
import { DiscoveryMeetingBookedDialog } from "@/components/deals/discovery-meeting-booked-dialog";
import { DashboardScreenshotDeterrent } from "@/components/dashboard-screenshot-deterrent";

const AUTH_PATHS = ["/login", "/forgot-password"];

function isAuthPath(pathname: string): boolean {
  return AUTH_PATHS.some(
    (path) => pathname === path || pathname.startsWith(`${path}/`),
  );
}

export function AppShell({ children }: { children: React.ReactNode }) {
  const pathname = usePathname();

  if (isAuthPath(pathname ?? "")) {
    return <>{children}</>;
  }

  return (
    <SidebarProvider className="h-svh overflow-hidden">
      <NotificationSocketProvider />
      <SessionExpiryGuard />
      <BusinessDealFormDialog />
      <MoveToLostDialog />
      <DiscoveryMeetingBookedDialog />
      <AppSidebar />
      <SidebarInset className="flex flex-col min-w-0 h-full overflow-hidden bg-transparent">
        {/* <AppHeader /> */}
        <main
          className="relative flex-1 flex flex-col min-h-0 p-1 sm:p-2 md:p-3 overflow-auto scrollbar-themed"
          onContextMenu={(e) => e.preventDefault()}
        >
          <DashboardScreenshotDeterrent />
          {children}
        </main>
      </SidebarInset>
    </SidebarProvider>
  );
}
