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

<?= $this->section('title') ?>¡Reserva Confirmada! - CinePlex<?= $this->endSection() ?>

<?= $this->section('content') ?>
<style>
    .success-container {
        max-width: 650px;
        margin: 40px auto;
        background: rgba(255, 255, 255, 0.03);
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 15px;
        padding: 40px;
        color: #fff;
        text-align: center;
        box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
    }

    .success-icon {
        width: 80px;
        height: 80px;
        background: #4caf50;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 3rem;
        color: #000;
        margin: 0 auto 25px auto;
        animation: scaleIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        box-shadow: 0 0 20px rgba(76, 175, 80, 0.4);
    }

    @keyframes scaleIn {
        from { transform: scale(0); opacity: 0; }
        to { transform: scale(1); opacity: 1; }
    }

    .success-container h2 {
        color: #4caf50;
        margin-bottom: 5px;
        font-size: 1.8rem;
    }

    .reservation-code-box {
        background: rgba(255, 152, 0, 0.1);
        border: 1px dashed #ff9800;
        border-radius: 8px;
        padding: 15px;
        margin: 25px auto;
        max-width: 320px;
    }

    .reservation-code-box span {
        display: block;
        font-size: 0.85rem;
        color: #aaa;
        text-transform: uppercase;
        letter-spacing: 1px;
        margin-bottom: 5px;
    }

    .reservation-code-box strong {
        font-size: 1.6rem;
        color: #ff9800;
        letter-spacing: 2px;
        font-family: monospace;
    }

    .info-card {
        background: rgba(255, 255, 255, 0.02);
        border: 1px solid rgba(255, 255, 255, 0.05);
        border-radius: 10px;
        padding: 25px;
        text-align: left;
        margin-bottom: 30px;
    }

    .info-card h4 {
        color: #ff9800;
        margin-top: 0;
        margin-bottom: 15px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        padding-bottom: 8px;
        font-size: 1.1rem;
    }

    .info-row {
        display: flex;
        justify-content: space-between;
        margin-bottom: 12px;
        font-size: 0.95rem;
        color: #ccc;
    }

    .info-row strong {
        color: #fff;
    }

    .actions-row {
        display: flex;
        gap: 15px;
        justify-content: center;
        margin-top: 20px;
    }

    .actions-row .btn {
        flex: 1;
        padding: 14px 20px;
        font-size: 1rem;
        font-weight: bold;
    }

    .seat-pill {
        display: inline-block;
        background: rgba(255, 255, 255, 0.1);
        padding: 2px 6px;
        border-radius: 4px;
        margin-left: 5px;
        font-size: 0.85rem;
    }

    .alert-mail {
        border-radius: 6px;
        padding: 12px;
        margin-bottom: 25px;
        text-align: left;
        font-size: 0.9rem;
    }

    .alert-mail.success {
        background: rgba(76, 175, 80, 0.1);
        border: 1px solid #4caf50;
        color: #a5d6a7;
    }

    .alert-mail.warning {
        background: rgba(255, 152, 0, 0.1);
        border: 1px solid #ff9800;
        color: #ffe082;
    }
</style>

<div class="success-container">
    <div class="success-icon">✓</div>
    
    <h2>¡Pago Aprobado con Éxito!</h2>
    <p style="color: #aaa; margin-top: 5px;">Tu transacción ha sido completada de forma segura.</p>

    <div class="reservation-code-box">
        <span>Código de Reserva</span>
        <strong><?= esc($reserva->referencia) ?></strong>
    </div>

    <!-- Feedback messages for email delivery status -->
    <?php if (session()->getFlashdata('success_email')): ?>
        <div class="alert-mail success">
            ✉️ <?= session()->getFlashdata('success_email') ?>
        </div>
    <?php elseif (session()->getFlashdata('warning_email')): ?>
        <div class="alert-mail warning">
            ⚠️ <?= session()->getFlashdata('warning_email') ?>
        </div>
    <?php endif; ?>

    <!-- Summary Details Card -->
    <div class="info-card">
        <h4>Resumen de Boleto</h4>
        
        <div class="info-row">
            <span>Película:</span>
            <strong><?= esc($detalles[0]->pelicula_titulo) ?></strong>
        </div>
        <div class="info-row">
            <span>Local / Cine:</span>
            <strong><?= esc($detalles[0]->local_nombre) ?></strong>
        </div>
        <div class="info-row">
            <span>Sala:</span>
            <strong><?= esc($detalles[0]->sala_nombre) ?></strong>
        </div>
        <div class="info-row">
            <span>Fecha y Hora:</span>
            <strong>
                <?= date('d/m/Y', strtotime($detalles[0]->fecha)) ?> - <?= date('g:i A', strtotime($detalles[0]->hora_inicio)) ?>
            </strong>
        </div>
        <div class="info-row">
            <span>Asientos:</span>
            <div>
                <?php foreach ($detalles as $det): ?>
                    <span class="seat-pill"><?= esc($det->fila) . $det->numero ?></span>
                <?php endforeach; ?>
            </div>
        </div>
        <div class="info-row" style="margin-top: 15px; padding-top: 15px; border-top: 1px solid rgba(255,255,255,0.05);">
            <span>Monto pagado:</span>
            <strong style="color: #ff9800; font-size: 1.1rem;">S/ <?= number_format($reserva->total, 2) ?></strong>
        </div>
        <div class="info-row">
            <span>Método de pago:</span>
            <strong style="text-transform: capitalize;"><?= esc($reserva->metodo) ?> (Simulado)</strong>
        </div>
    </div>

    <!-- Actions -->
    <div class="actions-row">
        <a href="<?= base_url('reserva/boleto/' . $reserva->id_reserva) ?>" class="btn btn-primary">
            📥 Descargar PDF
        </a>
        <a href="<?= base_url('/') ?>" class="btn btn-secondary">
            Volver a Cartelera
        </a>
    </div>
</div>
<?= $this->endSection() ?>
