"use client"; import { useAuth } from "@/lib/auth-context"; import { usePathname } from "next/navigation"; import { useEffect } from "react"; import { Sidebar } from "./Sidebar"; import { TopBar } from "./TopBar"; import { TVLayout } from "./TVLayout"; import { BottomNavigation } from "./BottomNavigation"; import { UniversalPlayer } from "../player/UniversalPlayer"; import { MediaControlsHandler } from "../player/MediaControlsHandler"; import { PlayerModeWrapper } from "../player/PlayerModeWrapper"; import { ActivityPanel } from "./ActivityPanel"; import { GalaxyBackground } from "../ui/GalaxyBackground"; import { GradientSpinner } from "../ui/GradientSpinner"; import { PWAInstallPrompt } from "../PWAInstallPrompt"; import { PullToRefresh } from "../ui/PullToRefresh"; import { ReactNode } from "react"; import { useIsMobile, useIsTablet } from "@/hooks/useMediaQuery"; import { useIsTV } from "@/lib/tv-utils"; import { useActivityPanel } from "@/hooks/useActivityPanel"; const publicPaths = ["/login", "/register", "/onboarding", "/sync"]; export function AuthenticatedLayout({ children }: { children: ReactNode }) { const { isAuthenticated, isLoading } = useAuth(); const pathname = usePathname(); const isMobile = useIsMobile(); const isTablet = useIsTablet(); const isTV = useIsTV(); const isMobileOrTablet = isMobile || isTablet; const activityPanel = useActivityPanel(); // Listen for activity panel events (toggle/open/close/tab) useEffect(() => { const handleToggle = () => activityPanel.toggle(); const handleOpen = () => activityPanel.open(); const handleClose = () => activityPanel.close(); const handleSetTab = ( e: CustomEvent<{ tab: "notifications" | "active" | "history" }> ) => { activityPanel.setActiveTab(e.detail.tab); }; window.addEventListener("toggle-activity-panel", handleToggle); window.addEventListener("open-activity-panel", handleOpen); window.addEventListener("close-activity-panel", handleClose); window.addEventListener( "set-activity-panel-tab", handleSetTab as EventListener ); return () => { window.removeEventListener("toggle-activity-panel", handleToggle); window.removeEventListener("open-activity-panel", handleOpen); window.removeEventListener("close-activity-panel", handleClose); window.removeEventListener( "set-activity-panel-tab", handleSetTab as EventListener ); }; }, [activityPanel]); const isPublicPage = publicPaths.includes(pathname); // Show loading state only on protected pages if (!isPublicPage && isLoading) { return (

Loading...

); } // On public pages (login/register), don't show sidebar/player/topbar if (isPublicPage) { return <>{children}; } // On protected pages, show appropriate layout based on device if (isAuthenticated) { // Android TV Layout - Optimized for 10-foot UI if (isTV) { return ( Skip to main content {children} ); } // Mobile/Tablet Layout if (isMobileOrTablet) { return ( Skip to main content
{/* Sidebar - renders MobileSidebar for hamburger menu */} {/* Activity Panel - for mobile notifications (rendered as overlay) */} {/* Main content area with rounded corners */}
{/* Padding at bottom for mini player floating above */}
{children}
{/* Mini Player - fixed, positioned above bottom nav */} {/* Bottom Navigation - fixed at bottom */}
); } // Desktop Layout return ( Skip to main content
{children}
); } // If not authenticated on a protected page, auth context will redirect return (

Redirecting...

); }