{# Card widget template #}
<style>
.card-link-pop {
  transition: all 0.2s ease-in-out;
  text-decoration: none;
  color: inherit;
  display: block;
  height: 100%;
}
.card-link-pop:hover {
  transform: translateY(-4px);
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.15) !important;
  text-decoration: none;
  color: inherit;
}
.card-link-pop:focus {
  text-decoration: none;
  color: inherit;
}
.card-progress {
  height: 0.25rem;
  border-radius: 0;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
}
.card-link-pop .card-body {
  padding-bottom: 1.5rem;
}
.card-link-pop {
  position: relative;
  overflow: hidden;
}
.card-link-pop .h1 {
  font-size: 2.5rem;
  font-weight: 300;
  line-height: 1;
}
.card-link-pop .subheader {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.6;
  color: #626976;
}
</style>

{% macro render_card(widget) %}

    {% if widget.url %}
        <a href="{{ widget.url }}" class="{{ widget.css_classes }}" id="{{ widget.widget_id }}">
    {% else %}
        <div class="{{ widget.css_classes }}" id="{{ widget.widget_id }}">
    {% endif %}

        {% if widget.image_url and widget.image_position == "top" %}
            <img src="{{ widget.image_url }}" class="card-img-top" alt="{{ widget.title or 'Card image' }}">
        {% endif %}

        {% if widget.header %}
            <div class="card-header">
                {{ widget.header | safe }}
            </div>
        {% endif %}

        <div class="card-body">
            {% if widget.subheader or widget.icon %}
                <div class="d-flex align-items-center mb-3">
                    {% if widget.subheader %}
                        <div class="subheader">{{ widget.subheader }}</div>
                    {% endif %}
                    {% if widget.icon %}
                        <div class="ms-auto">
                            {% if widget.icon.startswith('<svg') %}
                                {{ widget.icon | safe }}
                            {% else %}
                                <i class="icon {{ widget.icon }}"></i>
                            {% endif %}
                        </div>
                    {% endif %}
                </div>
            {% endif %}

            {% if widget.title %}
                <h5 class="card-title">{{ widget.title }}</h5>
            {% endif %}

            {% if widget.value is not none %}
                <div class="h1 mb-1"{% if widget.value_id %} id="{{ widget.value_id }}"{% endif %}>{{ widget.value }}</div>
            {% endif %}

            {% if widget.content %}
                <div class="card-text text-muted small">
                    {{ widget.content | safe }}
                </div>
            {% endif %}

            {% if widget.links %}
                <div class="card-links mt-3">
                    {% for link in widget.links %}
                        <a href="{{ link.url }}" class="btn btn-{{ link.type|default('primary') }} btn-sm">
                            {{ link.text }}
                        </a>
                    {% endfor %}
                </div>
            {% endif %}
        </div>

        {% if widget.image_url and widget.image_position == "bottom" %}
            <img src="{{ widget.image_url }}" class="card-img-bottom" alt="{{ widget.title or 'Card image' }}">
        {% endif %}

        {% if widget.progress is not none %}
            <div class="progress progress-sm card-progress">
                <div class="progress-bar bg-{{ widget.progress_color|default('blue') }}"
                     style="width: {{ widget.progress }}%"
                     role="progressbar"
                     aria-valuenow="{{ widget.progress }}"
                     aria-valuemin="0"
                     aria-valuemax="100"></div>
            </div>
        {% endif %}

        {% if widget.footer %}
            <div class="card-footer">
                {{ widget.footer | safe }}
            </div>
        {% endif %}

    {% if widget.url %}
        </a>
    {% else %}
        </div>
    {% endif %}
{% endmacro %}
