<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;

$this->title = Yii::t('app', 'Login');

?>

<div class="users-form middle-page-container">

    <div id="login-form-image" class="middle-page-container">
        <?= Html::img(Url::to('@web/images/logo-train.png'), ['alt' => 'login-img', 'class' => 'img-responsive']) ?>
    </div>

    <?php if($can_try_login): ?>
        <?php $form = ActiveForm::begin(); ?>

        <?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>

        <?= $form->field($model, 'password')->passwordInput(['maxlength' => true]) ?>

        <p>
            <?= Html::a(Yii::t('app', 'Forgot Password?'), ['forgot-password']) ?>
        </p>

        <?php if(Yii::$app->session->hasFlash('incorrect_login')): ?>
            <div class="alert alert-danger">
                <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                <?= Yii::$app->session->getFlash('incorrect_login') ?>
            </div>
        <?php endif; ?>

        <?php if(Yii::$app->session->hasFlash('inactive_account')): ?>
            <div class="alert alert-danger">
                <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                <?= Yii::$app->session->getFlash('inactive_account') ?>
            </div>
        <?php endif; ?>

        <?php if(Yii::$app->session->hasFlash('reset_password_token_sent')): ?>
            <div class="alert alert-success">
                <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                <?= Yii::$app->session->getFlash('reset_password_token_sent') ?>
            </div>
        <?php endif; ?>

        <?php if(Yii::$app->session->hasFlash('password_has_been_reset')): ?>
            <div class="alert alert-success">
                <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
                <?= Yii::$app->session->getFlash('password_has_been_reset') ?>
            </div>
        <?php endif; ?>

        <div class="form-group middle-page-container text-align-center">
            <?= Html::submitButton(Yii::t('app', 'Login'), ['class' => 'btn btn-success']) ?>
            <?= '<div class="pt5">' . Yii::t('app', 'Or') . '</div>' ?>
            <?= Html::a(Yii::t('app', 'Signup From Login Page'), ['signup']) ?>
        </div>

        <?php ActiveForm::end(); ?>
    <?php else: ?>
        <div class="alert alert-danger">
            <?= Yii::t('app', 'You will not be able to login untill the next {duration} seconds since the last attempt', ['duration' => \app\models\Settings::findOne(['name' => 'login_attempt_duration_in_seconds'])->value]) ?>
        </div>
    <?php endif; ?>

</div>
