<!-- checkout-area start -->
  <div class="checkout-area">
    <div class="container">
		@if (session('flash_failure'))
            <div class="alert alert-danger" role="alert">
                {{ session('flash_failure') }}
            </div>
        @endif
        <form action="{{  route('new.payment.form')  }}" method="post">@csrf
          <div class="row">
          <div class="col-lg-6 col-md-12">
            <div class="checkbox-form">
              <h3>Shipping / Account Details</h3>
              <div class="row">
                <div class="col-md-6">
                  <div class="checkout-form-list">
                    <label>Full Name <span class="required">*</span></label>
                    <input id="shipping_name" name="name" type="text" placeholder="" />
                    <span class="shipping_name required"></span>
                  </div>
                </div>
                <div class="col-md-6">
                  <div class="checkout-form-list">
                    <label>Email Address <span class="required">*</span></label>
                    <input id="shipping_email" name="email" type="email" placeholder="" required/>
                    <span class="shipping_email required"></span>
                    <span class="email_message required"></span>
                  </div>
                </div>
                <div class="col-md-6">
                  <div class="checkout-form-list">
                    <label>Password <span class="required">*</span></label>
                    <input id="password" name="password" type="password" placeholder="" required/>
                    <span class="password required"></span>
                   
                  </div>
                </div>
                <div class="col-md-6">
                  <div class="checkout-form-list">
                    <label>Confirm Password <span class="required">*</span></label>
                    <input id="confirm_password" name="confirm_password" type="password" placeholder="" required/>
                    <span class="confirm_password required"></span>
                  </div>
                </div>
                <div class="col-md-12">
                  <div class="checkout-form-list">
                    <label>Phone  <span class="required">*</span></label>
                    <input id="shipping_phone" type="text" name="phone" placeholder="Phone" required/>
                    <span class="shipping_phone required"></span>
					   <span class="email_phone required"></span>
                  </div>
                </div>
                <div class="col-md-12">
                  <div class="checkout-form-list">
                    <label>Address <span class="required">*</span></label>
                    <textarea id="shipping_address" name="address" class="form-control" placeholder="Street address" required></textarea>
                    <span class="shipping_address required"></span>
                  </div>
                </div>
                <div class="col-md-6">
                  <div class="checkout-form-list">
                    <label>State <span class="required">*</span></label>
                    <select class="form-control" id="shipping_state" name="state">
                      @foreach($states as $state)
                      <option value="{{$state->id}}">{{ $state->name }}</option>
                      @endforeach
                    </select>
                  </div>
                </div>
                <div class="col-md-6">
                  <div class="checkout-form-list">
                    <label>City <span class="required">*</span></label>
                    <input id="shipping_city" name="city" type="text" placeholder="City" required/>
                    <span class="shipping_city required"></span>
                  </div>
                </div>

                <div class="col-md-12">
                  <div class="checkout-form-list">
                    <label>Pincode <span class="required">*</span></label>
                    <input id="shipping_pincode" name="pincode" value="{{$pincode->pincode}}" type="text" placeholder="Pincode" readonly required/>
                    <span class="shipping_pincode required"></span>
                  </div>
                </div>

              </div>
            </div>
          </div>
          <div class="col-lg-6 col-md-12">
            <div class="your-order">
              <h3>Your order</h3>
              <div class="your-order-table table-responsive">
                <table>
                  <thead>
                    <tr>
                      <th class="product-name">Product</th>
                      <th class="product-total">Total</th>
                    </tr>
                  </thead>
                  <tbody>
                    @foreach($carts as $cart)
                    <?php
                     $subtotal[] = $cart->product->selling_price*$cart->quantity;
                    ?>
                    <tr class="cart_item">
                      <td class="product-name">
                        {{$cart->product->name}} <strong class="product-quantity"> × {{$cart->quantity}}</strong>
                      </td>
                      <td class="product-total">
                        <span class="amount">Rs {{$cart->product->selling_price * $cart->quantity}}</span>
                      </td>
                    </tr>
                    @endforeach
                  </tbody>
                  <tfoot>
                    <tr class="cart-subtotal">
                      <th>Cart Subtotal</th>
                      <td><span class="amount"> Rs {{array_sum($subtotal)}}</span></td>
                    </tr>
                    <tr class="shipping">
                      <th>Shipping</th>
                      <td><span class="amount">
                        @if(array_sum($subtotal) > 500)
                        <input type="hidden" id="delivery_charge" name="delivery_charge" value="0">
                        FREE
                        @else
                        <input type="hidden" id="delivery_charge" name="delivery_charge" value="{{$pincode->delivery_charge}}">
                         + Rs {{$pincode->delivery_charge}}
                        @endif</span></td>
                    </tr>
                    @if($isCoupon == 1)
                    <input type="hidden" id="coupon_amount" name="coupon_amount" value="{{ \App\Http\Controllers\CartController::getCouponDiscount(@array_sum(@$subtotal)) }}">
                    <tr class="shipping">
                      <th>Coupon Discount</th>
                      <td><span class="amount">- Rs {{ \App\Http\Controllers\CartController::getCouponDiscount(@array_sum(@$subtotal)) }}</span></td>
                    </tr>
                    @else
                    <input type="hidden" id="coupon_amount" name="coupon_amount" value="0">
                    @endif
                    @guest
                    <input type="hidden" id="wallet_amount" name="wallet_amount" value="0">
                    @else
                    @if($wallet > 0)
                    <input type="hidden" id="wallet_amount" name="wallet_amount" value="{{$wallet}}">
                    <tr>
                      <th>Wallet</th>
                      <td><span class="amount">- RS {{$wallet}}</span></td>
                    </tr>
                    @else
                    <input type="hidden" id="wallet_amount" name="wallet_amount" value="0">
                    @endif
                    @endguest
                    <tr class="order-total">
                      <th>Order Total</th>
                      <td><strong><span class="amount">Rs {{$total_payable_amount}}</span></strong>
                      </td>
                    </tr>
                  </tfoot>
                </table>
              </div>
				 @if($total_payable_amount==0)
                    <div class="order-button-payment">
                        <input type="submit" class="submit" value="Place order" />
                    </div>
                @else
              <div class="payment_method">
                 <div class="">
                      <input name="check_method" type="radio" value="Cod" />
                      <label >Cash on Delivery</label>
                  </div>
                 <div class="">
                      <input name="check_method" type="radio" value="Online" checked/>
                      <label >Pay Online</label>
                  </div>
                  <div class="order-button-payment">
                    <input type="submit" class="submit" value="Place order" />
                  </div>
              </div>
				 @endif
            </div>
            </div>
                </div>

            </form>
    </div>
  </div>
{ <!-- checkout-area end -->  --}}
 <script src="{{ asset('public/assets') }}/js/vendor/jquery-1.12.4.min.js"></script>
  <script type="text/javascript">
  required_status = 1;
    $("#shipping_email").keyup(function(){
       var shipping_email = $('#shipping_email').val();
       var _token = "{{@csrf_token()}}";
       $.ajax({
           url: "{{url('checkEmail')}}",
           type: 'post',
         dataType: 'json',
           data: {
            email : shipping_email,
            _token: _token,
           },
           success: function (response) {
              if (response.email_message == 1) {
             $('.submit').attr('disabled', false);
               $('.email_message').html('');
               required_status = 0;
             }
              else{
               $('.submit').attr('disabled', true);
               $('.email_message').html(response.email_message);
               required_status = 1;
            }
           }
      });
   });


    $("#shipping_phone").keyup(function(){
    var shipping_phone = $('#shipping_phone').val();
    var _token = "{{@csrf_token()}}";
    $.ajax({
    url: "{{url('checkPhone')}}",
               type: 'post',
    dataType: 'json',
    data: {
                  phone : shipping_phone,
                  _token: _token,
                 },
               success: function (res) {
                   if (res.email_phone == 1) {
                     $('.submit').attr('disabled', false);
                     $('.email_phone').html('');
                      required_status = 0;
                  }
                  else{
                      $('.submit').attr('disabled', true);
                     $('.email_phone').html(res.email_phone);
                      required_status = 1;
                  }
                }
             });
          });


    </script>

