{% extends "_layouts/basecp" %}
{% import "_includes/forms" as forms %}
{% set title = "Login"|t('app') %}
{% set bodyClass = 'login' %}
{% do view.registerAssetBundle("craft\\web\\assets\\login\\LoginAsset") %}
{% do view.registerTranslations('app', [
    "Reset Password",
    "Check your email for instructions to reset your password.",
]) %}

{% set username = (craft.app.config.general.rememberUsernameDuration ? craft.app.user.getRememberedUsername(): '') %}

{% if craft.app.config.general.useEmailAsUsername %}
    {% set usernamePlaceholder = 'Email'|t('app') %}
    {% set usernameType = 'email' %}
{% else %}
    {% set usernamePlaceholder = 'Username or Email'|t('app') %}
    {% set usernameType = 'text' %}
{% endif %}

{% set cpAssetUrl = view.getAssetManager().getPublishedUrl('@app/web/assets/cp/dist', true) %}

{% block body %}
    <script type="text/javascript">
        var cookieTest = 'CraftCookieTest='+Math.floor(Math.random() * 1000000);
        document.cookie = cookieTest;
        var cookiesEnabled = document.cookie.search(cookieTest) != -1;
        if (cookiesEnabled)
        {
            document.cookie = cookieTest + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';

            document.write(
                    '{%- set hasLogo = (CraftEdition == CraftPro and craft.rebrand.isLogoUploaded ? true : false) -%}'+
                    '<form id="login-form" method="post" accept-charset="UTF-8" {% if hasLogo -%}
            {%- set logo = craft.rebrand.logo -%}
            {%- set padding = logo.height + 30 -%}
        class="has-logo" style="background-image: url(\'{{ logo.url|e('css')|e('js') }}\'); background-size: {{ logo.width }}px {{ logo.height }}px; padding-top: {{ padding }}px; margin-top: -{{ ((353+padding)/2)|round }}px"
                {%- endif %}>' +
            '{% if not hasLogo -%}<h1>{{ systemName }}</h1>{%- endif %}'+
            "{{ forms.textField({ id: 'loginName', name: 'username', placeholder: usernamePlaceholder, value: username, autocomplete: 'username', type: usernameType })|e('js') }}" +

            '<div id="login-fields" class="nested-fields">' +
            "{{ forms.passwordField({ id: 'password', name: 'password', placeholder: 'Password'|t('app'), autocomplete: 'current-password' })|e('js') }}" +
            '<a id="forgot-password">{{ "Forgot your password?"|t('app') }}</a>' +
            {% if craft.app.config.general.rememberedUserSessionDuration %}
            '{{ forms.checkboxField({ id: "rememberMe", label: "Keep me logged in"|t('app') })|e("js") }}' +
            {% endif %}
            '</div>' +

            '<div class="buttons">' +
            '{# <div id="ssl-icon" class="disabled"><div class="{{ craft.app.request.getIsSecureConnection() ? "secure" : "insecure" }} icon"></div></div>#}' +
            '<input id="submit" class="btn submit disabled" type="submit" value="{{ "Login"|t('app') }}">' +
            '<div id="spinner" class="spinner hidden"></div>' +
            '</div>' +
            '<a id="poweredby" href="http://craftcms.com/" title="{{ "Powered by Craft CMS"|t('app') }}"><img src="{{ cpAssetUrl }}/images/craftcms.svg" /></a>'+
            '</form>'
        );

            {% if not craft.app.request.isMobileBrowser(true) %}
            document.getElementById("{{ (username ? 'password' : 'loginName') }}").focus();
            {% endif %}
        }
        else
        {
            document.write(
                '<div class="message-container no-access">' +
                    '<div class="pane notice">' +
                        '<p>{{ "Cookies must be enabled to access the Craft CMS Control Panel."|t('app') }}</p>' +
                    '</div>' +
                '</div>'
            );
        }
    </script>
{% endblock %}
