{{!
    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/job_details

    Template purpose and description.

    Example context (json):
    [
      {
        "id":"60",
        "jobid":"32979c0a-2b97-11ee-b5db-0242ac150004",
        "status":"FINISHED",
        "status_display_args": {
            "color":"success",
            "text":"Finished"
        },
        "timecreated":"1690363888",
        "timemodified":"1690364031",
        "user":{
          "id":"2",
          "firstname":"Admin",
          "lastname":"User",
          "username":"admin"
        },
        "course":{
          "id":"31",
          "name":"Example Moodle Course for Quiz Archiver"
        },
        "quiz":{
          "id":"36",
          "cmid":"108",
          "name":"Example Quiz"
        },
        "artifactfile":{
          "name":"quiz_archive_cid31_cmid108_qid36_2023-07-26_113348.tar.gz",
          "downloadurl":"http:\/\/127.0.0.1\/pluginfile.php\/201\/quiz_archiver\/artifact\/0\/31\/108\/36\/quiz_archive_cid31_cmid108_qid36_2023-07-26_113348.tar.gz?forcedownload=1",
          "size":"86915632",
          "size_human":"82.89 MB",
          "checksum":"3b837f73ea13991c6aaad9dd13d0c8b57dcaf2571a1d8c7ee1e7fb02b3a06048"
        },
        "tsp":{
            "timecreated":1690805384,
            "server":"https://example.com/tsr"
        },
        "tsp_enabled":true,
        "settings":[
            {
                "title":"Demo Title 1",
                "value":"Demo Value 1",
                "color":"primary"
            },
            {
                "title":"Demo Title 2",
                "value":"Demo Value 2",
                "color":"secondary"
            }
        ]
      },
      {
        "id":"79",
        "jobid":"23008fc4-2f9b-11ee-afb0-0242ac150004",
        "status":"FAILED",
        "status_display_args": {
            "color":"danger",
            "text":"Failed"
        },
        "timecreated":"1690805384",
        "timemodified":"1690805388",
        "user":{
          "id":"2",
          "firstname":"Admin",
          "lastname":"User",
          "username":"admin"
        },
        "course":{
          "id":"31",
          "name":"Example Moodle Course for Quiz Archiver"
        },
        "quiz":{
          "id":"36",
          "cmid":"108",
          "name":"Example Quiz"
        },
        "artifactfile":null,
        "tsp":null,
        "tsp_enabled":false,
        "settings":[
            {
                "title":"Demo Title 1",
                "value":"Demo Value 1",
                "color":"primary"
            },
            {
                "title":"Demo Title 2",
                "value":"Demo Value 2",
                "color":"secondary"
            }
        ]
      }
    ]
}}

