

<?php $__env->startSection('title','Beli Tiket'); ?>

<?php $__env->startSection('content'); ?>

<div class="container">

    <h2 class="mb-4 fw-bold">
        🎟️ Pembelian Tiket
    </h2>

    <?php if($errors->any()): ?>
        <div class="alert alert-danger">
            <ul class="mb-0">
                <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <li><?php echo e($error); ?></li>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </ul>
        </div>
    <?php endif; ?>

    <div class="card shadow">
        <div class="card-body">

            <div class="mb-3">
                <strong>Event</strong>
                <div><?php echo e($tiket->event->nama_event ?? '-'); ?></div>
            </div>

            <div class="mb-3">
                <strong>Jenis Tiket</strong>
                <div><?php echo e($tiket->jenis); ?></div>
            </div>

            <div class="mb-3">
                <strong>Harga</strong>
                <div>Rp <?php echo e(number_format($tiket->harga,0,',','.')); ?></div>
            </div>

            <div class="mb-3">
                <strong>Stok Tersedia</strong>
                <div>
                    <?php if($tiket->stok > 0): ?>
                        <span class="badge bg-success"><?php echo e($tiket->stok); ?> Tiket</span>
                    <?php else: ?>
                        <span class="badge bg-danger">Habis</span>
                    <?php endif; ?>
                </div>
            </div>

            <?php if($tiket->stok > 0): ?>

                <form action="<?php echo e(route('tiket.beli.process', $tiket->id)); ?>" method="POST">
                    <?php echo csrf_field(); ?>

                    <input type="hidden" name="tiket_id" value="<?php echo e($tiket->id); ?>">

                    <div class="mb-3">
                        <label>Nama Pembeli</label>
                        <input
                            type="text"
                            name="nama_pembeli"
                            class="form-control"
                            value="<?php echo e(auth()->user()->name); ?>"
                            placeholder="Nama pembeli" readonly>
                    </div>

                    <div class="mb-3">
                        <label>Jumlah</label>
                        <input
                            type="number"
                            id="jumlah"
                            name="jumlah"
                            class="form-control"
                            value="1"
                            placeholder="1"
                            min="1"
                            max="<?php echo e($tiket->stok); ?>">
                        <div class="form-text">Stok tersedia: <?php echo e($tiket->stok); ?></div>
                    </div>

                    <div class="mb-3">
                        <strong>Total Harga</strong>
                        <div>
                            Rp <span id="total_harga"><?php echo e(number_format($tiket->harga,0,',','.')); ?></span>
                        </div>
                        <input type="hidden" name="total_harga" id="total_harga_input" value="<?php echo e($tiket->harga); ?>">
                    </div>

                    <script>
                        (function(){
                            const price = <?php echo e((float) $tiket->harga); ?>;
                            const inputJumlah = document.getElementById('jumlah');
                            const outputTotal = document.getElementById('total_harga');
                            const hiddenTotal = document.getElementById('total_harga_input');

                            function formatIDR(n){
                                return new Intl.NumberFormat('id-ID').format(Math.round(n));
                            }

                            function update(){
                                const jumlah = parseInt(inputJumlah.value || '0', 10);
                                const total = jumlah * price;
                                outputTotal.textContent = formatIDR(total);
                                hiddenTotal.value = total;
                            }

                            if(inputJumlah){
                                inputJumlah.addEventListener('input', update);
                                update();
                            }
                        })();
                    </script>

                    <div class="mb-3">
                        <label>Metode Pembayaran</label>

                        <select name="metode_pembayaran" class="form-control">
                            <option value="Tunai">Tunai</option>
                            <option value="QRIS">QRIS</option>
                            <option value="Transfer">Transfer</option>
                        </select>
                    </div>



                    <button class="btn btn-success w-100">
                        🎫 Konfirmasi Pembelian
                    </button>

                </form>

            <?php else: ?>

                <div class="alert alert-warning mb-0">
                    Tiket habis, silakan pilih event lain.
                </div>

            <?php endif; ?>

        </div>
    </div>

</div>

<?php $__env->stopSection(); ?>


<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\tugas pa asur\konser-ticket\resources\views/tiket/beli.blade.php ENDPATH**/ ?>