<%=raw app.core.View.getTemplate( 'course-nav', { activeTab : 'course-categories', g : g } ) %>
<div class="row">
    <div class="col-sm-12">
        <div class="card">
            <div class="card-header">
                <div class="row">
                    <div class="col">
                        <label><%= _lc( 'GROUP' ) %></label>
                        <select class="form-control form-control-sm"
                                data-id="select-group-id">
                            <% for ( var gi = 0; gi < groups.length; gi++ ) {  %>
                                <option value="<%= groups[ gi ].getId() %>"
                                    <%= groups[ gi ].getId() == g.getId() ? 'selected="selected"' : '' %>
                                    >
                                    <%= groups[ gi ].getName() %>
                                </option>
                            <% }    %>
                        </select>
                    </div>
                </div>
            </div>
            <div class="card-body">

                <div class="table-responsive">
                    <table class="table table-course-categories">
                        <thead>
                        <tr>
                            <th>Name</th>
                            <th>&nbsp;</th>
                        </tr>
                        </thead>
                        <tbody>
                        <% var cc = g.getCourseCategories(); %>
                        <% var ccCount = 0; %>
                        <% if ( cc.length > 0 ) {   %>
                            <% for ( var cci = 0; cci < cc.length; cci++ ) {    %>
                                <% if ( false === cp.isOwnerOfGroup( g.getId() ) && false === cp.isInGroupCourseCategoryId( cc[ cci ].id ) ) {  %>
                                    <%  continue;   %>
                                <% } else {   %>
                                    <% ccCount++; %>
                                <% }    %>
                                <tr>
                                    <td>
                                        <%= cc[ cci ].name %>
                                        <% if ( g.isDefaultCategoryId( cc[ cci ].id ) )   {   %>
                                            <small>(<%= _lc( 'DEFAULT' ) %>)</small>
                                        <% }    %>
                                        <small><br /><%= _lc( 'ASSIGNED_MEMBERS_TO_CATEGORY' ) %>: <%= g.getCourseCategoryMemberCountById( cc[ cci ].id ) %></small>
                                    </td>
                                    <td class="text-right">
                                        <button type="button"
                                                data-type="btn-edit-category"
                                                data-category-id="<%= cc[ cci ].id %>"
                                                <%= false === cp.isOwnerOfGroup( g.getId() ) ? 'disabled="disabled"' : '' %>
                                                class="btn btn-primary btn-sm">
                                            <i class="far fa-edit"></i>
                                        </button>
                                        <button type="button"
                                                data-type="btn-edit-category-users"
                                                data-category-id="<%= cc[ cci ].id %>"
                                                class="btn btn-primary btn-sm">
                                            <i class="fas fa-users"></i>
                                        </button>
                                        <button type="button"
                                                data-type="btn-delete-category"
                                                data-category-id="<%= cc[ cci ].id %>"
                                                <%= g.isDefaultCategoryId( cc[ cci ].id ) || false === cp.isOwnerOfGroup( g.getId() ) ? 'disabled="disabled"' : '' %>
                                                class="btn btn-primary btn-sm">
                                            <i class="far fa-trash-alt"></i>
                                        </button>
                                    </td>
                                </tr>
                            <% }    %>
                            <% if ( 0 === ccCount ) {   %>
                                <tr>
                                    <td colspan="2"><%= _lc( 'NO_CATEGORIES_FOUND_FOR_ADMIN' ) %></td>
                                </tr>
                            <% }    %>
                        <% } else { %>
                            <tr>
                                <td colspan="2"><%= _lc( 'NO_CATEGORIES_FOUND' ) %></td>
                            </tr>
                        <% }    %>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="card-footer">
                <% if ( cp.isOwnerOfGroup( g.getId() ) ) {    %>
                    <button type="button"
                       data-id="btn-create-new-category"
                       class="btn btn-sm btn-primary">
                        <%= _lc( 'ADD_NEW_CATEGORY' ) %>
                    </button>
                <% } else { %>
                    <p>
                        <%= _lc( 'CATEGORY_CREATION_NOTE_FOR_ADMINS' ) %>
                    </p>
                <% }    %>
            </div>
        </div>
    </div>
</div>