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

{% block content %}
<div class="widget simpleTabs nomargin">

    <ul class="tabs">
        <li><a href="#tab-index">{% trans 'Canned responses' %}</a></li>
        <li><a href="#tab-new">{% trans 'New response' %}</a></li>
        <li><a href="#tab-new-category">{% trans 'New category' %}</a></li>
        <li><a href="#tab-categories">{% trans 'Categories' %}</a></li>
    </ul>

    <div class="tabs_container">

        <div class="fix"></div>
        <div class="tab_content nopadding" id="tab-index">

        {{ mf.table_search }}
        <table class="tableStatic wide">
            <thead>
                <tr>
                    <td>{% trans 'Title' %}</td>
                    <td style="width: 13%">&nbsp;</td>
                </tr>
            </thead>

            <tbody>
            {% set responses = admin.support_canned_get_list({"per_page":90, "page":request.page}|merge(request)) %}
            {% for i, response in responses.list %}

            {% if response.category.id != group %}
            <tr class="group">
                <th colspan="2"><a href="{{ '/support/canned-category'|alink }}/{{response.category.id}}">{{response.category.title}}</a></th>
            </tr>
            {% set group = response.category.id %}
            {% endif %}

            <tr>
                <td>{{ response.title }}</td>
                <td class="actions">
                    <a class="bb-button btn14" href="{{ '/support/canned'|alink }}/{{response.id}}"><img src="images/icons/dark/pencil.png" alt=""></a>
                    <a class="bb-button btn14 bb-rm-tr api-link" data-api-confirm="Are you sure?" href="admin/support/canned_delete?id={{response.id}}" data-api-redirect="support/canned-responses"><img src="images/icons/dark/trash.png" alt=""></a>
                </td>
            </tr>
            </tbody>

            {% else %}
            <tbody>
                <tr>
                    <td colspan="2">
                        {% trans 'The list is empty' %}
                    </td>
                </tr>
            </tbody>
            {% endfor %}

            {% if responses.pages > 1 %}
            <tfoot>
                <tr>
                    <td colspan="2">
                        {% include "partial_pagination.phtml" with {'list': responses, 'url':'support/canned-responses'} %}
                    </td>
                </tr>
            </tfoot>
            {% endif %}

        </table>
        </div>

        <div class="tab_content nopadding" id="tab-new">

            <form method="post" action="admin/support/canned_create" class="mainForm save api-form" data-api-redirect="support/canned-responses">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{% trans 'Category' %}:</label>
                        <div class="formRight">
                            {{ mf.selectbox('category_id', admin.support_canned_category_pairs, '', 1) }}
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{% trans 'Title' %}:</label>
                        <div class="formRight">
                            <input type="text" name="title" value="{{request.title}}" required="required" placeholder=""/>
                        </div>
                        <div class="fix"></div>
                    </div>
                    
                    <div class="rowElem">
                        <label>{% trans 'Content' %}</label>
                        <div class="formRight">
                            <textarea name="content" cols="5" rows="10">{{ request.content }}</textarea>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <input type="submit" value="{% trans 'Create' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>

        <div class="tab_content nopadding" id="tab-new-category">

            <form method="post" action="admin/support/canned_category_create" class="mainForm save api-form" data-api-redirect="support/canned-responses">
                <fieldset>
                    <div class="rowElem noborder">
                        <label>{% trans 'Title' %}:</label>
                        <div class="formRight">
                            <input type="text" name="title" value="{{request.title}}" required="required" placeholder=""/>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <input type="submit" value="{% trans 'Create' %}" class="greyishBtn submitForm" />
                </fieldset>
            </form>
        </div>
        
        <div class="tab_content nopadding" id="tab-categories">
            <table class="tableStatic wide">
                <tbody>
                    {% for cat_id, cat_title in admin.support_canned_category_pairs %}
                    <tr {% if loop.first %}class="noborder"{% endif %}>
                        <td>{{cat_title}}</td>
                        <td style="width:13%">
                            <a class="bb-button btn14" href="{{ '/support/canned-category'|alink }}/{{cat_id}}"><img src="images/icons/dark/pencil.png" alt=""></a>
                            <a class="bb-button btn14 api-link" data-api-confirm="Are you sure?" href="admin/support/canned_category_delete?id={{cat_id}}" data-api-redirect="support/canned-responses"><img src="images/icons/dark/trash.png" alt=""></a>
                        </td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="3">{% trans 'The list is empty' %}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

    </div>
</div>

{% endblock %}
