{% import "macros.html" as macros %}

<div class="dialog-body">
    <form method="dialog">
        <div class="mb-3">
            <h2 class="text-lg mb-1">Torrent</h2>
            <p class="text-break-all text-sm text-muted">{{release.name}}</p>
        </div>
        {% set languages = release.languages %}
        {% if languages %}
            <div class="d-flex p-2 mb-3 border-accent align-items-center rounded">
                {{macros.icon("#icon-info", width=20, height=20, class="mr-2")}}
                <div class="text-sm">
                    It looks like this episode contains subtitles or has been dubbed in: {{languages|join(", ")}}
                </div>
            </div>
        {% endif %}
        {% if allow_downloads %}
            <div class="py-3 border-top border-bottom" data-status="{{release.torrent.status}}">                
                {% if release.torrent.status == 'D' %}
                    {% set file_count = release.torrent.file_storage|length %}
                    <div class="d-flex align-items-center">
                        {{macros.icon("#icon-check-bold", width=16, height=16, class="text-success mr-1")}}<span class="text-sm">Downloaded {{file_count}} file{{file_count|pluralize}}</span>
                    </div>
                    {# {{macros.torrent_files(release.torrent)}} #}
                {% elif release.torrent.status == 'A' or release.torrent.status == 'M' or release.torrent.status == 'd' %}
                    {{macros.torrent_download_progress(release)}}
                {% else %}
                    {% set request_url = url_for('main.download_torrent', release_id=release.id) %}
                    <button type="button" onclick="Videobox.downloadTorrent('{{request_url}}', '_download-progress', event);" class="btn-icon">
                        {{macros.icon("#icon-download", width=20, height=20, class="mr-1")}}Download now
                    </button>
                {% endif %}
            </div>        
        {% else %}
            <div class="d-flex align-items-center rounded py-3 border-top border-bottom">             
                {{macros.icon("#icon-magnet", width=20, height=20, class="mr-2")}}
                <div>
                    <a download href="{{release.magnet_uri}}">Download with magnet link</a>
                    <div class="text-sm text-muted">
                        Install an external BitTorrent client to use magnet links
                    </div>
                </div>
            </div>       
        {% endif %}
        <dl class="mb-4">
            <dt>
                Swarm
            </dt>
            <dd>
                {{"{:,}".format(release.seeders)}} seeders, {{"{:,}".format(release.leechers)}} leechers, and {{"{:,}".format(release.completed)}} downloads.<br>
                Last checked {{release.last_updated_on|datetime_since(utc_now)}}.
            </dd>
            <dt>
                Added
            </dt>
            <dd>
                {{release.added_on | human_date_time}} <span class="font-small-caps">UTC</span>
            </dd>
            <dt>Size</dt>
            <dd>
                {{release.size | filesizeformat}} ({{release.size}} bytes)
            </dd>
            <dt>
                Info hash
            </dt>
            <dd class="">
                <code>{{release.info_hash|upper}}</code>
            </dd>
            <dd class="">
                <details>
                    <summary class="mb-1">Trackers ({{trackers|length}})</summary>
                    <div class="details-body">
                        {% for t in trackers %}
                            <div class="d-flex align-items-center mb-1" style="gap: .5rem">{{macros.tracker_status_icon(t.status)}}{{t.url|nice_url}}<small class="text-muted">{{macros.tracker_status_description(t.status)}}</small></div>
                        {% endfor %}
                    </div>
                </details>                
            </dd>
        </dl>  
        <button class="btn" type="submit">Close</button>        
    </form>
</div>