{{ $home        := site.BaseURL }}
{{ $logo        := site.Params.logos.navbar }}
{{ $social      := site.Params.social }}
{{ $github      := $social.github }}
{{ $discussions := $social.discussions }}
{{ $twitter     := printf "https://twitter.com/%s" $social.twitter }}
{{ $medium      := $social.medium }}
{{ $slack       := $social.slack }}
{{ $docsVersionBasePath := printf "%s" (delimit (first 3 (split .RelPermalink "/")) "/") }}
{{ $docsHome   := $.GetPage $docsVersionBasePath }}
{{ $allDocs     := where site.RegularPages "Section" "docs" }}
{{ $docs        := where $allDocs ".Params.kind" "eq" "documentation" }}
{{ $kubernetes  := where $allDocs ".Params.kind" "eq" "kubernetes" }}
{{ $envoy       := where $allDocs ".Params.kind" "eq" "envoy" }}
{{ $tutorials   := where $allDocs ".Params.kind" "eq" "tutorial" }}
{{ $operations  := where $allDocs ".Params.kind" "eq" "operations" }}
{{ $management  := where $allDocs ".Params.kind" "eq" "management" }}
{{ $contrib     := where $allDocs ".Params.kind" "eq" "contrib" }}
{{ $misc       := where (where $allDocs ".Params.kind" "eq" "misc") ".Title" "ne" "Ecosystem" }}
{{ $version     := index (split .File.Path "/") 1 }}
{{ $pageUrl     := .Permalink }}
<nav class="navbar is-primary">
  <div class="navbar-brand is-hidden-desktop">
    <a class="navbar-item" href="{{ $home }}">
      <img src="{{ $logo }}">
    </a>

    <a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="mobile-menu">
      <span aria-hidden="true"></span>
      <span aria-hidden="true"></span>
      <span aria-hidden="true"></span>
    </a>
  </div>

  <div class="navbar-menu is-hidden-desktop" id="mobile-menu">
    <div class="navbar-start">
      <span class="navbar-item is-size-5 has-text-weight-light is-uppercase">
        Core Docs
      </span>

      <a class="navbar-item" href="{{ $docsHome.Permalink }}">
        {{ $docsHome.Name }}
      </a>

      {{ range $docs }}
      {{ partial "docs/navbar-link.html" (dict "ctx" . "pageUrl" $pageUrl "version" $version) }}
      {{ end }}

      {{ partial "docs/navbar-section.html" ( dict "ctx" . "sectionTitle" "Kubernetes" "section" $kubernetes "pageUrl" $pageUrl "version" $version ) }}

      {{ partial "docs/navbar-section.html" ( dict "ctx" . "sectionTitle" "Envoy" "section" $envoy "pageUrl" $pageUrl "version" $version ) }}

      {{ partial "docs/navbar-section.html" ( dict "ctx" . "sectionTitle" "Other Use Cases" "section" $tutorials "pageUrl" $pageUrl "version" $version ) }}

      {{ partial "docs/navbar-section.html" ( dict "ctx" . "sectionTitle" "Operations" "section" $operations "pageUrl" $pageUrl "version" $version ) }}

      {{ partial "docs/navbar-section.html" ( dict "ctx" . "sectionTitle" "Management APIs" "section" $management "pageUrl" $pageUrl "version" $version ) }}

      {{ partial "docs/navbar-section.html" ( dict "ctx" . "sectionTitle" "Contributing" "section" $contrib "pageUrl" $pageUrl "version" $version ) }}

      {{ partial "docs/navbar-section.html" ( dict "ctx" . "sectionTitle" "Miscellaneous" "section" $misc "pageUrl" $pageUrl "version" $version ) }}

      <br />

      <span class="navbar-item is-size-5 has-text-weight-light is-uppercase">
        Support
      </span>
      <a class="navbar-item" href="/support">
        Enterprise
      </a>
      <a class="navbar-item" href="/community">
        Community
      </a>
      <a class="navbar-item" href="/ecosystem">
        OPA Ecosystem
      </a>
    </div>

    <div class="navbar-end">
      <div class="navbar-item">
        <div class="buttons">
          <a class="button is-primary" href="{{ $github }}" target="_blank">
            <span class="icon has-text-white-bis">
              <i class="fab fa-github"></i>
            </span>
          </a>

          <a class="button is-primary" href="{{ $discussions }}" target="_blank">
            <span class="icon has-text-white-bis">
              <i class="fas fa-comments"></i>
            </span>
          </a>

          <a class="button is-primary" href="{{ $twitter }}" target="_blank">
            <span class="icon has-text-white-bis">
              <i class="fab fa-twitter"></i>
            </span>
          </a>

          <a class="button is-primary" href="{{ $medium }}" target="_blank">
            <span class="icon has-text-white-bis">
              <i class="fab fa-medium"></i>
            </span>
          </a>

          <a class="button is-primary" href="{{ $slack }}" target="_blank">
            <span class="icon has-text-white-bis">
              <i class="fab fa-slack"></i>
            </span>
          </a>
        </div>
      </div>
    </div>
  </div>

  <div class="navbar-menu">
    <div class="navbar-end">
      <div class="navbar-item">
        <p class="control has-icons-right">
          <div id="docsearch">
          </div>
          <span class="icon is-small is-right">
            <icon />
          </span>
        </p>
      </div>

      <div class="navbar-item">
        <a class="button is-success has-text-weight-semibold" href="https://play.openpolicyagent.org/" target="_blank" title="Playground">
          Playground
        </a>
      </div>

      <a class="navbar-item" href="{{ $github }}" target="_blank" title="GitHub">
        <span class="icon has-text-white-bis">
          <i class="fab fa-github"></i>
        </span>
      </a>

      <a class="navbar-item" href="{{ $discussions }}" target="_blank" title="GitHub Discussions">
        <span class="icon has-text-white-bis">
          <i class="fas fa-comments"></i>
        </span>
      </a>

      <a class="navbar-item" href="{{ $twitter }}" target="_blank" title="Twitter">
        <span class="icon has-text-white-bis">
          <i class="fab fa-twitter"></i>
        </span>
      </a>

      <a class="navbar-item" href="{{ $medium }}" target="_blank" title="Medium">
        <span class="icon has-text-white-bis">
          <i class="fab fa-medium"></i>
        </span>
      </a>

      <a class="navbar-item" href="{{ $slack }}" target="_blank" title="Slack">
        <span class="icon has-text-white-bis">
          <i class="fab fa-slack"></i>
        </span>
      </a>
    </div>
  </div>
</nav>