{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Django Lumen — Excluded Apps</title>
  <link rel="stylesheet" href="{% static 'django_lumen/css/django_lumen.css' %}">
</head>
<body class="page-excluded-apps">
  <header>
    Django Lumen
    <a href="{% url 'django-lumen-diagram' %}">&larr; Back to diagram</a>
  </header>

  <div class="container">
    <div class="card">
      <h2>Excluded Apps</h2>
      <p class="subtitle">
        Checked apps are hidden from the diagram entirely.<br>
        Changes take effect after saving.
      </p>

      <form method="post">
        {% csrf_token %}
        <div class="app-list">
          {% for app in all_apps %}
            {% with is_excluded=app|lower %}
            <div class="app-row {% if app in excluded_apps %}checked{% endif %}" id="row-{{ forloop.counter }}">
              <input
                type="checkbox"
                name="excluded_apps"
                value="{{ app }}"
                id="app-{{ forloop.counter }}"
                {% if app in excluded_apps %}checked{% endif %}
              >
              <label for="app-{{ forloop.counter }}">{{ app }}</label>
            </div>
            {% endwith %}
          {% empty %}
            <p class="empty">No apps found.</p>
          {% endfor %}
        </div>

        <div class="actions">
          <a href="{% url 'django-lumen-diagram' %}" class="btn btn-secondary">Cancel</a>
          <button type="submit" class="btn btn-primary">Save</button>
        </div>
      </form>
    </div>
  </div>

  <script>
    // Toggle .checked class for visual feedback as checkboxes change.
    document.querySelectorAll('.app-row input[type="checkbox"]').forEach(cb => {
      cb.addEventListener('change', () => {
        cb.closest('.app-row').classList.toggle('checked', cb.checked);
      });
    });
  </script>
</body>
</html>
