"use client";

import { usePathname } from "next/navigation";
import { AuthProvider } from "@/contexts/AuthContext";
import { MenuProvider } from "@/contexts/MenuContext";
import { MessengerProvider } from "@/contexts/MessengerContext";
import { AppLayout } from "@/components/layout/AppLayout";
import { ApprovalGlobalListener } from "@/components/approval/ApprovalGlobalListener";
import { ApprovalDetailModal } from "@/components/approval/ApprovalDetailModal";
import { MessengerFAB } from "@/components/messenger/MessengerFAB";
import { MessengerModal } from "@/components/messenger/MessengerModal";

export default function MainLayout({ children }: { children: React.ReactNode }) {
  const pathname = usePathname();
  const isPop = pathname.includes("/pop/");

  if (isPop) {
    return <>{children}</>;
  }

  return (
    <AuthProvider>
      <MenuProvider>
        <MessengerProvider>
          <AppLayout>{children}</AppLayout>
          <ApprovalGlobalListener />
          <ApprovalDetailModal />
          <MessengerFAB />
          <MessengerModal />
        </MessengerProvider>
      </MenuProvider>
    </AuthProvider>
  );
}
