<% previous_file_rev = @filter.previous_revision_by_file[path] %>
<p>
  <strong>Full Path:</strong> <%= path %>
</p>
<%= form_tag '#', method: 'post', class: 'file_commits' do %>
  <%= hidden_field_tag :repository_path, @filter.repository_path %>
  <%= hidden_field_tag :project_slug, @filter.project_slug %>
  <%= hidden_field_tag :path, path %>
  <table class='table table-striped table-condensed'>
    <thead>
      <tr>
        <th colspan="2" style="width: 50px; text-align:center">
          <%= version_control_diff_link path, commits.first[:id].try(:to_s) %>
        </th>
        <th>Date</th>
        <th>Author</th>
        <th>Message</th>
      </tr>
    </thead>
    <tbody>
      <% param = params[version_control_path_id(path)] || {} %>
      <% commits.each_with_index do |commit, commits_index| %>
        <tr>
          <td style="width:25px; text-align:center">
            <% first_commit = previous_file_rev.blank? && commit[:id].try(:to_s) == commits.last[:id].try(:to_s) %>
            <% unless first_commit %>
              <% checked = param['rev'] == commit[:id].try(:to_s) ? true : false %>
              <% checked = true if commits_index == 0 && !param.has_key?('rev') %>
              <%= radio_button_tag :rev, commit[:id].try(:to_s), checked, id: '' %>
            <% end %>
          </td>
          <td style="width:25px; text-align:center">  
            <% unless commits_index == 0 %>
              <% checked = param['rev_to'] == commit[:id].try(:to_s) ? true : false %>
              <% checked = true if commits_index == (commits.length - 1) && !param.has_key?('rev_to') %>
              <%= radio_button_tag :rev_to, commit[:id].try(:to_s), checked, id: '' %>
            <% end %>
          </td>
          <td><%= version_control_file_revision_link commit[:committed_at], commit[:id], path, method: 'annotate' %></td>
          <td><%= commit[:author]%></td>
          <td>
            <%= raw commit[:message].gsub(/#([0-9]+)/, '<a href="https://projects.mtvnn.com/issues/\1">#\1</a>') %>
          </td>
        </tr>
      <% end %>
    </tbody>
    <tfoot>
      <% if previous_file_rev.present? %>
        <tr>
          <td>
          </td>
          <td style="width:25px; text-align:center">  
            <% checked = param['rev_to'] == previous_file_rev ? true : false %>
            <% checked = true unless param.has_key?('rev_to') %>
            <%= radio_button_tag :rev_to, previous_file_rev, checked, id: '' %>
          </td>
          <th colspan="3"/>
        </tr>
      <% end %>
      <tr>
        <th colspan="2" style="text-align:center">
          <%= version_control_diff_link path, commits.first[:id].try(:to_s) %>
        </th>
        <th colspan="3"/>
      </tr>
    </tfoot>
  </table>
<% end %>