<div class="row justify-content-center">
    <div class="col-xl-9">
        <form method="post" action="/animal/surgery/save" class="card"><input type="hidden" name="csrf"
                value="<?= h(Auth::csrf()) ?>"><input type="hidden" name="animal_id" value="<?= (int)$animal['id'] ?>">
            <div class="card-header">
                <h3 class="card-title">🏥 Chirurgie — <?= h($animal['name']) ?></h3>
            </div>
            <div class="card-body">
                <div class="row g-3">
                    <div class="col-md-4"><label class="form-label">Catégorie</label><select class="form-select"
                            name="category">
                            <option value="orthopedic">Orthopédie</option>
                            <option value="dental">Dentaire</option>
                            <option value="soft_tissue">Viscérale / tissus mous</option>
                            <option value="reproductive">Appareil reproducteur</option>
                            <option value="ophthalmology">Ophtalmologie</option>
                            <option value="oncology">Oncologie</option>
                            <option value="imaging_guided">Radiologie / intervention guidée</option>
                            <option value="wound">Plaie / reconstruction</option>
                            <option value="other">Autre</option>
                        </select></div>
                    <div class="col-md-8"><label class="form-label">Intitulé de l’intervention *</label><input
                            class="form-control" name="procedure_name" required
                            placeholder="Ex. ovariectomie, détartrage, ostéosynthèse…"></div>
                    <div class="col-md-4"><label class="form-label">Date *</label><input class="form-control"
                            type="date" name="surgery_date" value="<?= h(date('Y-m-d')) ?>" required></div>
                    <div class="col-md-4"><label class="form-label">Statut</label><select class="form-select"
                            name="status">
                            <option value="completed">Réalisée</option>
                            <option value="planned">Planifiée</option>
                            <option value="cancelled">Annulée</option>
                        </select></div>
                    <div class="col-md-4"><label class="form-label">Montant réel (€)</label><input class="form-control"
                            inputmode="decimal" name="amount" placeholder="Calculé depuis le tarif si vide"></div>
                    <div class="col-md-6"><label class="form-label">Structure</label><select class="form-select"
                            name="clinic_contact_id">
                            <option value="">—</option><?php foreach ($clinics as $c):?><option
                                value="<?= (int)$c['id'] ?>"><?= h($c['name']) ?></option><?php endforeach?>
                        </select></div>
                    <div class="col-md-6"><label class="form-label">Vétérinaire</label><select class="form-select"
                            name="veterinarian_contact_id">
                            <option value="">—</option><?php foreach ($vets as $v):?><option
                                value="<?= (int)$v['id'] ?>"
                                data-organization="<?= (int)($v['organization_id'] ?? 0) ?>"><?= h($v['name']) ?>
                            </option><?php endforeach?>
                        </select></div>
                    <div class="col-12"><label class="form-label">Tarif de référence (facultatif)</label><select
                            class="form-select" name="tariff_id">
                            <option value="">— Saisie libre —</option>
                            <?php foreach ($tariffs as $t):$net = (int)round($t['amount_cents'] * (1 - (float)$t['discount'] / 100));?>
                            <option value="<?= (int)$t['id'] ?>" data-clinic="<?= (int)$t['clinic_contact_id'] ?>">
                                <?= h($t['label']) ?> — <?= number_format($net / 100, 2, ',', ' ') ?> €</option>
                            <?php endforeach?>
                        </select></div>
                    <div class="col-md-6"><label class="form-label">Anesthésie / protocole</label><textarea
                            class="form-control" name="anesthesia" rows="3"></textarea></div>
                    <div class="col-md-6"><label class="form-label">Compte rendu / annotations</label><textarea
                            class="form-control" name="notes" rows="3"></textarea></div>
                    <div class="col-12"><label class="form-label">Suites et contrôles prévus</label><textarea
                            class="form-control" name="follow_up" rows="2"></textarea></div>
                </div>
            </div>
            <div class="card-footer text-end"><a class="btn btn-link"
                    href="/animal?id=<?= (int)$animal['id'] ?>">Annuler</a><button class="btn btn-primary">Enregistrer
                    la chirurgie</button></div>
        </form>
    </div>
</div>
