{# Section partial: Testimonials #}
{#
    Parameters:
    - testimonials: dict with enabled, title, subtitle, items
    - lang: Current language code
    - default_lang: Fallback language
#}

{% macro render_testimonials(testimonials, lang, default_lang) %}
{% if testimonials and testimonials.enabled %}
<section class="py-16 lg:py-24 bg-gray-50 dark:bg-gray-900">
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
        {# Section header #}
        <div class="text-center mb-12">
            {% set title = testimonials.title.translations.get(lang) or testimonials.title.translations.get(default_lang) or '' %}
            {% if title %}
            <h2 class="text-3xl md:text-4xl font-bold text-gray-900 dark:text-white mb-4">
                {{ title }}
            </h2>
            {% endif %}
        </div>

        {# Testimonial cards — use .get() to avoid dict.items() method collision with JSON dicts #}
        {% set testimonial_items = testimonials.get('items', []) if testimonials is mapping else [] %}
        {% if testimonial_items %}
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
            {% for item in testimonial_items %}
            <div class="bg-white dark:bg-gray-800 rounded-xl p-8 shadow-sm border border-gray-100 dark:border-gray-700">
                <div class="flex items-center mb-4">
                    <div class="flex text-yellow-400">
                        {% for _ in range(5) %}
                        <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20"><path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z"></path></svg>
                        {% endfor %}
                    </div>
                </div>
                {% set content = item.content %}
                {% if content is mapping %}
                    {% set content = content.translations.get(lang) or content.translations.get(default_lang) or '' %}
                {% endif %}
                <p class="text-gray-600 dark:text-gray-300 mb-6 italic">"{{ content }}"</p>
                <div class="flex items-center">
                    {% if item.avatar %}
                    <img src="{{ item.avatar }}" alt="" class="w-10 h-10 rounded-full mr-3">
                    {% else %}
                    <div class="w-10 h-10 rounded-full bg-purple-100 dark:bg-purple-900 flex items-center justify-center mr-3">
                        <span class="text-sm font-bold text-purple-600 dark:text-purple-300">
                            {% set author = item.author %}
                            {% if author is mapping %}{% set author = author.translations.get(lang) or author.translations.get(default_lang) or '?' %}{% endif %}
                            {{ author[0]|upper if author else '?' }}
                        </span>
                    </div>
                    {% endif %}
                    <div>
                        {% set author = item.author %}
                        {% if author is mapping %}{% set author = author.translations.get(lang) or author.translations.get(default_lang) or '' %}{% endif %}
                        <p class="text-sm font-semibold text-gray-900 dark:text-white">{{ author }}</p>
                        {% set role = item.role %}
                        {% if role is mapping %}{% set role = role.translations.get(lang) or role.translations.get(default_lang) or '' %}{% endif %}
                        {% if role %}
                        <p class="text-xs text-gray-500 dark:text-gray-400">{{ role }}</p>
                        {% endif %}
                    </div>
                </div>
            </div>
            {% endfor %}
        </div>
        {% else %}
        <p class="text-center text-gray-400 dark:text-gray-500">Coming soon</p>
        {% endif %}
    </div>
</section>
{% endif %}
{% endmacro %}
