{% extends 'helpdesk/base.html' %}{% load helpdesk %}{% load bootstrap3 %}{% load widget_tweaks %}

{% block content %}
    <div class="row">
        <div class="col-xs-8">
            <h2>HD-{{ object.pk }}: {{ object.title }}</h2>

            <div class="panel panel-primary">
                <div class="panel-heading">
                    <h3 class="panel-title text-right">{{ object.created|date:"d.m.Y H:i:s" }}</h3>
                </div>
                <div class="panel-body">
                    <iframe src="{% url 'helpdesk_email' object.pk %}" frameborder="none" width="100%" height="300px"
                            sandbox></iframe>

                    <ol>
                        {% for attachment in attachments %}
                            <li><a href="{{ attachment.signed_url }}">{{ attachment.filename }}</a>
                                ({{ attachment.attachment.size|filesizeformat }})
                            </li>
                        {% endfor %}
                    </ol>
                </div>
            </div>

            {% for comment in comments %}
                {% include 'helpdesk/comment.html' %}
            {% endfor %}

            <div class="panel panel-info" id="answer-panel">
                <div class="panel-heading">
                    <h3 class="panel-title">Add answer</h3>
                </div>
                <div class="panel-body">
                    <form method="post" enctype="multipart/form-data">
                        {% csrf_token %} {% bootstrap_form reply_form %}

                        {{ attachment_formset.management_form }}
                        {% for form in attachment_formset %}
                            {% bootstrap_form form %}
                        {% endfor %}

                        {% bootstrap_button 'Submit' button_type='submit' name='reply' %}
                    </form>
                </div>
            </div>
        </div>
        <div class="col-xs-4">
            <div class="panel panel-info">
                <div class="panel-heading">
                    <h3 class="panel-title">Ticket info</h3>
                </div>
                <div class="panel-body">
                    <form method="post">
                        {% csrf_token %}
                        <table class="table table-info">
                            <tr>
                                <th class="text-right">Assignee:</th>
                                <td>{{ ticket_form.assignee|add_class:"form-control" }}</td>
                            </tr>
                            <tr>
                                <th class="text-right">Project:</th>
                                <td>{{ ticket_form.project|add_class:"form-control" }}</td>
                            </tr>
                            <tr>
                                <th class="text-right">Priority:</th>
                                <td>{{ ticket_form.priority|add_class:"form-control" }}</td>
                            </tr>
                            <tr>
                                <th class="text-right">State:</th>
                                <td>{{ ticket_form.state|add_class:"form-control" }}</td>
                            </tr>
                            {% if perms.helpdesk.view_customer %}
                                <tr>
                                    <th class="text-right">Customer:</th>
                                    <td>{{ object.customer }}</td>
                                </tr>
                            {% endif %}

                            {% with user=ticket.customer_user %}
                                {% if user %}
                                    <tr>
                                        <th class="text-right">User:</th>
                                        <td>{{ user.get_full_name }}</td>
                                    </tr>
                                {% endif %}
                            {% endwith %}
                        </table>

                        <div class="text-center">
                            {% bootstrap_button 'Update' button_type='submit' name='ticket' %}
                        </div>
                    </form>

                    <ul class="history-list">
                        {% for action in history %}
                            <li>
                                <p>{{ action.created|date:"d.m.Y H:i:s" }} by {% me_or_user action.user %}:</p>
                                {{ action.change|safe|linebreaks }}
                            </li>
                        {% endfor %}
                    </ul>
                </div>
            </div>
        </div>
    </div>
{% endblock %}