<div class="row justify-content-center">
    <div class="col-xl-9">
        <div class="d-flex align-items-center justify-content-between mb-3">
            <div>
                <h2 class="mb-1"><?= h(t('death.record', ['name' => $animal['name']])) ?></h2>
                <div class="text-muted"><?= h(t('death.intro')) ?></div>
            </div><a class="btn btn-outline-secondary" href="/animal?id=<?= (int)$animal['id'] ?>">←
                <?= h(t('animal.back_record')) ?></a>
        </div>

        <form method="post" action="/animal/death/save" class="card border-dark overflow-hidden">
            <input type="hidden" name="animal_id" value="<?= (int)$animal['id'] ?>">
            <div class="card-status-top bg-dark"></div>
            <div class="card-body">
                <div class="alert alert-info"><strong><?= h(t('death.important')) ?></strong>
                    <?= h(t('death.important_help')) ?></div>

                <div class="row g-3">
                    <div class="col-md-4"><label class="form-label required"><?= h(t('death.date')) ?></label><input
                            class="form-control" type="date" name="deceased_date"
                            value="<?= h($death['deceased_date']) ?>" required></div>
                    <div class="col-md-4"><label
                            class="form-label required"><?= h(t('death.main_cause')) ?></label><select
                            class="form-select" name="cause_code" required><?php foreach ($causes as $key => $label): ?>
                            <option value="<?= h($key) ?>" <?= $death['cause_code'] === $key ? 'selected' : '' ?>>
                                <?= h(DeathController::causeLabel($key)) ?></option><?php endforeach; ?></select></div>
                    <div class="col-md-4 d-flex align-items-end"><label class="form-check mb-2"><input
                                class="form-check-input" type="checkbox" name="euthanized"
                                <?= !empty($death['euthanized']) ? 'checked' : '' ?>><span
                                class="form-check-label"><?= h(t('death.euthanized')) ?></span></label></div>
                    <div class="col-12"><label class="form-label"><?= h(t('death.cause_details')) ?></label><textarea
                            class="form-control" name="cause_details" rows="2"
                            placeholder="<?= h(t('death.cause_placeholder')) ?>"><?= h($death['cause_details']) ?></textarea>
                    </div>
                </div>

                <hr class="my-4">
                <h3 class="card-title mb-3"><?= h(t('death.context_place')) ?></h3>
                <div class="row g-3">
                    <div class="col-md-5"><label class="form-label required"><?= h(t('death.place')) ?></label><select
                            class="form-select" name="place_type" required><?php foreach ($places as $key => $label): ?>
                            <option value="<?= h($key) ?>" <?= $death['place_type'] === $key ? 'selected' : '' ?>>
                                <?= h(DeathController::placeLabel($key)) ?></option><?php endforeach; ?></select></div>
                    <div class="col-md-7"><label class="form-label"><?= h(t('death.place_details')) ?></label><input
                            class="form-control" name="place_details" value="<?= h($death['place_details']) ?>"
                            placeholder="<?= h(t('death.place_placeholder')) ?>"></div>
                    <div class="col-12"><label class="form-check form-switch"><input class="form-check-input"
                                type="checkbox" name="occurred_in_care"
                                <?= !empty($death['occurred_in_care']) ? 'checked' : '' ?>><span
                                class="form-check-label"><strong><?= h(t('death.in_care')) ?></strong><br><span
                                    class="text-muted small"><?= h(t('death.in_care_help')) ?></span></span></label>
                    </div>
                    <div class="col-md-6"><label class="form-label"><?= h(t('death.veterinarian')) ?></label><select
                            class="form-select" name="veterinarian_contact_id">
                            <option value="">— <?= h(t('common.not_provided_option')) ?> —</option>
                            <?php foreach ($veterinarians as $contact): ?><option value="<?= (int)$contact['id'] ?>"
                                <?= (int)$death['veterinarian_contact_id'] === (int)$contact['id'] ? 'selected' : '' ?>>
                                <?= h($contact['name']) ?><?= $contact['city'] ? ' — ' . h($contact['city']) : '' ?>
                            </option><?php endforeach; ?>
                        </select></div>
                </div>

                <hr class="my-4">
                <h3 class="card-title mb-3"><?= h(t('death.care_body')) ?></h3>
                <div class="row g-3">
                    <div class="col-md-5"><label
                            class="form-label required"><?= h(t('death.body_disposition')) ?></label><select
                            class="form-select" name="body_disposition"
                            required><?php foreach ($dispositions as $key => $label): ?><option value="<?= h($key) ?>"
                                <?= $death['body_disposition'] === $key ? 'selected' : '' ?>>
                                <?= h(DeathController::dispositionLabel($key)) ?></option><?php endforeach; ?></select>
                    </div>
                    <div class="col-md-5"><label class="form-label"><?= h(t('death.crematorium')) ?></label><select
                            class="form-select" name="crematorium_contact_id">
                            <option value="">— <?= h(t('common.not_provided_option')) ?> —</option>
                            <?php foreach ($crematoriums as $contact): ?><option value="<?= (int)$contact['id'] ?>"
                                <?= (int)$death['crematorium_contact_id'] === (int)$contact['id'] ? 'selected' : '' ?>>
                                <?= h($contact['name']) ?><?= $contact['city'] ? ' — ' . h($contact['city']) : '' ?>
                            </option><?php endforeach; ?>
                        </select>
                        <div class="form-hint"><?= h(t('death.crematorium_help')) ?></div>
                    </div>
                    <div class="col-md-2"><label class="form-label"><?= h(t('death.cremation_date')) ?></label><input
                            class="form-control" type="date" name="cremation_date"
                            value="<?= h($death['cremation_date']) ?>"></div>
                    <div class="col-12"><label class="form-label"><?= h(t('death.internal_notes')) ?></label><textarea
                            class="form-control" name="notes" rows="3"
                            placeholder="<?= h(t('death.notes_placeholder')) ?>"><?= h($death['notes']) ?></textarea>
                    </div>
                </div>
            </div>
            <div class="card-footer d-flex"><a class="btn btn-link"
                    href="/animal?id=<?= (int)$animal['id'] ?>"><?= h(t('common.cancel')) ?></a><button
                    class="btn btn-dark ms-auto"
                    onclick="return confirm(<?= h(json_encode(t('death.confirm'), JSON_HEX_APOS | JSON_HEX_QUOT)) ?>);"><?= h(t('death.save')) ?></button>
            </div>
        </form>
    </div>
</div>
