"use client"

import { usePathname } from "next/navigation"
import { useState } from "react"
import { SiteHeader } from "@/components/layout/site-header"
import { SportsSidebar } from "@/components/layout/sports-sidebar"
import { RightPanel } from "@/components/layout/right-panel"
import { SiteFooter } from "@/components/layout/site-footer"
import { AuthModal } from "@/components/layout/auth-modal"

type AuthMode = "login" | "register"

export default function LayoutClientWrapper({ children }: { children: React.ReactNode }) {
  const pathname = usePathname()
  const isLivePage = pathname === "/live"

  const [authOpen, setAuthOpen] = useState(false)
  const [authMode, setAuthMode] = useState<AuthMode>("login")

  function openAuth(mode: AuthMode) {
    setAuthMode(mode)
    setAuthOpen(true)
  }

  return (
    <div className="flex min-h-screen flex-col">
      <SiteHeader
        onLoginClick={() => openAuth("login")}
        onRegisterClick={() => openAuth("register")}
      />
      <div className="flex w-full flex-1 gap-0">
        {!isLivePage && <SportsSidebar />}
        <main className="flex-1 px-2 py-3 min-w-0">{children}</main>
        <RightPanel />
      </div>
      <SiteFooter />

      <AuthModal
        open={authOpen}
        defaultMode={authMode}
        onClose={() => setAuthOpen(false)}
      />
    </div>
  )
}
