{% macro render_card_header(widget) %}
    {% if widget.title and widget.hide_header == False %}
        <div class="card-header d-flex justify-content-between align-items-center pt-1 pb-1 {{ widget.title_css_class }}">
            <h3 class="card-title">
                <i class="{{ widget.title_icon }}"></i>
                {{ widget.title }}
            </h3>
            <div>
                {% if widget.header_links %}
                    {% for button in header_links %}
                        {% if button.type == "error" %}
                            <span class="badge bg-danger" data-bs-toggle="tooltip"
                                  data-bs-original-title="{{ button.message }}"><i class="ti ti-alert-circle"></i> Render Error
                            </span>
                        {% else %}
                            {{ render_button(button) }}
                        {% endif %}
                    {% endfor %}
                {% endif %}
                <button
                        class="btn-icon-collapse"
                        type="button"
                        data-bs-toggle="collapse"
                        data-bs-target="#collapse-{{ widget.widget_id }}"
                        aria-expanded="{% if not collapsed %}true{% else %}false{% endif %}"
                        aria-controls="collapse-{{ widget.widget_id }}"
                >
                    <i class="ti ti-chevron-{{ 'down' if widget.collapsed else 'up' }}"></i>
                </button>
            </div>
        </div>
    {% endif %}
{% endmacro %}
