{{!
    This file is part of Moodle - https://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 biblocks_html/preview

    Example context (json):
    {
      "element_id": "12345",
      "ajax_url": "https://example.com/chart_data",
      "error_data_loader": "Erro ao carregar os dados do gráfico",
      "reload_time": "60000"
    }

}}

<div class="area-chart" id="chart_{{element_id}}"></div>

{{#js}}
    require(["jquery", "core/notification"], function($, Notification) {

    function loadDataChart() {
    $.ajax({
    dataType: "json",
    url: "{{{ajax_url}}}",
    success: function(json) {
    $("#chart_{{element_id}}").html(json.html);
    },
    error: function() {
    $("#chart_{{element_id}}").html("{{error_data_loader}}");
    Notification.exception({message: "{{error_data_loader}}"});
    }
    });
    }

    loadDataChart();

    var reloadTime = parseInt("{{{reload_time}}}");
    if (reloadTime) {
    setInterval(loadDataChart, reloadTime);
    }
    });
{{/js}}
