
<style>

  :root {
    --color-one-cart: {{section.settings.color_one_cart}};
    --color-two-cart: {{section.settings.color_two_cart}};
    --color-three-cart: {{section.settings.color_three_cart}};
    --color-for-cart: {{section.settings.color_for_cart}};
    --color-five-cart: {{section.settings.color_five_cart}};

    --color-one-light-cart: {{section.settings.color_one_cart  | color_lighten: 57 }};
    --color-one-light-1-cart: {{section.settings.color_one_cart | color_lighten: 57 | color_modify: 'alpha', 0.5 }};

  }

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}


.cart-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 55px;
}

.cart-section-header {
    font-size: 24px;
    font-weight: 600;
    color: var(--color-one-cart);
    margin-bottom: 15px;
}

.cart-section-items {
    border-top: 1px solid var(--color-for-cart);
    padding-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.cart-section-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;

}

.cart-item-title {
    font-size: 16px;
    flex-basis: 50%;
}

.cart-item-title a {
  color: var(--color-two-cart);
}

.cart-item-informations {
    display: flex;
    flex: 1 1 0;
    justify-content: space-between;
    align-items: center;
}

.cart-item-quantity {
    display: flex;
    border: 1px solid var(--color-five-cart);
    border-radius: 100px;
    color: var(--color-two-cart);
    align-items: center;
    justify-content: center;
    height: min-content;
    padding: 3px 10px;
    gap: 2px;
}

.cart-item-quantity-input {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-two-cart);
    border: 0;
    outline: 0;
    text-align: center;
    max-width: 30px;
    min-height: 24px;
    padding: 0;

}
.cart-item-quantity-button {
    font-size: 18px;
    font-weight: 600;
    height: 23px; width: 23px;
    outline: 0;
    border: none;
    border-radius: 50%;
    background-color: var(--color-five-cart);
    box-shadow: 0 2px 4px #ccc;
    display: flex;
    justify-content: center;
    align-items: center;
}

.cart-item-quantity-button:hover {
    background: var(--color-two-cart);
    color: #fff;
    cursor: pointer;
}

.cart-item-input {
    padding: 0 12px;
    border: 0;
    background: #fff;
    overflow: hidden;
    display: flex;
    align-items: center;
    margin: 0;
    border-radius: 100px;
    border: 1px solid var(--color-five-cart);;
}

.cart-item-price {
    font-size: 20px;
    color: var(--color-one-cart);
    font-weight: 600;
    text-align: end;
    flex-basis: 18%;
}

.cart-section-finish {
    padding-top: 60px;
    row-gap: 60px;
    column-gap: 50px;
    display: flex;
    justify-content: space-between;
}

.cart-section-finish-left {
    width: 50%;
}

.cart-section-finish-right {
    width: 50%;
}

.cart-finish-coupon {
  overflow: hidden;
  border-radius: 4px;
  color: var(--color-one-cart);
}

.cart-finish-coupon-content {
  background-color: var(--color-one-light-cart);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  row-gap: 12px;
  column-gap: 5px;
}

.cart-finish-coupon-shipping {
  display: flex;
  justify-content: space-between;
  background: var(--color-one-light-1-cart);
  max-height: 0;
  padding: 0 18px;
  font-size: 13px;
  transition: all .4s;
}

.cart-finish-coupon-shipping.open-coupon-info {
  padding: 14px 18px;
  max-height: 100vh;
}

.cart-coupon-title {
    font-size: 14px;
    font-weight: 600;
}

.cart-coupon-input {
    max-width: 33%;
    min-width: 50px;
    height: 38px;
    border: 1px solid #fff;
    border-radius: 4px;
}

.cart-coupon-input:focus {
    border: 1px solid var(--color-one-cart);
}
.cart-coupon-input:focus {
    outline: none;
}
.cart-coupon-button {
    height: 38px;
    background-color: var(--color-one-cart);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 0 10px;
}




.cart-finish-subtotal {
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    padding: 25px 0;
    border-top: 1px solid var(--color-for-cart);
}

