{{!
    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 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 btn-block text-left text-decoration-none" type="button" data-toggle="collapse"';
        standart += 'data-target="#collapse" aria-expanded="false" aria-controls="collapse" >';
        standart += "{{{title}}}";
        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-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-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}}
