{% extends "layout_public.html.twig" %}

{% block meta_title %}{{ 'Set new Password'|trans }}{% endblock %}

{% block body_class %}page-set-password{% endblock %}
{% block body %}
<div class="container h-100">
    <div class="row h-75 justify-content-center align-items-center">
        <div class="col-md-6 col-lg-4">
            {% if settings.login_page_show_logo %}
                {% set company = guest.system_company %}
                <div class="d-flex justify-content-center">
                    <a href="{{ settings.login_page_logo_url|default('/') }}" target="_blank">
                        <img class="my-4" height="50px" src="{{ guest.system_company.logo_url }}" alt="{{ guest.system_company.name }}"/>
                    </a>
                </div>
            {% endif %}
            <div class="card">
                <div class="card-body">
                    <h5 class="text-center m-4">{{ 'Set new password'|trans }}</h5>
                    <form class="api-form auth" action="{{ 'api/guest/client/update_password'|link }}" method="post" data-api-redirect="{{ '/login'|link }}" autocomplete="off">
                        <input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
                        <input type="hidden" id="hash" name="hash" value="{{ hash }}"/>
                        <div class="mb-3">
                            <label class="form-label" for="password">{{ 'New password'|trans }}</label>
                            <input class="form-control" id="password" type="password" placeholder="{{ 'New password'|trans }}" name="password" required="required" autofocus>
                        </div>
                        <div class="mb-3">
                            <label class="form-label" for="password2">{{ 'Repeat new password'|trans }}</label>
                            <input class="form-control" id="password2" type="password" placeholder="{{ 'Repeat new password'|trans }}" name="password_confirm" required="required">
                        </div>
                        <button type="submit" class="btn btn-primary w-100 mb-3">{{ 'Set new password'|trans }}</button>
                    </form>
                    <a class="btn btn-secondary btn-sm col" href="{{ 'login'|link }}">{{ 'Back to login'|trans }}</a>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block js %}
<script type="text/javascript">
    // Set value of hash field to last part of URL
    $(document).ready(function() {
        var hash = window.location.href.split('/').pop();
        $('#hash').val(hash);
    });
</script>
{% endblock %}
