<?php require dirname(__DIR__) . '/layouts/header.php'; ?>

<main class="receipt-page">
    <section class="receipt">
        <header class="receipt-header">
            <div>
                <span class="brand-mark">L</span>
                <h1>Recu de paiement</h1>
                <p><?= e($settings['company_name']) ?> - Gestion locative</p>
                <?php if ($settings['company_address'] || $settings['company_city']): ?>
                    <p><?= e(trim($settings['company_address'] . ' ' . $settings['company_city'])) ?></p>
                <?php endif; ?>
                <?php if ($settings['company_phone'] || $settings['company_email']): ?>
                    <p><?= e(trim($settings['company_phone'] . ' ' . $settings['company_email'])) ?></p>
                <?php endif; ?>
            </div>
            <div class="receipt-meta">
                <strong>Recu #<?= (int) $payment['id'] ?></strong>
                <span>Date: <?= e($payment['payment_date'] ?: date('Y-m-d')) ?></span>
                <span>Statut: <?= e(payment_statuses()[$payment['status']] ?? $payment['status']) ?></span>
            </div>
        </header>

        <section class="receipt-grid">
            <article>
                <h2>Client</h2>
                <p><?= e($payment['first_name'] . ' ' . $payment['last_name']) ?></p>
                <p><?= e($payment['phone'] ?: '-') ?></p>
                <p><?= e($payment['email'] ?: '-') ?></p>
                <p>Identite: <?= e($payment['identity_number'] ?: '-') ?></p>
            </article>

            <article>
                <h2>Reservation</h2>
                <p>#<?= (int) $payment['reservation_id'] ?></p>
                <p><?= e($payment['property_title']) ?></p>
                <p><?= e($payment['city']) ?><?= $payment['district'] ? ', ' . e($payment['district']) : '' ?></p>
                <p><?= e($payment['start_date'] . ' - ' . $payment['end_date']) ?></p>
            </article>
        </section>

        <table class="receipt-table">
            <thead>
                <tr>
                    <th>Description</th>
                    <th>Mode</th>
                    <th>Montant</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Paiement reservation #<?= (int) $payment['reservation_id'] ?></td>
                    <td><?= e(payment_methods()[$payment['payment_method']] ?? $payment['payment_method']) ?></td>
                    <td><?= number_format((float) $payment['amount'], 2, ',', ' ') ?></td>
                </tr>
            </tbody>
        </table>

        <section class="receipt-total">
            <span>Montant reservation: <?= number_format((float) $payment['total_amount'], 2, ',', ' ') ?></span>
            <strong>Total paye: <?= number_format((float) $payment['amount'], 2, ',', ' ') ?></strong>
        </section>

        <section class="receipt-notes">
            <h2>Notes</h2>
            <p><?= nl2br(e($payment['notes'] ?: 'Aucune note.')) ?></p>
        </section>

        <footer class="receipt-footer">
            <span>Merci pour votre confiance.</span>
            <span>Signature</span>
        </footer>
    </section>

    <div class="receipt-actions no-print">
        <button type="button" onclick="window.print()">Imprimer</button>
        <a class="button-link secondary" href="<?= url('/payments/show?id=' . $payment['id']) ?>">Retour</a>
    </div>
</main>

<?php require dirname(__DIR__) . '/layouts/footer.php'; ?>
