"use client"; import { useState, useEffect } from 'react' import Link from 'next/link' import type { Category, MenuItem, StoreSettings } from '@homaroma/types' import { useTranslation } from 'react-i18next' import { resolveLocalized } from '../lib/localization' import { useLang } from '../hooks/useLang' interface FooterProps { categories?: Category[] exploreMenu?: MenuItem[] supportMenu?: MenuItem[] settings?: StoreSettings | null } export default function Footer({ categories = [], exploreMenu = [], supportMenu = [], settings = null, }: FooterProps) { const { t } = useTranslation() const lang = useLang() const [mounted, setMounted] = useState(false) useEffect(() => { setMounted(true) }, []) // Before mount: always 'th' to match SSR output → no hydration mismatch // After mount: real user language → correct content const effectiveLang = mounted ? lang : 'th' // Translate a menu item label using its translations array or i18n key map const translateMenuLabel = (item: MenuItem): string => { // Use outer `lang` from closure — hooks cannot be called inside nested functions if (effectiveLang !== 'en' && item.translations && item.translations.length > 0) { const trans = item.translations.find((tr: any) => tr.langCode === effectiveLang) if (trans?.label) return trans.label } const map: Record = { 'Home': 'nav.home', 'Shop': 'nav.shop', 'Scent Guide': 'nav.scentGuide', 'About Us': 'nav.about', 'About': 'nav.about', 'FAQ': 'nav.faq', 'Contact': 'nav.contact', 'Contact Us': 'nav.contact', 'Track Order': 'nav.trackOrder', 'Delivery & Returns': 'nav.delivery', } return map[item.label] ? t(map[item.label]) : item.label } // Social links — use settings if available, fallback to placeholder buttons const hasSocialLinks = settings && (settings.facebookUrl || settings.instagramUrl || settings.tiktokUrl) const brandName = settings?.brandName || 'HomAroma' return ( ) }