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

{# page title #}
{% block title %}Meine Links{% endblock %}
{% block page_id %}mylinks{% endblock %}

{# page‐specific content #}
{% block content %}
 
<!-- Main Container -->
<div class="container">
  <h2>Übersicht deiner Links</h2>
  <div class="row">
    {% if valid_secrets %}
      {% for secret in valid_secrets %}
        <div class="col-md-4 mb-4">
          <div class="card h-100 shadow-sm">
            <img src="data:image/png;base64,{{ secret_qr_codes[secret] }}"
                 class="card-img-top qr-code p-3"
                 alt="QR Code for secret">
            <div class="card-body">
              <h5 class="card-title">Secret Link:</h5>
              <p class="card-text">
                <small class="text-muted">Gültig bis: {{ secret_valid_to[secret] }}</small>
              </p>
              <button class="btn btn-secondary btn-sm" onclick="window.open('{{ secret_url[secret] }}', '_self')">Link öffnen</button>
              <button class="btn btn-secondary btn-sm" onclick="toClipboard('{{ secret_url[secret] }}')">Link kopieren</button>
              <br>
              <form method="post" action="{{ url_for('remove_secret') }}" class="mt-3">
                <input type="hidden" name="secret" value="{{ secret }}">
                <button type="submit" class="btn btn-danger btn-sm">Link entfernen</button>
              </form>
              {% if secret_folders[secret] %}
                <h5 class="mt-3">Ordner:</h5>
                  <div class="list-group">
                  {% for folder in secret_folders[secret] %}
                    <a class="btn btn-outline-secondary" style="margin: 5px;" href="/path/{{ folder.foldername }}">{{ folder.foldername }}</a>
                  {% endfor %}
                  </div>
              {% else %}
                <p class="text-muted">Keine Ordner für dieses Secret hinterlegt.</p>
              {% endif %}
            </div>
          </div>
        </div>
      {% endfor %}
    {% endif %}

    {% if valid_tokens %}
      {% for token in valid_tokens %}
        <div class="col-md-4 mb-4">
          <div class="card h-100 shadow-sm">
            <img src="data:image/png;base64,{{ token_qr_codes[token] }}"
                 class="card-img-top qr-code p-3"
                 alt="QR Code for token">
            <div class="card-body">
              <h5 class="card-title">Token-Link:</h5>
              <p class="card-text">
                <small class="text-muted">Gültig bis: {{ token_valid_to[token] }}</small>
              </p>
              <button class="btn btn-secondary btn-sm" onclick="window.open('{{ token_url[token] }}', '_self')">Link öffnen</button>
              <button class="btn btn-secondary btn-sm" onclick="toClipboard('{{ token_url[token] }}')">Link kopieren</button>
              <br>
              <form method="post" action="{{ url_for('remove_token') }}" class="mt-3">
                <input type="hidden" name="token" value="{{ token }}">
                <button type="submit" class="btn btn-danger btn-sm">Link entfernen</button>
              </form>
              {% if token_folders[token] %}
                <h5 class="mt-3">Ordner:</h5>
                  <div class="list-group">
                  {% for folder in token_folders[token] %}
                    <a class="btn btn-outline-secondary" style="margin: 5px;" href="/path/{{ folder.foldername }}">{{ folder.foldername }}</a>
                  {% endfor %}
                  </div>
              {% else %}
                <p class="text-muted">Keine Ordner für diesen Token hinterlegt.</p>
              {% endif %}
            </div>
          </div>
        </div>
      {% endfor %}
    {% endif %}

    {% if not valid_secrets and not valid_tokens %}
      <div class="alert alert-warning" role="alert">
        Du hast aktuell keine gültigen Links.
      </div>
    {% endif %}
  </div>
</div>
{% endblock %}
