<?php $__env->startSection('title'); ?>
    <?php echo e(__('Billing')); ?>

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

<style>
    
    .form-group label {
    font-size: 14px !important;
    font-weight: 600 ! important;
}

</style>

<?php $__env->startSection('content'); ?>
    <!-- Page Title-->
    <div class="page-title">
        <div class="container">
            <div class="column">
                <ul class="breadcrumbs">
                    <li><a href="<?php echo e(route('front.index')); ?>"><?php echo e(__('Home')); ?></a> </li>
                    <li class="separator"></li>
                    <li><?php echo e(__('Order Summary')); ?></li>
                </ul>
            </div>
        </div>
    </div>

    <!-- Page Content-->
    <div class="container padding-bottom-3x mb-1 checkut-page">
        <div class="row">
            <!-- Billing Adress-->
            <div class="col-xl-9 col-lg-8">
                
                <div class="card">
                    <div class="card-body">
                        <h6 class="text-center"><?php echo e(__('কাস্টমার ইনফরমেশন')); ?></h6>
                        <hr class="mb-4">

                        <form id="checkoutBilling" action="<?php echo e(route('front.checkout.submit')); ?>" method="POST">
                            <?php echo csrf_field(); ?>
                            <div class="row">
                                <div class="col-sm-6">
                                    <div class="form-group">
                                        <label for="checkout-fn"><?php echo e(__('আপনার নাম')); ?></label>
                                        <input class="form-control" name="bill_first_name" type="text" required
                                            id="checkout-fn" value="<?php echo e(isset($user) ? $user->first_name : ''); ?>">
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                  <div class="form-group">
                                      <label for="checkout-phone"><?php echo e(__('আপনার ফোন নাম্বার')); ?></label>
                                      <input class="form-control" name="bill_phone" type="text" id="checkout-phone"
                                          required value="<?php echo e(isset($user) ? $user->phone : ''); ?>">
                                  </div>
                              </div>
                              <div class="col-sm-6">
                                <div class="form-group">
                                    <label for="checkout-address1"><?php echo e(__('আপনার ঠিকানা')); ?></label>
                                    <input class="form-control" name="bill_address1" required type="text"
                                        id="checkout-address1"
                                        value="<?php echo e(isset($user) ? $user->bill_address1 : ''); ?>">
                                </div>
                              </div>

                                <div class="col-sm-6">
                                    <div class="form-group">
                                      <label for="bill_area"><?php echo e(__('আপনার এরিয়া সিলেক্ট করুন')); ?></label>
                                      <select class="form-control" required name="bill_area" 
                                          id="bill_area">
                                          <?php $__currentLoopData = $shippingAreas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $area): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                          <option data-id="<?php echo e($area->id); ?>" <?php echo e(Session::has('shipping') ? (Session::get('shipping')->id == $area->id ? 'selected' : '') : ''); ?> value="<?php echo e(PriceHelper::setCurrencyPrice($area->price)); ?>" ><?php echo e($area->title); ?></option>
                                          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                      </select>
                                  </div>
                                </div>
                            </div>
                            <div class="d-flex justify-content-center paddin-top-1x mt-4">

                              <button class="btn btn-primary btn-md" type="submit"><span
                                class=""><?php echo e(__('অর্ডার কনফার্ম করুন')); ?></span></button>
                            </div>
                            
                        </form>
                    </div>
                </div>
            </div>
            <!-- Sidebar          -->
            <?php echo $__env->make('includes.checkout_sitebar', $cart, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
    $(document).ready(function() {
        $('#bill_area').on('change', function() {
          var grandTotal = removeCurrency($('#grand_total').data('grand_total'));
          var oldShippingPrice = removeCurrency($('#shipping_price').data('price'));
          var newShippingPrice = removeCurrency($(this).val());
          var areaId = $(this).find(':selected').data('id');

          var newGrandTotal = parseFloat(grandTotal) + parseFloat(newShippingPrice) - parseFloat(oldShippingPrice);
          $('#shipping_price').text( addCurrency(newShippingPrice));
          $('#grand_total').text(addCurrency(newGrandTotal));
          $('#grand_total').data('grand_total', addCurrency(newGrandTotal));
          $('#shipping_price').data('price', addCurrency(newShippingPrice));

          //api call
          $.ajax({
            url: "<?php echo e(route('front.checkout.area.change')); ?>",
            method: "POST",
            data: {
              new_shipping_id: areaId,
              _token: "<?php echo e(csrf_token()); ?>",
            },
            success: function(response) {

              $('#shipping_price').text( addCurrency(newShippingPrice));
              $('#grand_total').text(addCurrency(newGrandTotal));
              $('#grand_total').data('grand_total', addCurrency(newGrandTotal));
              $('#shipping_price').data('price', addCurrency(newShippingPrice));

            }
          });


        })
    });

    //remove ৳ and space
    function removeCurrency(str) {
        str = str.replace(' ', '');
        str = str.replace(',', '');
        return str.replace('৳', '');
    }

    //add ৳ and  comma
    function addCurrency(str) {
        let num = parseFloat(str).toLocaleString('en-BD');
        return `৳${num}`;
    }
</script>

<?php echo $__env->make('master.front', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/sandsmhe/public_html/core/resources/views/front/checkout/billing.blade.php ENDPATH**/ ?>