{% 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(): '') %}
{% 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 }}\'); 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 %}'+
            '{% set placeHolderText = (craft.app.config.general.useEmailAsUsername ? "Email"|t('app') : "Username or Email"|t('app')) %}' +
            '{{ forms.textField({ id: "loginName", name: "username", placeholder: placeHolderText, value: username })|e("js") }}' +

            '<div id="login-fields" class="nested-fields">' +
            '{{ forms.passwordField({ id: "password", name: "password", placeholder: "Password"|t('app') })|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="no-access">' +
                    '<div class="pane">' +
                        '<div class="pane-body">' +
                            '<div class="notice">' +
                                '<div class="icon"></div>' +
                                '<p>{{ "Cookies must be enabled to access the Craft CMS control panel."|t('app') }}<br>' +
                                    '<a class="go nowrap" href="">{{ "See how"|t('app') }}</a>' +
                                '</p>' +
                            '</div>' +
                        '</div>' +
                    '</div>' +
                '</div>'
            );
        }
    </script>
{% endblock %}
