<!--users/templates/users/dashboard.html-->

{% extends 'base.html' %}{% csrf_token %}{% block content %}
<div>
  {% if user.is_authenticated %}
  <a href="{% url 'logout' %}">Выход</a>
  <a href="{% url 'password_change' %}">Изменить Пароль</a>
  {% else %}
  <a href="{% url 'login' %}">Вход</a>
  {% endif %}
  <div class="container">
    <h1>Мой Аккаунт</h1>
    <hr />
    <h2>Информация о Пользователе</h2>
    <p><strong>Имя Пользователя:</strong> {{ user.username }}</p>
    <p><strong>Email:</strong> {{ user.email }}</p>
    {% comment %} <p><strong>Phone:</strong> 555-555-5555</p> {% endcomment %}
    {% comment %} точно нужен телефон?? {% endcomment %}
    <hr />
    <h2>Продукты</h2>
    <table class="table">
      <thead>
        <tr>
          <th>Название Продукта</th>
          <th>Статус</th>
          <th>Срок Подписки</th>
          <th>Продлить</th>
          <th>Удалить</th>
        </tr>
      </thead>
      <tbody>
        {%for container in containeros%}
        <tr>
          <td>
            <p><a href="/{{container.name}}">{{container.name}}</a></p>
          </td>
          {%if container.status == 'd'%}
          <td>
            <button class="btn btn-success" id="run-script-start" onclick="window.location.href='{% url 'restatus_container' container_name=container.name%}'">Запустить</button>
          </td>
          {%elif container.status == 'e'%}
          <td>
            <button class="btn btn-danger" id="run-script-end" onclick="window.location.href='{% url 'restatus_container' container_name=container.name%}'">Остановить</button>
          </td>
          {%endif%}
          <td>{{container.expdate}}</td>
          <td>
            <button class="btn btn-primary" id="run-script-prolong" onclick="window.location.href='{% url 'prolong_container' container_name=container.name%}'">
              Продлить
            </button>
          </td>
          <td>
            <button class="btn btn-danger" onclick="deleteContainer('{% url 'delete_container' container_name=container.name %}')">
              Удалить
            </button>
          </td>
        </tr>
        {%endfor%}
        <tr>
          <td><button type="button" class="btn btn-light" onclick="window.location.href='{% url 'add_container' %}'">Добавить Продукт</button></td>
        </tr>
        <script>

          function deleteContainer(url) {
            var confirmation
            var result = confirm("Are you sure you want to delete this container?");
            if (result == true){
              window.location.href = url;
            }
            {% comment %} location.reload(); {% endcomment %}

          }
        </script>
        </tr>
      </tbody>
    </table>
  </div>
</div>

{% endblock %}
