{{!
    This file is part of Moodle - http://moodle.org/

    Moodle 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.

    Moodle 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 Moodle.  If not, see <http://www.gnu.org/licenses/>.
}}
{{!
    @template theme_boost_union/emailpreview

    Boost Union template for outputting an email preview.

    Context variables required for this template:
    * mail - The mail content

    Example context (json):
    {
        "mail": "Lorem ipsum",
        "type": "Html",
        "monospace": false
    }
}}
{{!
    This template uses Shadow DOM to avoid that any CSS styles which are added to the mail with a styles tag
    do not bleed into the admin page.
    See https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM.
}}
<template id="theme_boost_union-email{{type}}preview-shadow">{{{mail}}}</template>
<div class="shadow p-3 my-5 bg-white rounded {{#monospace}}text-monospace{{/monospace}}" id="theme_boost_union-email{{type}}preview-host"></div>
{{#js}}
    // Get the host element.
    const themeBoostUnionEmail{{type}}PreviewHost = document.querySelector('#theme_boost_union-email{{type}}preview-host');

    // Only if the host element exists on this page.
    if (typeof (themeBoostUnionEmail{{type}}PreviewHost) != 'undefined' && themeBoostUnionEmail{{type}}PreviewHost !== null) {
        // If the browser supports Shadow DOM.
        if (document.body.attachShadow) {
            // Add the email content within a Shadow DOM.
            const themeBoostUnionEmail{{type}}PreviewShadow = themeBoostUnionEmail{{type}}PreviewHost.attachShadow({mode: "open"});
            const themeBoostUnionEmail{{type}}PreviewTemplate = document.getElementById('theme_boost_union-email{{type}}preview-shadow');
            themeBoostUnionEmail{{type}}PreviewShadow.appendChild(themeBoostUnionEmail{{type}}PreviewTemplate.content);
        } else {
            // Add the email content without Shadow DOM (which will result in style bleeding anyway).
            const themeBoostUnionEmail{{type}}PreviewTemplate = document.getElementById('theme_boost_union-email{{type}}preview-shadow');
            themeBoostUnionEmail{{type}}PreviewHost.appendChild(themeBoostUnionEmail{{type}}PreviewTemplate.content);
        }
    }
{{/js}}
