<div class="{{ is_logged_in ? 'checkout-content' : '' }} checkout-{{ type }}-form">
    {% if (is_logged_in) %}
        <h2 class="secondary-title">
            <i class="fa fa-user"></i>{{ type == 'payment' ? 'Billing Address' : 'Delivery Address' }}
        </h2>
    {% endif %}
    <div class="box-inner">
        <form class="form-horizontal form-{{ type }}">
            {% if (addresses) %}
                <div class="radio">
                    <label>
                        <input type="radio" name="{{ type }}_address" value="existing" checked="checked"/>
                        {{ text_address_existing }}
                    </label>
                </div>
                <div id="{{ type }}-existing">
                    <select name="{{ type }}_address_id" class="form-control">
                        {% for address in addresses %}
                            {% if (address['address_id'] == address_id) %}
                                <option value="{{ address['address_id'] }}" selected="selected">{{ address['firstname'] }} {{ address['lastname'] }}, {{ address['address_1'] }}, {{ address['city'] }}, {{ address['zone'] }}, {{ address['country'] }}</option>
                            {% else %}
                                <option value="{{ address['address_id'] }}">{{ address['firstname'] }} {{ address['lastname'] }}, {{ address['address_1'] }}, {{ address['city'] }}, {{ address['zone'] }}, {{ address['country'] }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                </div>
                <div class="radio">
                    <label>
                        <input type="radio" name="{{ type }}_address" value="new"/>
                        {{ text_address_new }}
                    </label>
                </div>
            {% endif %}
            <div id="{{ type }}-new" style="display: {{ addresses ? 'none' : 'block' }};">
                {% if (name) %}
                    <div class="form-group required">
                        <input type="text" name="{{ type }}_firstname" value="{{ type ~ '_' ~ firstname }} *" placeholder="{{ entry_firstname }}" id="input-{{ type }}-firstname" class="form-control"/>
                    </div>
                    <div class="form-group required">
                        <input type="text" name="{{ type }}_lastname" value="{{ type ~ '_' ~ lastname }}" placeholder="{{ entry_lastname }} *" id="input-{{ type }}-lastname" class="form-control"/>
                    </div>
                {% endif %}
                <div class="form-group company-input">
                    <input type="text" name="{{ type }}_company" value="{{ type ~ '_' ~ company }}" placeholder="{{ entry_company }}" id="input-{{ type }}-company" class="form-control"/>
                </div>
                <div class="form-group required">
                    <input type="text" name="{{ type }}_address_1" value="{{ type ~ '_' ~ address_1 }}" placeholder="{{ entry_address_1 }} *" id="input-{{ type }}-address-1" class="form-control"/>
                </div>
                <div class="form-group address-2-input">
                    <input type="text" name="{{ type }}_address_2" value="{{ type ~ '_' ~ address_2 }}" placeholder="{{ entry_address_2 }}" id="input-{{ type }}-address-2" class="form-control"/>
                </div>
                <div class="form-group required">
                    <input type="text" name="{{ type }}_city" value="{{ type ~ '_' ~ city }}" placeholder="{{ entry_city }} *" id="input-{{ type }}-city" class="form-control"/>
                </div>
                <div class="form-group required">
                    <input type="text" name="{{ type }}_postcode" value="{{ type ~ '_' ~ postcode }}" placeholder="{{ entry_postcode }} *" id="input-{{ type }}-postcode" class="form-control"/>
                </div>
                <div class="form-group required">
                    <select name="{{ type }}_country_id" id="input-{{ type }}-country" class="form-control">
                        <option value="">{{ text_select }}</option>
                        {% for country in countries %}
                            {% if (country['country_id'] == country_id) %}
                                <option value="{{ country['country_id'] }}" selected="selected">{{ country['name'] }}</option>
                            {% else %}
                                <option value="{{ country['country_id'] }}">{{ country['name'] }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                </div>
                <div class="form-group required">
                    <select name="{{ type }}_zone_id" id="input-{{ type }}-zone" class="form-control">
                    </select>
                </div>
                {% for custom_field in custom_fields %}
                    {% if (custom_field['location'] == 'address') %}
                        {% if (custom_field['type'] == 'select') %}
                            <div class="form-group{{ custom_field['required'] ? ' required' : '' }} custom-field"
                                 data-sort="{{ custom_field['sort_order'] }}">
                                <label class="col-sm-2 control-label"
                                       for="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}">{{ custom_field['name'] }}</label>

                                <select name="{{ type }}_custom_field[{{ custom_field['custom_field_id'] }}]"
                                        id="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}"
                                        class="form-control">
                                    <option value="">{{ text_select }}</option>
                                    {% for custom_field_value in custom_field['custom_field_value'] %}
                                        <option
                                                value="{{ custom_field_value['custom_field_value_id'] }}">{{ custom_field_value['name'] }}</option>
                                    {% endfor %}
                                </select>
                            </div>
                        {% endif %}
                        {% if (custom_field['type'] == 'radio') %}
                            <div class="form-group{{ custom_field['required'] ? ' required' : '' }} custom-field"
                                 data-sort="{{ custom_field['sort_order'] }}">
                                <label class="col-sm-2 control-label">{{ custom_field['name'] }}</label>

                                <div id="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}">
                                    {% for custom_field_value in custom_field['custom_field_value'] %}
                                        <div class="radio">
                                            <label>
                                                <input type="radio"
                                                       name="{{ type }}_custom_field[{{ custom_field['custom_field_id'] }}]"
                                                       value="{{ custom_field_value['custom_field_value_id'] }}"/>
                                                {{ custom_field_value['name'] }}</label>
                                        </div>
                                    {% endfor %}
                                </div>
                            </div>
                        {% endif %}
                        {% if (custom_field['type'] == 'checkbox') %}
                            <div class="form-group{{ custom_field['required'] ? ' required' : '' }} custom-field"
                                 data-sort="{{ custom_field['sort_order'] }}">
                                <label class="col-sm-2 control-label">{{ custom_field['name'] }}</label>

                                <div id="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}">
                                    {% for custom_field_value in custom_field['custom_field_value'] %}
                                        <div class="checkbox">
                                            <label>
                                                <input type="checkbox"
                                                       name="{{ type }}_custom_field[{{ custom_field['custom_field_id'] }}][]"
                                                       value="{{ custom_field_value['custom_field_value_id'] }}"/>
                                                {{ custom_field_value['name'] }}</label>
                                        </div>
                                    {% endfor %}
                                </div>
                            </div>
                        {% endif %}
                        {% if (custom_field['type'] == 'text') %}
                            <div class="form-group{{ custom_field['required'] ? ' required' : '' }} custom-field"
                                 data-sort="{{ custom_field['sort_order'] }}">
                                <label class="col-sm-2 control-label"
                                       for="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}">{{ custom_field['name'] }}</label>

                                <input type="text" name="{{ type }}_custom_field[{{ custom_field['custom_field_id'] }}]"
                                       value="{{ custom_field['value'] }}"
                                       placeholder="{{ custom_field['name'] }}"
                                       id="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}"
                                       class="form-control"/>
                            </div>
                        {% endif %}
                        {% if (custom_field['type'] == 'textarea') %}
                            <div class="form-group{{ custom_field['required'] ? ' required' : '' }} custom-field"
                                 data-sort="{{ custom_field['sort_order'] }}">
                                <label class="col-sm-2 control-label"
                                       for="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}">{{ custom_field['name'] }}</label>

                                <textarea name="{{ type }}_custom_field[{{ custom_field['custom_field_id'] }}]" rows="5"
                                          placeholder="{{ custom_field['name'] }}"
                                          id="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}"
                                          class="form-control">{{ custom_field['value'] }}</textarea>
                            </div>
                        {% endif %}
                        {% if (custom_field['type'] == 'file') %}
                            <div class="form-group{{ custom_field['required'] ? ' required' : '' }} custom-field"
                                 data-sort="{{ custom_field['sort_order'] }}">
                                <label class="col-sm-2 control-label">{{ custom_field['name'] }}</label>

                                <button type="button"
                                        id="button-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}"
                                        data-loading-text="{{ text_loading }}" class="btn btn-default"><i
                                            class="fa fa-upload"></i> {{ button_upload }}</button>
                                <input type="hidden" name="{{ type }}_custom_field[{{ custom_field['custom_field_id'] }}]"
                                       value=""
                                       id="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}"/>
                            </div>
                        {% endif %}
                        {% if (custom_field['type'] == 'date') %}
                            <div class="form-group{{ custom_field['required'] ? ' required' : '' }} custom-field"
                                 data-sort="{{ custom_field['sort_order'] }}">
                                <label class="col-sm-2 control-label"
                                       for="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}">{{ custom_field['name'] }}</label>

                                <div class="input-group date">
                                    <input type="text" name="{{ type }}_custom_field[{{ custom_field['custom_field_id'] }}]"
                                           value="{{ custom_field['value'] }}"
                                           placeholder="{{ custom_field['name'] }}" data-date-format="YYYY-MM-DD"
                                           id="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}"
                                           class="form-control"/>
                                    <span class="input-group-btn">
                  <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                  </span></div>
                            </div>
                        {% endif %}
                        {% if (custom_field['type'] == 'time') %}
                            <div class="form-group{{ custom_field['required'] ? ' required' : '' }} custom-field"
                                 data-sort="{{ custom_field['sort_order'] }}">
                                <label class="col-sm-2 control-label"
                                       for="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}">{{ custom_field['name'] }}</label>

                                <div class="input-group time">
                                    <input type="text" name="{{ type }}_custom_field[{{ custom_field['custom_field_id'] }}]"
                                           value="{{ custom_field['value'] }}"
                                           placeholder="{{ custom_field['name'] }}" data-date-format="HH:mm"
                                           id="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}"
                                           class="form-control"/>
                                    <span class="input-group-btn">
                  <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                  </span></div>
                            </div>
                        {% endif %}
                        {% if (custom_field['type'] == 'datetime') %}
                            <div class="form-group{{ custom_field['required'] ? ' required' : '' }} custom-field"
                                 data-sort="{{ custom_field['sort_order'] }}">
                                <label class="col-sm-2 control-label"
                                       for="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}">{{ custom_field['name'] }}</label>

                                <div class="input-group datetime">
                                    <input type="text" name="{{ type }}_custom_field[{{ custom_field['custom_field_id'] }}]"
                                           value="{{ custom_field['value'] }}"
                                           placeholder="{{ custom_field['name'] }}"
                                           data-date-format="YYYY-MM-DD HH:mm"
                                           id="input-{{ type }}-custom-field{{ custom_field['custom_field_id'] }}"
                                           class="form-control"/>
                                    <span class="input-group-btn">
                  <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                  </span></div>
                            </div>
                        {% endif %}
                    {% endif %}
                {% endfor %}
            </div>
        </form>
    </div>
</div>
<input type="hidden" name="default_zone_id" id="default_zone_id" value="{{ zone_id }}"/>