.cart-finish-total {
    display: flex;
    justify-content: space-between;
    padding: 25px 0;
    border-top: 1px solid var(--color-for-cart);
}

.cart-finish-buy {
    display: flex;
    flex-wrap: wrap-reverse;
    justify-content: space-between;
    font-size: 16px;
    padding: 25px 0;
    border-top: 1px solid var(--color-for-cart);
    align-items: center;
    gap: 10px;
}


.cart-finish-subtotal-label {
  font-size: 16px;
}

.cart-finish-subtotal-price {
  font-size: 16px;
  color: var(--color-one-cart);
  font-weight: 600;
}

.cart-finish-total-label {
  font-size: 21px;
}

.cart-finish-total-price {
  font-size: 21px;
  color: var(--color-one-cart);
  font-weight: 600;
}

.cart-finish-total-label {
  color: var(--color-two-cart);
}

.cart-item-img {
  height: 65px; width: 65px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--color-five-cart);
  display: flex;
  justify-content: center;
}

.cart-buy-now button {
  background: var(--color-three-cart);
  border-radius: 4px;
  outline: none;
  border: none;
  color: #fff;
  padding: 7px 14px;
  font-size: 16px;
  width: 100%;
}

.cart-buy-more a {
  color: var(--color-one-cart);
  font-size: 15px;
}

.cart-buy-more a:hover {
  text-decoration: underline;
}

@media only screen and (max-width: 460px) {
  .cart-finish-buy {
    flex-direction: column-reverse;
  }

  .cart-buy-now {
    width: 100%;
  }
}


@media only screen and (max-width: 780px) {
  .cart-section-header {
    font-size: 18px;
  }
  .cart-section-item {
      align-items: flex-start;
  }
  .cart-item-img {
    height: 50px;
    width: 50px;
  }
  .cart-item-informations {
      flex-wrap: wrap;
      gap: 30px;
      flex-basis: 75%;
  }
  .cart-item-title {
      flex-basis: 100%;
  }
  .cart-container {
      padding: 35px 15px;
  }
  .cart-item-title {
      font-size: 16px;
  }
  .cart-item-price{
      font-size: 18px;
      flex-basis: auto;
  }
  .cart-item-quantity-input {
      font-size: 14px;
  }
  .cart-item-quantity-button {
      font-size: 14px;
      width: 18px; height: 18px;
  }
  .cart-item-quantity {
      padding: 0 6px;
  }

  .cart-finish-coupon-content {
      flex-wrap: wrap;
      justify-content: center;
  }

  .cart-coupon-input {
    max-width: none;
    flex-basis: 100%;
  }
  .cart-section-finish {
    flex-wrap: wrap;
  }
  .cart-section-finish-left, .cart-section-finish-right {
    width: 100%;
  }
  .cart-buy-now button {
    font-size: 15px;
  }

  .cart-buy-more a {
    font-size: 13px;
  }
  .cart-coupon-input, .cart-coupon-button {
    height: 32px;
  }
  
}

.cart-section-empty-{
  display: flex;
  justify-content: center;
}

.cart-section-empty-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.cart-empty-img {
  width: 70px;
}

.cart-empty-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-one-cart);
  text-align: center;
}

.cart-empty-button button {
  border: none;
  background-color: var(--color-three-cart);
  border-radius: 4px;
  color: #fff;
  font-weight: 600;
  padding: 7px 14px;
}
.cart-section-empty {
  padding-block: 125px;
}
</style>


<div class="cart-section-empty cart-container {% if cart.item_count > 0 %} hide {% endif %}">
  <div class="cart-section-empty-content">
    <div class="cart-empty-img">
      <img class="lazyload" data-src="{{ 'minicart_close.png' | asset_url }}" alt="" />
    </div>
  
    <div class="cart-empty-title">
      {{ 'cart.general.empty' | t }}
    </div>
  
    <div class="cart-empty-button">
      <a href="{{ routes.root_url }}">
        <button>
          {{ 'general.404.link' | t }}
        </button>
      </a>
    </div>
  </div>

