Spaces:
Running

File size: 5,035 Bytes
48e3948
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fafae3e
bcf5f89
 
48e3948
 
 
 
 
 
 
 
3539f8f
48e3948
 
 
 
 
 
 
 
 
 
 
dc6f920
48e3948
 
 
 
 
 
 
d36ecd1
 
 
48e3948
 
 
 
 
502b64f
48e3948
01e5fe2
48e3948
 
 
 
 
 
 
4b0f951
740eb5c
48e3948
 
 
 
 
 
 
d36ecd1
 
 
e023141
48e3948
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
'use client'

import { Sidebar } from '@/components/Sidebar'
import { Header } from '@/components/Header'
import { usePathname } from 'next/navigation'
import { useAuth } from '@/contexts/AuthContext'
import { cn } from '@/lib/utils'
import { useEffect } from 'react'
import { useRouter } from 'next/navigation'
import { MobileHeader, MobileSidebarWrapper } from '@/components/MobileNav'
import { MobileBottomNav } from '@/components/MobileBottomNav'
import { SecondaryNav } from '@/components/SecondaryNav'

function ProtectedLayout({ children }: { children: React.ReactNode }) {
    const { user, isLoading } = useAuth()
    const router = useRouter()

    useEffect(() => {
        if (!isLoading && !user) {
            router.push('/login')
        }
    }, [isLoading, user, router])

    if (!user && isLoading) {
        return (
            <div className="flex h-screen items-center justify-center bg-background">
                <div className="animate-spin rounded-full h-8 w-8 border-b-2 border-indigo-600"></div>
            </div>
        )
    }

    if (!user) return null

    return <>{children}</>
}

export function LayoutClient({ children }: { children: React.ReactNode }) {
    const pathname = usePathname()

    // Pages without sidebar (public pages)
    const publicPages = ['/', '/login', '/register', '/verify-email', '/forgot-password', '/terms', '/privacy', '/refund', '/pricing']
    const isPublicPage = publicPages.includes(pathname)

    return (
        <>
            {/* Global Background Atmosphere - Synced with Landing */}
            <div className="fixed inset-0 z-0 pointer-events-none overflow-hidden bg-[#050510]">
                <div className="absolute top-[-10%] right-[-5%] w-[60%] h-[60%] bg-gradient-to-b from-cyan-500/10 via-emerald-500/5 to-transparent blur-[50px] rounded-full" />
                <div className="absolute bottom-[-10%] left-[-10%] w-[60%] h-[60%] bg-gradient-to-t from-indigo-600/10 via-purple-600/5 to-transparent blur-[50px] rounded-full" />
            </div>

            {isPublicPage ? (
                // Public layout (no sidebar)
                <div className="relative z-10">{children}</div>
            ) : (
                // App layout (with sidebar)
                <ProtectedLayout>
                    <div className="flex h-[100dvh] md:h-screen lg:h-screen relative text-white overflow-hidden">
                        {/* Desktop Sidebar */}
                        <div className="hidden lg:flex h-full relative z-20 w-72 shrink-0">
                            <Sidebar />
                        </div>

                        {/* Mobile Sidebar (Drawer - opens from menu button) */}
                        <MobileSidebarWrapper>
                            <Sidebar />
                        </MobileSidebarWrapper>

                        {/* Main Content Area Container */}
                        <div className="flex-1 flex flex-col h-full overflow-hidden min-w-0 relative">
                            {/* Desktop Header */}
                            <Header />

                            {/* Secondary Nav - Tablet/Small Desktop Only (Full Sidebar Content) */}
                            <SecondaryNav />

                            {/* Mobile Header - FIXED at top - ONLY for Mobile (< md) */}
                            <div className="md:hidden contents">
                                <MobileHeader />
                            </div>

                            {/* Main Content - with padding for fixed header and bottom nav on Mobile */}
                            <main
                                className={cn(
                                    "flex-1 w-full md:pt-0 md:pb-0 overflow-x-hidden",
                                    "overflow-y-auto min-h-0"
                                )}
                                style={{
                                    // paddingTop: pathname?.startsWith('/chats') ? '0px' : 'var(--header-height-mobile)',
                                    // paddingBottom: 'var(--footer-height-mobile)'
                                }}
                            >
                                <div
                                    className="w-full h-full"
                                    style={{
                                        paddingTop: 'var(--header-height-mobile)',
                                        paddingBottom: 'var(--footer-height-mobile)'
                                    }}
                                >
                                    {children}
                                </div>
                            </main>

                            {/* Mobile Bottom Navigation - FIXED at bottom - ONLY for Mobile (< md) */}
                            <div className="md:hidden contents">
                                <MobileBottomNav />
                            </div>

                        </div>
                    </div>
                </ProtectedLayout>
            )}
        </>
    )
}