<h1>Return Addresses</h1>
<div class="actions">
  <%= create_button new_return_address_path, "new!" %>
</div>
<% if @return_addresses.any? %>
  <div class="return-addresses-list">
    <% @return_addresses.each do |address| %>
      <article class="card">
        <header>
          <h3><%= address.name %>
            <% if address == current_user&.home_return_address %>
              <abbr title="this is your default return address"><span class="badge success float-right">🏠</span></abbr>
            <% end %>
            <% if address.shared %>
              <span class="badge success float-right">Shared</span>
            <% end %>
            <% if address.user == current_user %>
              <span class="badge info float-right">Mine</span>
            <% end %>
          </h3>
        </header>
        <div class="address-content">
          <p>
            <%= address.line_1 %><br>
            <% if address.line_2.present? %><%= address.line_2 %><br>
            <% end %>
            <%= address.city %>, <%= address.state %> <%= address.postal_code %><br>
            <%= address.country %>
          </p>
        </div>
        <footer>
          <% if address.user == current_user || current_user.admin? %>
            <div class="actions">
              <%= link_to "Edit", edit_return_address_path(address), class: "btn btn-small" %>
              <%= button_to "delete", address, method: :delete, data: { confirm: "Are you sure you want to delete this return address?" }, class: "btn btn-small danger" %>
              <% unless address == current_user&.home_return_address %>
                <%= button_to "set as your default", set_as_home_return_address_path(address), method: :post, class: "btn btn-small success" %>
              <% end %>
            </div>
          <% end %>
        </footer>
      </article>
    <% end %>
  </div>
<% else %>
  <article>
    <p>No return addresses found.</p>
    <p><%= link_to "Create your first return address", new_return_address_path %></p>
  </article>
<% end %>
