"use client";
import React, { ReactNode, useEffect, useState } from "react";
import FooterBg from "@/images/footer-bg.webp";
import Link from "next/link";
import axiosInstance from "@/lib/axiosInstance";

interface FooterProps {
  children?: ReactNode;
  siteSettings: any;
}
interface FooterBadge {
  id: number;
  title: string;
  image: string;
}

const Footer = ({ children, siteSettings }: FooterProps) => {
  const [badges, setBadges] = useState<FooterBadge[]>([]);

  useEffect(() => {
    const fetchBadges = async () => {
      try {
        const res = await axiosInstance.get("/cms/footer-badges");
        const json = await res.data;

        if (json.success) {
          setBadges(json.data);
        }
      } catch (err) {
        console.error(err);
      }
    };

    fetchBadges();
  }, []);
  return (
    <footer
      className="footercontainer"
      style={{
        backgroundImage: `url(${FooterBg.src})`,
      }}
    >
      {/* Dynamic Section */}
      {children}

      {/* Common Footer */}
      <div className="footerinnertp">
        <div className="container container-xxl">
          <div className="row">
            <div className="col-12">
              <div className="footerbxouter">
                {/* <div className="row gx-lg-5 justify-content-center">
                  <div className="col-xxl-4 col-xl-4 col-lg-4 col-md-4 col-sm-6 col-12 footercolumn">
                    <div className="footerbadgebx">
                      <div className="footerbadgebxicon">
                        <svg viewBox="0 0 68 57" fill="none" xmlns="http://www.w3.org/2000/svg">
                          <path d="M47.9648 42.8929C44.1203 46.7374 39.0087 48.8547 33.5719 48.8547C28.1351 48.8547 23.0235 46.7374 19.179 42.8929C18.5125 42.226 17.893 41.5138 17.3248 40.7614H9.87492C10.8089 41.7268 11.7446 42.6906 12.6821 43.6527L16.7929 51.551L25.5743 53.0246L33.5419 57L41.5129 53.0325L50.2917 51.5591L54.4168 43.6706C54.4168 43.6706 56.0642 41.9789 57.2389 40.7614H49.8188C49.2508 41.5139 48.6313 42.2261 47.9648 42.8929ZM19.179 14.1071C23.0235 10.2626 28.1351 8.14533 33.5719 8.14533C39.0087 8.14533 44.1203 10.2626 47.9648 14.1071C48.6313 14.774 49.2509 15.4862 49.819 16.2386H57.2313C56.0608 15.0268 54.4242 13.3473 54.4242 13.3473L50.3133 5.44902L41.5319 3.97536L33.5643 0L25.5931 3.96749L16.8144 5.44089L12.6893 13.3294C12.6893 13.3294 11.0418 15.0211 9.86719 16.2386H17.3249C17.893 15.4861 18.5125 14.7739 19.179 14.1071Z" fill="url(#paint0_linear_4542_11488)" />
                          <path d="M33.5728 11.9482C29.1518 11.9482 24.9953 13.6699 21.8691 16.7961C15.4158 23.2495 15.4158 33.75 21.8691 40.2034C24.9953 43.3296 29.1517 45.0513 33.5728 45.0513C37.9939 45.0513 42.1502 43.3296 45.2764 40.2034C51.7297 33.75 51.7297 23.2495 45.2764 16.7961C42.1502 13.6699 37.9937 11.9482 33.5728 11.9482ZM30.9869 36.5555L24.2201 29.7886L27.0021 27.0067L30.9869 30.9916L40.1435 21.835L42.9254 24.617L30.9869 36.5555ZM52.2303 20.0415C54.6533 25.4017 54.6533 31.5979 52.2303 36.958H67.1455L64.5666 28.4997L67.1455 20.0415H52.2303ZM14.9152 20.0415H0L2.45225 28.4997L0 36.958H14.9152C12.4923 31.5979 12.4922 25.4016 14.9152 20.0415Z" fill="url(#paint1_linear_4542_11488)" />
                          <defs>
                            <linearGradient id="paint0_linear_4542_11488" x1="33.553" y1="0" x2="33.553" y2="57" gradientUnits="userSpaceOnUse">
                              <stop stop-color="currentColor" />
                            </linearGradient>
                            <linearGradient id="paint1_linear_4542_11488" x1="33.5728" y1="11.9482" x2="33.5728" y2="45.0513" gradientUnits="userSpaceOnUse">
                              <stop stop-color="currentColor" />
                            </linearGradient>
                          </defs>
                        </svg>
                      </div>

                      <div className="footerbadgebxcontent">
                        <h4>20 Years of Excellence</h4>
                      </div>
                    </div>
                  </div>

                  <div className="col-xxl-4 col-xl-4 col-lg-4 col-md-4 col-sm-6 col-12 footercolumn">
                    <div className="footerbadgebx">
                      <div className="footerbadgebxicon">
                        <svg viewBox="0 0 48 57" fill="none" xmlns="http://www.w3.org/2000/svg">
                          <path d="M46.6299 9.22976L24.8521 0.170207C24.3066 -0.05668 23.6933 -0.0567913 23.1479 0.170207L1.37011 9.22976C0.540667 9.57488 0 10.3862 0 11.2861V22.2992C0 37.4636 9.14767 51.1043 23.1602 56.8349C23.6984 57.055 24.3014 57.055 24.8398 56.8349C38.8521 51.1044 48 37.4637 48 22.2992V11.2861C48 10.3862 47.4594 9.57488 46.6299 9.22976ZM43.5556 22.2992C43.5556 35.1905 36 47.0578 24 52.355C12.3207 47.1992 4.44444 35.5398 4.44444 22.2992V12.7726L24 4.63736L43.5556 12.7726V22.2992ZM21.5438 29.8043L31.0953 20.2342C31.9631 19.3647 33.3701 19.3646 34.238 20.2342C35.1059 21.1038 35.1058 22.5136 34.2379 23.383L23.1151 34.5275C22.2471 35.3972 20.8401 35.3969 19.9724 34.5275L13.762 28.305C12.8941 27.4354 12.8941 26.0256 13.762 25.1562C14.6299 24.2867 16.0369 24.2866 16.9047 25.1562L21.5438 29.8043Z" fill="currentColor" />
                        </svg>
                      </div>

                      <div className="footerbadgebxcontent">
                        <h4>Certified Training</h4>
                      </div>
                    </div>
                  </div>

                  <div className="col-xxl-4 col-xl-4 col-lg-4 col-md-4 col-sm-6 col-12 footercolumn">
                    <div className="footerbadgebx">
                      <div className="footerbadgebxicon">
                        <svg viewBox="0 0 48 57" fill="none" xmlns="http://www.w3.org/2000/svg">
                          <path d="M46.6299 9.22976L24.8521 0.170207C24.3066 -0.05668 23.6933 -0.0567913 23.1479 0.170207L1.37011 9.22976C0.540667 9.57488 0 10.3862 0 11.2861V22.2992C0 37.4636 9.14767 51.1043 23.1602 56.8349C23.6984 57.055 24.3014 57.055 24.8398 56.8349C38.8521 51.1044 48 37.4637 48 22.2992V11.2861C48 10.3862 47.4594 9.57488 46.6299 9.22976ZM43.5556 22.2992C43.5556 35.1905 36 47.0578 24 52.355C12.3207 47.1992 4.44444 35.5398 4.44444 22.2992V12.7726L24 4.63736L43.5556 12.7726V22.2992ZM21.5438 29.8043L31.0953 20.2342C31.9631 19.3647 33.3701 19.3646 34.238 20.2342C35.1059 21.1038 35.1058 22.5136 34.2379 23.383L23.1151 34.5275C22.2471 35.3972 20.8401 35.3969 19.9724 34.5275L13.762 28.305C12.8941 27.4354 12.8941 26.0256 13.762 25.1562C14.6299 24.2867 16.0369 24.2866 16.9047 25.1562L21.5438 29.8043Z" fill="currentColor" />
                        </svg>
                      </div>

                      <div className="footerbadgebxcontent">
                        <h4>Michigan &amp; Online Classes</h4>
                      </div>
                    </div>
                  </div>
                </div> */}
                <div className="row gx-lg-5 justify-content-center">
                  {badges.map((badge) => (
                    <div
                      key={badge.id}
                      className="col-xxl-4 col-xl-4 col-lg-4 col-md-4 col-sm-6 col-12 footercolumn"
                    >
                      <div className="footerbadgebx">
                        <div className="footerbadgebxicon">
                          <img
                            src={badge.image}
                            alt={badge.title}
                          />
                        </div>

                        <div className="footerbadgebxcontent">
                          <h4>{badge.title}</h4>
                        </div>
                      </div>
                    </div>
                  ))}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div className="footerinnerbt">
        <div className="container container-xxl">
          <div className="row">
            <div className="col-12 text-center">
              <div className="socialicons d-inline-flex mb-3">
                <a
                  href={siteSettings?.site_whatsapp_link || "#"}
                  target="_blank"
                  rel="noopener noreferrer"
                  className="socialicon whatsapp"
                >
                  <i className="icon icon-whatsapp"></i>
                </a>

                <a
                  href={siteSettings?.site_facebook_link || "#"}
                  target="_blank"
                  rel="noopener noreferrer"
                  className="socialicon facebook"
                >
                  <i className="icon icon-facebook"></i>
                </a>

                <a
                  href={siteSettings?.site_youtube_link || "#"}
                  target="_blank"
                  rel="noopener noreferrer"
                  className="socialicon youtube"
                >
                  <i className="bi bi-youtube"></i>
                </a>

                <a
                  href={siteSettings?.site_instagram_link || "#"}
                  target="_blank"
                  rel="noopener noreferrer"
                  className="socialicon instagram"
                >
                  <i className="icon icon-instagram"></i>
                </a>

                <a
                  href={siteSettings?.site_twitter_link || "#"}
                  target="_blank"
                  rel="noopener noreferrer"
                  className="socialicon twitter"
                >
                  <i className="icon icon-twitter"></i>
                </a>
              </div>

              <p className="text-center">
                &copy; {new Date().getFullYear()}{" "}
                <Link href="/">{siteSettings?.site_name?.replace(/\s+/g, "")}</Link>. All Rights Reserved.
              </p>
            </div>
          </div>
        </div>
      </div>
    </footer>
  );
};

export default Footer;