{% extends 'membersmessaging/layouts/membersmessaging.twig' %}

{% block content %}

    <ul class="breadcrumbs el">
        <li><a href="{{ route('admin.messaging.index') }}">Home</a> /</li>
        <li class="end">Edit Template</li>
    </ul>

    <h1 class="end">Edit Template</h1>

    {% include 'membersmessaging/admin/widgets/tabnav.twig' %}

    <form action="{{ route('admin.messaging.save_template', template.id) }}" method="POST">

        <input type="hidden" name="_method" value="PATCH">
        <input type="hidden" name="_token" value="{{ csrf_token('submit_template') }}">

        <fieldset class="row">
            <div class="row">
                <label for="category">Category:</label>
                <select name="category" id="category">
                    {% for category, label in categories %}
                        <option value="{{ category }}"
                                {% if template and template.category == category %}selected{% endif %}>
                            {{ label|e }}
                        </option>
                    {% endfor %}
                </select>
            </div>

            <div class="row">
                <label for="role">Template for:</label>
                <select name="role" id="role">
                    <option value="0" {% if template and template.role == 0 %} selected="selected" {% endif %}>Everyone</option>
                    {% for role in roles %}
                        <option value="{{ role.id }}" {% if template and role.id == template.role %}selected{% endif %}>
                            {{ role.name|e }}
                        </option>
                    {% endfor %}
                </select>
            </div>

            <div class="row">
                <label for="name">Name:</label>
                <input type="text" value="{{ template.name ?? '' }}" id="name" name="name"/>
            </div>

            <div class="row">
                <label for="text">Text:</label>
                <textarea class="tinymce" name="text" id="text">{{ template.text ?? '' }}</textarea>
            </div>

            <div class="row">
                {% if template.id > 0 %}
                    <input type="hidden" value="{{ template.id }}" name="id"/>
                {% endif %}
                <input type="submit" value="Save"/>
            </div>
        </fieldset>
    </form>


{% endblock %}
