<div id="c-user-name-change-requests">
  <h1>Name Change Request</h1>

  <table class="aligned-vertical">
    <tbody>
      <tr>
        <th>Date</th>
        <td>
          <%= compact_time @change_request.created_at %>
          <% if @change_request.updated_at - @change_request.created_at > 5.minutes %>
            (updated <%= time_ago_in_words_tagged @change_request.updated_at %>)
          <% end %>
        </td>
      </tr>
      <tr>
        <th>User</th>
        <td><%= link_to_user @change_request.user %></td>
      </tr>
      <tr>
        <th>Request</th>
        <td>
          <strong><%= @change_request.original_name %></strong> ->
          <strong><%= @change_request.desired_name %></strong>
        </td>
      </tr>
      <tr>
        <th>Reason</th>
        <td><%= @change_request.change_reason %></td>
      </tr>
      <tr>
        <th>Status</th>
        <td>
          <%= @change_request.status %>
          <% if @change_request.approved? %>
            by <%= link_to_user @change_request.approver %>
          <% elsif @change_request.rejected? %>
            for reason: <%= link_to @change_request.rejection_reason %>
          <% end %>
        </td>
      </tr>
    </tbody>
  </table>
  
  <% if @change_request.pending? && CurrentUser.user.is_admin? %>
    <section>
      <h2>Feedback</h2>
      <ul>
        <% @change_request.feedback.each do |feedback| %>
          <li class="feedback-category-<%= feedback.category %>">
            <p><%= feedback.body %></p>
            <p class="author">Submitted by <%= link_to_user feedback.creator.name %> <%= time_ago_in_words_tagged feedback.created_at %></p>
          </li>
        <% end %>
      </ul>
    </section>

    <section>
      <h2>Statistics</h2>
      <ul>
        <li>Level: <%= @change_request.user.level_string %></li>
        <li>Uploads: <%= link_to @change_request.user.post_upload_count, posts_path("user:#{@change_request.user.name}") %></li>
        <li>Updates: <%= link_to @change_request.user.post_update_count, post_versions_path(:search => {:updater_id => @change_request.user.id}) %></li>
        <li>Notes: <%= link_to @change_request.user.note_update_count, note_versions_path(:search => {:updater_id => @change_request.user.id}) %></li>
        <li>Favorites: <%= @change_request.user.favorite_count %></li>
      </ul>
    </section>

    <section>
      <h2>Options</h2>
      <%= form_tag(approve_user_name_change_request_path(@change_request)) do %>
        <%= submit_tag "Approve" %>
      <% end %>

      <%= form_tag(reject_user_name_change_request_path(@change_request), :class => "simple_form") do %>
        <div class="input">
          <label>Reason</label>
          <%= text_field_tag "reason" %>
        </div>
        
        <div class="input">
          <%= submit_tag "Reject" %>
        </div>
      <% end %>
    </section>
  <% end %>
</div>

<%= render "secondary_links" %>
