{% extends "layouts/auth.twig" %}

{% block title %}Login{% endblock %}

{% block content %}
    <div class="page page-center">
      <div class="container container-tight py-4">
        <div class="text-center mb-4">
          <a href="." class="navbar-brand navbar-brand-autodark"><img src="./static/logo-bw.svg" height="36" alt=""></a>
          {% include 'partials/flash.twig' %}
        </div>
        <div class="card card-md">
          <div class="card-body">
            <h2 class="h2 text-center mb-4">Login to your account</h2>
            <form action="{{route('login')}}" name="login" method="post" autocomplete="off" novalidate>
            {{ csrf.field | raw }}
              <div class="mb-3">
                <label class="form-label">Email address</label>
                <input name="email" type="email" class="form-control" placeholder="your@email.com" autocomplete="off">
              </div>
              <div class="mb-2">
                <label class="form-label">
                  Password
                  <span class="form-label-description">
                    <a href="{{route('forgot.password')}}">I forgot password</a>
                  </span>
                </label>
                <div class="input-group input-group-flat">
                  <input name="password" type="password" class="form-control" placeholder="Your password" autocomplete="off">
                  <span class="input-group-text">
                    <a href="#" class="link-secondary" title="Show password"><svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><circle cx="12" cy="12" r="2" /><path d="M22 12c-2.667 4.667 -6 7 -10 7s-7.333 -2.333 -10 -7c2.667 -4.667 6 -7 10 -7s7.333 2.333 10 7" /></svg>
                    </a>
                  </span>
                </div>
              </div>
              <div class="mb-2">
                <label class="form-check">
                  <input name="remember" value="remember" id="remember" type="checkbox" class="form-check-input"/>
                  <span class="form-check-label">Remember me on this device</span>
                </label>
              </div>
              <div class="form-footer">
                <button type="submit" class="btn btn-primary w-100">Sign in</button>
              </div>
            </form>
          </div>
        </div>
        <div class="text-center text-muted mt-3">
          Don't have account yet? <a href="{{route('register')}}" tabindex="-1">Sign up</a>
        </div>
      </div>
    </div>
	<script>const passwordInput = document.querySelector('input[name="password"]');
	const togglePasswordBtn = document.querySelector('.input-group-text a');

	togglePasswordBtn.addEventListener('click', function() {
	  const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
	  passwordInput.setAttribute('type', type);
	  
	  const svg = togglePasswordBtn.querySelector('svg');
	  const title = togglePasswordBtn.getAttribute('title');
	  
	  if (type === 'text') {
		svg.innerHTML = '<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M3 3l18 18"></path><path d="M10.584 10.587a2 2 0 0 0 2.828 2.83"></path><path d="M9.363 5.365a9.466 9.466 0 0 1 2.637 -.365c4 0 7.333 2.333 10 7c-.778 1.361 -1.612 2.524 -2.503 3.488m-2.14 1.861c-1.631 1.1 -3.415 1.651 -5.357 1.651c-4 0 -7.333 -2.333 -10 -7c1.369 -2.395 2.913 -4.175 4.632 -5.341"></path>';
		togglePasswordBtn.setAttribute('title', 'Hide password');
	  } else {
		svg.innerHTML = '<path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M12 12m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0"></path><path d="M22 12c-2.667 4.667 -6 7 -10 7s-7.333 -2.333 -10 -7c2.667 -4.667 6 -7 10 -7s7.333 2.333 10 7"></path>';
		togglePasswordBtn.setAttribute('title', 'Show password');
	  }
	});
	</script>
{% endblock %}
