<?php
/** @var string|null $error */
/** @var string $redirect */
/** @var array $enabledMethods */
/** @var string $postedUsername */
/** @var Auth $auth */

$pageTitle = t('auth.login_title');
include WEBROOT_PATH . '/includes/header.php';
?>

<div class="auth-wrapper">
    <div class="auth-box">
        <h1><?= t('auth.login_title') ?></h1>

        <?php if ($error): ?>
        <div class="alert alert-error" role="alert">
            <?= htmlspecialchars($error) ?>
        </div>
        <?php endif; ?>

        <form method="post" action="/login?redirect=<?= urlencode($redirect) ?>" class="auth-form" novalidate>
            <input type="hidden" name="csrf_token" value="<?= htmlspecialchars(Session::get('csrf_token')) ?>">

            <div class="form-group">
                <label for="username"><?= t('auth.username') ?> *</label>
                <input type="text" id="username" name="username"
                       value="<?= htmlspecialchars($postedUsername) ?>"
                       required autofocus autocomplete="username">
            </div>

            <div class="form-group">
                <label for="password"><?= t('auth.password') ?> *</label>
                <input type="password" id="password" name="password"
                       required autocomplete="current-password">
            </div>

            <div class="form-actions">
                <button type="submit" class="btn btn-primary btn-full">
                    <?= t('auth.login') ?>
                </button>
            </div>
        </form>

        <?php if (in_array(AUTH_OAUTH, $enabledMethods)): ?>
        <?php $oauthUrl = $auth->getOAuthRedirectUrl(); ?>
        <?php if ($oauthUrl): ?>
        <div class="auth-separator"><?= t('auth.or_use') ?></div>
        <a href="<?= htmlspecialchars($oauthUrl) ?>" class="btn btn-oauth btn-full">
            <?= t('auth.method_oauth') ?>
        </a>
        <?php endif; ?>
        <?php endif; ?>
    </div>
</div>

<?php include WEBROOT_PATH . '/includes/footer.php'; ?>
