{#-
 This file is part of Supysonic.
 Supysonic is a Python implementation of the Subsonic server API.

 Copyright (C) 2013-2018 Alban 'spl0k' Féron
                    2017 Óscar García Amor

 Distributed under terms of the GNU AGPLv3 license.
-#}
{% extends "layout.html" %}
{% block navbar_playlists %}
<li class="active"><a href="{{ url_for('frontend.playlist_index') }}">Playlists <span
                      class="sr-only">(current)</span></a></li>
{% endblock %}
{% block body %}
<div class="page-header first-header">
  <h2>My playlists</h2>
</div>
{% if not mine.count() %}
<p>You don't have any playlists.</p>
{% else %}
<table class="table table-striped table-hover">
  <thead>
    <tr><th>Playlist</th><th>Tracks</th><th>Public</th><th>Export</th><th>Delete</th></tr>
  </thead>
  <tbody>
    {% for p in mine %}
    <tr>
      <td><a href="{{ url_for('frontend.playlist_details', uid = p.id) }}">{{ p.name }}</a></td>
      <td>{{ p.get_tracks()|length }}</td>
      <td>{% if p.public %}<span class="glyphicon glyphicon-check"
                                 aria-label="Public playlist"></span>{% else %}<span
                                 class="glyphicon glyphicon-unchecked"
                                 aria-label="Private playlist"></span>{% endif %}</td>
      <td><button class="btn btn-primary btn-xs" data-href="{{ url_for('frontend.playlist_export', uid = p.id) }}" data-toggle="modal" data-target="#confirm-export" aria-label="Export playlist">
        <span class="glyphicon glyphicon-arrow-down" aria-hidden="true" data-toggle="tooltip" data-placement="top" title="Export M3U playlist"></span></button></td>
      <td><button class="btn btn-danger btn-xs" data-href="{{ url_for('frontend.playlist_delete', uid = p.id) }}" data-toggle="modal" data-target="#confirm-delete" aria-label="Delete playlist">
        <span class="glyphicon glyphicon-remove-circle" aria-hidden="true" data-toggle="tooltip" data-placement="top" title="Delete playlist"></span></button></td>
    </tr>
    {% endfor %}
  </tbody>
</table>
{% endif %}
{% if others.count() %}
<div class="page-header">
  <h2>Others' playlists</h2>
</div>
<table class="table table-striped table-hover">
  <thead>
    <tr><th>Playlist</th><th>Owner</th><th>Tracks</th></tr>
  </thead>
  <tbody>
    {% for p in others %}
    <tr>
      <td><a href="{{ url_for('frontend.playlist_details', uid = p.id) }}">{{ p.name }}</a></td>
      <td>{{ p.user.name }}</td>
      <td>{{ p.get_tracks()|length }}</td>
    </tr>
    {% endfor %}
  </tbody>
</table>
{% endif %}
<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">Are you sure?</h4>
      </div>
      <div class="modal-body">
        <p>Are you sure that you want to delete playlist?</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Nope</button>
        <a type="button" class="btn btn-danger btn-ok">Yes, delete!</a>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div class="modal fade" id="confirm-export" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">Warning</h4>
      </div>
      <div class="modal-body">
        <p>The exported playlist will use the same local paths the server uses itself. This means the playlist will only
          work on the very same system the Supysonic server is running. If you were to export it from another machine it
          won't be usable.
        </p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Oh ok. Forget it</button>
        <a type="button" class="btn btn-primary btn-ok">Got it, export the playlist</a>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{% endblock %}
