const CLEARNET_HOST = "jetpham.com";
const ONION_HOST =
  "jet7tetd43snvjx3ng5jrhuwm2yhyp76tjtct5mtofg64apokcgq7fqd.onion";
const REPO_URL = "https://git.extremist.software/jet/website";

function isOnionHost(hostname: string): boolean {
  return hostname.endsWith(".onion");
}

function getMirrorLink() {
  if (isOnionHost(location.hostname)) {
    return {
      href: `https://${CLEARNET_HOST}`,
      label: "clearnet",
    };
  }

  return {
    href: `http://${ONION_HOST}`,
    label: ".onion",
  };
}

export function renderFooter() {
  const footer = document.getElementById("site-footer");
  if (!footer) return;

  const mirror = getMirrorLink();

  footer.innerHTML = `
    <div class="site-panel-frame px-[2ch] py-[1ch]">
      <div class="site-panel-frost" aria-hidden="true"></div>
      <div class="site-panel-border" aria-hidden="true"></div>
      <div class="site-panel-content site-footer-inner">
        <a href="${REPO_URL}">src</a>
        <span aria-hidden="true">|</span>
        <a href="/qa/rss.xml" data-native-link>rss</a>
        <span aria-hidden="true">|</span>
        <a href="/pgp.txt" data-native-link>pgp</a>
        <span aria-hidden="true">|</span>
        <a href="/ssh.txt" data-native-link>ssh</a>
        <span aria-hidden="true">|</span>
        <a href="${mirror.href}">${mirror.label}</a>
      </div>
    </div>`;
}
