<?php $__env->startSection('header-scripts'); ?>
    <script src="https://app.sandbox.midtrans.com/snap/snap.js" data-client-key="<?php echo e(env('MIDTRANS_CLIENT_KEY')); ?>"></script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <section class="py-5" style="background-color:#f1f1f1">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-8 offset-md-2">
                    <div class="card">
                        <div class="card-body">
                            <div class="order-md-last">
                                <h4 class="d-flex justify-content-between align-items-center mb-3">
                                    <span class="text-primary">List Pembayaran</span>
                                    <span class="badge bg-primary rounded-pill"><?php echo e(count($cart)); ?></span>
                                </h4>
                                <ul class="list-group mb-3">
                                    <?php if(count($cart) == 0): ?>
                                        <div class="align-self-center">
                                            Data keranjang kamu masih kosong :)
                                        </div>
                                    <?php endif; ?>
                                    <?php $__currentLoopData = $cart; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <li class="list-group-item d-flex justify-content-between lh-sm">
                                            <div class="d-flex justify-content-between">
                                                <img src="<?php echo e(asset('img_assets/product/' . $item->product->image)); ?>"
                                                    alt="" style="width: 100px; object-fit: contain">
                                                <div class="d-flex justify-content-center"
                                                    style="flex-direction: column; padding-left: 20px">
                                                    <h6 class="my-0"><?php echo e($item->product->name); ?></h6>
                                                    <small class="text-body-secondary"><?php echo e($item->amount); ?> Item</small>
                                                </div>
                                            </div>
                                            <div class="d-flex justify-content-between align-items-center">
                                                <span class="text-body-secondary d-flex align-items-center">
                                                    <?php if($item->product->is_discount): ?>
                                                        <span style="text-decoration: line-through">Rp.
                                                            <?php echo e(number_format($item->product->price * $item->amount)); ?>

                                                        </span>
                                                        <span style="padding-left: 20px">Rp.
                                                            <?php echo e(number_format($item->product->price * (1 - $item->product->discount_price / 100) * $item->amount)); ?></span>
                                                    <?php else: ?>
                                                        Rp. <?php echo e(number_format($item->product->price * $item->amount)); ?>

                                                    <?php endif; ?>
                                                </span>
                                            </div>
                                        </li>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                    <li class="list-group-item d-flex justify-content-between lh-sm">
                                        <div class="d-flex justify-content-between">
                                            <div class="d-flex justify-content-center"
                                                style="flex-direction: column; padding-left: 20px">

                                            </div>
                                        </div>
                                        <div class="d-flex justify-content-between align-items-center">
                                            <span class="text-body-secondary d-flex align-items-center">
                                                <h6 class="my-0" style="padding-right: 10px">Total</h6>
                                                <h6 class="my-0">Rp. <?php echo e(number_format($total)); ?></h6>
                                            </span>
                                        </div>
                                    </li>
                                </ul>


                                <input name="token" type="hidden" value="<?php echo e($snapToken); ?>" id="token">
                                <input name="token" type="hidden" value="<?php echo e($orderId); ?>" id="order-id">

                                <form action="<?php echo e(route('order.insert')); ?>" method="POST" id="form-order"
                                    style="padding-bottom: 40px">
                                    <?php echo csrf_field(); ?> <?php echo method_field('POST'); ?>
                                    <input type="hidden" name="product_ids" value="<?php echo e($product_ids); ?>" id="products-ids">
                                    <input type="hidden" name="products_amount" value="<?php echo e($products_amount); ?>"
                                        id="products-amount">
                                    <div class="form-group">
                                        <label class="form-label" for="">Alamat Pengiriman</label>
                                        <select type="text" class="form-control" name="shipping_address_id">
                                            <option value="">-Pilih-</option>
                                            <?php $__currentLoopData = $shipping_address; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($item->id); ?>">
                                                    <div>
                                                        <small class="text-body-secondary">Nama Penerima : </small>
                                                        <h6 class="my-0 mb-3"><?php echo e(auth()->user()->name); ?></h6>
                                                    </div>
                                                    <div>
                                                        <small class="text-body-secondary">Alamat :</small>
                                                        <h6 class="my-0 mb-3"><?php echo e($item->address_line); ?></h6>
                                                    </div>
                                                    <div>
                                                        <small class="text-body-secondary">Kota :</small>
                                                        <h6 class="my-0 mb-3"><?php echo e($item->city); ?></h6>
                                                    </div>
                                                    <div>
                                                        <small class="text-body-secondary">Provinsi :</small>
                                                        <h6 class="my-0 mb-3"><?php echo e($item->province); ?></h6>
                                                    </div>
                                                    <div>
                                                        <small class="text-body-secondary">Detail Alamat :</small>
                                                        <h6 class="my-0 mb-3"><?php echo e($item->detail_address); ?></h6>
                                                    </div>
                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>
                                </form>

                                <button class="w-100 btn btn-primary btn-lg" id="pay-button" type="submit">Mulai
                                    Pembayaran</button>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('footer-scripts'); ?>
    <script type="text/javascript">
        let token = document.getElementById('token').value;
        let orderId = document.getElementById('order-id').value;
        let formOrder = document.getElementById('form-order');

        document.getElementById('pay-button').onclick = function(e) {
            e.preventDefault();
            window.snap.pay(token, {
                onSuccess: async function() {
                    formOrder.submit();
                },
                onPending: function(result) {
                    // window.location.href = `/order`;
                },
                onError: function(result) {
                    console.log('tidak berhasil', result);
                },
                onClose: function() {
                    window.location.href = "<?php echo e(url('/')); ?>";
                }
            });
        };
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.web', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp8\htdocs\pasar_nelayan_zaskia\resources\views/apps/web/checkout.blade.php ENDPATH**/ ?>