"use client" import Link from "next/link" import { useEffect, useState } from "react" import { Menu, X, Search } from "lucide-react" import { ensureHttpsImageUrl } from "@/lib/utils" const navItems = [ { label: "Home", href: "#", isActive: true }, { label: "About", href: "#" }, { label: "ERP", href: "#" }, { label: "Tech Lab Setup", href: "#" }, { label: "Resources", href: "#" }, { label: "Contact", href: "#" }, ] export default function Navbar() { const [isOpen, setIsOpen] = useState(false) const [logoUrl, setLogoUrl] = useState("") useEffect(() => { const loadLogo = async () => { try { // Use Next.js API route instead of direct Strapi call const res = await fetch("/api/logo", { headers: { Accept: "application/json" }, }) if (!res.ok) { throw new Error(`logo status ${res.status}: ${res.statusText}`) } const json = await res.json() // Handle both Strapi v4 formats: data.logo (direct) or data.attributes.logo.data (nested) const logoData = json?.data?.logo || json?.data?.attributes?.logo?.data || json?.data?.attributes?.logo if (!logoData) { console.warn("No logo data found in response. Full response:", json) return } const logo = Array.isArray(logoData) ? logoData[0] : logoData // Logo object may have attributes or be direct const logoObj = logo?.attributes || logo const url = logoObj?.url || logoObj?.formats?.small?.url || logoObj?.formats?.thumbnail?.url || logoObj?.formats?.medium?.url || logoObj?.formats?.large?.url || "" if (url) { // Get base URL for constructing absolute URLs if needed const baseUrl = process.env.NEXT_PUBLIC_STRAPI_BASE_URL || "http://160.187.167.213" // Ensure HTTPS to prevent Mixed Content errors const absolute = ensureHttpsImageUrl(url, baseUrl) console.log("✅ Logo URL from API:", absolute) console.log("🔍 Original URL:", url) console.log("🔍 Base URL:", baseUrl) if (absolute) { setLogoUrl(absolute) } else { console.error("❌ ensureHttpsImageUrl returned empty string") } } else { console.warn("⚠️ No logo URL found in logo object. Logo object:", logoObj) } } catch (err) { console.error("❌ Failed to load navbar logo:", err) // Don't set fallback - user wants only Strapi logo } } loadLogo() }, []) return ( ) }