{% extends request.ajax ? 'layout_blank.html.twig' : 'layout_default.html.twig' %}

{% set active_menu = 'activity' %}
{% set can_send_emails = has_permission('email', 'send_emails') %}
{% set can_delete_email_history = has_permission('email', 'delete_email_history') %}

{% block meta_title %}{{ email.subject }}{% endblock %}

{% block breadcrumbs %}
    <ol class="breadcrumb">
        <li class="breadcrumb-item">
            <a href="{{ '/'|url }}">
                <svg class="icon">
                    <use xlink:href="#home" />
                </svg>
            </a>
        </li>
        <li class="breadcrumb-item">
            <a href="{{ 'email/history'|url }}">{{ 'Email History'|trans }}</a>
        </li>
        <li class="breadcrumb-item active" aria-current="page">{{ email.subject }}</li>
    </ol>
{% endblock %}

{% block content %}
<div class="card">
    <div class="card-body">
        <h5>{{ email.subject }}</h5>
    </div>

    <table class="table card-table table-vcenter table-striped text-nowrap">
        <tbody>
            <tr>
                <td class="w-50 text-end">{{ 'From'|trans }}:</td>
                <td>{{ email.sender }}</td>
            </tr>

            <tr>
                <td class="text-end">{{ 'To'|trans }}:</td>
                <td>{{ email.recipients }}</td>
            </tr>

            <tr>
                <td class="text-end">{{ 'Sent'|trans }}:</td>
                <td>{{ email.created_at|format_date }}</td>
            </tr>
         </tbody>
    </table>

    <div class="card-footer text-center">
        <button class="btn btn-primary email-preview-btn"
            data-email-subject="{{ email.subject }}"
            data-email-content="{{ email.content_html|e('html_attr') }}">
            <svg class="icon icon-tabler" width="24" height="24">
                <use xlink:href="#eye" />
            </svg>
            <span class="d-block text-secondary">{{ 'Preview'|trans }}</span>
        </button>
        {% if can_send_emails %}
        <a class="btn btn-primary"
            {{ fb_api_link({href: 'email/email_resend'|api_url(query: {id: email.id}), message: 'Email Resent'|trans}) }}>
            <svg class="icon icon-tabler" width="24" height="24">
                <use xlink:href="#refresh" />
            </svg>
            <span class="d-block text-secondary">{{ 'Resend'|trans }}</span>
        </a>
        {% endif %}
        {% if can_delete_email_history %}
        <a class="btn btn-primary"
            {{ fb_api_link({href: 'email/email_delete'|api_url(query: {id: email.id}), modal: {type: 'confirm', title: 'Are you sure?'|trans}, redirect: 'email/history'|url}) }}>
            <svg class="icon icon-tabler" width="24" height="24">
                <use xlink:href="#delete" />
            </svg>
            <span class="d-block text-secondary">{{ 'Delete'|trans }}</span>
        </a>
        {% endif %}
    </div>

    <div class="card-body">
        {{ email.content_html|raw }}
    </div>
</div>
{% endblock %}

{% block js %}
{{ include('partial_email_preview.html.twig') }}
{% endblock %}
