{% extends "base.html" %}
{% import "macros.html" as macros with context %}

{% block head %}
{{ super() }}
<meta name="srp_request_id" content="{{ srp_request.id }}">
{% endblock head %}

{% block body %}
<div class="modal fade" id="detailsModal" tabindex="-1" role=="dialog" aria-labelledby="detailsModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <form class="modal-content" method="post">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden"true">&times;</button>
        <h3 class="modal-title" id="detailsModalLabel">Update Details</h3>
      </div>
      <div class="modal-body">
        {{ details_form.csrf_token() }}
        {{ details_form.id_(value='details') }}
        {{ macros.render_input(details_form.details) }}
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
        <button type="submit" class="btn btn-primary">Save</button>
      </div>
    </form>
  </div>
</div>
{{ super() }}
{% endblock body %}

{% block content %}
<div class="row">
  <div class="col-sm-offset-1 col-sm-10 col-md-offset-0 col-md-6 col-lg-offset-1 col-lg-5">
    {% block left_col %}
    <dl class="dl-horizontal">
      {% block info %}
      <dt>Lossmail</dt>
      <dd><a href="{{ srp_request.killmail_url }}" target="_blank">{{ srp_request.id }}</a></dd>
      <dt>Time of Loss</dt>
      <dd>{{ srp_request.kill_timestamp.strftime('%d %b %Y %H:%M') }}</dd>
      <dt>Division</dt>
      <dd>
        <span id="request-division">{{ srp_request.division.name }}</span> &bull;
        <a href="{{ url_for('requests.request_change_division', request_id=srp_request.id) }}">Change Division</a>
      </dd>
      <dt>Details</dt>
      <dd>
        <div class="panel panel-default">
          <p class="panel-body" id="request-details">{{ srp_request.details }}</p>
        </div>
        {% if not srp_request.finalized and srp_request.submitter == current_user %}
        <button class="btn btn-default btn-sm" type="button" data-toggle="modal" data-target="#detailsModal">Update Details</button>
        {% endif %}
      </dd>
      <dt>Pilot</dt>
      <dd>
        {{ srp_request.transformed.pilot }}
      </dd>
      <dt>Corporation</dt>
      <dd>{{ srp_request.corporation }}</dd>
      <dt>Alliance</dt>
      <dd>{{ srp_request.alliance|default(' ') }}
      <dt>Location</dt>
      <dd>{{ srp_request.region }} / {{ srp_request.constellation }} / {{ srp_request.system }}</dd>
      <dt>Ship</dt>
      <dd>{{ srp_request.transformed.ship_type }}</dd>
      <dt>Status</dt>
      <dd><span id="request-status" class="label label-{{ macros.status_color(srp_request.status) }}">{{ srp_request.status }}</span></dd>
      <dt>Payout</dt>
      <dd>
        <span id="request-payout" data-initial-title="Base Payout: {{ srp_request.base_payout.currency() }}">
          {{ srp_request.payout.currency() }}
        </span>
      </dd>
      {% endblock info %}
    </dl>
    {% block action_form %}
    <form id="actionForm" class="form" method='post'>
      {{ action_form.id_ }}
      {{ action_form.type_ }}
      {{ action_form.csrf_token }}
      <div class="form-group input-group">
        {{ action_form.note(class="form-control") }}
        <div class="input-group-btn">
          <button type="submit" class="btn btn-default">Comment</button>
          {% if current_user.has_permission(PermissionType.elevated, srp_request.division) %}
          <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
            <span class="caret"></span>
            <span class="sr-only">Toggle Dropdown</span>
          </button>
          <ul class="dropdown-menu" role="menu" id="actionMenu">
            {% for action in srp_request.valid_actions(current_user) %}
            <li><a href="#" id="{{ action.value }}">{{ action.description }}</a></li>
            {% endfor %}
          </ul>
          {% endif %}
        </div>
      </div>
    </form>
    {% endblock action_form %}
    {% block action_list %}
    <div class="list-group" id="actionList">
      {% for action in srp_request.actions %}
      {% with %}
        {% set item_class = 'text-' ~ macros.status_color(action.type_) if macros.status_color(action.type_) != '' %}
        <div class="list-group-item">
          <h4 class="list-group-item-heading{{ ' ' ~ item_class if item_class is defined }}">{{ action.type_ if action.type_ != ActionType.comment }}</h4>
          <blockquote class="list-group-item-text">
            <p>{{ action.note }}</p>
            <footer>{{ action.user.name }} ({{ action.timestamp.strftime('%d %b %Y @ %H:%M') }})</footer>
          </blockquote>
        </div>
      {% endwith %}
      {% endfor %}
    </div>
    {% endblock action_list %}
    {% endblock left_col %}
  </div>
  <div class="col-sm-offset-1 col-sm-10 col-md-offset-0 col-md-6 col-lg-5">
    <dl class="dl-horizontal">
      {% block right_col %}
      <dt>Modifiers</dt>
      <dd>
        {% block list_modifiers %}
        <div class="panel-group" id="modifierList">
          {% for modifier in srp_request.modifiers %}
          {% if modifier.voided %}
          <div class="panel panel-default">
          {% elif modifier.value < 0 %}
          <div class="panel panel-danger">
          {% elif modifier.value >= 0 %}
          <div class="panel panel-success">
          {% endif %}
            <div class="panel-heading" data-toggle="collapse" data-target="#modifier{{ modifier.id }}">
              {% block modifier_header scoped %}
              {{ '<del>'|safe if modifier.voided }}
              <h4 class="panel-title">
                {{ modifier }}
              </h4>
              {{ '</del>'|safe if modifier.voided }}
              {% endblock modifier_header %}
            </div>
            <div id="modifier{{ modifier.id }}" class="collapse{{ ' in' if not modifier.voided }}">
              {% if modifier.voided %}
              <div class="panel-body">
                <del>{{ modifier.note ~ ' ' if modifier.note }} (voided by {{ modifier.voided_user.name }} at {{ modifier.voided_timestamp.strftime('%H:%M %d %b %Y') }})</del>
              </div>
              {% else %}
              {% if modifier.note %}
              <div class="panel-body">
                {{ modifier.note }}
              </div>
              {% endif %}
              {% endif %}
              <div class="panel-footer">
                {{ modifier.user }} at {{ modifier.timestamp.strftime('%H:%M %d %b %Y') }}
              </div>
            </div>
          </div>
          {% endfor %}
        </div>
        {% endblock list_modifiers %}
      </dd>
      {% endblock right_col %}
    </dl>
  </div>
</div>
{% endblock content %}
