{# templates/file_access.html #}
{% extends 'base.html' %}

{# page title #}
{% block title %}Dateizugriffe{% endblock %}

{# page content #}
{% block content %}

    <!-- Main Container -->
    <div class="container">
      <h2>Top 20 Dateizugriffe</h2>

      <!-- Dropdown Controls -->
      <div class="mb-4 d-flex flex-wrap gap-2">
        <!-- Timeframe Dropdown -->
        <div class="dropdown">
          <button class="btn btn-secondary dropdown-toggle" 
                  type="button" id="timeframeDropdown" data-bs-toggle="dropdown" aria-expanded="false">
            {% if session['timeframe'] == 'last24hours' %}
              Last 24 Hours
            {% elif session['timeframe'] == '7days' %}
              Last 7 Days
            {% elif session['timeframe'] == '14days' %}
              Last 14 Days
            {% elif session['timeframe'] == '30days' %}
              Last 30 Days
            {% elif session['timeframe'] == '365days' %}
              Last 365 Days
            {% else %}
              Select Timeframe
            {% endif %}
          </button>
          <ul class="dropdown-menu" aria-labelledby="timeframeDropdown">
            <li>
              <a class="dropdown-item {% if session['timeframe'] == 'last24hours' %}active{% endif %}" 
                href="{{ url_for('file_access', timeframe='last24hours') }}">
                Last 24 Hours
              </a>
            </li>
            <li>
              <a class="dropdown-item {% if session['timeframe'] == '7days' %}active{% endif %}" 
                href="{{ url_for('file_access', timeframe='7days') }}">
                Last 7 Days
              </a>
            </li>
            <li>
              <a class="dropdown-item {% if session['timeframe'] == '14days' %}active{% endif %}" 
                href="{{ url_for('file_access', timeframe='14days') }}">
                Last 14 Days
              </a>
            </li>
            <li>
              <a class="dropdown-item {% if session['timeframe'] == '30days' %}active{% endif %}" 
                href="{{ url_for('file_access', timeframe='30days') }}">
                Last 30 Days
              </a>
            </li>
            <li>
              <a class="dropdown-item {% if session['timeframe'] == '365days' %}active{% endif %}" 
                href="{{ url_for('file_access', timeframe='365days') }}">
                Last 365 Days
              </a>
            </li>
          </ul>
        </div>
      </div>


      <!-- Detailed Table of Top File Accesses -->
      {% for top20_item in top20 %}
      <div class="card mb-4">
        <div class="card-header d-flex justify-content-between align-items-center">
          <span>{{ top20_item['category'] }}</span>
          <span class="toggle-icon" aria-label="collapse" role="button" tabindex="0">+</span>
        </div>
        <div class="card-body collapsable">
          <div class="table-responsive">
            <table class="table table-striped">
              <thead>
                <tr>
                  <th>Access Count</th>
                  <th>File Path</th>
                </tr>
              </thead>
              <tbody>
                {% for row in top20_item['files'] %}
                <tr>
                  <td>{{ row.access_count }}</td>
                  <td>{{ row.rel_path }}</td>
                </tr>
                {% else %}
                <tr>
                  <td colspan="2">No data available for the selected timeframe.</td>
                </tr>
                {% endfor %}
              </tbody>
            </table>
          </div>
        </div>
      </div>
      {% endfor %}
    </div>
{% endblock %}
    

