{{!
    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 local_treestudyplan/invitations

    Template for rendering the invitations page

    Classes required for JS:
    * m-action-resend
    * m-action-confirm
    * m-action-delete
    * m-action-view

    Data attributes required for JS:
    * data-confirmtext
    * data-confirmbtn
    * data-actionhref

    Context variables required for this template:
    * none

    Example context (json):
    {
        "invites": [{
            "id": 1,
            "user_id": 33,
            "user_firstname": "Someone",
            "user_lastname": "Else",
            "name": "Test Recipient",
            "email": "test@test.tst",
            "idate": 1735513200,
            "unlockdate": 1746605920,
            "identifier": "x34s2",
            "unlocked": false
        }],
        "hasinvites": true
    }
}}
<div class="local_treestudyplan_invitations">
    <p>{{#str}} invite_manage_description, local_treestudyplan {{/str}}</p>
    <h3>{{#str}} invite_manage_tablecaption, local_treestudyplan {{/str}}</h3>
    <p><a  class='btn btn-primary'
        href='{{config.wwwroot}}/local/treestudyplan/cfg-edit-managedshare.php?userid={{user_id}}&add=true'  id='add_invite'>
        <i class='fa fa-plus'></i> {{#str}} invite_button_new, local_treestudyplan {{/str}}
    </a></p>
    <div>{{{userselector}}}</div>
    {{#userselected}}
    <h4>{{username}}</h4>
    <table class='m-manage_invites'>
        <thead>
            <tr>
                <th> {{#str}} invite_name, local_treestudyplan {{/str}} </th>
                <th> {{#str}} invite_email, local_treestudyplan {{/str}} </th>
                <th> {{#str}} invite_date, local_treestudyplan {{/str}} </th>
                <th> {{#str}} invite_unlock_date, local_treestudyplan {{/str}} </th>
                <th> {{#str}} invite_identifier, local_treestudyplan {{/str}} </th>
                <th>&nbsp;</th>
            </tr>
        </thead>
        <tbody>
            {{#hasinvites}}
            {{#invites}}
            <tr data-id='{{id}}'>
                <td data-field='name'>{{name}}</td>
                <td data-field='email'>{{email}}</td>
                <td data-field='date'>{{#userdate}} {{idate}}, %x {{/userdate}}</td>
                <td data-field='unlocks'>
                    <span class='{{#unlocked}}text-success{{/unlocked}}{{^unlocked}}text-danger{{/unlocked}}'>
                    {{#userdate}} {{unlockdate}}, %x {{/userdate}}
                    {{#unlocked}}<i>({{#str}} invite_unlocked, local_treestudyplan {{/str}})</i>{{/unlocked}}</td>
                    </span>
                <td data-field='identifier'>{{identifier}}</td>
                <td data-field='control'>
                    <a  class='m-action-view '
                        href='{{config.wwwroot}}/local/treestudyplan/invited.php?key={{invitekey}}'
                        title='{{#str}} invite_tooltip_testlink, local_treestudyplan {{/str}}'
                        ><i class='fa fa-eye'></i></a>

                    <a  class='m-action-resend m-action-confirm'
                        data-confirmtext='{{#str}} invite_confirm_resend, local_treestudyplan {{/str}}'
                        data-confirmbtn='{{#str}} send, local_treestudyplan {{/str}}'
                        href='#'
                        data-actionhref='{{config.wwwroot}}/local/treestudyplan/cfg-edit-managedshare.php?resend={{id}}'
                        title='{{#str}} invite_tooltip_resend, local_treestudyplan {{/str}}'
                    ><i class='fa fa-envelope'></i></a>

                    <a  href='{{config.wwwroot}}/local/treestudyplan/cfg-edit-managedshare.php?update={{id}}'
                        ><i class='fa fa-pencil' title='{{#str}} invite_tooltip_edit, local_treestudyplan {{/str}}'></i></a>

                    <a  class='m-action-delete m-action-confirm'
                        data-confirmtext='{{#str}} invite_confirm_delete, local_treestudyplan, {{name}} {{/str}}'
                        data-confirmbtn='{{#str}} delete, core {{/str}}'
                        href='#' data-actionhref='{{config.wwwroot}}/local/treestudyplan/cfg-edit-managedshare.php?delete={{id}}'
                        title='{{#str}} invite_tooltip_delete, local_treestudyplan {{/str}}'
                    ><i class='fa fa-trash'></i></a>
                </td>
            </tr>
            {{/invites}}
            {{/hasinvites}}
            {{^hasinvites}}
            <tr><td colspan='6'>{{#str}} invite_manage_nomadatoryshares, local_treestudyplan {{/str}}</td></tr>
            {{/hasinvites}}
        </tbody>
    </table>
    {{/userselected}}
    {{^userselected}}
        {{#str}} invite_manage_nouserselected, local_treestudyplan {{/str}}
    {{/userselected}}

</div>
{{#js}}
require(['local_treestudyplan/tool-actionhrefs', 'local_treestudyplan/cfg-manageshares'], function(manageshares, invitemanager) {
    invitemanager.init();
    manageshares.init();
});
{{/js}}