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

<p><%= l(:text_ux_toolkit_team_workload_help, count: @stale_days) %></p>

<%= form_tag ux_toolkit_team_workload_path_for(@project), method: :get, class: 'query-form' do %>
  <fieldset id="filters" class="collapsible">
    <legend><%= l(:label_filter_plural) %></legend>

    <p>
      <label for="ux-toolkit-workload-project"><%= l(:field_project) %></label>
      <%= select_tag :project_filter_id,
                     options_for_select([[l(:label_all), '']] + @available_projects.map {|project| [project.name, project.id] },
                                        @selected_project&.id),
                     id: 'ux-toolkit-workload-project' %>
    </p>

    <p>
      <label for="ux-toolkit-workload-user-status"><%= l(:label_ux_toolkit_user_status) %></label>
      <%= select_tag :user_status,
                     options_for_select([
                       [l(:label_ux_toolkit_active_users), 'active'],
                       [l(:label_ux_toolkit_all_users), 'all']
                     ], @user_status),
                     id: 'ux-toolkit-workload-user-status' %>
    </p>

    <p>
      <label class="inline">
        <%= check_box_tag :include_closed, '1', @include_closed %>
        <%= l(:label_ux_toolkit_include_closed_issues) %>
      </label>
    </p>

    <p class="buttons">
      <%= submit_tag l(:button_apply), name: nil, class: 'small' %>
      <%= link_to l(:button_clear), ux_toolkit_team_workload_path_for(@project), class: 'icon icon-reload' %>
    </p>
  </fieldset>
<% end %>

<% if @workload_rows.any? %>
  <table class="list ux-toolkit-team-workload">
    <thead>
      <tr>
        <th><%= l(:field_user) %></th>
        <th><%= l(:label_ux_toolkit_workload_open) %></th>
        <th><%= l(:label_ux_toolkit_workload_overdue) %></th>
        <th><%= l(:label_ux_toolkit_workload_due_today) %></th>
        <th><%= l(:label_ux_toolkit_workload_stale) %></th>
        <th><%= l(:label_ux_toolkit_workload_high_priority) %></th>
      </tr>
    </thead>
    <tbody>
      <% @workload_rows.each do |row| %>
        <tr>
          <td class="user"><%= link_to_user(row.user) %></td>
          <td class="count"><%= ux_toolkit_workload_count_link(row.open_count, row.user, :open) %></td>
          <td class="count"><%= ux_toolkit_workload_count_link(row.overdue_count, row.user, :overdue) %></td>
          <td class="count"><%= ux_toolkit_workload_count_link(row.due_today_count, row.user, :due_today) %></td>
          <td class="count"><%= ux_toolkit_workload_count_link(row.stale_count, row.user, :stale) %></td>
          <td class="count"><%= ux_toolkit_workload_count_link(row.high_priority_count, row.user, :high_priority) %></td>
        </tr>
      <% end %>
    </tbody>
  </table>
<% else %>
  <p class="nodata"><%= l(:text_ux_toolkit_no_team_workload) %></p>
<% end %>

<% html_title(l(:label_ux_toolkit_team_workload)) %>
