{{ header }}
<div id="account-address" class="container">
  <ul class="breadcrumb">
    {% for breadcrumb in breadcrumbs %}
      <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
    {% endfor %}
  </ul>
  {% if attention %}
    <div class="alert alert-info"><i class="fa fa-info-circle"></i> {{ attention }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
  {% endif %}
  {% if success %}
    <div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> {{ success }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
  {% endif %}
  <div class="row">{{ column_left }}
    {% if column_left and column_right %}
      {% set class = 'col-sm-6' %}
    {% elseif column_left or column_right %}
      {% set class = 'col-sm-9' %}
    {% else %}
      {% set class = 'col-sm-12' %}
    {% endif %}
    <div id="content" class="{{ class }}">{{ content_top }}
      <h2>{{ text_address_book }}</h2>
      <form class="form-horizontal" id="form-address">
        <div class="table-responsive">
          <table class="table table-bordered table-hover">
            <thead>
              <tr>
                <td class="text-center">{{ column_address }}</td>
                <td class="text-right">{{ column_action }}</td>
              </tr>
            </thead>
            <tbody>
            {% if addresses %}
              {% for address in addresses %}
                <tr>
                  <td class="text-center">{{ address.address }}</td>
                  <td class="text-right">
                    <button type="button" data-toggle="tooltip" title="{{ button_edit }}" onclick="address.update('{{ address.address_id }}');" class="btn btn-primary"><i class="fa fa-pencil"></i></button>
                    <button type="button" data-toggle="tooltip" title="{{ button_delete }}" onclick="address.remove('{{ address.address_id }}'); return false;" class="btn btn-danger"><i class="fa fa-times-circle"></i></button>
                  </td>
                </tr>
              {% endfor %}
            {% else %}
              <tr>
                <td class="text-center" colspan="2">{{ text_no_results }}</td>
              </tr>
            {% endif %}
            </tbody>
          </table>
        </div>
      </form>
      <div class="buttons clearfix">
        <div class="pull-left"><a href="{{ back }}" class="btn btn-default">{{ button_back }}</a></div>
        <div class="pull-right"><a href="{{ add }}" class="btn btn-primary">{{ button_new_address }}</a></div>
      </div>
      {{ content_bottom }}
    </div>
    {{ column_right }}
  </div>
</div>
<script type="text/javascript"><!--
    // Address update, and remove functions
    var address = {
        'update': function (key) {
            $('.alert-dismissible').remove();

            $.ajax({
                url: 'index.php?route=account/address/editAddress&customer_token={{ customer_token }}&address_id=' + key,
                dataType: 'json',
                success: function (json) {
                    if (json['redirect']) {
                        location = json['redirect'];
                    }
                }
            });
        },
        'remove': function (key) {
            $('.alert-dismissible').remove();

            $.ajax({
                url: 'index.php?route=account/address/delete&customer_token={{ customer_token }}&address_id=' + key,
                dataType: 'json',
                success: function (json) {
                    if (json['redirect']) {
                        location = json['redirect'];
                    }

                    if (json['warning']) {
                        var result = confirm('{{ text_confirm }}');

                        if (!result) {
                            return false;
                        } else {
                            $('#account-address > .breadcrumb').after('<div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> ' + json['warning'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');
                        }
                    }
                }
            });
        }
    }
//--></script>
{{ footer }}