{% extends "base.html" %}

{% block content %}
{% if folders %}
<h2>Folders</h2>
<ul>
  {% for name, rel in folders %}
  <li><a href="{{ url_for('browse', subpath=rel) }}">{{ name }}</a></li>
  {% endfor %}
</ul>
{% endif %}
{% if files %}
<h2>Media Files</h2>
<ul class="files">
  {% for name, rel in files %}
  {#- Create urlencoded stream URL based on user-individual token and path #}
  {%- set stream_path = ('dl-token', username, stream_token, rel) | join("/") | urlencode %}
  {%- set stream_url = protocol + '://' + request.host + '/' + stream_path %}
  <li>
    {{ name }} —
    <a href="/{{ stream_path }}" target="_blank"><button>💾 Download</button></a>
    <a href="{{ url_for('play', filepath=rel) }}"><button>🎬 Play in browser</button></a>
    <button onclick="copyToClipboard('{{ stream_url }}', this)">
      ▶️ Copy Stream URL
    </button>
  </li>
  {% endfor %}
</ul>
{% endif %}
{% endblock %}
