{% macro library_toolbar(title, category,
                          create_url=none, create_label=none,
                          has_batch_gen=true, has_regen_all=true,
                          has_lora_create=false, bulk_create_url=none,
                          has_tags=true, regen_tags_category=none,
                          rescan_url=none,
                          get_missing_url=none, clear_covers_url=none,
                          generate_url_pattern=none) %}
<div class="d-flex justify-content-between align-items-center mb-4"
     data-toolbar-category="{{ category }}"
     {% if get_missing_url %}data-get-missing-url="{{ get_missing_url }}"{% endif %}
     {% if clear_covers_url %}data-clear-covers-url="{{ clear_covers_url }}"{% endif %}
     {% if generate_url_pattern %}data-generate-url="{{ generate_url_pattern }}"{% endif %}
     {% if regen_tags_category %}data-regen-tags-category="{{ regen_tags_category }}"{% endif %}
     {% if bulk_create_url %}data-bulk-create-url="{{ bulk_create_url }}"{% endif %}>
    <h2>{{ title }} Library</h2>
    <div class="d-flex gap-2 align-items-center">
        {% if create_url %}
        <a href="{{ create_url }}" class="btn btn-sm btn-success">+ {{ create_label or title }}</a>
        {% endif %}

        <div class="dropdown">
            <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button"
                    data-bs-toggle="dropdown" aria-expanded="false">
                Actions
            </button>
            <ul class="dropdown-menu dropdown-menu-end">
                {% if has_batch_gen %}
                <li><button class="dropdown-item" id="batch-generate-btn" data-requires="comfyui">
                    Generate Missing Covers
                </button></li>
                {% endif %}
                {% if has_regen_all %}
                <li><button class="dropdown-item text-danger" id="regenerate-all-btn" data-requires="comfyui">
                    Regenerate All Covers
                </button></li>
                {% endif %}

                {% if (has_batch_gen or has_regen_all) and (has_tags or has_lora_create) %}
                <li><hr class="dropdown-divider"></li>
                {% endif %}

                {% if has_tags %}
                <li><button class="dropdown-item" id="regen-tags-all-btn" data-requires="llm">
                    Regenerate Tags (LLM)
                </button></li>
                {% endif %}

                {% if has_lora_create %}
                <li><button class="dropdown-item" id="bulk-create-btn" data-requires="llm">
                    Create from LoRAs (LLM)
                </button></li>
                <li><button class="dropdown-item text-danger" id="bulk-overwrite-btn" data-requires="llm">
                    Overwrite All from LoRAs (LLM)
                </button></li>
                {% endif %}

                {% if rescan_url %}
                <li><hr class="dropdown-divider"></li>
                <li>
                    <form action="{{ rescan_url }}" method="post" class="d-contents">
                        <button type="submit" class="dropdown-item">Rescan from Disk</button>
                    </form>
                </li>
                {% endif %}
            </ul>
        </div>
    </div>
</div>
{% endmacro %}
