{% extends 'buybacks2/page.html' %}
{% load i18n %}
{% load humanize %}
{% load bootstrap %}
{% load static %}
{% load dict %}
{% load number %}

{% block body %}
    <h4>{{ program.name }} - Buyback Program</h4>

    {% if value %}
        <div class="table-responsive" style="margin: 20px 0;">
            <p class="text-muted">Based on the item amounts you have given us, we have calculated them to be of the
                following value.</p>
            <p class="text-warning">Please click the <strong>Notify</strong> button to let us know you will be sending
                the contract.</p>

            <table id="value" style="width: 60%; margin: 20px auto;" class="table table-striped table-condensed">
                <thead>
                <tr>
                    <th style="width: 55%">Item</th>
                    <th style="width: 15%; text-align: center;">Quantity</th>
                    <th style="width: 30%; text-align: center;">Value</th>
                </tr>
                </thead>
                <tbody>
                {% for name, item in value %}
                    <tr>
                        <td data-type-id="{{ item.typeid }}">{{ name }}</td>
                        <td style="text-align: right;">{{ value.quantity|floatformat:"0g" }}</td>
                        <td style="text-align: right;">{{ value.unit_price|floatformat:"0g" }} ISK</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>

            <div style="text-align: center;">
                <p class="text-muted">Total Contract Value: <span class="text-primary" id="total">{{ total|floatformat:"0g" }}</span> ISK</p>
                <button id="notify" data-program-location="{{ program_location.id }}"
                        data-url="{% url 'buybacks2:program_notify' program_pk=program.id %}"
                        class="btn btn-warning btn-sm">Notify
                </button>
            </div>
        </div>
    {% endif %}

    <form class="form" action="{% url 'buybacks2:program_calculate' program_pk=program.id %}" method="POST">
        {% csrf_token %}
        {{ form|bootstrap }}
        <button type="submit" class="btn btn-primary">Calculate</button>
    </form>
{% endblock %}

{% block extra_javascript %}
    <script type="text/javascript" src="{% static 'buybacks2/js/notify.js' %}"></script>
{% endblock %}

{% block extra_css %}
{% endblock %}

{% block extra_script %}
{% endblock %}
