<div id="cart" class="container">
  <ul class="list-unstyled">
    {% if products or vouchers %}
    <li class="in50">{{ text_cart }}</li><li class="in50 text-right">{{ text_weight }} {{ weight }}</li>
    {% for product in products %}
    <li class="trow product-layout">
      <span class="r-talert">
      <p>{{ text_del }}</p>
      <b onclick="cart.remove('{{ product.cart_id }}');">{{ text_yes }}</b>
      <b class="cart-no">{{ text_no }}</b>
      </span>
        <div class="tblock timage">
          {% if not product.stock %}
          <i class="fa fa-exclamation"></i>
          {% endif %}
          {% if product.thumb %}
          <a href="{{ product.href }}"><img src="{{ product.thumb }}" alt="{{ product.name }}" title="{{ product.name }}" class="cart{{ product.cart_id }}" /></a>
          {% endif %}
	    </div>
		<div class="tblock tdes">
		  <div class="tblock pname">
            <div class="tblock w50">
              <a href="{{ product.href }}">{{ product.name }}</a>
			  {% if product.option %}
			  {% for option in product.option %}
			  <br />
			  <small>{{ option.name }}: {{ option.value }}</small>
			  {% endfor %}
			  {% endif %}
			  {% if product.reward %}
			  <br />
			  <small>{{ product.reward }}</small>
			  {% endif %}
			  {% if product.recurring %}
			  <br />
			  <span class="label label-info">{{ text_recurring_item }}</span> <small>{{ option.recurring }}</small>
			  {% endif %}
            </div><div class="tblock">
			  <i class="fa fa-trash-o"></i>
			  {% if iwishlist %}<i class="fa fa-heart-o" onclick="wishlist.add('{{ product.product_id }}','cart{{ product.cart_id }}');"></i>{% endif %}
			  {% if icompare %}<i onclick="compare.add('{{ product.product_id }}','cart{{ product.cart_id }}');" class="fa fa-align-left"></i>{% endif %}
			</div>
		  </div><div class="tblock tprice">
		    <div class="tblock">{{ product.price }}</div><div class="qty" title="{{ entry_qty }}">
		      <div class="plus" data-id="{{ product.cart_id }}"><i class="fa fa-caret-up"></i></div>
			  <input type="text" name="quantity[{{ product.cart_id }}]" value="{{ product.quantity }}" id="cart-quantity{{ product.cart_id }}" class="input-quantity" onchange="kolvo_cart()"/>
			  <div class="minus" data-id="{{ product.cart_id }}" data-min="{{ product.minimum }}"><i class="fa fa-caret-down"></i></div>
			</div><div class="tblock text-right">{{ product.total }}</div>
		  </div>
		</div>
    </li>{% endfor %}<li class="class50">
	  <div class="marg30">
	    <div class="input-group btn-block">
          <input type="text" name="coupon2" value="{{ coupon }}" placeholder="{{ text_cupon }}" id="input-coupon2" class="form-control">
          <span class="input-group-btn">                   
          {% if coupon %}
		  <button type="button" id="del-coupon" onclick="cupon_cart(1)"><i class="fa fa-times-circle"></i></button>
		  {% endif %}
          <button type="button" id="button-coupon" class="btn" onclick="cupon_cart(0)">{{ text_add }}</button>
          </span>
		</div>
	  </div>
	</li><li class="class50">
      <div class="over marg30">
        <table class="total-block">
          {% for total in totals %}
          <tr>
            <td class="text-right">{{ total.title }}</td>
            <td class="text-right"><strong>{{ total.text }}</strong></td>
          </tr>
          {% endfor %}
        </table>  
      </div>
	  </li>
      {% if button %}
	  <li class="class50"><p class="text-right"><a href="{{ checkout }}" class="abtn">{{ text_checkout }}</a></p></li>
	  {% else %}
	<li class="class100"><div class="cart-info">{{ text_error }}</div></li>
	{% endif %}
	{% if madeshop_order %}<li class="class50"><div id="fast-form-btn" class="abtn fast-form-btn">{{ text_btn }}</div></li>
	  <li class="fast-form">
  <div id="fast-form" class="table">
<div class="cart-panel fast-form-btn"><div class="container"><i class="fa fa-arrow-up"></i>{{ text_p }}</div></div> 	 
	<div class="table-cell">
	  <div class="w65"> 
		<form method="POST" id="form-order">
          <div class="over marg30">

		<table class="total-block">
          {% for total in totals %}
          <tr>
            <td class="text-left">{{ total.title }}</td>
            <td class="text-right"><strong>{{ total.text }}</strong></td>
          </tr>
          {% endfor %}
		  
        </table>  
      </div><hr>
		  <div class="form-group sm required"><input name="order_phone" type="tel" placeholder="{{ text_phone }}" value="" id="order-phone" required="" class="form-control no-border" data-inputmask="'mask': '{{ text_mask }}'"></div>
          <div class="form-group">
			<button type="submit" id="button-order" class="btn made-btn">{{ text_btn }}</button>
          </div>
          <div class="form-group">
            <p class="checkbox"><input type="checkbox" checked="checked" id="agree-order"/> <label for="agree">{{ text_agree }}</label></p>
          </div>
        </form>
	  </div>	
    </div>
  </div>
  </li>
	  {% endif %}
    {% else %}
    <li>
      <p class="empty">{{ text_empty }}</p>
    </li>
    {% endif %}
	
  </ul>
