{{!
    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 core_admin/setting_heading

    Admin heading setting template.

    Context variables required for this template:
    * title - Title text
    * description - Description containing descriptionformatted

    Example context (json):
    {
        "title": "Favourite cheeses",
        "description": true,
        "descriptionformatted": "Stilton, Cheddar, Edam"
    }
}}

{{#title}}
<script>

if ("{{title}}".substring(0, 1) == ":" || "{{title}}".substring(0, 1) == "!" ) {
    var randomnumber = Math.floor((Math.random() * 10000) + 1);
    var headingId ="heading" + randomnumber;
    var collapseId = "collapse" + randomnumber;
    var buttonId = "button" + randomnumber;
    var str = "{{{title}}}";
    str = str.substring(1);
    var standart = '<div class="card border-0 pb-2 pt-2"> <div class="card-header border p-0 rounded" id="heading" > <h4 class="mb-0">'; 
        standart += '<button id="button" class="btn btn-link text-start text-decoration-none w-100" type="button" data-bs-toggle="collapse"';
        standart += 'data-bs-target="#collapse" aria-expanded="false" aria-controls="collapse" >';
        standart += str;
        standart += '</button></h4></div>';
        standart += '<div id="collapse" class="collapse" aria-labelledby="heading" data-parent="#accordionHy">';
        standart += '<div class="card-body border rounded">';

    if ("{{title}}".substring(0, 1) == ":") {
        document.write('<div class="accordion" id="accordionHy">')
        document.write(standart);
        var randomnumber = Math.floor((Math.random() * 1000) + 1);
        var accordionHyId ="accordionHy" + randomnumber;
        document.getElementById('accordionHy').id = accordionHyId;
        
        document.getElementById('heading').id = headingId;
        document.getElementById('collapse').id = collapseId;
        document.getElementById('button').id = buttonId;
        document.getElementById(buttonId).setAttribute("aria-controls", collapseId);
        document.getElementById(buttonId).setAttribute("data-bs-target", "#"+collapseId);
        document.getElementById(collapseId).setAttribute("aria-labelledby", headingId);
        document.getElementById(collapseId).setAttribute("data-parent", "#"+accordionHyId);

    } else if ("{{title}}" == "--*/*--"){
        document.write('{{#str}} div, theme_almondb {{/str}}')
    } else {
        document.write('{{#str}} divdiv, theme_almondb {{/str}}');
        document.write(standart);
        document.getElementById('heading').id = headingId;
        document.getElementById('collapse').id = collapseId;
        document.getElementById('button').id = buttonId;
        document.getElementById(buttonId).setAttribute("aria-controls", collapseId);
        document.getElementById(buttonId).setAttribute("data-bs-target", "#"+collapseId);
        document.getElementById(collapseId).setAttribute("aria-labelledby", headingId);
        document.getElementById(collapseId).setAttribute("data-parent", "#"+accordionHyId);
    }
} else {
    document.write("<h3 class='main'>{{{title}}}</h3>");
}
</script>
{{/title}}
{{#description}}
    <div class="box generalbox formsettingheading">{{{descriptionformatted}}}</div>
{{/description}}
