<div class="contextual">
  <%= link_to l(:label_ux_toolkit_new_recurring_issue_rule),
              new_ux_toolkit_recurring_issue_rule_path,
              class: 'icon icon-add' %>
</div>

<h2><%= l(:label_ux_toolkit_recurring_issue_rules) %></h2>

<p><%= l(:text_ux_toolkit_recurring_issue_rules_help) %></p>

<% if @rules.any? %>
  <table class="list ux-toolkit-recurring-issue-rules">
    <thead>
      <tr>
        <th><%= l(:field_project) %></th>
        <th><%= l(:field_tracker) %></th>
        <th><%= l(:field_subject) %></th>
        <th><%= l(:label_ux_toolkit_recurring_interval) %></th>
        <th><%= l(:label_ux_toolkit_enabled) %></th>
        <th><%= l(:label_ux_toolkit_next_run_on) %></th>
        <th><%= l(:label_ux_toolkit_last_run_on) %></th>
        <th><%= l(:label_ux_toolkit_last_status) %></th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      <% @rules.each do |rule| %>
        <tr class="<%= cycle('odd', 'even') %>">
          <td><%= rule.project ? link_to_project(rule.project) : '-' %></td>
          <td><%= h(rule.tracker || '-') %></td>
          <td><%= h(rule.subject) %></td>
          <td><%= l(UxToolkitRecurringIssueRule.interval_label_key(rule.interval)) %></td>
          <td><%= rule.enabled? ? l(:general_text_Yes) : l(:general_text_No) %></td>
          <td><%= rule.next_run_on ? format_date(rule.next_run_on) : '-' %></td>
          <td><%= rule.last_run_on ? format_date(rule.last_run_on) : '-' %></td>
          <td>
            <%= rule.last_status.present? ? h(I18n.t(:"label_ux_toolkit_recurring_status_#{rule.last_status}", default: rule.last_status)) : '-' %>
            <% if rule.last_message.present? %>
              <br>
              <small><%= h(rule.last_message) %></small>
            <% end %>
          </td>
          <td class="buttons">
            <%= link_to l(:button_edit),
                        edit_ux_toolkit_recurring_issue_rule_path(rule),
                        class: 'icon icon-edit' %>
            <%= link_to l(:button_delete),
                        ux_toolkit_recurring_issue_rule_path(rule),
                        method: :delete,
                        data: {confirm: l(:text_ux_toolkit_confirm_delete_recurring_issue_rule)},
                        class: 'icon icon-del' %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
<% else %>
  <p class="nodata"><%= l(:text_ux_toolkit_no_recurring_issue_rules) %></p>
<% end %>
