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

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

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

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

{% block order_contents %}{% endblock %}

{% block shipping_address %}
    <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="row">
                <div class="choose-block col-sm-6">
                    <ul class="list-unstyled">
                        {% for address in addresses %}
                            {% block select_address_form %}
                                <li class="well">
                                    <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 }}">
                                        {% 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="icon-ok"></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-default btn-sm">{% trans "Edit address" %}</a>
                                            <button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu">
                                                <li><a href="{% url 'checkout:user-address-delete' pk=address.id %}" class="btn-remove-address">{% trans "Delete" %}</a></li>
                                            </ul>
                                        </div>
                                    </form>
                                </li>
                                {% if forloop.counter|divisibleby:2 %}
                                    </ul>
                                    {% if not forloop.last %}<ul class="row">{% endif %}
                                {% endif %}
                            {% endblock %}
                        {% endfor %}
                    </ul>
                </div>
            </div>
            <h3>
                {% trans "Or a new address?" %} 
            </h3>
        {% endif %}
    {% endif %}

    {% block new_address_form %}
        <div class="well">
            <form action="{% url 'checkout:shipping-address' %}" method="post" id="new_shipping_address" class="form form-horizontal">
                {% csrf_token %}
                {% include "partials/form_fields.html" with form=form style='horizontal' %}
                <div class="form-group">
                    <div class="col-sm-offset-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 %}
{% endblock shipping_address %}

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