<?php
$this->css($this->assetModule('front/front.css'));

// oauth
$url = Pi::api('oauth', 'user')->urlList();

// Description
$description = Pi::user()->config('login_description');

if (!empty($description) || !empty($url)) {
    $class = 'col-md-8 col-sm-7 col-12';
} else {
    $class = 'col-md-12';
}
$registerUrl = Pi::service('user')->getUrl('register');
if (isset($redirect) && !empty($redirect)) {
    $registerUrl .= '?redirect=' . $redirect;
}
?>
<div class="clearfix user-template">
    <div class="mb-3">
        <h1><?php echo _escape($title); ?></h1>
    </div>
    <?php if (!empty($message)) { ?>
        <div class="alert alert-danger">
            <?php echo _escape($message); ?>
        </div>
    <?php } ?>
    <div class="row clearfix loginFormWrapper">
        <div class="<?php echo $class; ?>">
            <?php echo $this->form($form); ?>
            <div class="clearfix">
                <div class="col-md-6 offset-md-3">
                    <a title="<?php _e('Forgot password?'); ?>"
                       href="<?php echo Pi::service('user')->getUrl('password'); ?>">
                        <?php _e('Forgot password?'); ?>
                    </a>
                </div>
            </div>
            <div class="clearfix user-action-bar">
                <div class="col-md-6 offset-md-3">
                    <h2><?php _e('Not registered yet ?'); ?></h2>
                    <p>
                        <a class="btn btn-simple" title="<?php _e('Sign up'); ?>"
                           href="<?php echo $registerUrl ?>">
                            <?php _e('Sign up'); ?>
                        </a>
                    </p>
                </div>
            </div>
        </div>
        <?php if ((isset($description) && !empty($description)) || (isset($url) && !empty($url))) { ?>
            <div class="col-md-4 col-sm-5 col-12 d-none d-sm-block ">
                <?php if (isset($description) && !empty($description)) { ?>
                    <div class="clearfix mb-3">
                        <?php echo $description; ?>
                    </div>
                <?php } ?>
                <?php if (isset($url) && !empty($url)) { ?>
                    <div class="clearfix mb-3">
                        <?php if (!empty($url['google'])) { ?>
                            <div class="oauth-login">
                                <?php if (isset($redirect) && !empty($redirect)) {
                                    $url['google'] = sprintf('%s?redirect=%s', $url['google'], $redirect);
                                } ?>
                                <a class="btn btn-socail btn-google btn-block" href="<?php echo $this->escape($url['google']); ?>">
                                    <i class="fab fa-google"></i> <?php _e('Login with google'); ?>
                                </a>
                            </div>
                        <?php } ?>
                        <?php if (!empty($url['twitter'])) { ?>
                            <div class="oauth-login">
                                <?php if (isset($redirect) && !empty($redirect)) {
                                    $url['twitter'] = sprintf('%s?redirect=%s', $url['twitter'], $redirect);
                                } ?>
                                <a class="btn btn-socail btn-twitter btn-block" href="<?php echo $this->escape($url['twitter']); ?>">
                                    <i class="fab fa-twitter"></i> <?php _e('Login with twitter'); ?>
                                </a>
                            </div>
                        <?php } ?>
                        <?php if (!empty($url['facebook'])) { ?>
                            <div class="oauth-login">
                                <?php if (isset($redirect) && !empty($redirect)) {
                                    $url['facebook'] = sprintf('%s?redirect=%s', $url['facebook'], $redirect);
                                } ?>
                                <a class="btn btn-socail btn-facebook btn-block" href="<?php echo $this->escape($url['facebook']); ?>">
                                    <i class="fab fa-facebook-f"></i> <?php _e('Login with facebook'); ?>
                                </a>
                            </div>
                        <?php } ?>
                        <?php if (!empty($url['github'])) { ?>
                            <div class="oauth-login">
                                <?php if (isset($redirect) && !empty($redirect)) {
                                    $url['github'] = sprintf('%s?redirect=%s', $url['github'], $redirect);
                                } ?>
                                <a class="btn btn-socail btn-github btn-block" href="<?php echo $this->escape($url['github']); ?>">
                                    <i class="fab fa-github"></i> <?php _e('Login with github'); ?>
                                </a>
                            </div>
                        <?php } ?>
                    </div>
                <?php } ?>
            </div>
        <?php } ?>
    </div>
</div>
