<?php $pageTitle = 'invite_title'; ?>
<div class="auth-header">
    <h2><?= t('invite_title') ?></h2>
    <p class="auth-subtitle">
        <?= t('invite_subtitle_pre') ?> <strong><?= Helper::e($inv['group_name']) ?></strong>
    </p>
</div>

<?php if (!empty($errors)): ?>
<div class="alert alert-error" style="margin-bottom:16px">
    <?php foreach ($errors as $e): ?>
    <div><?= Helper::e($e) ?></div>
    <?php endforeach; ?>
</div>
<?php endif; ?>

<?php if (($mode ?? 'register') === 'wrong_user'): ?>

<div class="alert alert-error" style="margin-bottom:16px">
    <?= t('invite_wrong_user') ?>
</div>
<p style="text-align:center;margin-top:16px;font-size:.875rem">
    <a href="/dashboard"><?= t('invite_to_dashboard') ?></a>
</p>

<?php elseif ($mode === 'login_required'): ?>

<p style="margin-bottom:1.25rem;font-size:.95rem;color:var(--text-secondary)">
    <?= t('invite_login_required') ?>
</p>
<a href="/login?redirect=<?= urlencode('/invite/' . $inv['token']) ?>"
   class="btn btn-primary" style="width:100%;display:block;text-align:center">
    <?= t('invite_login_btn') ?>
</a>

<?php elseif ($mode === 'join'): ?>

<p style="margin-bottom:1.25rem;font-size:.95rem;color:var(--text-secondary)">
    <?= t('invite_join_text') ?>
</p>
<form method="POST">
    <?= Helper::csrf() ?>
    <button type="submit" class="btn btn-primary" style="width:100%"><?= t('invite_join_btn') ?></button>
</form>

<?php else: /* register */ ?>

<form method="POST">
    <?= Helper::csrf() ?>
    <div class="form-group">
        <label class="form-label"><?= t('email') ?></label>
        <input type="email" class="form-input" value="<?= Helper::e($inv['email']) ?>" disabled>
    </div>
    <div class="form-group">
        <label class="form-label"><?= t('username') ?> *</label>
        <input type="text" name="username" class="form-input" required minlength="3"
               value="<?= Helper::e(Helper::post('username')) ?>" autofocus>
    </div>
    <div class="form-group">
        <label class="form-label"><?= t('password') ?> *</label>
        <input type="password" name="password" class="form-input" required minlength="8">
    </div>
    <div class="form-group">
        <label class="form-label"><?= t('password_confirm') ?> *</label>
        <input type="password" name="password_confirm" class="form-input" required minlength="8">
    </div>
    <button type="submit" class="btn btn-primary" style="width:100%"><?= t('invite_accept_btn') ?></button>
</form>
<p style="text-align:center;margin-top:16px;font-size:.875rem;color:var(--text-muted)">
    <a href="/login"><?= t('login') ?></a>
</p>

<?php endif; ?>
