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

    Show a competency tree and allow picking a competency.

    Context variables required for this template:
    * frameworks - array of competency framework
      * id
      * shortname
      * idnumber
      * selected

    * framework - competency framework
      * id
      * name
      * shortname
      * idnumber

    * competencies - array of nodes
      * id - competency id
      * name - competency idnumber
      * children - array of children
      * haschildren - boolean

    Example context (json):
    {
        "frameworks": [
            {
                "id": "1",
                "shortname": "Framework",
                "idnumber": "F1"
            }
        ],
        "competencies": [
        ]
    }
}}
<div data-region="competencylinktree">
{{^singleFramework}}
<h3 class="mb-2">{{#str}}competencyframeworks, tool_lp{{/str}}</h3>
<select data-action="chooseframework" class="custom-select">
{{#frameworks}}
<option value="{{id}}" {{#selected}}selected="selected"{{/selected}}>{{{shortname}}} <em>{{idnumber}}</em></option>
{{/frameworks}}
</select>
{{/singleFramework}}
<h3 class="mt-3 mb-2">{{#str}}locatecompetency, tool_lp{{/str}}</h3>

<form data-region="filtercompetencies" class="form-inline" data-frameworkid="{{framework.id}}">
    <div class="form-group row no-gutters w-100">
        <div class="col mr-2">
            <label class="accesshide" for="filter{{uniqid}}">{{#str}}search, tool_lp{{/str}}</label>
            <input type="text" class="form-control w-100 m-0" id="filter{{uniqid}}" placeholder="{{#str}}search, tool_lp{{/str}}" value="{{search}}">
        </div>
        <div class="col-2">
            <button class="btn btn-secondary w-100">
                <i class="icon fas fa-search fa-fw " aria-hidden="true" title="{{#str}}search{{/str}}" aria-label="{{#str}}search{{/str}}"></i>
            </button>
        </div>
    </div>
</form>
<ul data-enhance="linktree" style="display: none;" class="mt-1 mx-0 p-3 competency-tree">
    <li><span>{{{framework.shortname}}}</span>
        <ul class="pl-2">
            {{#competencies}}
                {{> tool_lp/competencies_tree }}
            {{/competencies}}
        </ul>
    </li>
</ul>
<div data-region="link-buttons" class="mt-1 float-sm-right">
    <input type="button" class="btn btn-primary" data-action="add" value="{{#str}}add{{/str}}"/>
    <input type="button" class="btn btn-secondary" data-action="cancel" value="{{#str}}cancel{{/str}}"/>
</div>
<div class="clearfix"></div>
</div>
