<%= content_tag_for(:div, worldwide_office, class: 'well') do %>
  <% if worldwide_organisation.is_main_office?(worldwide_office) %>
    <h4 class="main-flag">(Main office)</h4>
  <% end %>
  <h3><%= worldwide_office.title %></h3>

  <div class="vcard">
    <%= render_hcard_address(worldwide_office.contact) %>
  </div>
  <%= content_tag(:dl, class: "dl-horizontal") do %>
    <% worldwide_office.contact.contact_numbers.each do |cn| %>
      <%= definition(cn.label, cn.number) %>
    <% end %>
    <% if worldwide_office.contact.contact_form_url.present? %>
      <%= definition('Contact form', link_to(worldwide_office.contact.contact_form_url.truncate(25), worldwide_office.contact.contact_form_url)) %>
    <% end %>
    <% if worldwide_office.contact.email.present? %>
      <%= definition('Email', worldwide_office.contact.email) %>
    <% end %>
    <%= definition('Office type', worldwide_office.worldwide_office_type.name) %>
    <%= definition('Contact type', worldwide_office.contact.contact_type.name) %>
    <%= definition('Markdown to use', "[Contact:#{worldwide_office.contact.id}]") %>
    <%= definition('On home page?', worldwide_office_shown_on_home_page_text(worldwide_organisation, worldwide_office)) %>
    <%= definition("Access and<br/>opening times".html_safe, 'ignored') do |ignored| %>
      <% if worldwide_office.access_and_opening_times.present? %>
        Custom info
        <%= link_to 'Edit access info', [:edit, :admin, worldwide_organisation, worldwide_office, :access_and_opening_time] %>
      <% elsif worldwide_office.default_access_and_opening_times.present? %>
        Using default
        <%= link_to 'Customise access info', [:edit, :admin, worldwide_organisation, worldwide_office, :access_and_opening_time] %>
      <% else %>
        <%= link_to 'Add custom access info', [:edit, :admin, worldwide_organisation, worldwide_office, :access_and_opening_time] %>
      <% end %>
    <% end %>
  <% end %>
  <% if worldwide_office.contact.comments.present? %>
    <p class="comments"><%= format_with_html_line_breaks(h(worldwide_office.comments)) %></p>
  <% end %>

  <%= button_to "Delete",
        [:admin, worldwide_organisation, worldwide_office],
        method: "delete",
        class: "btn btn-danger",
        data: { confirm: "Delete office ‘#{worldwide_office.title}’?" } %>
  <%= link_to icon("Edit"), [:edit, :admin, worldwide_organisation, worldwide_office], class: "btn btn-default" %>
  <% unless worldwide_organisation.is_main_office?(worldwide_office) %>
    <%= button_to 'Set as main office', set_main_office_admin_worldwide_organisation_path(worldwide_organisation, worldwide_organisation: {main_office_id: worldwide_office.id}), method: :put, class: 'btn btn-info' %>
    <% if worldwide_organisation.office_shown_on_home_page?(worldwide_office) %>
      <%= button_to "Remove from home page", [:remove_from_home_page, :admin, worldwide_organisation, worldwide_office], class: 'btn btn-default' %>
    <% else %>
      <%= button_to "Add to home page", [:add_to_home_page, :admin, worldwide_organisation, worldwide_office], class: 'btn btn-default' %>
    <% end %>
  <% end %>
  <% if worldwide_office.contact.missing_translations.any? %>
    <a href="#add-translation-modal-<%= worldwide_office.contact.id %>" class="btn btn-default" data-toggle="modal"><i class="glyphicon glyphicon-plus-sign"></i> Add translation</a>
    <%= render partial: 'admin/shared/translation_modal', locals: { id: "add-translation-modal-#{worldwide_office.contact.id}", form_path: [:admin, worldwide_organisation, worldwide_office, :translations], locales: worldwide_office.contact.missing_translations } %>
  <% end %>

  <% worldwide_office.contact.non_english_localised_models([:contact_numbers]).each do |translated_contact| %>
    <hr />
    <h3><small><%= translated_contact.translation_locale.native_and_english_language_name %> translation</small></h3>

    <%= content_tag(:div, class: contact_translation_css_class(translated_contact)) do %>
      <h3><%= translated_contact.title %></h3>

      <div class="vcard">
        <%= render_hcard_address(translated_contact) %>
      </div>

      <%= content_tag(:dl, class: "dl-horizontal") do %>
        <% translated_contact.contact_numbers.each do |cn| %>
          <%= definition(cn.label, cn.number) %>
        <% end %>
        <% if translated_contact.email.present? %>
          <%= definition('Email', translated_contact.email) %>
        <% end %>
      <% end %>
    <% end %>

    <%= button_to "Delete",
          [:admin, worldwide_organisation, worldwide_office, translated_contact.translation_locale],
          method: "delete",
          class: "btn btn-danger",
          data: { confirm: "Delete '#{translated_contact.translation_locale.native_and_english_language_name}' translation from worldwide office '#{worldwide_office.title}'?" } %>
    <%= link_to icon("Edit"), edit_polymorphic_path([:admin, worldwide_organisation, worldwide_office, translated_contact.translation_locale]), class: "btn btn-default" %>
  <% end %>
<% end %>
