{% extends request.ajax ? "layout_blank.phtml" : "layout_default.phtml" %}
{% import "macro_functions.phtml" as mf %}
{% block meta_title %}{{ticket.subject}}{% endblock %}
{% set active_menu = 'support' %}

{% block breadcrumbs %}
<ul>
    <li class="firstB"><a href="{{ '/'|alink }}">{% trans 'Home' %}</a></li>
    <li><a href="{{ 'support/public-tickets'|alink({'status' : 'open'}) }}">{% trans 'Public tickets' %}</a></li>
    <li class="lastB">#{{ticket.id}}  - {{ticket.subject}}</li>
</ul>
{% endblock %}

{% block content %}

<div class="widget simpleTabs tabsRight">
    <div class="head">
        <h5 class="iSpeech">{{ ticket.subject }}</h5>
    </div>

    <ul class="tabs">
        <li><a href="#tab-index">Ticket</a></li>
        <li><a href="#tab-manage">Manage</a></li>
    </ul>

    <div class="tabs_container">
        <div class="fix"></div>
        <div class="tab_content nopadding" id="tab-index">
            <table class="tableStatic wide">
                <tbody>
                    <tr class="noborder">
                        <td>{% trans 'Ticket ID' %}</td>
                        <td><b>#{{ticket.id}}</b></td>
                    </tr>

                    <tr>
                        <td>{% trans 'Author' %}</td>
                        <td>{{ ticket.author_name }}</td>
                    </tr>

                    <tr>
                        <td>{% trans 'Email' %}</td>
                        <td>{{ ticket.author_email }}</td>
                    </tr>

                    <tr>
                        <td>{% trans 'Status' %}</td>
                        <td>{{ mf.status_name(ticket.status) }}</td>
                    </tr>

                    <tr>
                        <td>{% trans 'Time opened' %}</td>
                        <td>{{ticket.created_at|date('l, d F Y')}}</td>
                    </tr>
                    
                    {% if ticket.created_at != ticket.updated_at %}
                    <tr>
                        <td>{% trans 'Last updated' %}</td>
                        <td>{{ticket.updated_at|timeago}} ago</td>
                    </tr>
                    {% endif %}
                 </tbody>

                 <tfoot>
                     <tr>
                         <td colspan="2">
                            <div class="aligncenter">
                                {% if ticket.status != 'closed' %}
                                <a href="{{ 'api/admin/support/public_ticket_close'|link({'id' : ticket.id}) }}" data-api-redirect="{{ 'support/public-tickets'|alink }}" class="btn55 mr10 api-link" ><img src="images/icons/middlenav/stop.png" alt=""><span>Close ticket</span></a>
                                {% endif %}
                                <a href="{{ 'api/admin/support/public_ticket_delete'|link({'id' : ticket.id}) }}" data-api-confirm="Are you sure?" data-api-redirect="{{ 'support/public-tickets'|alink }}" class="btn55 mr10 api-link"><img src="images/icons/middlenav/trash.png" alt=""><span>Delete</span></a>
                                <a href="{{ 'support/contact-us/conversation'|link }}/{{ ticket.hash }}" class="btn55 mr10" target="_blank"><img src="images/icons/middlenav/userComment.png" alt=""><span>Open as client</span></a>
                            </div>
                         </td>
                     </tr>
                 </tfoot>
            </table>
        </div>

        <div class="tab_content nopadding" id="tab-manage">
            <form method="post" action="{{ 'api/admin/support/public_ticket_update'|link }}" class="mainForm api-form" data-api-reload="1">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{% trans 'Subject' %}</label>
                        <div class="formRight noborder">
                            <input type="text" name="subject" value="{{ticket.subject}}" required="required"/>
                        </div>
                        <div class="fix"></div>
                    </div>

                    <div class="rowElem">
                        <label>{% trans 'Status' %}</label>
                        <div class="formRight">
                            {{ mf.selectbox('status', admin.support_ticket_get_statuses({"titles":1}), ticket.status, 1) }}
                        </div>
                        <div class="fix"></div>
                    </div>

                     <input type="submit" value="{% trans 'Update' %}" class="greyishBtn submitForm" />
                </fieldset>
                <input type="hidden" name="id" value="{{ ticket.id }}">
            </form>
        </div>

    </div>
</div>

{% set canned_response_selector %}
<div class="canned_response">
    <select name="canned_response" class="canned">
    {% for response in admin.support_canned_get_list({"per_page":90}).list %}
        <option value="{{ response.id }}">{{ response.title }}</option>
    {% endfor %}
    </select>
</div>
{% endset %}

<div class="conversation">
{% for i, message in ticket.messages %}
<div class="widget simpleTabs tabsRight">
    <div class="head" style="cursor: pointer;">
        <h5 class="no-icon"><img src="{{ message.author.email|gravatar }}?size=20" alt="{{ message.author.email }}" title="{{ message.author.email }}" class="gravatar"/> {{ message.author.name }}</h5>
        <h5 style="float:right;">{{ message.created_at|bb_datetime }}</h5>
    </div>
    <div class="body">
        {{ message.content|bbmd }}
        <div class="clear"></div>
    </div>
    <div class="clear"></div>
</div>
{% endfor %}
</div>

<div class="widget" id="reply-box">
    <div class="head">
        <h5 class="iSpeech">{% trans 'Reply as' %} {{ profile.name }}</h5>
        {%  include 'mod_support_canned_selector.phtml' %}
    </div>

    <form method="post" action="{{ 'api/admin/support/public_ticket_reply'|link }}" class="mainForm api-form" data-api-redirect="{{ 'support/public-tickets'|alink({'status' : 'open' }) }}">
        <fieldset>
            <textarea name="content" cols="5" rows="20" required="required" class="bb-textarea" id="rt">Hello {{ ticket.client.first_name }},
{{ canned_delay_message }}



{{ profile.signature }}
{{ ticket.helpdesk.signature }}</textarea>
            <input type="hidden" name="id" value="{{ ticket.id }}">
            <input type="submit" value="{% trans 'Post' %}" class="greyishBtn submitForm" />


            <div class="body">
                <a href="#"  class="btnIconLeft mr10" onclick="$('.conversation .body').toggle(); return false;"><span>Show/Hide messages</span></a>

                {% if ticket.messages|length > 2 and ticket.status != 'closed' %}
                <a href="{{ 'api/admin/support/public_ticket_close'|link({'id' : ticket.id}) }}" data-api-confirm="Are you sure?" data-api-redirect="{{ 'support/public-tickets'|alink({'status' : 'open' }) }}" class="btnIconLeft mr10 api-link" ><span>Close ticket</span></a>
                {% endif %}
            </div>
        </fieldset>
    </form>

    <div class="clear"></div>
</div>

{% endblock %}

{% block js%}
<script type="text/javascript">
$(function() {
    $('#reply-box textarea').focus();

    $('.conversation .head').click(function(){
        $(this).siblings('.body').toggle();
        return false;
    });
});
</script>
{% endblock %}


{% block head %}{{ mf.bb_editor('.bb-textarea') }}{% endblock %}