"use client";

import { usePathname } from "next/navigation";
import { Sidebar } from "@/components/layout/Sidebar";

export function MainContentWrapper({ children }: { children: React.ReactNode }) {
  const pathname = usePathname();
  const isAdminOrAuth = pathname?.startsWith("/admin") || pathname?.startsWith("/login") || pathname?.startsWith("/register");
  const isShorts = pathname?.startsWith("/shorts");

  const isLive = pathname?.startsWith("/live") || pathname?.startsWith("/cam") || pathname?.startsWith("/mtbrcam");

  // 🔴 Mode Live : Plein écran sans sidebar ni offset
  if (isLive) {
    return (
      <div className="flex-1 w-full min-h-screen relative p-0 m-0 overflow-x-hidden">
        <main className="w-full min-h-screen p-0 m-0">
          {children}
        </main>
      </div>
    );
  }

  // 📱 Mode Shorts : Plein écran natif bord à bord sans décalage
  if (isShorts) {
    return (
      <div className="flex-1 w-full h-[100dvh] md:h-[calc(100vh-96px)] relative p-0 m-0 overflow-hidden pt-0 md:pt-[96px]">
        <main className="w-full h-full p-0 m-0 overflow-hidden">
          {children}
        </main>
      </div>
    );
  }

  // 🛡️ Mode Admin & Auth : Sans sidebar
  if (isAdminOrAuth) {
    return (
      <div className="flex-1 flex w-full max-w-[2000px] mx-auto relative px-4 lg:px-6 pt-[96px]">
        <main className="flex-1 w-full min-w-0 pb-20 md:pb-0">
          {children}
        </main>
      </div>
    );
  }

  // 💻 Mode Standard : Sidebar Desktop + Contenu fluide
  return (
    <div className="flex-1 flex w-full max-w-[2000px] mx-auto relative px-4 lg:px-6 pt-[96px]">
      <Sidebar />
      <main
        className="flex-1 w-full min-w-0 pb-20 md:pb-0 transition-all duration-150 pl-0 lg:pl-[var(--custom-main-pl,240px)]"
      >
        {children}
      </main>
    </div>
  );
}
