{{!
    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_courseformat/local/courseindex/cm

    Displays a course index course-module entry.

    Example context (json):
    {
        "id": "12",
        "name": "Announcements",
        "url": "#",
        "visible": 1,
        "isactive": 1,
        "uniqid": "0",
        "accessvisible": 1,
        "hascmrestrictions": 0,
        "indent": 1
    }
}}
<li class="courseindex-item
        {{#isactive}}active{{/isactive}}
        {{#hascmrestrictions}}restrictions{{/hascmrestrictions}}
        {{^accessvisible}}dimmed{{/accessvisible}}
        d-flex
        {{#indent}} indented {{/indent}}
        {{#hasdelegatedsection}}py-0{{/hasdelegatedsection}}"
    id="course-index-cm-{{{id}}}"
    data-for="cm"
    data-id="{{{id}}}"
    role="treeitem">
    {{^hasdelegatedsection}}
        <span class="completioninfo" data-for="cm_completion" data-value="NaN"></span>

        {{#uservisible}}
            <a class="courseindex-link text-truncate"
                {{#url}} href="{{{url}}}" {{/url}}
                {{^url}} href="#{{{anchor}}}" data-anchor="true" {{/url}}
                    data-for="cm_name"
                    tabindex="-1">
                {{#module}}
                    <div class="activity-icon">
                        <img src="/theme/image.php?theme=eadtraining&component={{{module}}}&image=monologo&filtericon=1"
                             alt="{{{modname}}} ícone" title="{{{modname}}}">
                    </div>
                {{/module}}
                {{{name}}}
            </a>
        {{/uservisible}}
        {{^uservisible}}
            <a class="courseindex-link text-truncate"
               href="#{{{anchor}}}"
               data-for="cm_name" tabindex="-1" data-anchor="true">
                {{#module}}
                    <div class="activity-icon">
                        <img src="/theme/image.php?theme=eadtraining&component={{{module}}}&image=monologo&filtericon=1"
                             alt="{{{modname}}} ícone" title="{{{modname}}}">
                    </div>
                {{/module}}
                {{{name}}}
            </a>
        {{/uservisible}}
        <span class="courseindex-locked ms-1" data-for="cm_name">
            {{#pix}} t/locked, core {{/pix}}
        </span>
    {{/hasdelegatedsection}}
    {{#hasdelegatedsection}}
        {{#sectioninfo}}
            {{> core_courseformat/local/courseindex/section}}
        {{/sectioninfo}}
    {{/hasdelegatedsection}}
</li>
{{#js}}
    require(['core_courseformat/local/courseindex/cm'], function(component) {
        component.init('#course-index-cm-{{{id}}}');

        if (new URL(M.cfg.wwwroot).pathname !== "/") {
            const img = document.querySelector('#course-index-cm-{{{id}}} img[src^="/theme"]');
            if (img) {
                if (img.getAttribute('src').startsWith('/theme')) {
                    img.src = img.getAttribute('src').replace('/theme', `${M.cfg.wwwroot}/theme`);
                }
            }
        }
    });
{{/js}}
