{{!
    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.

    Edwiser RemUI 
    @package    theme_remui
    @copyright  (c) 2018 WisdmLabs (https://wisdmlabs.com/)
    @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 
}}
{{!
    @template theme_remui/admin_setting_tabs


    Example context (json):
    {
        "tabs": [
         {
            "name": "tab1",
            "active": 0,
            "displayname": "Inactive tab1",
            "html": "<p>Tab 1 content</p>"
         },
         {
            "name": "tab2",
            "active": 1,
            "displayname": "Active tab2",
            "html": "<p>Tab 2 content</p>"
         }
        ]
    }
}}
<ul class="nav nav-tabs nav-tabs-line" role="tablist">
    {{#tabs}}
        <li class="nav-item">
            <a href="#{{name}}" class="nav-link {{#active}}active{{/active}} {{ customclass }}" data-toggle="tab" role="tab">{{displayname}}</a>
        </li>
    {{/tabs}}
</ul>
<div class="tab-content mt-10">
    {{#tabs}}
        <div class="tab-pane {{#active}}active{{/active}}" id="{{name}}" role="tabpanel">
            {{{html}}}
        </div>
    {{/tabs}}
</div>

{{#js}}
    require([], function () {
        // hide save cahnges buttons on custom tabs made for remui
        jQuery('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
          if(jQuery(this).hasClass('remuitab')) {
            jQuery('.form-buttons').hide();
            jQuery('#onLicensePage').val(1);
          } else {
            jQuery('.form-buttons').show();
            jQuery('#onLicensePage').val(0);
          }
        });

        // RemUI feedback form ajax call
        jQuery('#sendfeedback').click( function() {
            jQuery(this).prop('disabled', true);
            jQuery('.feedbacki').toggleClass('d-none');
            jQuery('.feedbackm').text('');
            var email = jQuery('.remail').val();
            var rating = jQuery("[name='rrating']:checked").val();
            if(rating == undefined) {
                rating = 'Not Given';
            }
            var fullname = jQuery('.rfullname').val();
            var feedback = jQuery('.rfeedback').val();
            
            jQuery.ajax({
                type: "GET",
                async: true,
                url: M.cfg.wwwroot + '/theme/remui/request_handler.php?action=send_remuifeedback_ajax&email=' + email + '&rating=' + rating + '&fullname=' + fullname + '&feedback=' + feedback + '&sesskey=' + M.cfg.sesskey,
                success: function(response) {
                    jQuery('.feedbacki').toggleClass('d-none');
                    if (response == null || response['sent'] == 0) {
                        jQuery('.feedbackm').text('Not sent!').css('color', 'red');
                    } else if( response['sent'] == 1) {
                        jQuery('.feedbackm').text('Sent.').css('color', 'green');
                    }
                    jQuery('#sendfeedback').prop('disabled', false);
                },
                error: function(xhr, status, error) {
                    jQuery('.feedbacki').toggleClass('d-none');
                    jQuery('.feedbackm').text('Not sent!').css('color', 'red');
                    jQuery('#sendfeedback').prop('disabled', false);
                }
            });
        });
    });
{{/js}}
