{{ $pages := .pages }}
{{ $parent := .parent }}
{{ $current := .current }}
{{ $collapse := .collapse }}

<ul class="tree{{ if $collapse }} collapse{{ end }}">
    {{ range $pages }}
        {{ if eq .Parent $parent }}
            {{ if not .IsPage }}
                <li class="sublist">
                    {{ $collapse := not (.IsAncestor $current) }}

                    <label class='tree-toggle'>
                        {{- if $collapse -}}
                            <i class="chevron">{{- partial "icon.html" "right-chevron" -}}</i><i class="chevron d-none">{{- partial "icon.html" "down-chevron" -}}</i>
                        {{- else -}}
                            <i class="chevron d-none">{{- partial "icon.html" "right-chevron" -}}</i><i class="chevron">{{- partial "icon.html" "down-chevron" -}}</i>
                        {{- end -}}
                        <a {{ if eq $current.Permalink .Permalink }}class="current"{{ end }} title="{{ .Description }}" href="{{ .Permalink }}">{{ .LinkTitle}}</a>
                    </label>

                    {{ partial "sidebar-level.html" (dict "pages" $pages "parent" . "current" $current "collapse" $collapse) }}
                </li>
            {{ else }}
                <li>
                    {{ if eq $current.Permalink .Permalink }}
                        <span class="current" title="{{ .Description }}">{{ .LinkTitle }}</span>
                    {{ else }}
                        <a title="{{ .Description }}" href="{{ .Permalink }}">{{ .LinkTitle }}</a>
                    {{ end }}
                </li>
             {{ end }}
        {{ end }}
    {{ end }}
</ul>
