{{ define "document.gohtml" }}{{ template "base" . }}{{ end }}

{{ define "document_content" }}
<section class="workspace-shell workspace-shell--document">
  {{ template "browser" .Browser }}
  <article class="document-shell" data-document-path="{{ .Path }}" data-document-hash="{{ .Hash }}">
    <nav class="breadcrumbs" aria-label="Breadcrumb">
      <ol>
        {{ $lastIdx := sub (len .Breadcrumbs) 1 }}
        {{ range $i, $crumb := .Breadcrumbs }}
          <li>
            {{ if eq $i $lastIdx }}
              <span aria-current="page">{{ $crumb.Name }}</span>
            {{ else }}
              <a href="{{ $crumb.URL }}">{{ $crumb.Name }}</a>
            {{ end }}
          </li>
        {{ end }}
      </ol>
    </nav>
    <div class="document-meta">
      <div class="document-meta__header">
        <h1>{{ .Title }}</h1>
        <a class="document-edit-link" href="/docs/{{ trimMd .Path }}/edit">Edit</a>
      </div>
      <details class="document-meta-panel">
        <summary>
          <span>Document details</span>
        </summary>
        <dl class="meta-grid">
          <div>
            <dt>File</dt>
            <dd><code>{{ .Path }}</code></dd>
          </div>
          <div>
            <dt>Hash</dt>
            <dd><code>{{ .Hash }}</code></dd>
          </div>
          {{ if .Tags }}
            <div>
              <dt>Tags</dt>
              <dd>
                <ul class="tag-list">
                  {{ range .Tags }}
                    <li><a href="/?tag={{ . }}">#{{ . }}</a></li>
                  {{ end }}
                </ul>
              </dd>
            </div>
          {{ end }}
        </dl>
      </details>
    </div>

    <div class="markdown-body">
      {{ .HTML }}
    </div>
  </article>
</section>
{{ end }}

{{ define "browser" }}
<nav class="miller-browser" aria-label="Documents">
  {{ range .Columns }}
    <section class="miller-column {{ if eq .Title "Content" }}miller-column--root{{ end }}" aria-label="{{ .Title }}">
      <h2 title="{{ .Title }}">
        {{ if eq .Title "Content" }}
          {{ template "icon-library" }}
        {{ end }}
        <span class="miller-column-title-text">{{ .Title }}</span>
      </h2>
      <ul>
        {{ range .Items }}
          <li>
            <a class="{{ if .Active }}is-active{{ end }} {{ if .IsFolder }}is-folder{{ end }}" href="{{ .URL }}" title="{{ .Name }}">
              <span class="browser-item-label">
                {{ if .IsFolder }}{{ template "icon-folder" }}{{ else }}{{ template "icon-file-text" }}{{ end }}
                <span class="browser-item-name">{{ .Name }}</span>
              </span>
              {{ if .IsFolder }}{{ template "icon-chevron-right" }}{{ end }}
            </a>
          </li>
        {{ end }}
      </ul>
    </section>
  {{ end }}
</nav>
{{ end }}

{{ define "icon-folder" }}
<svg class="browser-icon browser-icon--folder" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round">
  <path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.7-.9l-.8-1.2A2 2 0 0 0 7.9 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"></path>
</svg>
{{ end }}

{{ define "icon-file-text" }}
<svg class="browser-icon browser-icon--page" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round">
  <path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"></path>
  <path d="M14 2v4a2 2 0 0 0 2 2h4"></path>
  <path d="M10 9H8"></path>
  <path d="M16 13H8"></path>
  <path d="M16 17H8"></path>
</svg>
{{ end }}

{{ define "icon-library" }}
<svg class="browser-icon browser-icon--root" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round">
  <path d="m16 6 4 14"></path>
  <path d="M12 6v14"></path>
  <path d="M8 8v12"></path>
  <path d="M4 4v16"></path>
</svg>
{{ end }}

{{ define "icon-chevron-right" }}
<svg class="browser-item-chevron" aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.1" stroke-linecap="round" stroke-linejoin="round">
  <path d="m9 18 6-6-6-6"></path>
</svg>
{{ end }}
