<div ng-controller="Wizdom365PermissionsController">
    <div class="lt-module-page__top lt-module-page-top">
        <div class="lt-module-page-top__title mr-auto">
            <h1>{{'Permissions' | translate}}</h1>
        </div>
        <div class="lt-module-page-top__actions">
            <button class="btn btn-primary wide-config-btn pull-right"
                    ng-disabled="saving" ng-click="saveConfig()">
                {{(saving ? 'Saving' : 'Save configuration')  | translate}}
            </button>
        </div>
    </div>

    <div class="panel lt-module-page__content-panel panel-admin-permissions">
        <p>
            {{'Permissions are cached for 24 hours' | translate}}.
        </p>
        <p>
            {{'Click'| translate}} "{{'Save configuration' | translate}}" {{'to clear the permission cache within the next 5 mins' | translate }}.
        </p>
        <p>
            {{'Clearing of cache is also needed if users are added or removed from one of the groups' | translate}}.
        </p>
    </div>

    <div class="panel lt-module-page__content-panel" ng-repeat="permission in permissions" ng-init="config.Wizdom365.Permissions[permission.groupName] = config.Wizdom365.Permissions[permission.groupName] || {}">
        <div class="wizdom-controls-row">
            <div class="panel-heading">
                {{permission.name | translate}}{{' permissions' | translate}}
            </div>
            <div ng-switch="permission.name">
                <div ng-switch-when="Admin_Global_Admin">
                    <div ng-show="adminPrincipals.length <= 0" class="alert alert-danger">
                        {{'No Admin groups defined. Everyone currently has access to everything' | translate}}
                    </div>
                    <div ng-show="adminPrincipals.length > 0" class="alert alert-info">
                        {{'Admin groups has access to everything' | translate}}
                    </div>
                    <div wizdom365-principalpicker principals="permission.principals" add-fn="add(config.Wizdom365.Permissions[permission.groupName], principal)" remove-fn="remove(config.Wizdom365.Permissions[permission.groupName], principal)" mode="groups" allowwizdomgroups="true" class="principal-picker"></div>
                </div>
                <div ng-switch-default>
                    <div ng-show="adminPrincipals.length <= 0" class="alert alert-danger">
                        {{'No Admin groups defined. Everyone currently has access' | translate}}
                    </div>
                    <div ng-show="adminPrincipals.length > 0 && permission.principals.length <= 0"
                         class="alert alert-danger">
                        {{'No groups defined. Everyone currently has access' | translate}}
                    </div>
                    <div ng-show="adminPrincipals.length > 0 && permission.principals.length > 0"
                         class="alert alert-info">
                        {{permission.name | translate}}  {{' groups and Admin groups has access' | translate}}
                    </div>
                    <div ng-if="adminPrincipals.length > 0" wizdom365-principalpicker principals="permission.principals" add-fn="add(config.Wizdom365.Permissions[permission.groupName], principal)" remove-fn="remove(config.Wizdom365.Permissions[permission.groupName], principal)" mode="groups" allowwizdomgroups="true" class="principal-picker"></div>
                </div>
            </div>
        </div>
    </div>
</div>
