'use client'; import { useEffect, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import Link from 'next/link'; import { IRootState } from '@/store'; import { toggleTheme, toggleSidebar, toggleRTL } from '@/store/themeConfigSlice'; import Dropdown from '@/components/dropdown'; import IconMenu from '@/components/icon/icon-menu'; import IconCalendar from '@/components/icon/icon-calendar'; import IconEdit from '@/components/icon/icon-edit'; import IconChatNotification from '@/components/icon/icon-chat-notification'; import IconSearch from '@/components/icon/icon-search'; import IconXCircle from '@/components/icon/icon-x-circle'; import IconSun from '@/components/icon/icon-sun'; import IconMoon from '@/components/icon/icon-moon'; import IconLaptop from '@/components/icon/icon-laptop'; import IconMailDot from '@/components/icon/icon-mail-dot'; import IconArrowLeft from '@/components/icon/icon-arrow-left'; import IconInfoCircle from '@/components/icon/icon-info-circle'; import IconBellBing from '@/components/icon/icon-bell-bing'; import IconUser from '@/components/icon/icon-user'; import IconMail from '@/components/icon/icon-mail'; import IconLockDots from '@/components/icon/icon-lock-dots'; import IconLogout from '@/components/icon/icon-logout'; import IconMenuDashboard from '@/components/icon/menu/icon-menu-dashboard'; import IconCaretDown from '@/components/icon/icon-caret-down'; import IconMenuApps from '@/components/icon/menu/icon-menu-apps'; import IconMenuComponents from '@/components/icon/menu/icon-menu-components'; import IconMenuElements from '@/components/icon/menu/icon-menu-elements'; import IconMenuDatatables from '@/components/icon/menu/icon-menu-datatables'; import IconMenuForms from '@/components/icon/menu/icon-menu-forms'; import IconMenuPages from '@/components/icon/menu/icon-menu-pages'; import IconMenuMore from '@/components/icon/menu/icon-menu-more'; import { usePathname, useRouter } from 'next/navigation'; import { getTranslation } from '@/i18n'; import axios from 'axios'; const Header = () => { const pathname = usePathname(); const dispatch = useDispatch(); const router = useRouter(); const { t, i18n } = getTranslation(); const [userId, setUserId] = useState(null); const [user, setUser] = useState(null); // 🧠 Check localStorage-based UID (manual login) useEffect(() => { const uid = localStorage.getItem("data4auto_uid"); const email = localStorage.getItem("d4a_email"); if (uid && email) { setUserId(uid); setUser(email); } else { axios .get("https://ebay.backend.data4autos.com/api/auth/protected", { withCredentials: true }) .then((res: any) => { const userData = res.data.user; if (userData) { setUser(userData.email); setUserId(userData.userid); // ✅ Save both values for reload persistence localStorage.setItem("data4auto_uid", userData.userid); localStorage.setItem("d4a_email", userData.email); } }) .catch(() => { router.push("/login"); }); } }, [router]); useEffect(() => { const selector = document.querySelector('ul.horizontal-menu a[href="' + window.location.pathname + '"]'); if (selector) { const all: any = document.querySelectorAll('ul.horizontal-menu .nav-link.active'); for (let i = 0; i < all.length; i++) { all[0]?.classList.remove('active'); } let allLinks = document.querySelectorAll('ul.horizontal-menu a.active'); for (let i = 0; i < allLinks.length; i++) { const element = allLinks[i]; element?.classList.remove('active'); } selector?.classList.add('active'); const ul: any = selector.closest('ul.sub-menu'); if (ul) { let ele: any = ul.closest('li.menu').querySelectorAll('.nav-link'); if (ele) { ele = ele[0]; setTimeout(() => { ele?.classList.add('active'); }); } } } }, [pathname]); const isRtl = useSelector((state: IRootState) => state.themeConfig.rtlClass) === 'rtl'; const themeConfig = useSelector((state: IRootState) => state.themeConfig); const setLocale = (flag: string) => { if (flag.toLowerCase() === 'ae') { dispatch(toggleRTL('rtl')); } else { dispatch(toggleRTL('ltr')); } router.refresh(); }; const handleSignOut = async () => { try { // Call the logout API to clear the d4a_uid cookie const response = await fetch('/api/auth/logout', { method: 'POST', headers: { 'Content-Type': 'application/json', }, }); if (response.ok) { // Navigate to login page after successful logout router.push('/login'); localStorage.removeItem('data4auto_uid') localStorage.removeItem('d4a_auth_uid') localStorage.removeItem('payment_session') } else { console.error('Logout API failed:', await response.json()); // Optionally handle the error (e.g., show a notification) } } catch (error) { console.error('Logout error:', error); // Optionally handle the error (e.g., show a notification) } }; function createMarkup(messages: any) { return { __html: messages }; } const [messages, setMessages] = useState([ { id: 1, image: '', title: 'Congratulations!', message: 'Your OS has been updated.', time: '1hr', }, { id: 2, image: '', title: 'Did you know?', message: 'You can switch between artboards.', time: '2hr', }, { id: 3, image: ' ', title: 'Something went wrong!', message: 'Send Reposrt', time: '2days', }, { id: 4, image: ' ', title: 'Warning', message: 'Your password strength is low.', time: '5days', }, ]); const removeMessage = (value: number) => { setMessages(messages.filter((user) => user.id !== value)); }; const [notifications, setNotifications] = useState([ { id: 1, profile: 'user-profile.jpeg', message: 'John Doeinvite you to Prototyping', time: '45 min ago', }, { id: 2, profile: 'profile-34.jpeg', message: 'Adam Nolanmentioned you to UX Basics', time: '9h Ago', }, { id: 3, profile: 'profile-16.jpeg', message: 'Anna MorganUpload a file', time: '9h Ago', }, ]); const removeNotification = (value: number) => { setNotifications(notifications.filter((user) => user.id !== value)); }; const [search, setSearch] = useState(false); return (
logo logo {/* Data4Autos */}
{/*
*/}
{/*
*/} {/*
{themeConfig.theme === 'light' ? ( ) : ( '' )} {themeConfig.theme === 'dark' && ( )} {themeConfig.theme === 'system' && ( )}
*/} {/*
} >
    {themeConfig.languageList.map((item: any) => { return (
  • ); })}
*/} {/*
} >
  • e.stopPropagation()}>

    Messages

  • {messages.length > 0 ? ( <>
  • e.stopPropagation()}> {messages.map((message) => { return (
    {message.title}
    {message.message}
    {message.time}
    ); })}
  • ) : (
  • e.stopPropagation()}>
  • )}
*/} {/*
} >
  • e.stopPropagation()}>

    Notification

    {notifications.length ? {notifications.length}New : ''}
  • {notifications.length > 0 ? ( <> {notifications.map((notification) => { return (
  • e.stopPropagation()}>
    profile
    {notification.time}
  • ); })}
  • ) : (
  • e.stopPropagation()}>
  • )}
*/}
} >
  • Data4Autos {/* Pro */}

  • {/*
  • Profile
  • Inbox
  • */} {/*
  • Lock Screen
  • */}
{/* horizontal menu */} {/*
    • {t('sales')}
    • {t('analytics')}
    • {t('finance')}
    • {t('crypto')}
    • {t('chat')}
    • {t('mailbox')}
    • {t('todo_list')}
    • {t('notes')}
    • {t('scrumboard')}
    • {t('contacts')}
      • {t('list')}
      • {t('preview')}
      • {t('add')}
      • {t('edit')}
    • {t('calendar')}
    • {t('tabs')}
    • {t('accordions')}
    • {t('modals')}
    • {t('cards')}
    • {t('carousel')}
    • {t('countdown')}
    • {t('counter')}
    • {t('sweet_alerts')}
    • {t('timeline')}
    • {t('notifications')}
    • {t('media_object')}
    • {t('list_group')}
    • {t('pricing_tables')}
    • {t('lightbox')}
    • {t('alerts')}
    • {t('avatar')}
    • {t('badges')}
    • {t('breadcrumbs')}
    • {t('buttons')}
    • {t('button_groups')}
    • {t('color_library')}
    • {t('dropdown')}
    • {t('infobox')}
    • {t('jumbotron')}
    • {t('loader')}
    • {t('pagination')}
    • {t('popovers')}
    • {t('progress_bar')}
    • {t('search')}
    • {t('tooltips')}
    • {t('treeview')}
    • {t('typography')}
    • {t('tables')}
      • {t('basic')}
      • {t('advanced')}
      • {t('skin')}
      • {t('order_sorting')}
      • {t('multi_column')}
      • {t('multiple_tables')}
      • {t('alt_pagination')}
      • {t('checkbox')}
      • {t('range_search')}
      • {t('export')}
      • {t('column_chooser')}
    • {t('basic')}
    • {t('input_group')}
    • {t('layouts')}
    • {t('validation')}
    • {t('input_mask')}
    • {t('select2')}
    • {t('touchspin')}
    • {t('checkbox_and_radio')}
    • {t('switches')}
    • {t('wizards')}
    • {t('file_upload')}
    • {t('quill_editor')}
    • {t('markdown_editor')}
    • {t('date_and_range_picker')}
    • {t('clipboard')}
      • {t('profile')}
      • {t('account_settings')}
    • {t('knowledge_base')}
    • {t('contact_us_boxed')}
    • {t('contact_us_cover')}
    • {t('faq')}
    • {t('coming_soon_boxed')}
    • {t('coming_soon_cover')}
    • {t('maintenence')}
      • {t('404')}
      • {t('500')}
      • {t('503')}
      • {t('login_cover')}
      • {t('login_boxed')}
      • {t('register_cover')}
      • {t('register_boxed')}
      • {t('recover_id_cover')}
      • {t('recover_id_boxed')}
      • {t('unlock_cover')}
      • {t('unlock_boxed')}
    • {t('drag_and_drop')}
    • {t('charts')}
    • {t('font_icons')}
    • {t('widgets')}
    • {t('documentation')}
*/}
); }; export default Header;