{{!
    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 format_thinkera/manage

    Lessons and access: step and free or paid access per activity, with a whole-lesson shortcut.

    Example context (json):
    {
        "sesskey": "x", "action": "#", "intro": "Choose the step and the access of every activity.",
        "lessons": [{"id": 1, "title": "Lesson 1", "hasrows": true, "rows": [{"id": 5, "name": "Video", "modtype": "Page",
            "iconurl": "", "editurl": "#", "stepoptions": [{"value": "auto", "label": "Automatic", "selected": true}], "free": true}]}]
    }
}}
<div class="tk-learn">
    <p class="tk-lesson-summary">{{intro}}</p>
    {{#orderurl}}<p><a class="btn btn-outline-primary" href="{{orderurl}}">{{#str}}seq_title, local_thinkera{{/str}}</a></p>{{/orderurl}}
    <form method="post" action="{{action}}">
        <input type="hidden" name="sesskey" value="{{sesskey}}">
        {{#lessons}}
        <section class="tk-manage-lesson" aria-labelledby="tk-lesson-{{id}}">
            <header>
                <h3 id="tk-lesson-{{id}}">{{title}}</h3>
                {{#hasrows}}{{#canaccess}}
                <label class="d-flex align-items-center gap-2 mb-0">
                    <span>{{#str}}wholelesson, format_thinkera{{/str}}</span>
                    <select class="form-select form-select-sm" name="lesson_{{id}}">
                        <option value="keep">{{#str}}keep, format_thinkera{{/str}}</option>
                        <option value="free">{{#str}}access_free, format_thinkera{{/str}}</option>
                        <option value="paid">{{#str}}access_paid, format_thinkera{{/str}}</option>
                    </select>
                </label>
                {{/canaccess}}{{/hasrows}}
            </header>
            {{^hasrows}}<p class="p-3 mb-0 text-muted">{{#str}}noactivities, format_thinkera{{/str}}</p>{{/hasrows}}
            {{#hasrows}}
            <div class="table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th scope="col">{{#str}}col_activity, format_thinkera{{/str}}</th>
                            <th scope="col">{{#str}}col_step, format_thinkera{{/str}}</th>
                            <th scope="col">{{#str}}col_access, format_thinkera{{/str}}</th>
                        </tr>
                    </thead>
                    <tbody>
                        {{#rows}}
                        <tr>
                            <th scope="row" class="fw-normal">
                                <img src="{{iconurl}}" alt="" width="24" height="24" class="me-2">
                                <a href="{{editurl}}">{{name}}</a>
                                <span class="d-block small text-muted">{{modtype}}{{#hidden}} · {{#str}}hiddenfromstudents, moodle{{/str}}{{/hidden}}</span>
                            </th>
                            <td>
                                <label class="visually-hidden" for="step_{{id}}">{{#str}}col_step, format_thinkera{{/str}}: {{name}}</label>
                                <select class="form-select" id="step_{{id}}" name="step_{{id}}">
                                    {{#stepoptions}}<option value="{{value}}"{{#selected}} selected{{/selected}}>{{label}}</option>{{/stepoptions}}
                                </select>
                            </td>
                            <td>
                                <label class="visually-hidden" for="access_{{id}}">{{#str}}col_access, format_thinkera{{/str}}: {{name}}</label>
                                {{#canaccess}}
                                <select class="form-select" id="access_{{id}}" name="access_{{id}}">
                                    <option value="free"{{#free}} selected{{/free}}>{{#str}}access_free, format_thinkera{{/str}}</option>
                                    <option value="paid"{{#paid}} selected{{/paid}}>{{#str}}access_paid, format_thinkera{{/str}}</option>
                                </select>
                                {{/canaccess}}
                                {{^canaccess}}
                                {{! the price list, as a fact: an instructor sees it and cannot change it }}
                                <span id="access_{{id}}" class="badge {{#paid}}text-bg-warning{{/paid}}{{#free}}text-bg-success{{/free}}">
                                    {{#free}}{{#str}}access_free, format_thinkera{{/str}}{{/free}}{{#paid}}{{#str}}access_paid, format_thinkera{{/str}}{{/paid}}
                                </span>
                                {{/canaccess}}
                            </td>
                        </tr>
                        {{/rows}}
                    </tbody>
                </table>
            </div>
            {{/hasrows}}
        </section>
        {{/lessons}}
        <button type="submit" class="btn btn-primary">{{#str}}save, format_thinkera{{/str}}</button>
    </form>
</div>
