{% extends "base.html" %}
{% block head %}
{{ super() }}
<script>
  function copyPassword(password) {
    navigator.clipboard.writeText(password);
  }
</script>
{% endblock %}

{% block content %}
{% if osx_ssl_warning %}
<div class="alert alert-danger" style="text-align: center;">
  <p>
  Contacts.app and Calendar.app on macOS and Windows Calendar and Windows People on Windows require SSL even when explicitly disabled. <br/>
  For more inormation please refer to the <a href="https://github.com/etesync/etesync-dav/blob/master/macos-instructions.md">macOS instructions</a>.
  </p>
  <p style="font-weight: bold;">
  IMPORTANT: this operation will shutdown etesync-dav and require you to start it again.
  </p>
  <div>
    <form method="post" action="{{ url_for('certgen') }}">
      <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
      <button class="btn btn-success">Setup SSL</button>
    </form>
  </div>
</div>
{% endif %}

<ul>
  <li class="d-flex" style="margin-bottom: 2.5rem;">
    <a class="btn btn-success btn-lg" href="{{ url_for('add_user') }}">Add user</a>
  </li>
  {% for username, password in users %}
  <li class="d-flex" style="margin-bottom: 1.5rem;">
    <a style="min-width: 400px" href="{{ url_for('user_index', user=username) }}">{{ username }}</a>
    <div class="d-inline">
      <button class="btn btn-sm btn-success" onclick="copyPassword('{{ password }}')">Copy Password</button>
      <form class="d-inline" method="post" action="{{ url_for('remove_user') }}">
        <input name="username" type="hidden" value="{{ username }}"/>
        {{ remove_user_form.csrf_token }}
        <button class="btn btn-sm btn-danger">Remove</button>
      </form>
    </div>
  </li>
  {% endfor %}
</ul>
{% endblock content %}
