{% extends 'layouts/base-auth.html' %}
{% load static widget_tweaks i18n %}

{% block content %}
<style>
  body {
    background: url("{{ background_url }}") no-repeat center center fixed;
    background-size: cover;
  }

  .reset-panel {
    background-color: rgba(15, 15, 15, 0.92);
    color: #f0e6d2;
    border-radius: 1rem;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.9);
    border: 1px solid #e0c36b;
  }

  .form-control:focus {
    background-color: rgba(255, 255, 255, 0.15);
    border-color: #f0e68c;
    box-shadow: 0 0 10px rgba(255, 255, 160, 0.5);
  }

  .text-danger {
    color: #ffaaaa;
  }

  .btn-golden {
    background: linear-gradient(to right, #b89b56, #d5c170);
    color: #000;
    font-weight: bold;
    text-shadow: 0 0 5px #fff8dc;
    border: none;
  }

  .btn-golden:hover {
    background: linear-gradient(to right, #d5c170, #b89b56);
    color: #000;
  }

  .link-login {
    color: #e0c36b;
    text-decoration: none;
    font-weight: bold;
    transition: color 0.3s ease;
  }

  .link-login:hover {
    color: #fff2aa;
  }

  /* Estilos para o ícone de olho */
  .password-field {
    position: relative;
  }

  .password-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #e0c36b;
    cursor: pointer;
    padding: 5px;
    transition: color 0.3s ease;
    z-index: 10;
  }

  .password-toggle:hover {
    color: #fff;
  }

  .password-toggle:focus {
    outline: none;
    box-shadow: none;
  }

  .password-field .form-control {
    padding-right: 40px; /* Espaço para o ícone */
  }


</style>

<section class="vh-100 d-flex align-items-center justify-content-center">
  <div class="container">
    <div class="row justify-content-center">
      <p class="text-center mb-4">
        <a href="{% url 'login' %}" class="d-flex align-items-center justify-content-center link-login">
          <svg class="icon icon-xs me-2" fill="currentColor" viewBox="0 0 20 20"
            xmlns="http://www.w3.org/2000/svg">
            <path fill-rule="evenodd"
              d="M7.707 14.707a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 1.414L5.414 9H17a1 1 0 110 2H5.414l2.293 2.293a1 1 0 010 1.414z"
              clip-rule="evenodd"></path>
          </svg>
          {% trans "Voltar para o login" %}
        </a>
      </p>
      <div class="col-md-6 col-lg-5">
        <div class="p-5 reset-panel">
          <h1>{% trans "Redefinir Senha" %}</h1>
          <form method="post">
            {% csrf_token %}
            <div class="form-group mb-4">
              <label for="password">{% trans "Nova Senha" %}</label>
              <div class="password-field">
                <div class="input-group">
                  <span class="input-group-text" id="basic-addon2">
                    <svg class="icon icon-xs text-gray-300" fill="currentColor" viewBox="0 0 20 20"
                      xmlns="http://www.w3.org/2000/svg">
                      <path fill-rule="evenodd"
                        d="M5 9V7a5 5 0 0110 0v2a2 2 0 012 2v5a2 2 0 01-2 2H5a2 2 0 01-2-2v-5a2 2 0 012-2zm8-2v2H7V7a3 3 0 016 0z"
                        clip-rule="evenodd"></path>
                    </svg>
                  </span>
                  {{ form.new_password1 }}
                </div>
                <button type="button" class="password-toggle" onclick="togglePassword('id_new_password1')">
                  <i class="bi bi-eye" id="eye-icon-new_password1"></i>
                </button>
              </div>
              <div class="text-danger my-2">{{ form.new_password1.errors }}</div>
            </div>

            <div class="form-group mb-4">
              <label for="confirm_password">{% trans "Confirmar Senha" %}</label>
              <div class="password-field">
                <div class="input-group">
                  <span class="input-group-text" id="basic-addon2">
                    <svg class="icon icon-xs text-gray-300" fill="currentColor" viewBox="0 0 20 20"
                      xmlns="http://www.w3.org/2000/svg">
                      <path fill-rule="evenodd"
                        d="M5 9V7a5 5 0 0110 0v2a2 2 0 012 2v5a2 2 0 01-2 2H5a2 2 0 01-2-2v-5a2 2 0 012-2zm8-2v2H7V7a3 3 0 016 0z"
                        clip-rule="evenodd"></path>
                    </svg>
                  </span>
                  {{ form.new_password2 }}
                </div>
                <button type="button" class="password-toggle" onclick="togglePassword('id_new_password2')">
                  <i class="bi bi-eye" id="eye-icon-new_password2"></i>
                </button>
              </div>
              <div class="text-danger my-2">{{ form.new_password2.errors }}</div>
            </div>

            <div class="d-grid mt-4">
              <button type="submit" class="btn btn-golden">{% trans "Redefinir Senha" %}</button>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</section>

<script>
function togglePassword(inputId) {
  const input = document.getElementById(inputId);
  const icon = document.getElementById('eye-icon-' + inputId.split('_')[1] + '_' + inputId.split('_')[2]);
  
  if (input.type === 'password') {
    input.type = 'text';
    icon.classList.remove('bi-eye');
    icon.classList.add('bi-eye-slash');
  } else {
    input.type = 'password';
    icon.classList.remove('bi-eye-slash');
    icon.classList.add('bi-eye');
  }
}
</script>
{% endblock %}
