<?php
$this->load->view("top");
$values_posted_back = (is_array($this->input->post())) ? TRUE : FALSE;
$is_same = $values_posted_back === TRUE ? $this->input->post('is_same') : '';
$discount_amount = $this->session->userdata('discount_amount');
$cart = $this->cart->contents();
?>

<div class="page_breadcrumbs">
  <div class="container">
    <ul>
     <li><a href="<?= site_url(); ?>" title="Home">Home</a></li>
    <li>Checkout</li>
    </ul>
  </div>
</div>
    <section class="checkout_page">
      <div class="container">
        <div class="row">
          <div class="col-xxl-9 col-xl-9 col-lg-9 col-md-8 col-sm-8 col-12">
            <div class="cart_left">
          <h1 class="bg-title">Checkout</h1>
          <div class="panel-group checkout-steps" id="accordion">
            <!-- checkout-step-1  -->
            <section class="panel panel-default checkout-step-01">
              <h4 class="checkout_title">
                <a data-toggle="collapse" data-parent="#accordion" href="javascript:void(0);"><span>1</span>Login or Signup </a>
              </h4>
              <div id="collapseOne" class="panel-collapse collapse show active">
                <div class="panel-body">
                  <div class="row">   
                    <div class="col-xxl-7 col-xl-7 col-md-7 col-sm-7 col-12">
                    <?php echo error_message();
                      echo validation_message();
                
                      echo form_open('cart/checkout', 'class="sending-form"');
              
                      ?> 
                     
                      <div class="form-group">
                   <label class="input_label">
                    <input id="email" class="form_input" name="email" type="email" placeholder="Enter Email ID *" value="<?php echo set_value('email'); ?>"  required=""></label>
                          <?php echo form_error('email'); ?>
                      </div>

                      <div class="form-group register_box" style="display: none;">
                      <label class="input_label">
                    <input type="text" name="name" class="form_input" placeholder="Enter Your Name *" value="<?php echo set_value('name'); ?>">
                         </label>
                       
                      </div>
                      <div class="form-group register_box" style="display: none;">
                       <label class="input_label">
                          <input type="text" name="mobile_number" class="form_input" placeholder="Enter Your Mobile Number *" value="<?php echo set_value('mobile_number'); ?>">
                        </label>
                      </div>
                      <div class="form-group register_box" style="display: none;">
                           <label class="input_label">
                         <input type="password" name="password_register" placeholder="Enter Your Password *" class="form_input"  value="">
                         </label>
                         </div>

                      <div class="form-group password_cont" style="display: none;">
                        <label class="input_label">
                          <input  type="password" id="password" name="password" placeholder="Enter Password *" class="form_input" value="">
                           </label>
                       
                      </div>
                      <div class="clearfix"></div>

                      <div class="row" style="margin-top:10px;">
                        <div class="col-sm-4 col-12">
                          <label class="radio_btn">
                            <input name="checkout_type" type="radio" value="Guest" checked="" onclick="$('.email').slideDown('fast');
                                $('.password_cont').slideUp('fast');
                                $('.register_box').slideUp('fast')
                                $('.gestButton').show('fast');
                                $('.gestButton').html('Contnue as Guest');" <?php
                                   if ($this->input->post('checkout_type') == 'Guest') {
                                     echo 'checked';
                                   }
                                   ?>> Continue as Guest</label>
                        </div>
                        <div class="col-sm-4 col-12">
                          <label class="radio_btn">
                            <input name="checkout_type" id="checkout_type_user" type="radio" value="User" onclick="$('.email').slideDown('fast');
                                $('.register_box').slideUp('fast')
                                $('.password_cont').slideDown('fast');
                                $('.gestButton').show('fast');
                                $('.gestButton').html('Login Now');" <?php
                                   if ($this->input->post('checkout_type') == 'User') {
                                     echo 'checked';
                                   }
                                   ?>>I have an account</label>
                        </div>
                      </div>
                      <div class="clearfix"></div>
                      <button type="submit" class="step_login_btn logButton gestButton">Contnue as Guest</button>
                        <a id="signup" href="<?=base_url();?>register" class="step_login_btn hover_btn">New User? SignUp</a>
                      <div class="clearfix"></div>

                        
                    </div>
                    <div class="col-xxl-5 col-xl-5 col-md-5 col-sm-6 col-12">
                      <div class="checkout_right">
                        <h4>Advantages of our secure login</h4>
                        <ul>
                          <li><i class="fa fa-check"></i> Easily Track Orders, Hassle free Returns</li>
                          <li><i class="fa fa-check"></i> Get Relevant Alerts and Recommendation</li>
                          <li><i class="fa fa-check"></i> Wishlist, Reviews, Ratings and more.</li>
                        </ul>
                      </div>
                    </div>  

                  </div>      
                </div>
              </div>
            </section>
            <!-- checkout-step-02  -->
            <section class="panel panel-default checkout-step-02">
              <h4 class="checkout_title"><a data-toggle="collapse" class="collapsed"><span>2</span>Enter Address <!-- <button class="change">Change</button> --></a></h4>

            </section>
            <!-- checkout-step-03  -->
            <!--<div class="panel panel-default checkout-step-03">
              <h4 class="checkout_title">
                <a data-toggle="collapse" data-toggle="collapse" class="collapsed">
                  <span>3</span>Order Summary  <button class="change">View Order Summary</button></a> </h4>

            </div>-->
            <!-- checkout-step-04  -->
            <div class="panel panel-default checkout-step-04">
              <h4 class="checkout_title">
                <a data-toggle="collapse" class="collapsed">
                  <span>3</span>Payment Options</a></h4>

            </div>
            <!-- checkout-step-04  -->
          </div>
          <!-- /.checkout-steps -->
        </div>
      </div>
        <div class="col-xxl-3 col-xl-3 col-lg-3 col-md-4 col-sm-4 col-12">
        <div class="cart_right_title">Cart Details</div>
        <div class="cart_right">
          <table class="table table-totals">
            <tbody>
              <?php
              $totalAmount = $discountAmt = $total_shipping = 0;
              $i = 1;
              foreach ($cart as $items) {
                $link = ($this->session->userdata('user_id') > 0) ? 'href="' . site_url() . 'cart/add_to_wishlist/' . $items['pid'] . '"' : 'href="#" data-toggle="modal" data-target="#log-modal"';
                $pprice = $items['product_price'];
                $totalAmount += ($pprice * $items['qty']);
                $discountAmt += $pprice * $items['qty'];
                $catid = $this->db->query("SELECT category_id FROM wps_products WHERE products_id = '" . $items['pid'] . "'")->row_array();
                $url = $this->db->query("SELECT friendly_url FROM wps_products WHERE products_id = '" . $items['pid'] . "'")->row_array();
                $i++;
              }
              ?>
              <tr>
                <td>Sub Total</td>
                <td><?php if($catid['category_id']==2){ echo display_price($totalAmount);} else { echo display_price_india($totalAmount); } ?></td>
              </tr>
              <?php if ($discount_amount > 0) { ?>
                <tr>
                  <td>Discount Price</td>
                  <td>- <?php if($catid['category_id']==2){ echo display_price($discount_amount);} else { echo display_price_india($discount_amount); } ?></td>
                </tr>
              <?php } ?>
              <?php $deliveryCharge = 0; //delivery_charge(0, $totalAmount); 
              if($catid['category_id']==2){ $deliverchargewithsymble = display_price($deliveryCharge);} else {  $deliverchargewithsymble = display_price_india($deliveryCharge); }
              ?>
              <tr>
                <td>Delivery Charges</td>
                <td class="free"><?php echo ($deliveryCharge > 0) ? $deliverchargewithsymble : 'Free'; ?></td>
              </tr>
              <!--<tr>
                <td>GST(18%)</td>
                <td class="free"><?php
              $gst = gst($totalAmount);
              echo display_price($gst);
              ?></td>
              </tr>-->
            </tbody>
            <tfoot>
              <tr>
                <td>Amount Payable</td>
                <!-- <td><?= display_price(($totalAmount - $discount_amount) + $deliveryCharge + $gst); ?></td> -->
                <td><?php if($catid['category_id']==2){ echo display_price(($totalAmount - $discount_amount) + $deliveryCharge);} else { echo display_price_india(($totalAmount - $discount_amount) + $deliveryCharge); } ?></td>
               </tr>
            </tfoot>
          </table>
          <!--  <a class="order_btn" href="javascript:void()" title="Place Order">Place Order</a> -->
          <p class="safe_info"><i class="fa fa-shield"></i> Safe and Secure Payments. Easy returns. 100% Authentic products.</p>
        </div>
      </div>
    </div>
        </div>
</section>

<?php $this->load->view("bottom"); ?>
<script type="text/javascript">
  $(document).ready(function () {
    var value = $('input[name=checkout_type]:checked').val();

    if (value == 'User') {
      $(".password_cont").css('display', 'block');
      $('.gestButton').html('Login Now');
    } else if (value == 'Register') {
      $(".password_cont").css('display', 'none');
      $(".register_box").css('display', 'block');
      $('.gestButton').html('Register');
    } else {
      $('.gestButton').html('Continue as Guest');
    }
  });
</script>
