<div class="page-header">
    <h1><?= e($name['name']) ?></h1>
    <div class="page-header-actions">
        <a class="button button-secondary button-sm"
           href="/householder-names/<?= e($name['id']) ?>/edit">Edit</a>
        <form method="POST" action="/householder-names/<?= e($name['id']) ?>/delete"
              class="inline-form"
              onsubmit="return confirm('Delete this name?')">
            <?= csrf_field() ?>
            <button class="button button-danger button-sm" type="submit">Delete</button>
        </form>
        <a class="button button-secondary button-sm"
           href="/households/<?= e($name['household_id']) ?>">← Household</a>
    </div>
</div>

<div class="section-panel">
    <dl class="detail-list">
        <dt>Household</dt>
        <dd>
            <a href="/households/<?= e($name['household_id']) ?>">
                <?= e($name['household_address']) ?>
            </a>
        </dd>

        <dt>Territory</dt>
        <dd>
            <a href="/territories/<?= e($name['territory_id']) ?>">
                <?= e($name['territory_name']) ?>
            </a>
        </dd>

        <dt>Letter Returned</dt>
        <dd>
            <?php if ($name['letter_returned']): ?>
                <span class="badge badge-success">Yes</span>
                <?php if ($name['return_date']): ?>
                    <span class="text-secondary">(<?= e($name['return_date']) ?>)</span>
                <?php endif; ?>
            <?php else: ?>
                No
            <?php endif; ?>
        </dd>

        <dt>Added</dt>
        <dd class="text-secondary"><?= e((string) ($name['created_at'] ?? '')) ?></dd>
    </dl>

    <div class="form-actions" style="margin-top:1.25rem">
        <form method="POST"
              action="/householder-names/<?= e($name['id']) ?>/mark-returned"
              class="inline-form">
            <?= csrf_field() ?>
            <button class="button button-secondary" type="submit">
                <?= $name['letter_returned'] ? 'Unmark as Returned' : 'Mark Letter Returned' ?>
            </button>
        </form>
    </div>
</div>
