'use client' import Link from 'next/link' import { usePathname, useRouter } from 'next/navigation' import { LayoutDashboard, User, Bookmark, Bell, LogOut, ChevronRight, ChevronLeft, Car, } from 'lucide-react' import { useEffect, useState } from 'react' import { useMarketplacePreferences } from '@/components/MarketplaceShell' import { clearRenterSession, loadRenterProfile } from '@/lib/renter' const NAV_ITEMS = [ { href: '/renter/dashboard', key: 'dashboard', icon: LayoutDashboard, exact: true }, { href: '/renter/profile', key: 'profile', icon: User }, { href: '/renter/saved-companies', key: 'savedCompanies', icon: Bookmark }, { href: '/renter/notifications', key: 'notifications', icon: Bell }, ] as const const dicts = { en: { dashboard: 'Dashboard', profile: 'Profile', savedCompanies: 'Saved companies', notifications: 'Notifications', signOut: 'Sign out', renterPortal: 'Renter Portal', rights: 'All rights reserved.', }, fr: { dashboard: 'Tableau de bord', profile: 'Profil', savedCompanies: 'Entreprises sauvegardées', notifications: 'Notifications', signOut: 'Déconnexion', renterPortal: 'Espace client', rights: 'Tous droits réservés.', }, ar: { dashboard: 'لوحة التحكم', profile: 'الملف الشخصي', savedCompanies: 'الشركات المحفوظة', notifications: 'الإشعارات', signOut: 'تسجيل الخروج', renterPortal: 'بوابة المستأجر', rights: 'جميع الحقوق محفوظة.', }, } as const function computeInitials(name: string): string { const parts = name.trim().split(/\s+/).filter(Boolean) if (parts.length === 0) return 'R' if (parts.length === 1) return parts[0].slice(0, 1).toUpperCase() return `${parts[0].slice(0, 1)}${parts[1].slice(0, 1)}`.toUpperCase() } export default function RenterShell({ children }: { children: React.ReactNode }) { const pathname = usePathname() const router = useRouter() const { language } = useMarketplacePreferences() const dict = dicts[language] const isRtl = language === 'ar' const [open, setOpen] = useState(false) const [userInitials, setUserInitials] = useState('R') const [userName, setUserName] = useState(null) const [userEmail, setUserEmail] = useState(null) useEffect(() => { loadRenterProfile() .then((profile) => { const fullName = `${profile.firstName ?? ''} ${profile.lastName ?? ''}`.trim() setUserName(fullName || profile.email.split('@')[0]) setUserEmail(profile.email) setUserInitials(computeInitials(fullName || profile.email)) }) .catch(() => {}) }, []) useEffect(() => { setOpen(false) }, [pathname]) function signOut() { clearRenterSession() router.push('/') } const isActive = (item: (typeof NAV_ITEMS)[number]) => { if ('exact' in item && item.exact) return pathname === item.href return pathname.startsWith(item.href) } const activeNav = NAV_ITEMS.find((item) => isActive(item)) const pageTitle = activeNav ? (dict[activeNav.key as keyof typeof dict] as string) : dict.dashboard return (
{open && (
setOpen(false)} /> )} {!open && ( )}

{pageTitle}

{userInitials}
{children}
) }