{{--     $('.submit').on('click', function(e){--}}
{{--      e.preventDefault();--}}
{{--      //--}}
{{--      var shipping_name = $('#shipping_name').val();--}}
{{--      var shipping_email = $('#shipping_email').val();--}}
{{--      var shipping_phone = $('#shipping_phone').val();--}}
{{--      var shipping_state = $('#shipping_state').val();--}}
{{--      var shipping_city = $('#shipping_city').val();--}}
{{--      var shipping_pincode = $('#shipping_pincode').val();--}}
{{--      var password = $('#password').val();--}}
{{--      var confirm_password = $('#confirm_password').val();--}}
{{--      var shipping_address = $('#shipping_address').val();--}}
{{--      var payment_type = $("input[name=check_method]:checked").val();--}}
{{--      if(shipping_name != ''){--}}
{{--        required_status = 1;--}}
{{--      }else{--}}
{{--        required_status = 0;--}}
{{--        $('.shipping_name').html('Name field is required');--}}
{{--      }--}}
{{--      if(shipping_email != ''){--}}
{{--        required_status = 1;--}}
{{--      }else{--}}
{{--        required_status = 0;--}}
{{--        $('.shipping_email').html('Email field is required');--}}
{{--      }--}}
{{--      if(password != ''){--}}
{{--        required_status = 1;--}}
{{--      }else{--}}
{{--        required_status = 0;--}}
{{--        $('.password').html('Password field is required');--}}
{{--      }--}}
{{--      if(confirm_password != ''){--}}
{{--        required_status = 1;--}}
{{--      }else{--}}
{{--        required_status = 0;--}}
{{--        $('.confirm_password').html('Confirm field is required');--}}
{{--      }--}}
{{--      if(shipping_phone != ''){--}}
{{--        required_status = 1;--}}
{{--      }else{--}}
{{--        required_status = 0;--}}
{{--        $('.shipping_phone').html('Phone field is required');--}}
{{--      }--}}
{{--      if(shipping_state != ''){--}}
{{--        required_status = 1;--}}
{{--      }else{--}}
{{--        required_status = 0;--}}
{{--        $('.shipping_state').html('State field is required');--}}
{{--      }--}}
{{--      if(shipping_address != ''){--}}
{{--        required_status = 1;--}}
{{--      }else{--}}
{{--        required_status = 0;--}}
{{--        $('.shipping_address').html('Address feild is required');--}}
{{--      }--}}
{{--      if(shipping_city != ''){--}}
{{--        required_status = 1;--}}
{{--      }else{--}}
{{--        required_status = 0;--}}
{{--        $('.shipping_city').html('City feild is required');--}}
{{--      }--}}
{{--      if(shipping_pincode != ''){--}}
{{--        required_status = 1;--}}
{{--      }else{--}}
{{--        required_status = 0;--}}
{{--        $('.shipping_pincode').html('Pincode feild is required');--}}
{{--      }--}}
{{--      //--}}
{{--      if (password != confirm_password) {--}}
{{--        required_status = 1;--}}
{{--        alert('Password and Confirm password must be same');--}}
{{--      }--}}
{{--      else{--}}
{{--        required_status = 0;--}}
{{--      }--}}
{{--      if (required_status == 0) {--}}
{{--        $('.submit').html('Processing Please Wait');--}}
{{--        $('.submit').attr('disabled', true);--}}
{{--        var delivery_charge = $('#delivery_charge').val();--}}
{{--        var coupon_amount = $('#coupon_amount').val();--}}
{{--        if (payment_type == "Cod") {--}}
{{--          $.ajax({--}}
{{--               url: "{{url('placeOrder')}}",--}}
{{--               type: 'post',--}}
{{--               dataType: 'json',--}}
{{--                data: {--}}
{{--                amount: <?php echo @$total_payable_amount; ?>*100,--}}
{{--                 shipping_name : shipping_name,--}}
{{--                 shipping_email : shipping_email,--}}
{{--                 confirm_password : confirm_password,--}}
{{--                 shipping_phone : shipping_phone,--}}
{{--                 shipping_state : shipping_state,--}}
{{--                 shipping_city : shipping_city,--}}
{{--                 shipping_pincode : shipping_pincode,--}}
{{--                 shipping_address : shipping_address,--}}
{{--                 delivery_charge : delivery_charge,--}}
{{--                 coupon_amount : coupon_amount,--}}
{{--                 _token: "{{@csrf_token()}}",--}}
{{--                 payment_type : payment_type,--}}
{{--               }, --}}
{{--               success: function (msg) {--}}
{{--                    window.location.href = "{{url('thankyou')}}"--}}
{{--               }--}}
{{--           });--}}
{{--        }--}}
{{--        else{--}}
{{--          var options = {--}}
{{--             "key": "<?php echo env('RAZOR_KEY'); ?>",--}}
{{--             "amount":<?php echo @$total_payable_amount; ?>*100, // 2000 paise = INR 20--}}
{{--             "name": "Nakoda",--}}
{{--             "description": "Payment",--}}
{{--             "image": "{{url('public/assets/img/logo/nalogo.jpg')}}",--}}
{{--             "handler": function (response){--}}
{{--                  $.ajax({--}}
{{--                     url: "{{url('placeOrder')}}",--}}
{{--                     type: 'post',--}}
{{--                     dataType: 'json',--}}
{{--                      data: {--}}
{{--                      amount: <?php echo @$total_payable_amount; ?>*100,--}}
{{--                      razorpay_payment_id: response.razorpay_payment_id ,--}}
{{--                       shipping_name : shipping_name,--}}
{{--                       shipping_email : shipping_email,--}}
{{--                       confirm_password : confirm_password,--}}
{{--                       shipping_phone : shipping_phone,--}}
{{--                       shipping_state : shipping_state,--}}
{{--                       shipping_city : shipping_city,--}}
{{--                       shipping_pincode : shipping_pincode,--}}
{{--                       shipping_address : shipping_address,--}}
{{--                       delivery_charge : delivery_charge,--}}
{{--                       coupon_amount : coupon_amount,--}}
{{--                       _token: "{{@csrf_token()}}",--}}
{{--                       payment_type : payment_type,--}}
{{--                     }, --}}
{{--                     success: function (msg) {--}}
{{--                          window.location.href = "{{url('thankyou')}}"--}}
{{--                     }--}}
{{--                 });--}}
{{--              },--}}
{{--             "prefill": {--}}
{{--                 "contact": shipping_phone,--}}
{{--                 "email": shipping_email,--}}
{{--              },--}}
{{--             "theme": {--}}
{{--                 "color": "#528FF0"--}}
{{--             }--}}
{{--          };--}}
{{--          var rzp1 = new Razorpay(options);--}}
{{--          rzp1.open();--}}
{{--          e.preventDefault();--}}
{{--        }--}}
{{--      }--}}
{{--    });--}}
{{--  </script>--}}
