{% from 'components/message-count-label.html' import message_count_label %}

<div class="column-whole">
  {% if template._template.archived %}
    <p class="hint">
      This template was deleted {{ template._template.updated_at|format_datetime_relative }}.
    </p>
  {% elif not current_user.has_permissions('send_messages', 'manage_api_keys', 'manage_templates', 'manage_service') or not user_has_template_permission %}
    <p class="top-gutter-1-3 {% if template.template_type != 'sms' %}bottom-gutter{% endif %}">
      If you need to send this
      {{ message_count_label(1, template.template_type, suffix='') }}
      or edit this template, contact your manager.
    </p>
  {% else %}
    <div class="bottom-gutter-2-3">
      <div class="grid-row">
        {% if template.template_type == 'letter' %}
          {% if current_user.has_permissions('send_messages', restrict_admin_usage=True) %}
            <div class="column-half">
              <a href="{{ url_for(".set_sender", service_id=current_service.id, template_id=template.id) }}" class="pill-separate-item">
                Send
              </a>
            </div>
          {% endif %}
        {% else %}
          {% if current_user.has_permissions('send_messages', restrict_admin_usage=True) %}
            <div class="column-half">
              <a href="{{ url_for(".set_sender", service_id=current_service.id, template_id=template.id) }}" class="pill-separate-item">
                Send
              </a>
            </div>
          {% endif %}
          {% if current_user.has_permissions('manage_templates') %}
            <div class="column-half">
              <a href="{{ url_for(".edit_service_template", service_id=current_service.id, template_id=template.id) }}" class="pill-separate-item">
                Edit
              </a>
            </div>
          {% endif %}
        {% endif %}
      </div>
    </div>
  {% endif %}
</div>
<div class="column-whole template-container">
  {% if current_user.has_permissions('manage_templates') and template.template_type == 'letter' %}
    {% if not current_service.letter_branding_id %}
      <a href="{{ url_for(".request_letter_branding", service_id=current_service.id, from_template=template.id) }}" class="edit-template-link-letter-branding">Add logo</a>
    {% endif %}
    <a href="{{ url_for(".edit_template_postage", service_id=current_service.id, template_id=template.id) }}" class="edit-template-link-letter-postage">Change</a>
    <a href="{{ url_for(".edit_service_template", service_id=current_service.id, template_id=template.id) }}" class="edit-template-link-letter-body">Edit</a>
    {% if current_service.count_letter_contact_details %}
      <a href="{{ url_for(".set_template_sender", service_id=current_service.id, template_id=template.id) }}" class="edit-template-link-letter-contact">Edit</a>
    {% else %}
      <a href="{{ url_for(".service_add_letter_contact", service_id=current_service.id, from_template=template.id) }}" class="edit-template-link-letter-contact">Edit</a>
    {% endif %}
  {% endif %}
  {{ template|string }}
</div>
