{{!
    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_grades/penalty_indicator

    This template is used to render the penalty indicator.


    Example context (json):
    {
        "penalty": 20,
        "finalgrade": 50,
        "maxgrade": 100,
        "info": "Late penalty applied -20 marks"
    }
}}

{{#icon}}
    <span data-bs-toggle="tooltip" class="penalty-indicator-icon" title="{{info}}">
        {{#pix}}{{name}}, {{component}}{{/pix}}
    </span>
{{/icon}}
{{#finalgrade}}
    <span class="penalty-indicator-value">
        {{#grademax}}
            {{finalgrade}} / {{grademax}}
        {{/grademax}}
        {{^grademax}}
            {{finalgrade}}
        {{/grademax}}
    </span>
{{/finalgrade}}

{{#js}}
require(['theme_boost/bootstrap/tooltip'], function(Tooltip) {
    // Re-init the tooltip to ensure those dynamically added through AJAX are initialized
    document.querySelectorAll('.penalty-indicator-icon[data-bs-toggle="tooltip"]').forEach(tooltipElement => {
        Tooltip.getInstance(tooltipElement)?.dispose();
        new Tooltip(tooltipElement);
    });
});
{{/js}}
