import Link from "next/link"; import SocialLinks from "./socialLinks"; import SiteInfo from "./siteInfo"; import Image from "next/image"; import type { ReactNode } from "react"; import { fetchMenuBySlug } from "@/graphql/queries/getMenuBySlug"; import { X } from "../../../../public/footer/x"; import { facebook } from "../../../../public/footer/facebook"; import { Instagram } from "../../../../public/footer/instagram"; import { getStoreName } from "@/app/utils/branding"; // Define types for footer sections and menu items type FooterChild = { id: string; name: string; href?: string; url?: string; metadata?: Array<{ key: string; value: string; }>; }; type FooterSection = { id: string; name: string; url?: string; children: FooterChild[]; }; const SectionTitle = ({ children }: { children: React.ReactNode }) => ( {children} ); type SocialIcon = { icon: ReactNode; link: string; label: string }; const SocialIcons: SocialIcon[] = (() => { const items: SocialIcon[] = []; const fb = process.env.NEXT_PUBLIC_SOCIAL_FACEBOOK_URL; const x = process.env.NEXT_PUBLIC_SOCIAL_X_URL; const ig = process.env.NEXT_PUBLIC_SOCIAL_INSTAGRAM_URL; if (fb) items.push({ icon: facebook, link: fb, label: "Facebook" }); if (x) items.push({ icon: X, link: x, label: "X (Twitter)" }); if (ig) items.push({ icon: Instagram, link: ig, label: "Instagram" }); return items; })(); // ---------- STATIC SECTIONS ---------- const STATIC_SECTIONS: FooterSection[] = [ { id: "support", name: "SUPPORT", children: [ { id: "contact", name: "Contact", href: "/contact" }, { id: "faq", name: "Become a Dealer", href: "/dealer-application" }, ], }, ]; const getTargetFromMetadata = ( metadata?: Array<{ key: string; value: string }> ) => { const targetMetadata = metadata?.find((meta) => meta.key === "target"); return targetMetadata?.value === "_blank" ? "_blank" : "_self"; }; const Footer = async () => { const currentYear = new Date().getFullYear(); const storeName = getStoreName(); // Fetch footer menu data from backend const footerMenu = await fetchMenuBySlug("footer"); // Always show static data, add dynamic data if available const dynamicSections: FooterSection[] = footerMenu && typeof footerMenu === "object" && "items" in footerMenu && Array.isArray(footerMenu.items) && footerMenu.items.length > 0 ? ( footerMenu.items as Array<{ id: string; name: string; url: string; children?: Array<{ id: string; name: string; href: string; url: string; metadata?: Array<{ key: string; value: string; }>; }>; }> ).map((item) => ({ id: item.id, name: item.name, url: item.url, children: item.children?.map((child) => ({ id: child.id, name: child.name, href: child.href, url: child.url, metadata: child.metadata, })) || [], })) : []; // Combine static sections with dynamic sections const sectionsToRender: FooterSection[] = [ ...dynamicSections, ...STATIC_SECTIONS, ]; return ( ); }; export default Footer;