{{!
    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 tool_lp/course_competencies_page

    Course competencies template.

    For a full list of the context for this template see the course_competencies_page renderable.

    This template includes ajax functionality, so it cannot be shown in the template library.

    Example context (json):
    {
        "canmanagecoursecompetencies": true,
        "cangradecompetencies": true,
        "settings": {
            "pushratingstouserplans": true
        },
        "canconfigurecoursecompetencies": true,
        "competencies": [{
            "competency": {
                "id": 2,
                "shortname": "Competency1",
                "idnumber": "COMP1",
                "description": "Competency1 description"
            },
            "coursecompetency": {
                "id": 1
            },
            "ruleoutcomeoptions": [{
                "value": "1",
                "text": "Mark as complete"
            }, {
                "value": "2",
                "text": "Mark as complete and request review"
            }]
        }]
    }
}}
<div data-region="coursecompetenciespage">
    <div data-region="actions" class="clearfix">
        <div class="float-sm-start">
            {{#canmanagecoursecompetencies}}
                <button class="btn btn-secondary" disabled>{{#str}}addcoursecompetencies, tool_lp{{/str}}</button>
            {{/canmanagecoursecompetencies}}
        </div>
    </div>
    <div data-region="configurecoursecompetencies">
    {{#cangradecompetencies}}
        <p class="alert {{^settings.pushratingstouserplans}}alert-info{{/settings.pushratingstouserplans}}">
        {{#settings.pushratingstouserplans}}
            {{#str}}coursecompetencyratingsarepushedtouserplans, tool_lp{{/str}}
        {{/settings.pushratingstouserplans}}
        {{^settings.pushratingstouserplans}}
            {{#str}}coursecompetencyratingsarenotpushedtouserplans, tool_lp{{/str}}
        {{/settings.pushratingstouserplans}}
        {{#canconfigurecoursecompetencies}}
            <a href="#"
               data-action="configure-course-competency-settings"
               data-courseid="{{courseid}}"
               data-pushratingstouserplans="{{settings.pushratingstouserplans}}">
                {{#pix}}i/settings, core, {{#str}}edit{{/str}}{{/pix}}
            </a>
        {{/canconfigurecoursecompetencies}}
        </p>
    {{/cangradecompetencies}}
    </div>
{{#statistics}}
{{> tool_lp/course_competency_statistics }}
{{/statistics}}
<div data-region="coursecompetencies">
<table class="generaltable fullwidth managecompetencies">
<tbody class="drag-parentnode">
{{#competencies}}
    <tr class="drag-samenode" data-id="{{competency.id}}">
    <td>
        {{#canmanagecoursecompetencies}}
        <span class="drag-handlecontainer float-sm-start"></span>
        <div class="float-sm-end">
            <a href="#" data-action="delete-competency-link" data-id="{{competency.id}}">
                {{#pix}}t/delete, core, {{#str}}delete{{/str}}{{/pix}}
            </a>
        </div>
        <div class="clearfix"></div>
        {{/canmanagecoursecompetencies}}
        {{#competency}}
            <a href="{{pluginbaseurl}}/user_competency_in_course.php?courseid={{courseid}}&competencyid={{competency.id}}&userid={{gradableuserid}}"
                   id="competency-info-link-{{competency.id}}"
                   title="{{#str}}viewdetails, tool_lp{{/str}}">
                <p><strong>{{{competency.shortname}}} <em>{{competency.idnumber}}</em></strong></p>
            </a>
            <p>{{{competency.description}}}</p>
        {{/competency}}
        {{#comppath}}
            <span class="float-sm-start">{{#str}}path, tool_lp{{/str}}&nbsp;</span>{{> tool_lp/competency_path }}
        {{/comppath}}
        {{#usercompetencycourse}}
            {{#grade}}
            <span class="badge {{#proficiency}}bg-success{{/proficiency}}{{^proficiency}}bg-danger{{/proficiency}} text-white">{{gradename}}</span>
            {{/grade}}
        {{/usercompetencycourse}}
        {{#canmanagecoursecompetencies}}
        <div data-region="coursecompetency-ruleoutcome">
            <label>
                {{#str}}uponcoursecompletion, tool_lp{{/str}}
                <select data-field="ruleoutcome" data-id="{{coursecompetency.id}}" class="form-select">
                  {{#ruleoutcomeoptions}}
                     <option value="{{value}}" {{#selected}}selected{{/selected}}>{{text}}</option>
                  {{/ruleoutcomeoptions}}
                </select>
            </label>
        </div>
        {{/canmanagecoursecompetencies}}
        <div data-region="coursecompetencyactivities">
        <p>
        <strong>{{#str}}activities{{/str}}</strong>
        <ul class="inline list-inline p-2">
        {{#coursemodules}}
            <li class="list-inline-item"><a href="{{url}}"><img class="icon" src="{{iconurl}}"> {{name}} </a></li>
        {{/coursemodules}}
        {{^coursemodules}}
            <li class="list-inline-item">{{#str}}noactivities, tool_lp{{/str}}</li>
        {{/coursemodules}}
        </ul>
        </p>
        </div>
        <div data-region="learningplans">
        <p>
        <strong>{{#str}}userplans, core_competency{{/str}}</strong>
        <ul class="inline list-inline p-2">
        {{#plans}}
            <li class="list-inline-item"><a href="{{pluginbaseurl}}/plan.php?id={{id}}">{{{name}}}</a></li>
        {{/plans}}
        {{^plans}}
            <li class="list-inline-item">{{#str}}nouserplanswithcompetency, core_competency{{/str}}</li>
        {{/plans}}
        </ul>
        </p>
        </div>
    </td>
    </tr>
{{/competencies}}
</tbody>
</table>
{{^competencies}}
<p class="alert alert-info">
    {{#moduleid}}
        {{#str}}nocompetenciesinactivity, tool_lp{{/str}}
    {{/moduleid}}
    {{^moduleid}}
        {{#str}}nocompetenciesincourse, tool_lp{{/str}}
    {{/moduleid}}
</p>
{{/competencies}}
</div>
<div data-region="actions">
    {{#canmanagecompetencyframeworks}}
        <p><a href="{{manageurl}}">{{#str}}managecompetenciesandframeworks, tool_lp{{/str}}</a></p>
    {{/canmanagecompetencyframeworks}}
</div>
</div>
{{#js}}
require(['tool_lp/competencies'], function(mod) {
    (new mod({{courseid}}, 'course', {{pagecontextid}}));
});
{{/js}}
{{#canconfigurecoursecompetencies}}
{{#js}}
require(['tool_lp/course_competency_settings'], function(Mod) {
    (new Mod('[data-action=configure-course-competency-settings]'));
});
{{/js}}
{{/canconfigurecoursecompetencies}}
