{{ $pageProseLang := partial "i18n/lang.html" . -}}
{{ $siteLang := .Site.Language -}}

{{ if ne .Language.Lang "en" -}}
  {{ if .Params.drifted_from_default -}}
    {{ with partial "_inline/ot-page-drifted-banner.html" . -}}
      {{ . -}}
    {{ end -}}
  {{ else if ne $siteLang $pageProseLang -}}
    {{ with partial "_inline/ot-page-not-found-banner.html" . -}}
    <div class="pageinfo pageinfo-secondary">
      <div class="ps-4">
        {{ . }}
      </div>
    </div>
    {{ end -}}
  {{ else if false -}}
    {{ with partial "_inline/ot-page-drifted-banner.html" . -}}
      {{ . -}}
    {{ end -}}
  {{ end -}}
{{ end -}}


{{ define "partials/_inline/ot-page-drifted-banner.html" }}
  {{/* Assumption: .Params.drifted_from_default */ -}}

  {{ $resultsArray := where .Translations "Lang" "en" -}}
  {{ $defaultLangPage := index $resultsArray 0 -}}

  <div class="pageinfo pageinfo-secondary">
    <div class="ps-4">
      <p>
        <i class="fa-solid fa-triangle-exclamation" style="margin-left: -1.9rem; padding-right: 0.5rem;"></i>
        The content of this page may be <b>outdated</b> and some links may be invalid.

        {{- if and $defaultLangPage .Params.default_lang_commit }}
          A <strong>newer version</strong> of this page exists in
          <a href="{{ $defaultLangPage.RelPermalink }}">English</a>.
          <details class="mt-2">
            <summary>More information ...</summary>
            <p>
              To see the changes to the English page since this page was last updated: visit
              {{ $compareUrl := printf "%s/compare/%s..%s"
                  .Site.Params.github_repo .Params.default_lang_commit $defaultLangPage.GitInfo.Hash -}}
              <a href="{{ $compareUrl }}" class="external-link" target="_blank" rel="noopener" data-proofer-ignore>
                GitHub compare
                {{ substr .Params.default_lang_commit 0 8 }}..{{ $defaultLangPage.GitInfo.AbbreviatedHash -}}
              </a>
              and search for
              {{ $defLangPath := strings.TrimPrefix (add hugo.WorkingDir "/") $defaultLangPage.File.Filename -}}
              <code>{{ $defLangPath }}</code>.
            </p>
          </details>
        {{ else if not $defaultLangPage }}
          This page no longer has a corresponding English page.
        {{ end -}}
      </p>
    </div>
</div>
{{ end -}}


{{ define "partials/_inline/ot-page-not-found-banner.html" }}
  {{ $path := "page-not-translated-msg.md" -}}
  {{ $args := (dict
      "path" $path
      "page" .Page) -}}
  {{ $page := partial "func/find-include.html" $args -}}
  {{ with $page -}}
    {{ .Content }}
  {{ else -}}
    {{ $lang := .Page.Language.Lang -}}
    {{ warnf "_inline/ot-page-not-found-banner: '%s' not found from page %s (%s)" $path .Page.Path $lang -}}
  {{ end -}}
{{ end -}}
