
(function () {
  const { useMemo } = React;

  const HOMEPAGE = "DSMADE Homepage.html";

  function joinBase(base, path) {
    if (!path) return "#";
    if (path.startsWith("#")) {
      if (base === "." || base === "") return path;
      return `${base}/${HOMEPAGE}${path}`;
    }
    if (/^([a-z]+:)?\/\//i.test(path)) return path;
    if (base === "." || base === "") return path;
    return `${base}/${path}`;
  }
  function homeHref(base) {
    if (base === "." || base === "") return "#top";
    return `${base}/${HOMEPAGE}`;
  }

  function SharedFooter({ base = "." }) {
    const symbolSrc = useMemo(
      () => joinBase(base, "assets/ds-symbol-white.png"),
      [base]
    );

    const isPT = typeof window !== "undefined" &&
      window.location.pathname.includes("/pt/");

    const termsHref = isPT
      ? joinBase(base, "pt/terms.html")
      : joinBase(base, "terms.html");
    const privacyHref = isPT
      ? joinBase(base, "pt/privacy.html")
      : joinBase(base, "privacy.html");
    const contactHref = isPT
      ? joinBase(base, "pt/contact.html")
      : joinBase(base, "pages/contact.html");

    const labels = isPT
      ? {
          terms: "Termos de Uso",
          privacy: "Política de Privacidade",
          contact: "Fale Conosco",
          copy: "© 2026 Grupo DS. Todos os direitos reservados.",
        }
      : {
          terms: "Terms of Use",
          privacy: "Privacy Policy",
          contact: "Contact Us",
          copy: "© 2026 DS Group All rights reserved",
        };

    return (
      <footer className="footer footer--compact" id="contact" data-nav-theme="dark">
        <div className="grain" aria-hidden="true" />

        <div className="container footer-container">
          <div className="footer-row">
            <a className="footer-symbol" href={homeHref(base)} aria-label="DS Made">
              <img
                src={symbolSrc}
                alt="DS Made"
                className="footer-symbol-img"
              />
            </a>
            <div className="footer-linkstack">
              <nav className="footer-links" aria-label="Footer">
                <a href={termsHref}>{labels.terms}</a>
                <a href={privacyHref}>{labels.privacy}</a>
                <a href={contactHref}>{labels.contact}</a>
              </nav>
              <div className="footer-copy">
                {labels.copy}
              </div>
            </div>
          </div>
        </div>
      </footer>
    );
  }

  function mount() {
    const el = document.getElementById("shared-footer");
    if (!el) return;
    const base = el.getAttribute("data-footer-base") || ".";
    const root = ReactDOM.createRoot(el);
    root.render(<SharedFooter base={base} />);
  }

  window.SharedFooter = SharedFooter;
  window.SharedFooterMount = mount;

  if (document.readyState === "loading") {
    document.addEventListener("DOMContentLoaded", mount);
  } else {
    mount();
  }
})();
