{{define "headScripts"}}<script src="/_/search/actions.js"></script>{{end}}

{{define "searchQuery"}}{{.Query}}{{end}}

{{define "content"}}
{{if .Query}}
    {{if .Exact}}
    <h2 class="search-section">Exact Match</h2>
    {{range .Exact}}
    <article class="search-card">
        <a href="{{.URL}}">{{.Name}}</a>
        <div class="muted">/{{.Path}}</div>
    </article>
    {{end}}
    {{else}}
    <p class="muted">No page named &ldquo;{{.Query}}&rdquo; — <button class="btn btn-small" data-create-page="{{.Query}}">create it</button></p>
    {{end}}
    {{if .Pages}}
    <h2 class="search-section">Matching Pages <span class="muted">{{.PageTotal}}</span></h2>
    {{range .Pages}}
    <article class="search-card">
        <a href="{{.URL}}">{{.Name}}</a>
        <div class="muted">/{{.Path}}</div>
    </article>
    {{end}}
    {{end}}
    {{if .Files}}
    <h2 class="search-section">Matching Files <span class="muted">{{.FileTotal}}</span></h2>
    {{range .Files}}
    <article class="search-card">
        <div class="row">
            {{fileIcon .Name}}
            <a href="{{.URL}}">{{.Name}}</a>
            <button class="btn btn-small" data-companion-file-reveal="{{.Path}}" hidden title="Open location in file manager">open</button>
        </div>
        <div class="muted">/{{.Path}} · {{.Meta}}</div>
    </article>
    {{end}}
    {{end}}
{{else}}
<p class="empty">Enter a query above.</p>
{{end}}
{{end}}

{{define "footerExtras"}}
{{if not .IndexBuiltAt.IsZero}}<span class="muted">· Index: {{.IndexBuiltAt.Format "2006-01-02 15:04"}}</span>{{end}}
{{end}}

{{define "extras"}}
<div class="fab dropdown">
    <button class="btn btn-fab" data-action="actions-drop" title="Actions" aria-label="Actions">≡</button>
    <div class="dropdown-menu align-right open-up">
        <button class="btn btn-block" onclick="rebuildIndex()" title="Rebuild search index">REBUILD INDEX</button>
    </div>
</div>
{{end}}