<table class="table w-100">
    <tr>
        <td class="border-top-0">{{#str}} jobid, quiz_archiver {{/str}}</td>
        <td class="border-top-0">{{jobid}}</td>
    </tr>
    <tr>
        <td>{{#str}} status {{/str}}</td>
        <td>
            <span
                class="badge badge-{{status_display_args.color}}"
                {{! 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"
                title="{{status_display_args.help}}"
            >
                {{status_display_args.text}}
            </span>
            {{#status_display_args.statusextras.progress}}
                <span>
                    &nbsp;&ndash;&nbsp;&nbsp;{{#str}} progress, quiz_archiver {{/str}}:
                    {{status_display_args.statusextras.progress}}%
                </span>
            {{/status_display_args.statusextras.progress}}
        </td>
    </tr>
    <tr>
        <td>{{#str}} course {{/str}}</td>
        <td>
            <a href="{{{action_urls.course}}}" target="_blank">
                {{course.name}}
            </a>
        </td>
    </tr>
    <tr>
        <td>{{#str}} modulename, mod_quiz {{/str}}</td>
        <td>
            <a href="{{{action_urls.quiz}}}" target="_blank">
                {{quiz.name}}
            </a>
        </td>
    </tr>
    <tr>
        <td>{{#str}} user {{/str}}</td>
        <td>
            <a href="{{{action_urls.user}}}" target="_blank">
                {{user.firstname}} {{user.lastname}} ({{user.username}})
            </a>
        </td>
    </tr>
    <tr>
        <td>{{#str}} timecreated {{/str}}</td>
        <td>{{#userdate}} {{timecreated}}, {{#str}} strftimedatetimeaccurate, core_langconfig {{/str}} {{/userdate}}</td>
    </tr>
    <tr>
        <td>{{#str}} timemodified, reportbuilder {{/str}} </td>
        <td>{{#userdate}} {{timemodified}}, {{#str}} strftimedatetimeaccurate, core_langconfig {{/str}} {{/userdate}}</td>
    </tr>
    <tr>
        <td class="align-middle">{{#str}} quiz_archive, quiz_archiver {{/str}}</td>
        <td>
            {{#artifactfile}}
                <table class="table mb-0">
                    <tr>
                        <td class="border-top-0">{{#str}} filename, backup {{/str}}</td>
                        <td class="border-top-0">{{artifactfile.name}}</td>
                    </tr>
                    <tr>
                        <td>{{#str}} size {{/str}}</td>
                        <td>{{artifactfile.size_human}}</td>
                    </tr>
                    <tr>
                        <td>{{#str}} checksum, quiz_archiver {{/str}}</td>
                        <td class="word-break-all">sha256:{{artifactfile.checksum}}</td>
                    </tr>
                    <tr>
                        <td class="border-bottom-0"></td>
                        <td class="border-bottom-0">
                            <a href="{{{artifactfile.downloadurl}}}" target="_blank">
                                {{#pix}} a/download_all, core, {{#str}} downloadfile {{/str}} {{/pix}}{{#str}} downloadfile {{/str}}
                            </a>
                            &nbsp;&ndash;&nbsp;
                            <a href="{{{action_urls.delete_artifact}}}">
                                {{#pix}} t/delete, core, {{#str}} delete {{/str}} {{/pix}}{{#str}} delete {{/str}}
                            </a>
                        </td>
                    </tr>
                </table>
            {{/artifactfile}}
            {{^artifactfile}}
                {{#autodelete_done}}
                    {{#str}} archive_deleted, quiz_archiver {{/str}}
                {{/autodelete_done}}
                {{^autodelete_done}}
                    {{#str}} quiz_archive_not_ready, quiz_archiver {{/str}}
                {{/autodelete_done}}
            {{/artifactfile}}
        </td>
    </tr>
    <tr>
        <td class="align-middle">{{#str}} archive_signature, quiz_archiver {{/str}}</td>
        <td>
            {{#artifactfile}}
                {{#tsp}}
                    {{#str}} signed_on, quiz_archiver {{/str}}
                    <pre style="display: inline;">{{#userdate}} {{tsp.timecreated}}, {{#str}} strftimedatetimeaccurate, core_langconfig {{/str}} {{/userdate}}</pre>
                    {{#str}} signed_by, quiz_archiver {{/str}}
                    <pre style="display: inline;">{{tsp.server}}</pre>
                    <br>
                    {{#str}} download {{/str}}:
                    <a href="{{tsp.queryfiledownloadurl}}" target="_blank">
                        {{#pix}} a/download_all, core, {{#str}} downloadfile {{/str}} {{/pix}}{{#str}} tsp_query_filename, quiz_archiver {{/str}}
                    </a>
                    &nbsp;&ndash;&nbsp;
                    <a href="{{tsp.replyfiledownloadurl}}" target="_blank">
                        {{#pix}} a/download_all, core, {{#str}} downloadfile {{/str}} {{/pix}}{{#str}} tsp_reply_filename, quiz_archiver {{/str}}
                    </a>
                {{/tsp}}
                {{^tsp}}
                    {{#str}} archive_not_signed, quiz_archiver {{/str}}.
                    {{#tsp_enabled}}
                        &nbsp;&ndash;&nbsp;
                        <a href="{{{action_urls.sign_artifact}}}">{{#pix}} t/edit, core, {{#str}} sign_archive, quiz_archiver{{/str}} {{/pix}}{{#str}} sign_archive, quiz_archiver {{/str}}</a>
                    {{/tsp_enabled}}
                {{/tsp}}
            {{/artifactfile}}
            {{^artifactfile}}
                {{#autodelete_done}}
                    {{#str}} archive_deleted, quiz_archiver {{/str}}
                {{/autodelete_done}}
                {{^autodelete_done}}
                    {{#str}} quiz_archive_not_ready, quiz_archiver {{/str}}
                {{/autodelete_done}}
            {{/artifactfile}}
        </td>
    </tr>
    <tr>
        <td>{{#str}} archive_autodelete_short, quiz_archiver {{/str}}</td>
        <td>{{autodelete_str}}</td>
    </tr>
    <tr>
        <td class="border-bottom-0 align-middle">{{#str}} settings {{/str}}</td>
        <td class="border-bottom-0">
            <ul class="list-group small">
                {{#settings}}
                    <li class="list-group-item d-flex justify-content-between align-items-center p-2">
                        {{title}}
                        <span class="badge badge-{{color}} badge-pill">{{value}}</span>
                    </li>
                {{/settings}}
                {{^settings}}
                    <li class="list-group-item">{{#str}} not_signed, quiz_archiver {{/str}}</li>
                {{/settings}}
            </ul>
        </td>
    </tr>
    <tr>
        <td class="border-0 py-0"></td>
        <td class="border-0 py-0 text-right">
            <a href="{{{action_urls.delete_job}}}" class="btn btn-danger mx-1" role="button" title="{{#str}} delete {{/str}}">
                {{#str}} delete {{/str}}
            </a>
        </td>
    </tr>
</table>