{% extends "shop/checkout/dialog-base.html" %}
{% load i18n static sass_tags sekizai_tags shop_tags %}

{% block extra-styles %}
	{{ block.super }}
	{% for stylesheet in shipping_address_form.media.render_css %}{% addtoblock "css" %}{{ stylesheet }}{% endaddtoblock %}{% endfor %}
	{% addtoblock "css" %}<link href="{% sass_src 'shop/css/fix-checkbox-inline.scss' %}" rel="stylesheet" type="text/css" />{% endaddtoblock %}
{% endblock %}

{% block extra-scripts %}
	{{ block.super }}
	{% addtoblock "js" %}<script src="{% static 'shop/js/address.js' %}" type="text/javascript"></script>{% endaddtoblock %}
	{% add_data "ng-requires" "django.shop.address" %}
{% endblock %}

{% block dialog_form %}

<form shop-address-form djng-endpoint="{% url 'shop:edit-shipping-address' '{{ priority }}' %}" name="{{ shipping_address_form.form_name }}" novalidate>
	{% if shipping_address_form.allow_use_primary %}
	<div class="has-feedback form-group">
		{{ shipping_address_form.use_primary_address }}
	</div>
	{% endif %}
	<fieldset{% if shipping_address_form.allow_use_primary %} ng-hide="shipping_address.use_primary_address" class="animate-show" ng-cloak{% endif %}>
	{% if headline_legend %}
	<legend>{{ shipping_address_form.legend }}</legend>
	{% endif %}
	{% if shipping_address_form.multi_addr %}
		<input type="hidden" name="siblings_summary" ng-model="shipping_address.siblings_summary" ng-init="shipping_address.siblings_summary={{ shipping_address_form.siblings_summary|rest_json|force_escape }};" />
		<div class="form-group" ng-show="shipping_address.siblings_summary.length>0">
			<label for="shipping_address_active_priority">{% trans "Choose a previously used shipping address" context "checkout" %}</label>
			<select id="shipping_address_active_priority" class="form-control input-sm" name="active_priority" ng-change="switchSiblingAddress(shipping_address.active_priority)" ng-model="shipping_address.active_priority">
				{% verbatim %}
				<option ng-repeat="addr in shipping_address.siblings_summary" value="{{ addr.value }}">{{ addr.label }}</option>
				{% endverbatim %}
				<option value="add">{% trans "Add a new shipping address" context "checkout" %}</option>
			</select>
		</div>
	{% endif %}
	{% spaceless %}
		{{ shipping_address_form.as_div }}
	{% endspaceless %}
	{% if shipping_address_form.multi_addr %}
		<div class="form-group" ng-show="shipping_address.siblings_summary.length>1 || shipping_address.siblings_summary.length>0 && shipping_address.active_priority=='add'">
			<button class="btn btn-danger btn-sm" ng-click="deleteSiblingAddress()">
				<span class="fa fa-trash mr-2"></span>{% trans "Remove this address" context "checkout" %}
			</button>
		</div>
	{% endif %}
	</fieldset>
</form>
{% endblock %}
