"use client"; import { useState, useEffect, useMemo } from "react"; import { usePathname } from "next/navigation"; import Link from "next/link"; import Image from "next/image"; import OffcanvasMenu from "./OffcanvasMenu"; import { useNavigationServices } from "@/lib/hooks/useServices"; const Header = () => { const [isOffcanvasOpen, setIsOffcanvasOpen] = useState(false); const [scrolled, setScrolled] = useState(false); const [isActive, setIsActive] = useState(true); const [openDropdown, setOpenDropdown] = useState(null); const [isMobile, setIsMobile] = useState(false); // Fetch services from API const { services: apiServices, loading: servicesLoading, error: servicesError } = useNavigationServices(); // Create dynamic navigation data - only use API data, no hardcoded fallback const navigationData = useMemo(() => { const baseNavigation = [ { id: 1, title: "Home", path: "/", submenu: null, }, { id: 2, title: "About Us", path: "/about-us", submenu: null, }, { id: 3, title: "Services", path: "/services", submenu: apiServices.length > 0 ? apiServices.map(service => ({ id: service.id + 1000, title: service.title, path: `/services/${service.slug}`, display_order: service.display_order, })) : null, }, { id: 4, title: "Case Studies", path: "/case-study", submenu: null, }, { id: 5, title: "Insights", path: "/insights", submenu: null, }, { id: 6, title: "Career", path: "/career", submenu: null, }, { id: 7, title: "Support Center", path: "/support-center", submenu: null, }, { id: 8, title: "Contact Us", path: "/contact-us", submenu: null, }, ]; return baseNavigation; }, [apiServices]); // Static header data const headerData = { title: "EnterpriseSoft Solutions", logoUrl: "/images/logo.png", logoLightUrl: "/images/logo-light.png", navigationType: "both", headerClass: "tp-header", scrolledClass: "navbar-active", buttonText: "Support Center", buttonUrl: "/support-center", buttonClass: "btn btn-primary d-none d-sm-flex", isActive: true, displayOrder: 1, metaData: JSON.stringify({ mobileBreakpoint: 992, scrollThreshold: 50, hideOnMobile: false, mobileFirst: true, hamburgerMenu: true }) }; const handleClick = () => { setTimeout(() => { setIsOffcanvasOpen(false); }, 900); setIsActive(false); }; const handleDropdownToggle = (index: number) => { setOpenDropdown(openDropdown === index ? null : index); }; useEffect(() => { const handleScroll = () => { const scrollPosition = window.scrollY; if (scrollPosition > 50) { setScrolled(true); } else { setScrolled(false); } }; window.addEventListener("scroll", handleScroll); handleScroll(); return () => { window.removeEventListener("scroll", handleScroll); }; }, [scrolled]); useEffect(() => { const handleResize = () => { setIsMobile(window.innerWidth < 992); setTimeout(() => { setIsOffcanvasOpen(false); }, 900); setIsActive(false); }; handleResize(); // Check on mount window.addEventListener("resize", handleResize); return () => { window.removeEventListener("resize", handleResize); }; }, []); // Use static data let logoSrc: string = headerData.logoUrl; let headerClass = headerData.headerClass; let buttonText = headerData.buttonText; let buttonUrl = headerData.buttonUrl; let buttonClass = headerData.buttonClass; const pathname = usePathname(); // Override logo based on pathname if needed (maintain existing behavior) if ( pathname === "/career" || pathname === "/" || pathname === "/index" || pathname === "/services" || pathname === "/service-single" ) { logoSrc = headerData.logoLightUrl; } const handleOffCanvas = () => { setIsOffcanvasOpen(true); setIsActive(true); }; return ( <>
); }; export default Header;