</div>


<div class="cart-section cart-container {% if cart.item_count == 0 %} hide{% endif %} ">
  <div class="cart-section-header ">
    {{ 'cart.general.title' | t }}
  </div>

  <form action="{{ routes.cart_url }}" method="post" novalidate onkeydown="return event.key != 'Enter';">
    <div class="cart-section-items">
      {% for item in cart.items %}
      <div class="cart-section-item">
          <div class="cart-item-img">
            {% if item.image %}
              <img class="lazyload" data-src="{{ item | img_url: 'x190' }}" alt="{{ item.image.alt | escape }}" data-cart-item-image>
            {% else %}
              {% capture current %}{% cycle 1, 2, 3, 4, 5, 6 %}{% endcapture %}

              {{ 'product-'| append: current  | placeholder_svg_tag }}
            {% endif %}
          </div>
          <div class="cart-item-informations">
              <div class="cart-item-title">
                <a href="{{ item.url }}">{{ item.product.title }}
                  {% if item.product.has_only_default_variant == false %}
                    {% for option in item.options_with_values %}
                      /{{option.value}}
                    {% endfor %}
                  {% endif %}

                </a>
              </div>

              <div class="cart-item-quantity"> 
                  <button class="cart-item-quantity-button" onclick="this.parentNode.querySelector('input[type=number]').stepDown()" >
                    -
                  </button>

                  <input class="cart-item-quantity-input" min="0" type="number" name="updates[]" value="{{ item.quantity }}" >

                  <button class="cart-item-quantity-button" onclick="this.parentNode.querySelector('input[type=number]').stepUp()" class="plus">
                    +
                  </button>
              </div>
              
              <div class="cart-item-price">
                  {{ item.original_price | money }}
              </div>
          </div>
      </div>
      {% endfor %}
    </div>

    <div class="cart-section-finish">
      <div class="cart-section-finish-left">
        {% if section.settings.enable_simulator_ship == true%}

        <div class="cart-finish-coupon">
          <div class="cart-finish-coupon-content">
            <div class="cart-coupon-title">
              {{section.settings.title_simulator_ship}}
            </div>

            <input class="cart-coupon-input" type="number" placeholder="CEP" id="cart_cep_input">

            <button type="button" class="cart-coupon-button" id="cart_cep_button" onclick="getCepData()">
              {{section.settings.button_simulator_ship}}
            </button>
          </div>

            <div class="cart-finish-coupon-shipping" id="data_of_cep">
              <div id="destination_ship">

              </div>
              <div>
                <span id="time_ship_1"></span>
                <span id="time_ship_2"></span>
              </div>

              <div id="price_ship">

              </div>
            </div>
        </div>
        {% endif %}

      </div>
      <div class="cart-section-finish-right">


          <div class="cart-finish-total">
              <div class="cart-finish-total-label">
                  Total
              </div>
              <div class="cart-finish-total-price">
                {{ cart.total_price  | money}}
              </div>
          </div>

          <div class="cart-finish-buy">
              <div class="cart-buy-more">
                  <a href="{{ routes.all_products_collection_url }}">
                    Comprar mais produtos
                  </a>
              </div>
              <div class="cart-buy-now">
                  <button type="submit" name="checkout">
                      Continuar a compra
                  </button>
              </div>
          </div>
      </div>
    </div>    
  </form>
</div>


