{% set init = 1 %}
{% set telefone = phone_number|replace({'-':'', '(':'', ')':'', '+':'', ' ':''}) %}
{% if telefone|length == 13 or telefone|length == 12 %}
	{% set telefone = telefone|slice(2, phone_number|length - 1) %}
{% elseif telefone|length == 11 or telefone|length == 10 %}
	{% set telefone = telefone %}
{% else %}
	{% set telefone = '(00)00000000' %}
{% endif %}
<form action="https://cieloecommerce.cielo.com.br/Transactional/Order/Index" method="post" id="cielo_form" {{ exibir_btn ? 'class="ftr-js-btn-confirm"' : '' }}>
	<!-- detalhes -->
	<input type="hidden" name="merchant_id" value="{{ merchant_id }}">
	<input type="hidden" name="order_number" value="{{ pedido }}">
	<input type="hidden" name="shipping_type" value="{{ shipping_tipo_frete }}">
	{% if frete and frete.value > 0 %}
		<input type="hidden" name="Shipping_Zipcode" value="{{ shipping_postcode }}">
	{% endif %}
	<input type="hidden" name="soft_descriptor" value="{{ soft }}">
	<input type="hidden" name="Antifraud_enabled" value="{{ fraude }}">

	<!-- itens -->
	{% for produto in produtos %}
		<input type="hidden" name="cart_{{ init }}_name" value="{{ produto.name }}">
		<input type="hidden" name="cart_{{ init }}_unitprice" value="{{ produto.price|number_format(2, '', '') }}">
		<input type="hidden" name="cart_{{ init }}_quantity" value="{{ produto.quantity }}">
		<input type="hidden" name="cart_{{ init }}_type" value="3">
		{% set init = init + 1 %}
	{% endfor %}

	{% if taxas and taxas > 0 %}
		<!-- taxas -->
		<input type="hidden" name="cart_{{ init }}_name" value="Taxas e Impostos">
		<input type="hidden" name="cart_{{ init }}_unitprice" value="{{ taxas|number_format(2, '', '') }}">
		<input type="hidden" name="cart_{{ init }}_quantity" value="1">
		<input type="hidden" name="cart_{{ init }}_type" value="3">
	{% endif %}

	<!-- descontos -->
	{% if desconto > 0 %}
		<input type="hidden" name="discount_type" value="1">
		<input type="hidden" name="discount_value" value="{{ desconto|number_format(2, '', '') }}">
	{% endif %}


	<!-- endereco frete -->
	{% if frete and frete.value > 0 %}
		<input type="hidden" name="shipping_1_name"  value="{{ frete.title }}">
		<input type="hidden" name="shipping_1_price" value="{{ frete.value|number_format(2, '', '') }}">
		<input type="hidden" name="Shipping_Address_Name" value="{{ shipping_address_1 }}">
		<input type="hidden" name="Shipping_Address_Number" value="{{ shipping_numero }}">
		<input type="hidden" name="Shipping_Address_Complement" value="{{ shipping_complemento }}">
		<input type="hidden" name="Shipping_Address_District" value="{{ shipping_address_2 }}">
		<input type="hidden" name="Shipping_Address_City" value="{{ shipping_city }}">
		<input type="hidden" name="Shipping_Address_State" value="{{ shipping_zone }}">
	{% endif %}

	<!-- cliente -->
	<input type="hidden" name="Customer_Name" value="{{ firstname }} {{ lastname }}">
	<input type="hidden" name="Customer_Identity" value="{{ (fiscal|length == 11 or fiscal|length == 14) ? fiscal : '' }}">
	<input type="hidden" name="Customer_Phone" value="{{ telefone|replace({'-':'', '(':'', ')':'', '+':'', ' ':''}) }}">
	<input type="hidden" name="Customer_Email" value="{{ email }}">
</form>
<script>
	if (typeof loadSpecificSources != 'undefined') {
		loadSpecificSources({
			scripts: {{ scriptsApp }}
		});
	}
</script>
