"use client" import Image from "next/image" import Link from "next/link" import { useEffect, useState } from "react" import { ensureHttpsImageUrl } from "@/lib/utils" interface QuickLink { label: string href: string } interface ContactItem { svg: string text: string link: string | null } interface SocialIcon { name: string svg: string link?: string | null } export default function Footer() { const [logoUrl, setLogoUrl] = useState("") const [quickLinks, setQuickLinks] = useState([]) const [quickLinksHeading, setQuickLinksHeading] = useState("Quick Links") const [resourcesLinks, setResourcesLinks] = useState([]) const [resourcesHeading, setResourcesHeading] = useState("Resources") const [contactHeading, setContactHeading] = useState("Contact") const [contactItems, setContactItems] = useState([]) const [tagline, setTagline] = useState("Transforming education through innovative technology solutions.") const [copyright, setCopyright] = useState("© 2025 School For Schools. All rights reserved.") const [privacyPolicy, setPrivacyPolicy] = useState("") const [socialIcons, setSocialIcons] = useState([]) useEffect(() => { const loadFooterData = async () => { try { // Use Next.js API route instead of direct Strapi calls const res = await fetch("/api/footer", { headers: { Accept: "application/json" }, }) if (!res.ok) { throw new Error(`Footer API status ${res.status}`) } const data = await res.json() // Load Quick Links if (data.quickLinks) { const json = data.quickLinks const items = Array.isArray(json?.data) ? json.data : [] if (items.length > 0) { const item = items[0] const attrs = item?.attributes || item || {} if (attrs.heading) setQuickLinksHeading(attrs.heading) const links: QuickLink[] = [] let index = 1 while (true) { const labelKey = `list${index}` as keyof typeof attrs const linkKey = `list${index}_link` as keyof typeof attrs const label = attrs[labelKey] const href = attrs[linkKey] if (!label || !href) break links.push({ label: String(label), href: String(href) }) index++ } if (links.length > 0) setQuickLinks(links) } } // Load Resources Links if (data.resources) { const json = data.resources const items = Array.isArray(json?.data) ? json.data : [] if (items.length > 0) { const item = items[0] const attrs = item?.attributes || item || {} if (attrs.heading) setResourcesHeading(attrs.heading) const links: QuickLink[] = [] let index = 1 while (true) { const labelKey = `resource${index}` as keyof typeof attrs const linkKey = `resource${index}_link` as keyof typeof attrs const label = attrs[labelKey] const href = attrs[linkKey] if (!label || !href) break links.push({ label: String(label), href: String(href) }) index++ } if (links.length > 0) setResourcesLinks(links) } } // Load Contact Links if (data.contact) { const json = data.contact const items = Array.isArray(json?.data) ? json.data : [] if (items.length > 0) { const item = items[0] const attrs = item?.attributes || item || {} if (attrs.heading) setContactHeading(attrs.heading) const contacts: ContactItem[] = [] if (attrs.email && attrs.email_svg) { contacts.push({ svg: attrs.email_svg, text: attrs.email, link: attrs.email_link || `mailto:${attrs.email}`, }) } if (attrs.phone && attrs.phone_svg) { contacts.push({ svg: attrs.phone_svg, text: attrs.phone, link: attrs.phone_link || `tel:${attrs.phone.replace(/\D/g, '')}`, }) } if (attrs.address && attrs.address_svg) { contacts.push({ svg: attrs.address_svg, text: attrs.address, link: attrs.address_link || null, }) } if (contacts.length > 0) setContactItems(contacts) } } // Load Tagline if (data.logoTag) { const json = data.logoTag const item = json?.data if (item) { const attrs = item?.attributes || item || {} const taglineText = attrs?.tag_line || attrs?.tagline || "" if (taglineText) setTagline(taglineText) } } // Load Privacy Policy if (data.privacy) { const json = data.privacy const item = json?.data if (item) { const attrs = item?.attributes || item || {} const privacyText = attrs?.privacy_policy || "" if (privacyText) setPrivacyPolicy(privacyText) } } // Load Social Icons if (data.socialIcons) { const json = data.socialIcons const items = Array.isArray(json?.data) ? json.data : [] const icons: SocialIcon[] = items.map((item: any) => { const attrs = item?.attributes || item || {} return { name: attrs?.company_name || "", svg: attrs?.company_svg || "", link: attrs?.company_link || null, } }).filter((icon: SocialIcon) => icon.name && icon.svg) if (icons.length > 0) setSocialIcons(icons) } // Load Logo if (data.logo) { const json = data.logo const logoData = json?.data?.logo || json?.data?.attributes?.logo?.data || json?.data?.attributes?.logo if (logoData) { const logo = Array.isArray(logoData) ? logoData[0] : logoData 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) { // Ensure HTTPS to prevent Mixed Content errors const absolute = ensureHttpsImageUrl(url) setLogoUrl(absolute) } } } } catch (err) { console.error("Failed to load footer data:", err) } } loadFooterData() }, []) return ( ) }