<h2 class="inline-block"><%= t("admin.milestones.index.milestone") %></h2>

<%= link_to t("admin.progress_bars.manage"),
            admin_polymorphic_path(milestoneable.progress_bars.new),
            class: "button hollow float-right" %>

<% if milestoneable.milestone_tag_list.any? %>
  <div>
    <strong>
      <%= t("admin.milestones.index.milestone_tags") %>:
    </strong> <%= milestoneable.milestone_tag_list.sort.join(", ") %>
  </div>
<% end %>

<% if milestoneable.milestones.any? %>
  <table>
    <thead>
      <tr>
        <th><%= t("admin.milestones.index.table_id") %></th>
        <th><%= t("admin.milestones.index.table_title") %></th>
        <th><%= t("admin.milestones.index.table_description") %></th>
        <th><%= t("admin.milestones.index.table_publication_date") %></th>
        <th><%= t("admin.milestones.index.table_status") %></th>
        <th><%= t("admin.milestones.index.image") %></th>
        <th><%= t("admin.milestones.index.documents") %></th>
        <th><%= t("admin.milestones.index.table_actions") %></th>
      </tr>
    </thead>
    <tbody>
      <% milestoneable.milestones.order_by_publication_date.each do |milestone| %>
        <tr id="<%= dom_id(milestone) %>" class="milestone">
          <td class="text-center"><%= milestone.id %></td>
          <td><%= milestone.title %></td>
          <td class="small small-5"><%= milestone.description %></td>
          <td class="small">
            <%= l(milestone.publication_date.to_date) if milestone.publication_date.present? %>
          </td>
          <td class="small">
            <%= milestone.status.present? ? milestone.status.name : "" %>
          </td>
          <td class="small">
            <%= link_to t("admin.milestones.index.show_image"),
                        milestone.image.variant(:large) if milestone.image.present? %>
          </td>
          <td class="small">
            <% if milestone.documents.present? %>
              <% milestone.documents.each do |document| %>
                <%= link_to document.title,
                            document.attachment,
                            rel: "nofollow" %><br>
              <% end %>
            <% end %>
          </td>
          <td><%= render Admin::TableActionsComponent.new(milestone) %></td>
        </tr>
      <% end %>
    </tbody>
  </table>
<% else %>
  <p><%= t("admin.milestones.index.no_milestones") %></p>
<% end %>

<p>
  <%= link_to t("admin.milestones.index.new_milestone"),
              admin_polymorphic_path(milestoneable.milestones.new, action: :new),
              class: "button hollow" %>
</p>
