{{!
    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 quiz_archiver/overview

    Template purpose and description.

    Example context (json):
    {
        "archiveQuizForm": "<!-- Generated Moodle form HTML -->",
        "baseurl": "https://example.com/mod/quiz/archiver/",
        "jobOverviewTable": "<!-- Generated Moodle table HTML -->",
        "jobs": [
            {
                "jobid": "3e6273fe-3784-11ee-be56-0242ac120002",
                "base64Data": "{...}"
            },
            {
                "jobid": "45edd9f6-3784-11ee-be56-0242ac120002",
                "base64Data": "{...}"
            }
        ],
        "time": 0
    }
}}

{{! Quiz archive form }}
<div class="quiz_archiver-archive-quiz-form mb-4">
    {{{archiveQuizForm}}}
</div>

{{! List of existing archives }}
{{#jobOverviewTable}}
<h1>
    {{#str}} job_overview, quiz_archiver {{/str}}
    <a
        href="{{{baseurl}}}"
        class="small mx-2"
        title="{{#str}} refresh, moodle {{/str}}"
        {{! Remove data-toggle and data-placement after Moodle 4.5 (LTS) deprecation }}
        data-toggle="tooltip"
        data-placement="top"
        data-bs-toggle="tooltip"
        data-bs-placement="top"
    >
        <i class="fa fa-rotate-right"></i>
    </a>
</h1>
<div>
    {{#str}} last_updated, quiz_archiver {{/str}}:
    {{#userdate}} {{time}}, %T {{/userdate}}
</div>
<div class="quiz_archiver-job-overview-table">
    {{{jobOverviewTable}}}
</div>

{{#js}}
    require(['jquery', 'core/modal_factory', 'core/templates'], function($, ModalFactory, Templates) {
        {{#jobs}}
            $('#job-details-{{jobid}}').click(async() => {
                var modal = await ModalFactory.create({
                    type: ModalFactory.types.DEFAULT,
                    title: '{{#str}} quiz_archive_details, quiz_archiver {{/str}}',
                    body: Templates.render('quiz_archiver/job_details', JSON.parse(atob('{{{base64Data}}}'))),
                    large: true,
                });
                modal.show();
            });
        {{/jobs}}
    });
{{/js}}
{{/jobOverviewTable}}
