{% extends "base.html" %}
{% load custom_tags_and_filters %}
{% load static %}
{% block extrahead %}
    <link rel="stylesheet" type="text/css" href="{% static "osticket.css" %}" />
{% endblock %}
{% block content %}
    {% if ticket %}
        <div class="panel panel-default" style="margin-bottom: 0">
            <div class="panel-heading ticket-title">
                <a target="_blank" href="{{ ticket.get_osticket_absolute_url }}">Ticket #{{ ticket.number }}</a>
            </div>
            <div class="panel-body">
                <div class="clearfix">
                    <div class="col-xs-4 col-sm-3 col-md-2 ticket-label">Status:</div>
                    <div class="col-xs-8 col-sm-3 col-md-3 ticket-value">{{ ticket.status.name }}</div>
                    <div class="col-xs-4 col-sm-2 col-md-1 ticket-label">Name:</div>
                    <div class="col-xs-8 col-sm-4 col-md-6 ticket-value">{{ ticket.creator_name }}</div>
                    <div class="col-xs-4 col-sm-3 col-md-2 ticket-label">
                        {{ ticket.form_entry_values|get_item:"priority"|get_item:0 }}:
                    </div>
                    <div class="col-xs-8 col-sm-3 col-md-3 ticket-value">
                        {{ ticket.form_entry_values|get_item:"priority"|get_item:1|default_if_none:"" }}
                    </div>
                    <div class="col-xs-4 col-sm-2 col-md-1 ticket-label">Email:</div>
                    <div class="col-xs-8 col-sm-4 col-md-6 ticket-value">{{ ticket.user.default_email.address }}</div>
                    <div class="col-xs-4 col-sm-3 col-md-2 ticket-label">Created date:</div>
                    <div class="col-xs-8 col-sm-3 col-md-3 ticket-value">{{ ticket.created|date:"SHORT_DATETIME_FORMAT" }}</div>
                    <div class="col-xs-4 col-sm-2 col-md-1 ticket-label">Source:</div>
                    <div class="col-xs-8 col-sm-4 col-md-6 ticket-value">{{ ticket.source }}</div>
                </div>
                <br>
                <div class="clearfix">
                    <div class="col-sm-12 ticket-title">
                        {{ ticket.form_entry_values|get_item:"subject"|get_item:0 }}: {{ ticket.form_entry_values|get_item:"subject"|get_item:1 }}
                    </div>
                </div>
                <br>
                <div class="clearfix">
                    <div class="col-xs-4 col-sm-3 col-md-2 ticket-label">Assigned to:</div>
                    <div class="col-xs-8 col-sm-3 col-md-3 ticket-value">{{ ticket.assigned_to|default_if_none:"unassigned" }}</div>
                    <div class="col-xs-4 col-sm-2 col-md-1 ticket-label">
                        {{ customizations|get_item:"osticket_create_ticket_help_topic_label" }}:
                    </div>
                    <div class="col-xs-8 col-sm-4 col-md-6 ticket-value">{{ ticket.topic.topic }}</div>
                    <div class="col-xs-4 col-sm-3 col-md-2 ticket-label">Last response:</div>
                    <div class="col-xs-8 col-sm-3 col-md-3 ticket-value">
                        {{ ticket.thread.lastresponse|date:"SHORT_DATETIME_FORMAT" }}
                    </div>
                    <div class="col-xs-4 col-sm-2 col-md-1 ticket-label">IP:</div>
                    <div class="col-xs-8 col-sm-4 col-md-6 ticket-value">{{ ticket.ip_address }}</div>
                    <div class="col-xs-4 col-sm-3 col-md-2 ticket-label">Last message:</div>
                    <div class="col-xs-8 col-sm-3 col-md-3 ticket-value">{{ ticket.thread.lastmessage|date:"SHORT_DATETIME_FORMAT" }}</div>
                    <div class="col-xs-4 col-sm-2 col-md-1 ticket-label">Due:</div>
                    <div class="col-xs-8 col-sm-4 col-md-6 ticket-value">
                        {% if ticket.duedate %}
                            {{ ticket.duedate|date:"SHORT_DATETIME_FORMAT" }}
                        {% else %}
                            {{ ticket.est_duedate|date:"SHORT_DATETIME_FORMAT" }}
                        {% endif %}
                    </div>
                </div>
                <br>
                <div class="clearfix">
                    <div class="col-sm-12 ticket-title">{{ ticket_field_labels|get_item:"message" }}</div>
                </div>
                <br>
                <div class="clearfix">
                    <div class="col-sm-12">
                        {% for thread_entry in ticket.ostthreadentry_set %}
                            {% with internal_note="N" message="M" response="R" %}
                                {% if thread_entry.type != internal_note or user.is_any_part_of_staff %}
                                    <div style="margin-bottom:5px"
                                         class="panel panel-{% if thread_entry.type == response %}warning{% elif thread_entry.type == internal_note %}default{% else %}info{% endif %}">
                                        <div class="panel-heading">
                                            {{ thread_entry.created }} <span class="pull-right">{{ thread_entry.poster_name }}</span>
                                        </div>
                                        <div class="panel-body">{{ thread_entry.body|safe|linebreaksbr }}</div>
                                    </div>
                                {% endif %}
                            {% endwith %}
                        {% endfor %}
                        <div class="panel panel-default">
                            <div class="panel-heading">
                                <label for="message" style="margin-bottom: 0">Post a reply</label>
                            </div>
                            <div class="panel-body">
                                <form action="{% url 'osticket_reply_to_ticket' ticket.ticket_id %}" method="post">
                                    {% csrf_token %}
                                    <textarea class="form-control" name="message" id="message" required></textarea>
                                    {% if user.is_any_part_of_staff %}
                                        <div class="checkbox">
                                            <label>
                                                <input type="checkbox" name="internal" id="internal">
                                                Make this an internal note
                                            </label>
                                        </div>
                                    {% endif %}
                                    <div>{% button type="warn" icon="glyphicon-send" submit=True value="Post reply" %}</div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    {% endif %}
{% endblock %}
