"use client"; import React, { useEffect, useState } from "react"; import Link from "next/link"; import Image from "next/image"; export default function Footer3() { const [success, setSuccess] = useState(true); const [showMessage, setShowMessage] = useState(false); const handleShowMessage = () => { setShowMessage(true); setTimeout(() => { setShowMessage(false); }, 2000); }; const sendEmail = async (e) => { e.preventDefault(); const email = e.target.email.value; try { const response = await fetch('/api/contact', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ type: 'newsletter', email, }), }); if (response.ok) { e.target.reset(); setSuccess(true); handleShowMessage(); } else { setSuccess(false); handleShowMessage(); } } catch (error) { console.error('Error:', error); setSuccess(false); handleShowMessage(); e.target.reset(); } }; useEffect(() => { const headings = document.querySelectorAll(".footer-heading-mobile"); const toggleOpen = (event) => { const parent = event.target.closest(".footer-col-block"); const content = parent.querySelector(".tf-collapse-content"); if (parent.classList.contains("open")) { parent.classList.remove("open"); content.style.height = "0px"; } else { parent.classList.add("open"); content.style.height = content.scrollHeight + 10 + "px"; } }; headings.forEach((heading) => { heading.addEventListener("click", toggleOpen); }); return () => { headings.forEach((heading) => { heading.removeEventListener("click", toggleOpen); }); }; }, []); return ( ); }