<?php $__env->startPush('meta'); ?>
    <meta name='description' content="Buy now product" />
    <meta name='keywords' content="<?php $__currentLoopData = $product->tags; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tag): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><?php echo e($tag->name . ', '); ?> <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>" />
<?php $__env->stopPush(); ?>

<?php $__env->startSection('title', 'Minimal - Buy now product'); ?>

<?php $__env->startSection('content'); ?>
    <?php
        $order = App\Models\Order::where('user_id', auth()->id())
            ->select('address', 'shipping_charge', 'town', 'district', 'thana')
            ->first();
    ?>
    <div id="checkout">
        <div class="container">
            <form action="<?php echo e(route('order.store_minimal')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <div class="row mt-3">
                    <div class="col-md-8 offset-md-2 alert-message">
                        <div class="alert"></div>
                    </div>
                    
                    
                    <div class="widget3 col-md-7">
                        <h4 class="form-title"><span>1</span> Billing Info </h4>
                        <?php echo $__env->make('frontend.partial.checkout.checkout_part.billing_info_minimal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                    </div>
                    

                    <div class="widget3 col-md-5">

                        
                        <div class="row">
                            <style>
                                #accordion .card {
                                    padding: 0 !important;
                                }
                        
                                #accordion .card-body {
                                    padding: 0;
                                    margin-top: 10px;
                                }
                        
                                #accordion .card-header {
                                    padding: 0;
                                }
                        
                                #accordion .card-header h5 div {
                                    font-size: 15px;
                                    padding: 10px;
                                    background: var(--primary_color);
                                    color: white;
                                    cursor: pointer;
                                }
                        
                                label img {
                                    width: 100px;
                                    height: 50px;
                                    object-fit: contain;
                                }
                        
                                .pa label {
                                    text-align: center;
                                    box-shadow: 0px 0px 6px gainsboro;
                                    padding: 10px 20px;
                                    border-radius: 5px;
                                    position: relative;
                                    cursor: pointer;
                                }
                        
                                .arrow-in {
                                    top: 5px;
                                }
                        
                                .payment_method {
                                    position: absolute;
                                    z-index: -9;
                                }
                            </style>
                            <div class="widget-3 col-md-12">
                                <div class="widget3">
                                    <h4 class="form-title"><span>2</span>Payment Method</h4>
                                    <?php echo $__env->make('frontend.partial.checkout.checkout_part.payment_methode_minimal', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                                </div>
                            </div>
                        </div>

                        <input type="hidden" value="<?php echo e($request->dynamic_price); ?>" name="dynamic_prices">

                        <h4 class="form-title"><span>3</span>Order Summary </h4>
                        <div class="card">
                            <?php
                            if ($request->qty >= 6 && $product->whole_price > 0) {
                                $sub_total = $product->whole_price * $request->qty;
                            } else {
                                $sub_total = $request->dynamic_price * $request->qty;
                            }
                            ?>
                            <div style="margin-bottom: 10px;display: flex;" class="product">
                                
                                <img style="width:50px" src="<?php echo e(asset('uploads/product/' . ($product->color_image ? $product->color_image : $product->image))); ?>"
                                    alt="">
                                <a id="product_name" class="product_name" style="margin-left:10px"
                                    href="<?php echo e(route('product.details', $product->slug)); ?>"><?php echo e($product->title); ?></a>
                                <span class="text-muted"><?php echo e($product->color); ?></span>
                                <span style="flex: 1 auto;text-align: right;"> <?php echo e($sub_total); ?></span>
                                <input type="hidden" name="id" value="<?php echo e($request->id); ?>">
                                <input type="hidden" name="qty" value="<?php echo e($request->qty); ?>">
                                <?php
                                $attr = [];
                                $attributes = DB::table('attributes')->get();
                                foreach ($attributes as $attribute) {
                                    $attribute_prouct = DB::table('attribute_product')
                                        ->select('*')
                                        ->join('attribute_values', 'attribute_values.id', '=', 'attribute_product.attribute_value_id')
                                        ->addselect('attribute_values.name as vName')
                                        ->addselect('attribute_product.id as vid')
                                        ->join('attributes', 'attributes.id', '=', 'attribute_values.attributes_id')
                                        ->where('attribute_product.product_id', $product->id)
                                        ->where('attributes.id', $attribute->id)
                                        ->get();
                                    if ($attribute_prouct->count() > 0) {
                                        $slug = $attribute->slug;
                                        $attr[$slug] = $request->$slug;
                                    }
                                }
                                ?>
                                <input type="hidden" name="size"
                                    value="<?php echo e($attr != '' ? json_encode($attr) : 'blank'); ?>">
                                <input type="hidden" name="color" value="<?php echo e($request->color); ?>">
                            </div>

                            <style>
                                .arrow2 .icofont-simple-down {
                                    display: block;
                                }

                                .arrow2 .icofont-simple-right {
                                    display: none;
                                }

                                .collapsed .arrow2 .icofont-simple-down {
                                    display: none !important;
                                }

                                .collapsed .arrow2 .icofont-simple-right {
                                    display: block !important;
                                }
                            </style>
                            <div class="form-group">
                                <div class="form-group instruction">
                                    <a class="collapsed" data-toggle="collapse" href="#collapseExample" role="button"
                                        aria-expanded="false" aria-controls="collapseExample">
                                        <span><label for="">Coupon</label> </span><span class="arrow2"></span>
                                    </a>
                                    <div class="collapse" id="collapseExample">
                                        <input type="text" id="coupon" class="form-control"
                                            placeholder="Coupon Code" />
                                        <button type="button" class="btn btn-primary btn-block py-2"
                                            id="apply-coupon">Apply</button>
                                    </div>
                                </div>
                            </div>
                            <input type="hidden" value="0" id="partial_paid" name="partial_paid"
                                class="form-control" placeholder="Partial Amount" />
                            <div class="rvinfo">
                                <span>Subtotal</span>
                                <span><span id="sub-total"> <?php echo e($sub_total); ?></span> <strong> <?php echo e(setting('CURRENCY_CODE_MIN') ?? 'TK'); ?></strong></span>
                            </div>
                            <div class="rvinfo">
                                <span>Shipping Charge</span>
                                <span>+ <span id="ship-charge">
                                        <?php if(isset($order->shipping_charge)): ?>
                                            <?php echo e($order->shipping_charge); ?>

                                        <?php else: ?>
                                            0.00
                                        <?php endif; ?>
                                    </span><strong> <?php echo e(setting('CURRENCY_CODE_MIN') ?? 'TK'); ?></strong></span>
                            </div>

                            <div class="rvinfo coupon">
                                <span>Coupon <span class="coupon-name"></span> <a id="reset_coupon_btn" href="<?php echo e(route('reset.coupon')); ?>" class="btn bg-danger text-white text-sm-left <?php if(Session::has('coupon')): ?>d-visible <?php else: ?> d-none <?php endif; ?>" style="padding:.0rem .4rem;">x</a></span>
                                <span>- <span
                                        id="coupon"><?php echo e(Session::has('coupon') ? number_format(Session::get('coupon')['discount'], 2, '.', ',') : '0.00'); ?></span><strong>
                                            <?php echo e(setting('CURRENCY_CODE_MIN') ?? 'TK'); ?></strong></span>
                            </div>
                            <hr>
                            <div class="rvinfo">
                                <span>Total</span>
                                <h4>
                                    <?php if(Session::has('coupon')): ?>
                                        <?php
                                            $discount = Session::get('coupon')['discount'];
                                            $total = number_format($sub_total - $discount, 2, '.', ',');
                                        ?>
                                    <?php endif; ?>
                                    <strong>
                                        <span id="total">
                                            <?php echo e($total ?? number_format($sub_total, 2, '.', ',')); ?></span> <?php echo e(setting('CURRENCY_CODE_MIN') ?? 'TK'); ?>

                                    </strong>
                                </h4>
                            </div>
                        </div>
                        <input value="Order" type="submit">
                    </div>
                </div>
            </form>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>
    
    <script>
        $(document).ready(function() {
            
            // Coupon
            $(document).on('click', '#apply-coupon', function(e) {
                e.preventDefault();
                $('#coupon').removeClass('is-invalid');
                let code = $('input#coupon').val();
                let id = "<?php echo $request->id; ?>";
                let qty = "<?php echo $request->qty; ?>";
                let dynamic_price = "<?php echo $request->dynamic_price; ?>";
                let shipping_charge = 0;
                let download_able = "<?php echo $product->download_able; ?>";

                if (download_able != 1) {
                    if ($("select[name='shipping_range']").val() == 1) {
                        let charge = "<?php echo setting('shipping_charge'); ?>";
                        shipping_charge += parseInt(charge);
                    } else {
                        let charge = "<?php echo setting('shipping_charge_out_of_range'); ?>";
                        shipping_charge += parseInt(charge);
                    }
                }

                if (code != '') {
                    $.ajax({
                        type: 'GET',
                        url: '/apply/coupon/buy-now/' + code + '/' + id + '/' + qty + '/' +
                            dynamic_price,
                        dataType: "JSON",
                        success: function(response) {
                            console.log(response);
                            $('.alert-message').removeClass('d-none');
                            if (response.alert == 'success') {
                                $('.alert-message .alert').removeClass('alert-danger').addClass(
                                    'alert-success').text(response.message);
                                $('span#ship-charge').text(number_format(shipping_charge, 2,
                                    '.', ','));
                                $('span#coupon').text(number_format(response.discount, 2, '.',
                                    ','));
                                let total = response.total + shipping_charge;
                                $('span#total').text(number_format(total, 2, '.', ','));
                                $('span.coupon-name').text('(' + code + ')');
                                $('#coupon').val('');
                                $('#reset_coupon_btn').removeClass('d-none');
                                // $('#reset_coupon_btn').addClass('d-visible');
                                
                            } else {
                                $('.alert-message .alert').removeClass('alert-success')
                                    .addClass('alert-danger').text(response.message);
                            }
                        },
                        error: function(xhr) {
                            console.log(xhr);
                        }
                    });
                } else {
                    $('#coupon').addClass('is-invalid');
                }
                setTimeout(() => {
                    $('.alert-message .alert').removeClass('alert-danger alert-success').text('');
                }, 10000);

            });




            /* 
            ** Shipping
            * */
            $(document).on('change', '#shipping_range', function(e) {
                divis()
            });

            divis();
            function divis() {
                let shipping_charge = 0;
                let download_able = "<?php echo $product->download_able; ?>";
                if (download_able != 1) {
                    if($("select[name='shipping_range']").val() == 3){
                        let charge = 0;
                        shipping_charge += parseInt(charge);
                    }else if($("select[name='shipping_range']").val() == 2){
                        let charge = "<?php echo $product->dedicated_shipping_charge; ?>";
                        shipping_charge += parseInt(charge);
                    }else if ($("select[name='shipping_range']").val() == 1) {
                        let charge = "<?php echo setting('shipping_charge'); ?>";
                        shipping_charge += parseInt(charge);
                    } else {
                        let charge = "<?php echo setting('shipping_charge_out_of_range'); ?>";
                        shipping_charge += parseInt(charge);
                    }
                }
                let subtotal = $('span#sub-total').text();
                let coupon = $('span#coupon').text();
                let rep_subtotal = subtotal.replace(',', '');
                let rep_coupon = coupon.replace(',', '');
                let total = (parseInt(rep_subtotal) + shipping_charge) - parseInt(rep_coupon);
                $('span#ship-charge').text(number_format(shipping_charge, 2, '.', ','));
                $('span#total').text(number_format(total, 2, '.', ','));
            }

            function number_format(number, decimals, dec_point, thousands_sep) {
                var n = !isFinite(+number) ? 0 : +number,
                    prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
                    sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
                    dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
                    toFixedFix = function(n, prec) {
                        // Fix for IE parseFloat(0.55).toFixed(0) = 0;
                        var k = Math.pow(10, prec);
                        return Math.round(n * k) / k;
                    },
                    s = (prec ? toFixedFix(n, prec) : Math.round(n)).toString().split('.');
                if (s[0].length > 3) {
                    s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
                }
                if ((s[1] || '').length < prec) {
                    s[1] = s[1] || '';
                    s[1] += new Array(prec - s[1].length + 1).join('0');
                }
                return s.join(dec);
            }
        });
    </script>

    <?php if(setting('GTM_DATA_LAYER_STATUS') == 1 || setting('GTM_DATA_LAYER_STATUS') == null): ?>
        <script type="text/javascript">

            $(document).ready(function() {
            
                var price = <?php echo e($request->dynamic_price); ?>;
                var quantity = <?php echo e($request->qty); ?>;
                var totalPrice = price * quantity;

              
                window.dataLayer = window.dataLayer || [];
                window.dataLayer.push({
                    event: "begin_checkout",
                    ecommerce: {
                        currency: "<?php echo setting('CURRENCY_CODE'); ?>",  
                        value: totalPrice,
                        coupon: "",  
                        items: [
                            {
                                item_id: "<?php echo $product->id; ?>",  
                                item_name: "<?php echo $product->title; ?>",
                                affiliation: "",  
                                coupon: "",  
                                discount: <?php echo Session::get('coupon')['discount'] ?? 0; ?>,  
                                index: "",  
                                item_brand: "<?php echo $product->brand['name']; ?>",  
                                item_category: "",  
                                item_category2: "",  
                                item_category3: "",  
                                item_category4: "",  
                                item_variant: "",  
                                item_list_id: "",  
                                item_list_name: "",  
                                location_id: "",  
                                price: price,  
                                quantity: quantity
                            }
                        ]
                    }
                });
            });
        </script>
    <?php endif; ?>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.frontend.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/apleusbj/shopping.apleefix.com/resources/views/frontend/partial/checkout/bc_minimal.blade.php ENDPATH**/ ?>