<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<h1 class="h3 mb-3">Possible Duplicate Guest</h1>

<div class="alert alert-warning">
    Another guest already has a matching phone number or ID number. Double-check before creating a new record —
    or continue anyway if this is genuinely a different person (e.g. a shared household number).
</div>

<div class="card shadow-sm mb-3" style="max-width: 640px;">
    <div class="card-body">
        <h2 class="h6">Possible matches</h2>
        <ul class="list-group list-group-flush">
            <?php foreach ($duplicates as $dup): ?>
                <li class="list-group-item d-flex justify-content-between align-items-center">
                    <div>
                        <div class="fw-semibold"><?= esc($dup->full_name) ?></div>
                        <div class="text-muted small"><?= esc($dup->phone) ?> <?= $dup->id_number ? ' · ' . esc($dup->id_number) : '' ?></div>
                    </div>
                    <a href="<?= site_url('guests/' . $dup->id) ?>" class="btn btn-sm btn-outline-secondary">View</a>
                </li>
            <?php endforeach; ?>
        </ul>
    </div>
</div>

<form action="<?= $formAction ?>" method="post">
    <?= csrf_field() ?>
    <?php foreach ($formData as $key => $value): ?>
        <input type="hidden" name="<?= esc($key) ?>" value="<?= esc($value) ?>">
    <?php endforeach; ?>
    <input type="hidden" name="confirm_duplicate" value="1">
    <button type="submit" class="btn btn-warning">Create Anyway — This Is a Different Person</button>
    <a href="<?= site_url('guests') ?>" class="btn btn-outline-secondary">Cancel</a>
</form>

<?= $this->endSection() ?>
