{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2025 Teclib' and contributors.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{% import 'components/form/fields_macros.html.twig' as fields %}

<div class="asset">
    {{ fields.largeTitle(__('Preview')) }}

    {% if can_preview %}
        <div class="d-flex">
            {{ fields.dropdownField(
                template.fields['itemtype'],
                template.fields['itemtype']|itemtype_foreign_key,
                get_saved_option('NotificationTemplateTranslation', template.fields['itemtype']|itemtype_foreign_key, 0),
                template.fields['itemtype']|itemtype_name,
                {
                    field_class: 'col-6',
                    on_change: 'reloadTab("' ~ template.fields['itemtype']|itemtype_foreign_key ~ '="+this.value)',
                }
            ) }}

            {{ fields.htmlField('', call('NotificationEvent::dropdownEvents', [template.fields['itemtype'], {
                value: get_saved_option('NotificationTemplateTranslation', template.fields['itemtype']|itemtype_foreign_key ~ '_event', ''),
                on_change: 'reloadTab("' ~ template.fields['itemtype']|itemtype_foreign_key ~ '_event="+this.value)',
                display: false
            }]), 'NotificationEvent'|itemtype_name(1), {
                field_class: 'col-6'
            }) }}
        </div>
    {% else %}
        <div class="alert alert-info d-flex align-items-center m-0" role="alert">
            <i class="ti ti-info-circle me-1"></i>
            {{ __('The preview is not available for the notifications related to %s.')|format(template.fields['itemtype']|itemtype_name(get_plural_number())) }}
        </div>
    {% endif %}

    {% if data is not null %}
        <table class="table table-borderless">
            <tbody>
                <tr>
                    <th colspan="2">{{ __('Subject') }}</th>
                </tr>
                <tr>
                    <td colspan="2">{{ data['subject'] }}</td>
                </tr>
                <tr>
                    <th>{{ __('Email text body') }}</th>
                    <th>{{ __('Email HTML body') }}</th>
                </tr>
                <tr>
                    <td>{{ data['content_text']|nl2br }}</td>
                    <td>{{ data['content_html']|raw }}</td>
                </tr>
            </tbody>
        </table>
    {% endif %}
</div>
