{**
  * 2007-2019 PrestaShop and Contributors
  *
  * NOTICE OF LICENSE
  *
  * This source file is subject to the Academic Free License 3.0 (AFL-3.0)
  * that is bundled with this package in the file LICENSE.txt.
  * It is also available through the world-wide-web at this URL:
  * https://opensource.org/licenses/AFL-3.0
  * If you did not receive a copy of the license and are unable to
  * obtain it through the world-wide-web, please send an email
  * to license@prestashop.com so we can send you a copy immediately.
  *
  * DISCLAIMER
  *
  * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  * versions in the future. If you wish to customize PrestaShop for your
  * needs please refer to https://www.prestashop.com for more information.
  *
  * @author    PrestaShop SA <contact@prestashop.com>
  * @copyright 2007-2019 PrestaShop SA and Contributors
  * @license   https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
  * International Registered Trademark & Property of PrestaShop SA
  *}
{extends file='checkout/_partials/steps/checkout-step.tpl'}

{block name='step_content'}
    <div class="js-address-form p-4 flex flex-col gap-4">
      <form
        method="POST"
        action="{url entity='order' params=['id_address' => $id_address]}"
        data-refresh-url="{url entity='order' params=['ajax' => 1, 'action' => 'addressForm']}"
        class="w-full flex flex-col gap-8"
      >

      <div class="w-full flex flex-col gap-4">
        {if !$use_same_address}
          <h2 class="text-lg">{l s='Shipping Address' d='Shop.Theme.Checkout'}</h2>
        {/if}

        {if $use_same_address && !$cart.is_virtual}
          <span class="font-semibold mb-2">
            {l s='The selected address will be used both as your personal address (for invoice) and as your delivery address.' d='Shop.Theme.Checkout'}
          </span>
        {elseif $use_same_address && $cart.is_virtual}
          <span class="font-semibold mb-2">
            {l s='The selected address will be used as your personal address (for invoice).' d='Shop.Theme.Checkout'}
          </span>
        {/if}

        {if $show_delivery_address_form}
          <div id="delivery-address">
            {render file                      = 'checkout/_partials/address-form.tpl'
              ui                        = $address_form
              use_same_address          = $use_same_address
              type                      = "delivery"
              form_has_continue_button  = $form_has_continue_button
            }
          </div>
        {elseif $customer.addresses|count > 0}
          <div id="delivery-addresses" class="address-selector js-address-selector w-full flex max-md:flex-col gap-4 flex-wrap md:gap-0">
            {include  file        = 'checkout/_partials/address-selector-block.tpl'
              addresses   = $customer.addresses
              name        = "id_address_delivery"
              selected    = $id_address_delivery
              type        = "delivery"
              interactive = !$show_delivery_address_form and !$show_invoice_address_form
            }
          </div>

          {if isset($delivery_address_error)}
            <p class="alert alert-danger js-address-error" name="alert-delivery" id="id-failure-address-{$delivery_address_error.id_address}">{$delivery_address_error.exception}</p>
          {else}
            <p class="alert alert-danger js-address-error" name="alert-delivery" style="display: none">{l s="Your address is incomplete, please update it." d="Shop.Notifications.Error"}</p>
          {/if}

          <div class="add-address w-full flex flex-col gap-2">
            <a href="{$new_address_delivery_url}" class="flex items-center gap-2">
              <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-home-plus" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M19 12h2l-9 -9l-9 9h2v7a2 2 0 0 0 2 2h5.5" /><path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2" /><path d="M16 19h6" /><path d="M19 16v6" /></svg>
              {l s='add new address' d='Shop.Theme.Actions'}
            </a>
            {if $use_same_address && !$cart.is_virtual}
              <a data-link-action="different-invoice-address" class="flex items-center gap-2" href="{$use_different_address_url}">
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-layers-difference" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M16 16v2a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2v-8a2 2 0 0 1 2 -2h2v-2a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-2" /><path d="M10 8l-2 0l0 2" /><path d="M8 14l0 2l2 0" /><path d="M14 8l2 0l0 2" /><path d="M16 14l0 2l-2 0" /></svg>
                {l s='Billing address differs from shipping address' d='Shop.Theme.Checkout'}
              </a>
            {/if}
          </div>
        {/if}
      </div>
        {if !$use_same_address}
      <hr>
      <div class="w-full flex flex-col gap-4">
          <h2 class="text-lg">{l s='Your Invoice Address' d='Shop.Theme.Checkout'}</h2>
          {if $show_invoice_address_form}
            <div id="invoice-address">
              {render file                      = 'checkout/_partials/address-form.tpl'
                ui                        = $address_form
                use_same_address          = $use_same_address
                type                      = "invoice"
                form_has_continue_button  = $form_has_continue_button
              }
            </div>
          {else}
            <div id="invoice-addresses" class="address-selector js-address-selector w-full flex max-md:flex-col gap-4 flex-wrap md:gap-0">
              {include  file        = 'checkout/_partials/address-selector-block.tpl'
                addresses   = $customer.addresses
                name        = "id_address_invoice"
                selected    = $id_address_invoice
                type        = "invoice"
                interactive = !$show_delivery_address_form and !$show_invoice_address_form
              }
            </div>

            {if isset($invoice_address_error)}
              <p class="alert alert-danger js-address-error" name="alert-invoice" id="id-failure-address-{$invoice_address_error.id_address}">{$invoice_address_error.exception}</p>
            {else}
              <p class="alert alert-danger js-address-error" name="alert-invoice" style="display: none">{l s="Your address is incomplete, please update it." d="Shop.Notifications.Error"}</p>
            {/if}

            <div class="add-address w-full">
              <a href="{$new_address_invoice_url}"  class="flex items-center gap-2">
              <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-home-plus" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M19 12h2l-9 -9l-9 9h2v7a2 2 0 0 0 2 2h5.5" /><path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2" /><path d="M16 19h6" /><path d="M19 16v6" /></svg>
              {l s='add new address' d='Shop.Theme.Actions'}
              </a>
            </div>
          </div>
          {/if}

        {/if}

        {if !$form_has_continue_button}
          <div class="clearfix w-full flex">
            <button type="submit" class="flex-1 uppercase py-2 font-medium text-center bg-blue-950 text-gray-50 hover:text-gray-50 hover:bg-blue-900" name="confirm-addresses" value="1">
              {l s='Continue' d='Shop.Theme.Actions'}
            </button>
            <input type="hidden" id="not-valid-addresses" value="{$not_valid_addresses}">
          </div>
        {/if}

      </form>
    </div>
{/block}