{{ template "document.html" . }}

{{ define "document-title" }}{{ .Page.Title }}{{ end }}

{{ define "document-head-before" }}
<script>
    const pageData = {
        slug: "{{ .Page.Slug }}",
        baseURL: "{{ .App.Config.Server.BaseURL }}",
    };
</script>
{{ end }}

{{ define "document-root-attrs" }}class="{{ if .App.Config.Theme.Light }}light-scheme {{ end }}{{ if ne "" .Page.Width }}page-width-{{ .Page.Width }} {{ end }}{{ if .Page.CenterVertically }}page-center-vertically{{ end }}"{{ end }}

{{ define "document-head-after" }}
{{ .App.ParsedThemeStyle }}

{{ if ne "" .App.Config.Theme.CustomCSSFile }}
<link rel="stylesheet" href="{{ .App.Config.Theme.CustomCSSFile }}?v={{ .App.Config.Server.StartedAt.Unix }}">
{{ end }}

{{ if ne "" .App.Config.Document.Head }}{{ .App.Config.Document.Head }}{{ end }}
{{ end }}

{{ define "navigation-links" }}
{{ range .App.Config.Pages }}
<a href="{{ $.App.Config.Server.BaseURL }}/{{ .Slug }}" class="nav-item{{ if eq .Slug $.Page.Slug }} nav-item-current{{ end }}"{{ if eq .Slug $.Page.Slug }} aria-current="page"{{ end }}>{{ .Title }}</a>
{{ end }}
{{ end }}

{{ define "document-body" }}
<div class="flex flex-column body-content">
    {{ if not .Page.HideDesktopNavigation }}
    <div class="header-container content-bounds">
        <div class="header flex padding-inline-widget widget-content-frame">
            <!-- TODO: Replace G with actual logo, first need an actual logo -->
            <div class="logo" aria-hidden="true">{{ if ne "" .App.Config.Branding.LogoURL }}<img src="{{ .App.Config.Branding.LogoURL }}" alt="">{{ else if ne "" .App.Config.Branding.LogoText }}{{ .App.Config.Branding.LogoText }}{{ else }}G{{ end }}</div>
            <nav class="nav flex grow">
                {{ template "navigation-links" . }}
            </nav>
        </div>
    </div>
    {{ end }}

    <div class="mobile-navigation">
        <div class="mobile-navigation-icons">
            <a class="mobile-navigation-label" href="#top">↑</a>
            {{ range $i, $column := .Page.Columns }}
            <label class="mobile-navigation-label"><input type="radio" class="mobile-navigation-input" name="column" value="{{ $i }}" autocomplete="off"{{ if eq $i $.Page.PrimaryColumnIndex }} checked{{ end }}><div class="mobile-navigation-pill"></div></label>
            {{ end }}
            <label class="mobile-navigation-label"><input type="checkbox" class="mobile-navigation-page-links-input" autocomplete="on"{{ if .Page.ExpandMobilePageNavigation }} checked{{ end }}><div class="hamburger-icon"></div></label>
        </div>
        <div class="mobile-navigation-page-links">
            {{ template "navigation-links" . }}
        </div>
    </div>

    <div class="content-bounds grow">
        <main class="page" id="page" aria-live="polite" aria-busy="true">
            <h1 class="visually-hidden">{{ .Page.Title }}</h1>
            <div class="page-content" id="page-content"></div>
            <div class="page-loading-container">
                <!-- TODO: add a bigger/better loading indicator -->
                 <div class="visually-hidden">Loading</div>
                <div class="loading-icon" aria-hidden="true"></div>
            </div>
        </main>
    </div>

    {{ if not .App.Config.Branding.HideFooter }}
    <footer class="footer flex items-center flex-column">
    {{ if eq "" .App.Config.Branding.CustomFooter }}
        <div>
            <a class="size-h3" href="https://github.com/glanceapp/glance" target="_blank" rel="noreferrer">Glance</a> {{ if ne "dev" .App.Version }}<a class="visited-indicator" title="Release notes" href="https://github.com/glanceapp/glance/releases/tag/{{ .App.Version }}" target="_blank" rel="noreferrer">{{ .App.Version }}</a>{{ else }}({{ .App.Version }}){{ end }}
        </div>
    {{ else }}
        {{ .App.Config.Branding.CustomFooter }}
    {{ end }}
    </footer>
    {{ end }}

    <div class="mobile-navigation-offset"></div>
</div>
{{ end }}
