{#-
 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_users %}
{% if request.user.id != user.id %}
<li class="active"><a href="{{ url_for('frontend.user_index') }}">Users <span
                      class="sr-only">(current)</span></a></li>
{% else %}
{{ super() }}
{% endif %}
{% endblock %}
{% block navbar_profile %}
{% if request.user.id == user.id %}
<li class="active"><a href="{{ url_for('frontend.user_profile', uid = 'me') }}">{{ request.user.name }} <span class="sr-only">(current)</span></a></li>
{% else %}
{{ super() }}
{% endif %}
{% endblock %}
{% block body %}
<div class="page-header first-header">
  <h2>{{ user.name }}{% if user.admin %} <small><span class="glyphicon
  glyphicon-certificate" data-toggle="tooltip" data-placement="right"
  title="{% if request.user.id == user.id %}You're an admin!{% else %}The user is an admin!{% endif %}"></span></small>{% endif %}</h2>
</div>
<div class="row">
  <div class="col-md-6">
    <form>
      <div class="form-group">
        <label class="sr-only" for="email">User eMail</label>
        <div class="input-group">
          <div class="input-group-addon">User eMail</div>
          <input type="text" class="form-control" id="email" placeholder="{{ user.mail }}" readonly>
          <div class="input-group-btn">
            {% if request.user.id == user.id %}
            <a href="{{ url_for('frontend.change_mail_form', uid = 'me') }}" class="btn btn-default">Change eMail</a>
            {% else %}
            <a href="{{ url_for('frontend.change_mail_form', uid = user.id) }}" class="btn btn-default">Change eMail</a>
            {% endif %}
          </div>
        </div>
      </div>
    </form>
  </div>
  <div class="col-md-6">
    <form>
      <div class="form-group">
        <label class="sr-only" for="lastfm">LastFM status</label>
        <div class="input-group">
          <div class="input-group-addon">LastFM status</div>
          {% if api_key != None %}
            {% if user.lastfm_session %}
            <input type="text" class="form-control" id="lastfm" placeholder="{% if user.lastfm_status %}Linked{% else %}Invalid session{% endif %}" readonly>
            <div class="input-group-btn">
              {% if request.user.id == user.id %}
              <a href="{{ url_for('frontend.lastfm_unreg', uid = 'me') }}" class="btn btn-default">Unlink</a>
              {% else %}
              <a href="{{ url_for('frontend.lastfm_unreg', uid = user.id) }}" class="btn btn-default">Unlink</a>
              {% endif %}
            </div>
            {% else %}
            <input type="text" class="form-control" id="lastfm" placeholder="Unlinked" readonly>
            <div class="input-group-btn">
              {% if request.user.id == user.id %}
              <a href="https://www.last.fm/api/auth/?api_key={{ api_key }}&cb={{ request.url_root[:-(request.script_root|length+1)] + url_for('frontend.lastfm_reg', uid = 'me') }}" class="btn btn-default">Link</a>
              {% else %}
              <a href="https://www.last.fm/api/auth/?api_key={{ api_key }}&cb={{ request.url_root[:-(request.script_root|length+1)] + url_for('frontend.lastfm_reg', uid = user.id) }}" class="btn btn-default">Link</a>
              {% endif %}
            </div>
            {% endif %}
          {% else %}
          <input type="text" class="form-control" id="lastfm" placeholder="Unavailable" readonly>
          {% endif %}
        </div>
      </div>
    </form>
  </div>
</div>
{% if request.user.id == user.id %}
<a href="{{ url_for('frontend.change_password_form', uid = 'me') }}" class="btn btn-default">Change password</a></li>
{% else %}
<a href="{{ url_for('frontend.change_username_form', uid = user.id) }}" class="btn btn-default">Change username or admin status</a></li>
<a href="{{ url_for('frontend.change_password_form', uid = user.id) }}" class="btn btn-default">Change password</a></li>
{% endif %}
{% if clients.count() %}
<div class="page-header">
  <h2>Clients</h2>
</div>
<p>Here's a list of clients you used to stream music. If you want to use
transcoding or downsampling with one of them (for instance using a low bitrate
on mobile connections to reduce used bandwidth), but the client doesn't provide
options to do so, you can set default values here. They'll only be used if no
transcoding/downsampling is requested by the client.<br/>
The first field is used to specify the format all files will be converted to. It
means if you enter <em>mp3</em>, all media will be served as mp3, whether the
original file is a mp3, ogg, FLAC or whatever. The bitrate option specify the
maximum streaming bitrate. If a file has a higher bitrate it will be transcoded
to match this value. Note that either the format or bitrate field can be left
out, for instance you can only enter a bitrate so files will be streamed using
their original format, only transcoded if their bitrate exceed the selected
one.</p>
<form method="post">
  <table id="clients" class="table table-striped">
    <thead>
      <tr><th>Client</th><th>Format</th><th>Max bitrate</th><th>Forget</th></tr>
    </thead>
    <tbody>
      {% for client in clients %}
      <tr>
        <td><label>{{ client.client_name }}</label></td>
        <td><input type="text" class="form-control" name="{{ client.client_name }}_format"
            value="{{ client.format if client.format else '' }}"
            pattern="[a-z0-9]{0,8}" title="Up to 8 letters and numbers" /></td>
        <td><select class="form-control" name="{{ client.client_name }}_bitrate">
            <option />
            <option {{ 'selected="selected"' if client.bitrate == 64 else ''  }}>64</option>
            <option {{ 'selected="selected"' if client.bitrate == 96 else ''  }}>96</option>
            <option {{ 'selected="selected"' if client.bitrate == 128 else '' }}>128</option>
            <option {{ 'selected="selected"' if client.bitrate == 192 else '' }}>192</option>
            <option {{ 'selected="selected"' if client.bitrate == 256 else '' }}>256</option>
            <option {{ 'selected="selected"' if client.bitrate == 320 else '' }}>320</option>
          </select></td>
          <td><input type="checkbox" name="{{ client.client_name }}_delete" /></td>
      </tr>
      {% endfor %}
    <tbody>
  </table>
  <input class="btn btn-default" type="submit" value="Save" />
</form>
{% endif %}
{% endblock %}
