<section id="folders-list" class="mb-12"
            hx-trigger="folder-list-invalidated from:body"
            hx-include="[name=filter], [name=show_hidden]"
            hx-get="/api/folders"
            hx-swap="outerHTML settle:300ms" >
    {% if current_user.imap_config %}
        <div class="mb-8 grid grid-cols-1 md:grid-cols-4 gap-4">
            <div class="card bg-base-100 shadow-md border border-base-300 p-4">
                <div class="text-2xl font-bold text-primary">{{ folders|length }}</div>
                <div class="text-sm text-base-content/70">Total Folders</div>
            </div>
            <div class="card bg-base-100 shadow-md border border-base-300 p-4">
                <div class="text-2xl font-bold text-warning">{{ folders|selectattr('folder_type', 'equalto', 'tidy')|list|length }}</div>
                <div class="text-sm text-base-content/70">Folders to Tidy</div>
            </div>
            <div class="card bg-base-100 shadow-md border border-base-300 p-4">
                <div class="text-2xl font-bold text-secondary">{{ folders|selectattr('folder_type', 'equalto', 'destination')|list|length }}</div>
                <div class="text-sm text-base-content/70">Destination Folders</div>
            </div>
            <div class="card bg-base-100 shadow-md border border-base-300 p-4">
                <div class="text-2xl font-bold text-info">
                    {{ folders|selectattr('folder_type', 'equalto', 'tidy')|sum(attribute='pending_count') }}
                </div>
                <div class="text-sm text-base-content/70">Pending Emails</div>
            </div>
        </div>

        <!-- Search and Filter -->
        <div class="mb-6 flex justify-between items-center">
            <div class="flex items-center space-x-4">
                <div class="relative w-64">
                    <input type="text" placeholder="Search folders..." class="input input-bordered w-full pr-10">
                    <i class="fas fa-search absolute right-3 top-3 text-base-content/50"></i>
                </div>
                <div class="flex items-center space-x-2">
                    <input type="checkbox" id="show-hidden" 
                    {% if show_hidden %} checked="checked" {% endif %}
                    name="show_hidden"
                    @change="$dispatch('folder-list-invalidated')"
                    class="toggle">
                    <label for="show-hidden" class="label-text cursor-pointer">Show Hidden</label>
                </div>
            </div>
            <div class="flex space-x-2" x-data="{filter: ''}" x-effect="filter; $nextTick(() => $dispatch('folder-list-invalidated'))">
                <input type="hidden" name="filter" id="filter-choice" x-model="filter">
                <button class="btn btn-sm btn-outline" @click="filter=''">All</button>
                <button class="btn btn-sm btn-outline" @click="filter='high'">High Priority</button>
                <button class="btn btn-sm btn-outline" @click="filter='normal'">Normal</button>
            </div>
        </div>
                
        {% include 'partials/folders_to_tidy_section.html' %}
        {% include 'partials/destination_folders_section.html' %}
        {% if show_hidden %}
        {% include 'partials/hidden_folders_section.html' %}
        {% endif %}
    {% endif %}
</section>