{{if .Tree}}
{{if .Tree.Children}}
    {{template "tree-node" .Tree}}
{{else}}
    <p style="color: var(--text-muted); font-size: 0.85rem;">Aucune note trouvée.</p>
{{end}}
{{else}}
    <p style="color: var(--text-muted); font-size: 0.85rem;">Aucune note trouvée.</p>
{{end}}

{{define "tree-node"}}
    {{range .Children}}
        {{if .IsDir}}
            <div class="folder-item" data-path="{{.Path}}" data-is-dir="true">
                <div class="folder-header">
                    <span class="folder-toggle">▶</span>
                    <span class="folder-icon">📁</span>
                    <span class="folder-name">{{.Name}}</span>
                </div>
                <div class="folder-children" style="display: none;">
                    {{if .Children}}
                        {{template "tree-node" .}}
                    {{end}}
                </div>
            </div>
        {{else}}
            <a href="#"
               class="file-item"
               data-path="{{.Path}}"
               data-is-dir="false"
               hx-get="/api/notes/{{.Path}}"
               hx-target="#editor-container"
               hx-swap="innerHTML"
               draggable="true">
               📄 {{.Name}}
            </a>
        {{end}}
    {{end}}
{{end}}