<?php
use App\Core\{Csrf, Session};
use function App\Core\{__, e, url};

$errors = Session::flash('auth_errors') ?: [];
$token = (string) ($token ?? '');
$tokenIsValid = (bool) ($tokenIsValid ?? false);
?>
<section class="auth-card">
    <h1><?= e(__('reset_password')) ?></h1>
    <p class="auth-copy"><?= e(__('reset_intro')) ?></p>

    <?php if ($errors): ?>
        <div class="auth-errors" role="alert">
            <?php foreach ($errors as $error): ?><p><?= e($error) ?></p><?php endforeach; ?>
        </div>
    <?php elseif ($token !== '' && !$tokenIsValid): ?>
        <div class="auth-errors" role="alert"><p><?= e(__('reset_token_invalid')) ?></p></div>
    <?php endif; ?>

    <form method="post" action="<?= url('/sifre-sifirla') ?>" novalidate>
        <?= Csrf::field() ?>
        <?php if ($tokenIsValid): ?>
            <input name="token" type="hidden" value="<?= e($token) ?>">
        <?php else: ?>
            <label>
                <?= e(__('reset_token')) ?>
                <input name="token" required value="<?= e($token) ?>">
            </label>
        <?php endif; ?>
        <label>
            <?= e(__('new_password')) ?>
            <input name="password" type="password" autocomplete="new-password" required>
        </label>
        <label>
            <?= e(__('password_confirmation')) ?>
            <input name="password_confirmation" type="password" autocomplete="new-password" required>
        </label>
        <button class="pill primary" type="submit"><?= e(__('save_password')) ?></button>
    </form>

    <div class="auth-links">
        <a href="<?= url('/giris-yap') ?>"><?= e(__('back_to_login')) ?></a>
    </div>
</section>
