<div class="col-sm-9 col-md-10 col-sm-push-3 col-md-push-2">

    <ol class="breadcrumb">
        <li><a href="#/realms/{{realm.realm}}/clients">{{:: 'clients' | translate}}</a></li>
        <li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}">{{client.clientId}}</a></li>
        <li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server">Authorization</a></li>
        <li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/permission">Permissions</a></li>
        <li data-ng-show="create">Add Scope Permission</li>
        <li data-ng-hide="create">{{policy.name}}</li>
    </ol>

    <h1 data-ng-show="create">Add Scope Permission</h1>
    <h1 data-ng-hide="create">{{policy.name|capitalize}}<i class="pficon pficon-delete clickable" data-ng-click="remove()"></i></h1>

    <form class="form-horizontal" name="clientForm" novalidate>
        <fieldset class="border-top">
            <div class="form-group">
                <label class="col-md-2 control-label" for="name">Name <span class="required">*</span></label>
                <div class="col-sm-6">
                    <input class="form-control" type="text" id="name" name="name" data-ng-model="policy.name" autofocus required>
                </div>
                <kc-tooltip>The name of this permission.</kc-tooltip>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label" for="description">Description </label>
                <div class="col-sm-6">
                    <input class="form-control" type="text" id="description" name="description" data-ng-model="policy.description">
                </div>
                <kc-tooltip>A description for this permission.</kc-tooltip>
            </div>
            <div class="form-group clearfix">
                <label class="col-md-2 control-label" for="reqActions">Resource</label>

                <div class="col-md-6">
                    <select class="form-control" id="reqActions"
                            ng-model="policy.config.resources"
                            ng-change="resolveScopes(policy)"
                            data-ng-options="resource._id as resource.name for resource in resources">
                        <option value="">Any resource...</option>
                    </select>
                </div>
                <kc-tooltip>Restrict the scopes to those associated with the selected resource. If not selected all scopes would be available.</kc-tooltip>
            </div>
            <div class="form-group clearfix" data-ng-show="policy.config.resources">
                <label class="col-md-2 control-label" for="reqActions">Scopes <span class="required">*</span></label>

                <div class="col-md-6">
                    <select ui-select2 id="reqActions"
                            data-ng-model="policy.config.scopes"
                            data-placeholder="Any scope..." multiple
                            data-ng-required="policy.config.resources != ''"
                            data-ng-options="scope.id as scope.name for scope in scopes track by scope.id"/>
                </div>

                <kc-tooltip>Specifies that this permission must be applied to one or more scopes.</kc-tooltip>
            </div>
            <div class="form-group clearfix" data-ng-show="!policy.config.resources">
                <label class="col-md-2 control-label" for="reqActions">Scopes <span class="required">*</span></label>

                <div class="col-md-6">
                    <select ui-select2="{ minimumInputLength: 1}" id="reqActions"
                            data-ng-model="policy.config.scopes"
                            data-placeholder="Any scope..." multiple
                            data-ng-required="policy.config.resources == ''"
                            data-ng-options="scope.id as scope.name for scope in scopes track by scope.id"/>
                    </select>
                </div>
                <kc-tooltip>Specifies that this permission must be applied to one or more scopes.</kc-tooltip>
            </div>
            <div class="form-group clearfix">
                <label class="col-md-2 control-label" for="reqActions">Apply Policy <span class="required">*</span></label>

                <div class="col-md-6">
                    <select ui-select2 id="reqActions" data-ng-model="policy.config.applyPolicies" data-placeholder="Select a policy..." multiple required>
                        <option ng-repeat="policy in policies" value="{{policy.id}}" ng-selected="true">{{policy.name}}</option>
                    </select>
                </div>

                <kc-tooltip>Specifies all the policies that must be applied to the scopes defined by this permission.</kc-tooltip>
            </div>
            <div class="form-group clearfix">
                <label class="col-md-2 control-label" for="policy.decisionStrategy">Decision Strategy</label>

                <div class="col-md-6">
                    <select class="form-control" id="policy.decisionStrategy"
                            data-ng-model="policy.decisionStrategy"
                            ng-change="selectDecisionStrategy()">
                        <option ng-repeat="strategy in decisionStrategies" value="{{strategy}}">{{strategy}}</option>
                    </select>
                </div>

                <kc-tooltip>The decision strategy dictates how the policies associated with a given permission are evaluated and how a final decision is obtained.
                    'Affirmative' means that at least one policy must evaluate to a positive decision in order to the overall decision be also positive.
                    'Unanimous' means that all policies must evaluate to a positive decision in order to the overall decision be also positive.
                    'Consensus' means that the number of positive decisions must be greater than the number of negative decisions. If the number of positive and negative is the same, the final decision will be negative.</kc-tooltip>
            </div>
            <input type="hidden" data-ng-model="policy.type"/>
        </fieldset>

        <div class="form-group">
            <div class="col-md-10 col-md-offset-2" data-ng-show="create">
                <button kc-save data-ng-disabled="!changed">Save</button>
                <button kc-cancel data-ng-click="cancel()">Cancel</button>
            </div>
            <div class="col-md-10 col-md-offset-2" data-ng-show="!create && access.manageClients">
                <button kc-save  data-ng-disabled="!changed">Save</button>
                <button kc-reset data-ng-disabled="!changed">Cancel</button>
            </div>
        </div>
    </form>
</div>

<kc-menu></kc-menu>