<%#
# Show

This view is the template for the show page.
It renders the attributes of a resource,
as well as a link to its edit page.

## Local variables:

- `page`:
  An instance of [Administrate::Page::Show][1].
  Contains methods for accessing the resource to be displayed on the page,
  as well as helpers for describing how each attribute of the resource
  should be displayed.

[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Show
%>

<% content_for(:title) { t("administrate.actions.show_resource", name: page.page_title) } %>
<% procedure = page.resource %>

<header class="main-content__header" role="banner">
  <h1 class="main-content__page-title">
    <%= content_for(:title) %>
    <% if procedure.discarded? %>
      (Supprimé)
    <% end %>
  </h1>

  <div>
    <%= link_to(
      t("administrate.actions.edit_resource", name: page.page_title),
      [:edit, namespace, page.resource],
      class: "button",
    ) if valid_action? :edit %>
  </div>

  <div>
    <%= link_to 'aperçu', apercu_admin_procedure_path(procedure), class: 'button' %>

    <% if !procedure.whitelisted? %>
      <%= link_to 'whitelister', whitelist_manager_procedure_path(procedure), method: :post, class: 'button' %>
    <% end %>

    <% if procedure.can_be_deleted_by_manager? %>
      <%= link_to 'Supprimer la démarche', discard_manager_procedure_path(procedure), method: :post, class: 'button', data: { confirm: "Confirmez-vous la suppression de la démarche ?" } %>
    <% elsif procedure.discarded? %>
      <%= link_to 'Restaurer la démarche', restore_manager_procedure_path(procedure), method: :post, class: 'button', data: { confirm: "Confirmez-vous la restauration de la démarche ?" } %>
    <% end %>
  <div>

</header>

<section class="main-content__body">
  <dl>
    <% page.attributes.each do |attribute| %>
      <dt class="attribute-label" id="<%= attribute.name %>">
      <%= t(
        "helpers.label.#{resource_name}.#{attribute.name}",
        default: attribute.name.titleize,
      ) %>
      </dt>

      <dd class="attribute-data attribute-data--<%=attribute.html_class%>">
        <%= render_field attribute, page: page %>
        <% if attribute.name == 'administrateurs' %>
          <%= form_tag(add_administrateur_manager_procedure_path(procedure), style: 'margin-top: 1rem;') do %>
            <%= email_field_tag(:email, '', placeholder: 'Email', autocapitalize: 'off', autocorrect: 'off', spellcheck: 'false', style: 'margin-bottom: 1rem;width:24rem;') %>
            <button>Ajouter un administrateur</button>
          <% end %>
        <% end %>
      </dd>
    <% end %>
    <dd class="attribute-data">
      <a class="button" href="<%= export_mail_brouillons_manager_procedure_url(procedure) %>">Télécharger un export CSV contenant les emails des demandeurs ayant effectué une demandes en brouillon</a>
    </dd>
  </dl>
</section>
