<!--
  Accordion Macro - Easy accordion creation
  Usage: {% import "../includes/macros/accordion.html" as accordions %}
         {{ accordions.render(items, variant="", exclusive=false) }}
-->

{# Single accordion item #}
{% macro item(title, content, variant="", open=false, id="") %}
  <details class="{{ 'accordion--' + variant if variant }}"{{ ' open' if open }}{{ ' id="' + id + '"' if id }}>
    <summary>{{ title }}</summary>
    <div class="accordion-content">
      {{ content }}
    </div>
  </details>
{% endmacro %}

{# Accordion group #}
{% macro group(items, variant="", exclusive=false, class="") %}
  <div class="accordion-group{{ ' accordion--' + variant if variant }}{{ ' ' + class if class }}"{{ ' data-exclusive' if exclusive }}>
    {% for item in items %}
      <details{{ ' open' if item.open }}{{ ' id="' + item.id + '"' if item.id }}>
        <summary>{{ item.title|safe }}</summary>
        <div class="accordion-content">
          {{ item.content|safe }}
        </div>
      </details>
    {% endfor %}
  </div>
{% endmacro %}

{# FAQ Schema accordion group - SEO optimized #}
{% macro faq(items, variant="") %}
  <div class="accordion-group accordion-faq{{ ' accordion--' + variant if variant }}" itemscope itemtype="https://schema.org/FAQPage">
    {% for item in items %}
      <details itemscope itemtype="https://schema.org/Question"{{ ' open' if item.open }}>
        <summary itemprop="name">{{ item.question|safe }}</summary>
        <div class="accordion-content" itemscope itemtype="https://schema.org/Answer">
          <div itemprop="text">
            {{ item.answer|safe }}
          </div>
        </div>
      </details>
    {% endfor %}
  </div>
  
  {# Structured data for SEO #}
  <script type="application/ld+json">
  {
    "@context": "https://schema.org",
    "@type": "FAQPage",
    "mainEntity": [
      {% for item in items %}
      {
        "@type": "Question",
        "name": {{ item.question|tojson }},
        "acceptedAnswer": {
          "@type": "Answer",
          "text": {{ item.answer|striptags|tojson }}
        }
      }{% if not loop.last %},{% endif %}
      {% endfor %}
    ]
  }
  </script>
{% endmacro %}

{# Quick accordion for simple use #}
{% macro simple(title, content) %}
  <details>
    <summary>{{ title }}</summary>
    <div class="accordion-content">
      {{ content }}
    </div>
  </details>
{% endmacro %}