{% extends "base.html" %}
{% load i18n %}

{% block sub_title %}{% trans "Log In" %} - {% endblock %}

{% block header_css_class %}hide{% endblock %}

{% block extra_base_style %}
<link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}css/seafile-ui.css?t=20250313" />
{% endblock %}

{% block extra_style %}
<style type="text/css">
html, body, #wrapper { height:100%; }
#wrapper {
    background: url('{{ MEDIA_URL }}{{login_bg_image_path}}') center top no-repeat scroll;
    background-size: cover;
    padding-top:1px;
}
#lang {
    margin:0;
}
#lang-context {
    font-weight:normal;
}
#lang-context-selector {
    text-align:left;
}
</style>
{% endblock %}

{% block main_content %}
<div class="login-panel-outer-container vh">
<div class="login-panel" id="log-in-panel">
    <h1 class="login-panel-hd">{% trans "Log In" %}</h1>
    <form action="" method="post" id="login-form">{% csrf_token %}
        <input type="text" name="login" placeholder="{% trans "Email or Username" %}" aria-label="{% trans "Email or Username" %}" title="{% trans "Email or Username" %}" value="" class="input" /><br />

        <input type="hidden" name="next" value="{% if next %}{{ next|escape }}{% else %}{{ SITE_ROOT }}{% endif %}" />
        {% if error_msg %}
        <p class="error">{{ error_msg }}</p>
        {% else %}
        <p class="error hide"></p>
        {% endif %}

        <button type="submit" class="submit btn btn-primary btn-block h-auto mb-3">{% trans "Log In" %}</button>
    </form>
    <div class="login-panel-bottom-container d-flex justify-content-center" id="login-bottom"></div>
</div>
</div>
{% include "snippets/policy_service_link.html" %}
{% endblock %}

{% block extra_script %}
<script type="text/javascript">
$('.login-panel-outer-container').prepend($($('#logo').html()).attr({'height': 40}).addClass('login-panel-logo'));
$('.login-panel-bottom-container').append($('#lang').removeClass('fright').addClass('px-2'));

var $el = $('.login-panel-outer-container');
var elHeight = $el.outerHeight();
var wdHeight = $(window).height();
if (wdHeight > elHeight) {
    $el.css({'margin-top': (wdHeight - elHeight)/2});
}
$el.removeClass('vh');

$('#lang-context').on('click', function() {
    var langTop = $('#lang').offset().top;
    var langSelectorTop;
    var langSelectorHeight = $('#lang-context-selector .sf-popover-con').outerHeight();
    if (langSelectorHeight > langTop) {
        langSelectorTop = '-' + (langTop - 5) + 'px';
    } else {
        langSelectorTop = '-' + (langSelectorHeight + 5) + 'px';
    }
    $('#lang-context-selector').css({
        'top': langSelectorTop,
        'right': 0
    });
    $('#lang-context-selector .sf-popover-con').css({
        'max-height': $('#lang').offset().top - 10
    });
});

$('[name="login"]').trigger('focus');

$('#login-form').on('submit', function(){
    if (!$('input[name="login"]').val().trim()) {
        $('.error').removeClass('hide').html("{% trans "Email or username cannot be blank" %}");
        return false;
    }
});

</script>
{% endblock %}
