"use client";

import { type ReactNode } from "react";
import { usePathname } from "next/navigation";
import { I18nProvider } from "@/lib/i18n";
import { ThemeProvider } from "@/lib/theme";
import { TimeRangeProvider } from "@/lib/time-range-context";
import { Sidebar } from "@/components/Sidebar";

export function ClientProviders({ children }: { children: ReactNode }) {
  const pathname = usePathname();
  const isPortal = pathname === "/portal";

  return (
    <ThemeProvider>
      <I18nProvider>
        <TimeRangeProvider>
          {isPortal ? (
            <>{children}</>
          ) : (
            <>
              <Sidebar />
              <main className="min-h-screen px-4 pb-6 pt-24 sm:px-6 lg:ml-[220px] lg:p-8">{children}</main>
            </>
          )}
        </TimeRangeProvider>
      </I18nProvider>
    </ThemeProvider>
  );
}