{% if section.settings.enable_simulator_ship == true %}
<script>
  //Consulta e cep estimativa de envio
  document.getElementById('cart_cep_input').oninput = function () {
    if (this.value.length > 8) {
          this.value = this.value.slice(0,8); 
    }
  }

  function getCepData() {
    let cep = document.getElementById('cart_cep_input').value
    if (cep != "" && cep.length == 8) {
      document.getElementById('cart_cep_button').innerHTML = 'Carregando'
      
      fetch(`https://viacep.com.br/ws/${cep}/json/`) 
      .then(response => {
        response.json()
        .then(data => showData(data))
      })
      .finally(function() {
        setTimeout(function () {
          document.getElementById('cart_cep_button').innerHTML = `{{section.settings.button_simulator_ship}}`

        }, 150)
      })
    }
  }

  function showData(data) {
    let firstDate = {{section.settings.first_date}}
    let secondDate = firstDate + {{section.settings.interval_date}}
    
    if (data.erro != "true"){
      document.getElementById("data_of_cep").classList.add("open-coupon-info")

      document.getElementById("time_ship_1").innerHTML = `de ${firstDate} até `
      document.getElementById("time_ship_2").innerHTML = `${secondDate} dias úteis`
      document.getElementById("destination_ship").innerHTML = data.localidade
      document.getElementById("price_ship").innerHTML = `{{section.settings.price_simulator_ship}}`
    }
    else {
      document.getElementById("data_of_cep").classList.add("open-coupon-info")
      document.getElementById("destination_ship").innerHTML = "CEP não encontrado"
      document.getElementById("time_ship_1").innerHTML = ""
      document.getElementById("time_ship_2").innerHTML = ""
      document.getElementById("price_ship").innerHTML = ""
    }

  }
</script>
{% endif %}





{% schema %}
{
  "name": {
    "cs": "Stránka košíku",
    "da": "Side med indkøbskurv",
    "de": "Warenkorb-Seite",
    "en": "Cart page",
    "es": "Página del carrito",
    "fi": "Ostoskorisivu",
    "fr": "Page du panier",
    "it": "Pagina del carrello",
    "ja": "カートページ",
    "ko": "카트 페이지",
    "nb": "Handlekurvside",
    "nl": "Winkelwagenpagina",
    "pl": "Strona koszyka",
    "pt-BR": "Página do carrinho",
    "pt-PT": "Página do carrinho",
    "sv": "Varukorgssida",
    "th": "หน้าตะกร้าสินค้า",
    "tr": "Sepet sayfası",
    "vi": "Trang giỏ hàng",
    "zh-CN": "购物车页面",
    "zh-TW": "購物車頁面"
  },
  "settings": [
    {
      "type": "checkbox",
      "label": "Habilitar simulador de frete",
      "id": "enable_simulator_ship",
      "default": true
    },
    {
      "type": "text",
      "label": "Título simulador de frete",
      "id": "title_simulator_ship",
      "default": "Calcular frete e prazo de entrega"
    },
    {
      "type": "text",
      "label": "Botão simulador de frete",
      "id": "button_simulator_ship",
      "default": "Calcular"
    },
    {
      "type": "text",
      "label": "Preço do frete no simulador",
      "id": "price_simulator_ship",
      "default": "R$29,99"
    },
    {
      "type": "range",
      "id": "first_date",
      "label": "Prazo mínimo em dias",
      "min": 1,
      "max": 90,
      "unit": "d",
      "step": 1,
      "default": 9
    },
    {
      "type": "range",
      "id": "interval_date",
      "label": "Intervalo de dias",
      "min": 1,
      "max": 90,
      "unit": "d",
      "step": 1,
      "default": 5
    },
    {
      "type": "color",
      "label": "Cor #1",
      "id": "color_one_cart",
      "info": "Cor dos títulos e do simulador de frete",
      "default": "#0033C6"
    },
    {
      "type": "color",
      "label": "Cor #2",
      "id": "color_two_cart",
      "info": "Cor dos textos",
      "default": "#3A3A3A"
    },
    {
      "type": "color",
      "label": "Cor #3",
      "id": "color_three_cart",
      "info": "Cor do botão de compra",
      "default": "#1a9008"
    },
    {
      "type": "color",
      "label": "Cor #4",
      "id": "color_for_cart",
      "info": "Cor das linhas do topo",
      "default": "#b2b2b2"
    },
    {
      "type": "color",
      "label": "Cor #5",
      "id": "color_five_cart",
      "info": "Cor do input de quantidade",
      "default": "#f2f2f2"
    }
  ]
}
{% endschema %}
