{% extends "epic/base_layout.html" %}
{% load crispy_forms_tags %}
{% load humanize %}

{% block buttons %}
  <a class="btn btn-default" href="{% url 'epic:warehouse_list' %}">
    Up <i class="glyphicon glyphicon-chevron-up"></i>
  </a>
{% endblock buttons %}

{% block content %}
{{ block.super }}

<h1>Warehouse {{ warehouse }}</h1>

<div class="panel panel-default">
  <div class="panel-heading">
    <h2 class="panel-title">Shipping Address</h2>
  </div>
  <div class="panel-body">
    <address>
      {{ warehouse.address|linebreaks }}
    </address>
  </div>
</div>

<p>
  <a class="btn btn-primary"
     href="{% url 'epic:warehouse_edit' warehouse.id %}">
    Edit <i class="glyphicon glyphicon-edit"></i>
  </a>

  <a class="btn btn-default"
     href="{% url 'epic:warehouse_stock' warehouse.id %}">
    View Stock <i class="glyphicon glyphicon-list"></i></a>

  <a class="btn btn-default"
     href="{% url 'epic:warehouse_add_inventory' warehouse.id %}">
    Add Inventory <i class="glyphicon glyphicon-plus"></i></a>

  <a class="btn btn-default"
     href="{% url 'epic:warehouse_add_shipment' warehouse.id %}">
    Ship Parts to other Warehouse <i class="glyphicon glyphicon-plus"></i></a>

  <a class="btn btn-danger" href="{% url 'epic:warehouse_delete' warehouse.id %}"
     onclick="return confirm ('Are you sure you want to delete this warehouse?')">
    Delete <i class="glyphicon glyphicon-remove"></i></a>
</p>

<div class="panel-group" id="accordion" role="tablist">

  <div class="panel panel-default">
    <div class="panel-heading" role="tab">
      <h2 class="panel-title">
	<a data-toggle="collapse" data-parent="#accordion" href="#collapse1">
	  Existing Inventories
	</a>
      </h2>
    </div>
    <div id="collapse1" class="panel-collapse collapse {% if 'ipg' in request.GET %}in{% endif %}" role="tabpanel">
      {{ inventories_pager|safe }}
      <table class="table table-bordered table-hover table-striped"
             style="background-color: white">
	<thead>
	  <tr>
	    <th>Inventory #</th><th>Created on</th><th>Notes</th>
	  </tr>
	</thead>
	<tbody>
	  {% for inv in inventories %}
	  <tr>
	    <td> {{ inv.html_link|safe }} </td>
	    <td> {{ inv.ts|date:"Y-m-d h:i A" }}</td>
	    <td> {{ inv.notes|linebreaksbr }} </td>
	  </tr>
	  {% endfor %}
	</tbody>
      </table>
      {{ inventories_pager|safe }}
    </div>
  </div>

  <div class="panel panel-default">
    <div class="panel-heading" role="tab">
      <h2 class="panel-title">
	<a data-toggle="collapse" data-parent="#accordion" href="#collapse2">
	  Orders and Shipments affecting {{ warehouse }}
	</a>
      </h2>
    </div>
    <div id="collapse2" class="panel-collapse collapse in" role="tabpanel">
      {{ txtns_pager|safe }}
      <table class="table table-bordered table-hover table-striped"
             style="background-color: white">
	<thead>
	  <tr>
	    <th>Date</th><th>Transaction</th><th>Notes</th>
	  </tr>
	</thead>
	<tbody>
	  {% for txtn in txtns %}
	  <tr>
	    <td>{{ txtn.ts|date:"Y‑m‑d" }}</td>
	    <td>{{ txtn.description|safe }}</td>
	    <td>{{ txtn.notes|linebreaksbr }}</td>
	  </tr>
	  {% endfor %}
	</tbody>
      </table>
      {{ txtns_pager|safe }}
    </div>
  </div>

</div>

{% endblock content %}
