{% extends 'base.twig' %}

{% block title %}{{ 'page.login'|trans }}{% endblock %}
{% block meta_description %}{{ 'page.login'|trans }}{% endblock %}

{% block canonical_url %}<link rel="canonical" href="{{ url('app_login') }}" />{% endblock %}
{% block breadcrumb_schema %}
    <script type="application/ld+json">
        {
          "@context": "https://schema.org",
          "@type": "BreadcrumbList",
          "itemListElement": [
            {
              "@type": "ListItem",
              "position": 1,
              "name": "{{ 'breadcrumb.home'|trans }}",
              "item": "{{ app.request.schemeAndHttpHost }}"
          },
            {
              "@type": "ListItem",
              "position": 2,
              "name": "{{ 'breadcrumb.login'|trans }}",
              "item": "{{ app.request.schemeAndHttpHost }}{{ app.request.pathInfo }}"
          }
        ]
      }
    </script>
{% endblock %}

{% block body %}
    <div class="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8">
        <div class="max-w-md w-full space-y-8 p-10 bg-white rounded-xl shadow-lg">

            <h2 class="mt-6 text-center text-3xl font-extrabold text-gray-900">
                {{ 'security.login'|trans }}
            </h2>

            {# Display error messages if login fails #}
            {% if error %}
                <div class="p-4 mb-4 text-sm text-red-700 bg-red-100 rounded-lg" role="alert">
                    {{ error.messageKey|trans(error.messageData, 'security') }}
                </div>
            {% endif %}
            {% for message in app.flashes('success') %}
                <div class="p-4 text-sm text-green-700 bg-green-100 rounded-lg" role="alert">
                    {{ message }}
                </div>
            {% endfor %}
            {# The actual login form #}
            <form class="mt-8 space-y-6" action="{{ path('app_login') }}" method="post">
                <input type="hidden" name="remember" value="true">

                {# Username Field (Email) #}
                <div class="rounded-md shadow-sm -space-y-px">
                    <div>
                        <label for="username" class="sr-only">{{ 'label.email'|trans }}</label>
                        <input id="username" name="_username" type="email" autocomplete="email" required
                               class="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
                               placeholder="{{ 'label.email'|trans }}" value="{{ last_username }}" autofocus>
                    </div>

                    {# Password Field #}
                    <div>
                        <label for="password" class="sr-only">{{ 'label.password'|trans }}</label>
                        <input id="password" name="_password" type="password" autocomplete="current-password" required
                               class="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-b-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm"
                               placeholder="{{ 'label.password'|trans }}">
                    </div>
                </div>

                {# Remember Me & Forgot Password (Optional) #}
                <div class="flex items-center justify-between">
                    <div class="text-sm">
                        <a href="{{ path('app_forgot_password') }}" class="font-medium text-indigo-600 hover:text-indigo-500">
                            {{ 'link.forgot_password'|trans }}
                        </a>
                    </div>
                </div>

                {# CSRF Token (Important for security) #}
                <input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">

                {# Submit Button #}
                <div>
                    <button type="submit"
                            class="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
                        {{ 'button.sign_in'|trans }}
                    </button>
                </div>
            </form>

        </div>
    </div>
{% endblock %}
