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

<?= $this->section('content') ?>
<div class="container py-5">
    <div class="row fade-in">
        <div class="col-12 mb-4 text-center">
            <h2 class="fw-bold text-dark"><i class="fa-solid fa-lock text-success me-2"></i>Secure Checkout</h2>
            <p class="text-muted">Complete your booking securely.</p>
        </div>
    </div>

    <div class="row g-5 fade-in" style="animation-delay: 0.1s;">
        <!-- Payment Details -->
        <div class="col-lg-8">
            <div class="card border-0 shadow-sm rounded-4 mb-4">
                <div class="card-body p-4">
                    <h4 class="fw-bold mb-4">Passenger / Guest Details</h4>
                    <form action="<?= base_url('checkout/process') ?>" method="POST">
                        <?= csrf_field() ?>
                        <input type="hidden" name="booking_type" value="<?= esc($booking_type) ?>">
                        <input type="hidden" name="item_id" value="<?= esc($item_id) ?>">
                        <input type="hidden" name="total" value="<?= esc($total) ?>">
                        <div class="row g-3 mb-4">
                            <div class="col-md-2">
                                <label class="form-label text-muted small">Title</label>
                                <select class="form-select border-0 bg-light">
                                    <option>Mr.</option>
                                    <option>Ms.</option>
                                    <option>Mrs.</option>
                                </select>
                            </div>
                            <div class="col-md-5">
                                <label class="form-label text-muted small">First Name</label>
                                <input type="text" class="form-control border-0 bg-light" required>
                            </div>
                            <div class="col-md-5">
                                <label class="form-label text-muted small">Last Name</label>
                                <input type="text" class="form-control border-0 bg-light" required>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label text-muted small">Email Address (For E-Ticket)</label>
                                <input type="email" class="form-control border-0 bg-light" value="<?= session()->get('email') ?>" required>
                            </div>
                            <div class="col-md-6">
                                <label class="form-label text-muted small">Phone Number</label>
                                <input type="tel" class="form-control border-0 bg-light" required>
                            </div>
                        </div>

                        <hr class="text-muted mb-4">

                        <h4 class="fw-bold mb-4">Payment Method</h4>
                        <div class="mb-4">
                            <div class="form-check border rounded p-3 mb-2 bg-white shadow-sm hover-lift">
                                <input class="form-check-input ms-1 me-3 mt-2" type="radio" name="payment" id="cc" checked>
                                <label class="form-check-label w-100 fw-semibold" for="cc">
                                    Credit / Debit Card
                                    <div class="float-end">
                                        <i class="fa-brands fa-cc-visa text-primary fs-4 me-1"></i>
                                        <i class="fa-brands fa-cc-mastercard text-danger fs-4"></i>
                                    </div>
                                </label>
                            </div>
                            
                            <div class="card border-0 bg-light p-3 mb-3 rounded-4">
                                <div class="row g-3">
                                    <div class="col-12">
                                        <input type="text" class="form-control" placeholder="Card Number" required>
                                    </div>
                                    <div class="col-md-6">
                                        <input type="text" class="form-control" placeholder="MM/YY" required>
                                    </div>
                                    <div class="col-md-6">
                                        <input type="text" class="form-control" placeholder="CVV" required>
                                    </div>
                                    <div class="col-12">
                                        <input type="text" class="form-control" placeholder="Name on Card" required>
                                    </div>
                                </div>
                            </div>

                            <div class="form-check border rounded p-3 mb-2 bg-white shadow-sm hover-lift">
                                <input class="form-check-input ms-1 me-3 mt-2" type="radio" name="payment" id="upi">
                                <label class="form-check-label w-100 fw-semibold" for="upi">
                                    UPI (Google Pay, PhonePe)
                                    <div class="float-end text-success fw-bold">UPI</div>
                                </label>
                            </div>
                        </div>

                        <button type="submit" class="btn btn-primary btn-lg w-100 rounded-pill shadow fw-bold">
                            <i class="fa-solid fa-lock me-2"></i>Pay ₹<?= number_format($total, 2) ?> Securely
                        </button>
                    </form>
                </div>
            </div>
        </div>

        <!-- Order Summary -->
        <div class="col-lg-4">
            <div class="card border-0 shadow-sm rounded-4 sticky-top" style="top: 100px;">
                <div class="card-body p-4 bg-primary text-white rounded-top-4" style="background: var(--primary-gradient) !important;">
                    <h5 class="fw-bold mb-0">Booking Summary</h5>
                </div>
                <div class="card-body p-4 bg-white rounded-bottom-4">
                    <div class="d-flex justify-content-between mb-3">
                        <span class="text-muted">Base Fare</span>
                        <span class="fw-semibold">₹<?= number_format($base_price, 2) ?></span>
                    </div>
                    <div class="d-flex justify-content-between mb-3">
                        <span class="text-muted">Taxes & Fees (18%)</span>
                        <span class="fw-semibold">₹<?= number_format($taxes, 2) ?></span>
                    </div>
                    
                    <?php if(session()->get('role') === 'agent'): ?>
                        <div class="d-flex justify-content-between mb-3 text-success">
                            <span><i class="fa-solid fa-tags me-1"></i>Agent Commission</span>
                            <span class="fw-bold">- ₹<?= number_format($base_price * 0.05, 2) ?></span>
                        </div>
                    <?php endif; ?>

                    <hr>
                    <div class="d-flex justify-content-between align-items-center mb-3">
                        <span class="fw-bold fs-5">Total Amount</span>
                        <span class="fw-bold fs-4 text-primary">₹<?= number_format(session()->get('role') === 'agent' ? $total - ($base_price * 0.05) : $total, 2) ?></span>
                    </div>
                    
                    <div class="alert alert-info py-2 small mb-0 rounded-3 border-0 bg-opacity-10">
                        <i class="fa-solid fa-shield-halved me-2"></i>256-bit SSL encrypted checkout
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
.hover-lift {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}
.hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.08) !important;
}
</style>
<?= $this->endSection() ?>