</div>
<script type="text/javascript"><!--
$(document).ready(function() {
		$(document).on('click', '#fast-form-btn', function() { 
			$.getScript("catalog/view/theme/madeshop/script/inputmask.min.js", function() {
			$("#order-phone").inputmask();
			});
        });
    });
    $(document).on('click', '.fast-form-btn', function() {
	   $('#cart li:not(.fast-form)').slideToggle(500);
	   $('.fast-form').toggleClass('iopen');
	   
    });
	
    $(document).on('click', '#button-order', function(e) {
    e.preventDefault();
        $.ajax({
			url: 'index.php?route=madeshop/order',
			type: 'post',
			data: $('#order-phone').serialize(), 
            dataType: 'json',
			beforeSend: function() {
			//$('#cart').addClass('load-block');
			},
			complete: function(json) {	
            console.log(json);			
			},
			success: function(json) {
            $('#form-order .form-group').removeClass('has-error');
			if (json['error']) {
            $('#order-phone').parent().addClass('has-error');
			
			} else {
            $('#cart-url .total').replaceWith('<span class="total red">0</span>');	
            $('#form-order').slideUp();
				$('#fast-form .w65').append('<div class="text-center a-success">' + json['text_order']+ '</div>');
				setTimeout(function () {
					$('body').click();
					$('#cart > ul').load('index.php?route=madeshop/cart/info ul li');
				}, 4000);
			}
			}			
        });
    });

	$(document).on('click', '.fa-trash-o', function(e) { 
        $('.trow.open').removeClass('open');
        $(this).parent().parent().parent().parent().addClass('open');

    });

	$(document).mouseup(function (e) {
		var container = $(".trow");
		if (container.has(e.target).length === 0){
			$('.trow.open').removeClass('open');
		}
	});

	$(document).on('click', '.cart-product', function() { 
	    $('.cart-alert').removeClass('open');
	    $(this).prev().addClass('open');
	});

    $(document).on('click', '.cart-no', function() { 
        $(this).parent().parent().removeClass('open');
    });
    
	$(document).on('click', '.cart-wishlist', function() {
        $(this).parent().parent().removeClass('open');
        var id = $(this).attr('data-id');
        var pid = $(this).attr('data-pid');
        cart.remove(id);
        wishlist.add(pid,2);
    });

    $(document).on('click', '.minus', function() { 
        $id = $(this).attr('data-id'); 
        $min = $(this).attr('data-min');		
		var $input = $('#cart-quantity'+$id);
		var count = parseInt($input.val()) - 1;
        count = count < $min ? $min : count;
        $input.val(count);
        $input.change();
        return false;
    });
   $(document).on('click', '.plus', function() {
        var id = $(this).attr('data-id');
		var $input = $('#cart-quantity'+id);
        $input.val(parseInt($input.val()) + 1);

        $input.change();
        return false;
    });

    function kolvo_cart() {
		$.ajax({
			url: 'index.php?route=madeshop/cart/edit',
			type: 'post',
			data: $('#cart .input-quantity').serialize(), 
            dataType: 'json',
			beforeSend: function() {
			$('#cart').addClass('load-block');
			},
			complete: function() {			
			},
			success: function(json) {
				$('#cart').removeClass('load-block');
				$('#cart > ul').load('index.php?route=madeshop/cart/info ul li');
				$('#cart-url .total').replaceWith('<span class="total red">' + json['total']+ '</span>');	
			}			
        });			
	}

    function cupon_cart(del) {
        $.ajax({
		url: 'index.php?route=madeshop/cart/coupon',
		type: 'post',
		data: 'coupon=' + encodeURIComponent($('input[name=\'coupon2\']').val())+'&del='+del,
		dataType: 'json',
		beforeSend: function() {			
			$('#cart').addClass('load-block');
			$('#button-coupon').button('loading');
		},
		complete: function() {			
			
			$('#button-coupon').button('reset');
		},
		success: function(json) {
			$('#cart').removeClass('load-block');
			$('.alert').remove();

			if (json['error']) {
				alert(json['error']);

			}

			if (json['redirect']) {
				$('#cart > ul').load('index.php?route=madeshop/cart/info ul li');
			}
		}
	    });
    }
    $('#agree-order').on('click', function(e) {
    e.preventDefault();
    alert('{{ text_alert }}');
    });
	
	
	$(document).delegate('.madeshop-agree', 'click', function(e) {
    e.preventDefault();
    $("#form-order").slideUp( 300, "linear", function(){
    $.ajax({
        url: $(element).attr('href'),
        type: 'get',
        dataType: 'html',
        success: function(data) {
            html = '        <div id="agree-block">';
            html += '        <b class="back"><i class="fa fa-long-arrow-left"></i>{{ text_back }}</b>';
            html += '        <div class="modal-title">' + $(element).text() + '</div>';
            html += '      <div class="form-body">' + data + '</div>';
            html += '</div>';

            $('#fast-form .table-cell').after(html);
        }
    });
    });
    var element = this;
});
$(document).delegate('.back', 'click', function(e) {
    $("#form-order").slideDown();
    $('#agree-block').remove();
});
//--></script>