{% extends "oscar/checkout/checkout.html" %}
{% load i18n %}

{% block title %}
    {% trans "Shipping address" %} | {{ block.super }}
{% endblock %}

{% block checkout_nav %}
    {% include 'oscar/checkout/nav.html' with step=1 %}
{% endblock %}

{% block checkout_title %}{% trans "Shipping address" %}{% endblock %}

{% block order_contents %}{% endblock %}

{% block shipping_address %}
<div class="col-sm-12">
    <div class="sub-header">
        <h2>{% trans "Where should we ship to?" %}</h2>
    </div>
    {% if user.is_authenticated %}
        {% if addresses %}
            <h3>{% trans "An address from your address book?" %}</h3>
            <div class="choose-block">
                <div class="row">
                    {% for address in addresses %}
                        {% block select_address_form %}
                            <div class="col-sm-6 d-flex">
                                <div class="card card-body bg-light">
                                    <address>
                                        {% block select_address_fields %}
                                            {% for field in address.active_address_fields %}
                                                <span>{{ field }}</span>{% if not forloop.first %}<br/>{% endif %}
                                            {% endfor %}
                                        {% endblock %}
                                    </address>
                                    <form action="{% url 'checkout:shipping-address' %}" method="post" id="select_shipping_address_{{ address.id }}" class="mb-0">
                                        {% csrf_token %}
                                        <input type="hidden" name="action" value="ship_to" />
                                        <input type="hidden" name="address_id" value="{{ address.id }}" />
                                        {% if address.is_default_for_shipping %}
                                            <button type="submit" class="btn btn-success btn-large ship-address" data-loading-text="{% trans 'Saving...' %}"><i class="fas fa-check-circle"></i> {% trans "Ship to your default shipping address" %}</button>
                                        {% else %}
                                            <button type="submit" class="btn btn-primary btn-large ship-address" data-loading-text="{% trans 'Saving...' %}">{% trans "Ship to this address" %}</button>
                                        {% endif %}

                                        <div class="btn-group address-controls">
                                            <a href="{% url 'checkout:user-address-update' pk=address.id %}" class="btn btn-secondary">{% trans "Edit address" %}</a>
                                            <button class="btn btn-secondary dropdown-toggle" data-toggle="dropdown"></button>
                                            <ul class="dropdown-menu">
                                                <a href="{% url 'checkout:user-address-delete' pk=address.id %}" class="btn-remove-address nav-link">{% trans "Delete" %}</a>
                                            </ul>
                                        </div>
                                    </form>
                                </div>
                            </div>
                            {% if forloop.counter|divisibleby:2 %}
                                </div><div class="row">
                            {% endif %}
                        {% endblock %}
                    {% endfor %}
                </div>
            </div>
            <h3>{% trans "Or a new address?" %}</h3>
        {% endif %}
    {% endif %}

    {% block new_address_form %}
        <div class="card card-body bg-light">
            <form action="{% url 'checkout:shipping-address' %}" method="post" id="new_shipping_address">
                {% csrf_token %}
                {% include "oscar/partials/form_fields.html" with form=form style='horizontal' %}
                <div class="form-group row">
                    <div class="offset-sm-4 col-sm-8">
                        <button type="submit" class="btn btn-lg btn-primary" data-loading-text="{% trans 'Continuing...' %}">{% trans "Continue" %}</button>
                        {% trans "or" %} <a href="{% url 'basket:summary' %}">{% trans "return to basket" %}</a>
                    </div>
                </div>
            </form>
        </div>
    {% endblock %}
</div>
{% endblock shipping_address %}

{% block shipping_method %}{% endblock %}
{% block payment_method %}{% endblock %}
