{% extends 'base.html' %}

{% block title %}Consent Renewal{% endblock %}
{% block content_title %}Consent Renewal{% endblock %}
{% block content_description %}Renew consents that require attention{% endblock %}

{% block content %}
<div class="container">
  {% if statuses and statuses|length > 0 %}
    <div class="alert alert-warning">Some consents need renewal. Please review and accept the latest version.</div>
    <div class="row">
      {% for s in statuses %}
        <div class="col-12 col-md-6 mb-4">
          <div class="card h-100">
            <div class="card-body">
              <h5 class="card-title">{{ s.consent_type }}</h5>
              <p class="card-text">
                Status: <span class="badge {% if s.status == 'RENEWAL_REQUIRED' %}bg-warning text-dark{% else %}bg-danger{% endif %}">{{ s.status }}</span>
              </p>
              <p class="card-text small text-muted">Active version: {{ s.active_version or 'n/a' }}, Last accepted: {{ s.last_version or 'n/a' }}</p>
              <div class="d-flex gap-2">
                <button type="button" class="btn btn-outline-secondary btn-view-consent"
                        data-consent-type="{{ s.consent_type }}" data-version="{{ s.active_version }}"
                        data-url="{{ prefixed_url_for('user_bp.view_consent_markdown', consent_type=s.consent_type, version=s.active_version) }}"
                        {% if not s.active_version %}disabled{% endif %}>
                  Bekijk document
                </button>
                <form method="post" action="{{ prefixed_url_for('user_bp.accept_tenant_consent', tenant_id=tenant_id, consent_type=s.consent_type) }}">
                  <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                  <button type="submit" class="btn btn-primary">Renew and accept</button>
                </form>
              </div>
            </div>
          </div>
        </div>
      {% endfor %}
    </div>
  {% else %}
    <div class="alert alert-success">All consents are up to date.</div>
  {% endif %}

  <!-- Consent document viewer moved into main content -->
  <div class="container mt-4" id="consent-viewer-section" style="display:none;">
    <div class="card">
      <div class="card-header d-flex justify-content-between align-items-center">
        <div>
          <strong>Document viewer:</strong>
          <span id="viewer-type"></span>
          <span class="text-muted">version</span>
          <span id="viewer-version"></span>
        </div>
        <div id="viewer-loading" class="text-muted" style="display:none;">Loading...</div>
      </div>
      <div class="card-body">
        <div id="consent-document-viewer" class="markdown-body"></div>
      </div>
    </div>
  </div>
</div>
{% endblock %}
