---
import '../styles/global.css';
import Search from '../components/Search.astro';
import ThemeSwitcher from '../components/ThemeSwitcher.astro';
import ThemeSwitcher_CSSOnly from '../components/ThemeSwitcher@CSSOnly.astro';
import BackToTop from "../components/BackToTop.astro";
import Meta from "../components/helper/head/Meta.astro";

import { siteConfig } from "../config";
import Statistics from "../components/Statistics.astro";
import Navbar from "../components/Navbar.astro";

interface Props {
  title?: string;
  description?: string;
  author?: string;
  path?: string;
  ogImage?: string;
}

import { ClientRouter } from "astro:transitions";
import PoweredBy from "../components/PoweredBy.astro";
const spaEnabled = siteConfig.spa

const noscript = siteConfig.noClientJavaScript

const statisticsEnabled = siteConfig.siteAnalytics.enabled

const defaultTitle = siteConfig.title
const formattedRootPath = defaultTitle.toLowerCase().replace(/\s+/g, '-');
const relativePath = Astro.url.pathname
const path = formattedRootPath + (relativePath === '/' ? '' : relativePath)

const pageTitle = (relativePath === '/' ? defaultTitle : `${Astro.props.title} - ${defaultTitle}`)

const customFooter = siteConfig.customFooter
const nekoType = siteConfig.neko?.type

const { title = pageTitle, author = siteConfig.defaultAuthor.name,description = siteConfig.description, ogImage = "" } = Astro.props;
---

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width" />
    <meta name="generator" content={Astro.generator} />
    <Meta title={pageTitle} author={author} description={description} ogImage={ogImage} />
    <title>{pageTitle}</title>
    {spaEnabled && <ClientRouter fallback="animate" />}
    <!--transitional animation is broken in firefox though-->
  </head>
  <body class="container">
        {noscript && <div id="top" style="visibility: hidden">Back To Top</div>}
        <header>
              <div class="terminal-path">
                {path}
              </div>
              <Navbar />
              <Search />
        </header>
        <main class="content-box">
              <slot />
        </main>

      <footer class="footer">
        <div class="floating">
          <BackToTop/>
          {noscript ? <ThemeSwitcher_CSSOnly/> : <ThemeSwitcher/>}
        </div>
        <div class="container">
          <Fragment set:html={customFooter} />
          <PoweredBy />
        </div>
      </footer>
    {statisticsEnabled && <Statistics/>}
    { (siteConfig.neko.enabled && !noscript) &&
      <>
        <script is:inline define:vars={{ nekoType }}>
          window.NekoType = nekoType;
        </script>
        <script is:inline src="https://webneko.net/n20171213.js"></script>
      </>
    }
  </body>
</html>