{% extends "base.html" %}

{% load static %}

{% block page_title %}
InvenTree | Build - {{ build }}
{% endblock %}

{% block content %}

<div class='row'>
    <div class='col-sm-6'>
        <div class="media">
            <div class="media-left">
                <div class='dropzone' id='part-thumb'>
                    <img class="part-thumb"
                    {% if build.part.image %}
                    src="{{ build.part.image.url }}"
                    {% else %}
                    src="{% static 'img/blank_image.png' %}"
                    {% endif %}/>
                </div>
            </div>
            <div class='media-body'>
                <h4>Build Details</h4>

                <p>
                    <div class='btn-row'>
                        <div class='btn-group'>
                            <button type='button' class='btn btn-default btn-glyph' id='build-edit' title='Edit Build'>
                                <span class='glyphicon glyphicon-edit'/>
                            </button>
                            {% if build.is_active %}
                            <button type='button' class='btn btn-default btn-glyph' id='build-complete' title="Complete Build">
                                <span class='glyphicon glyphicon-send'/>
                            </button>
                            <button type='button' class='btn btn-default btn-glyph' id='build-cancel'>
                                <span class='glyphicon glyphicon-remove'/>
                            </button>
                            {% endif %}
                            {% if build.status == BuildStatus.CANCELLED %}
                            <button type='button' class='btn btn-default btn-glyph' id='build-delete' title='Delete Build'>
                                <span class='glyphicon glyphicon-trash'/>
                            </button>
                            {% endif %}
                        </div>
                    </div>
                </p>

                <table class='table table-striped table-condensed'>
                    <tr>
                        <td>{{ build.title }}</td>
                        <td>{% include "build_status.html" with build=build %}</td>
                    </tr>
                    <tr>
                        <td>Part</td>
                        <td><a href="{% url 'part-detail' build.part.id %}">{{ build.part.full_name }}</a></td>
                    </tr>
                    <tr>
                        <td>Quantity</td>
                        <td>{{ build.quantity }}</td>
                    </tr>
                    <tr>
                        <td>BOM Price</td>
                        <td>
                            {% if bom_price %}
                            {{ bom_price }}
                            {% if build.part.has_complete_bom_pricing == False %}
                            <br><span class='warning-msg'><i>BOM pricing is incomplete</i></span>
                            {% endif %}
                            {% else %}
                            <span class='warning-msg'><i>No pricing information</i></span>
                            {% endif %}
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>

<hr>

<div class='container-fluid'>
{% block details %}

{% endblock %}

</div>

{% endblock %}

{% block js_ready %}

    $("#build-edit").click(function () {
        launchModalForm("{% url 'build-edit' build.id %}",
                        {
                            reload: true
                        });
    });

    $("#build-cancel").click(function() {
        launchModalForm("{% url 'build-cancel' build.id %}",
                        {
                            reload: true,
                            submit_text: "Cancel Build",
                        });
    });

    $("#build-complete").on('click', function() {
        launchModalForm(
            "{% url 'build-complete' build.id %}",
            {
                reload: true,
                submit_text: "Complete Build",
            }
        );
    });

    $("#build-delete").on('click', function() {
        launchModalForm(
            "{% url 'build-delete' build.id %}",
            {
                redirect: "{% url 'build-index' %}",
            }
        );
    });
    
{% endblock %}