<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">{{:: 'authz-authorization' | translate}}</a></li>
        <li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/policy">{{:: 'authz-policies' | translate}}</a></li>
        <li data-ng-show="policyState.state.policy.name != null && historyBackOnSaveOrCancel">{{policyState.state.policy.name}}</li>
        <li data-ng-show="policyState.state.policy.name == null && historyBackOnSaveOrCancel">{{:: policyState.state.previousPage.name | translate}}</li>
        <li data-ng-show="create">{{:: 'authz-add-aggregated-policy' | translate}}</li>
        <li data-ng-hide="create">{{:: 'authz-aggregated' | translate}}</li>
        <li data-ng-hide="create">{{originalPolicy.name}}</li>
    </ol>

    <h1 data-ng-show="create">{{:: 'authz-add-aggregated-policy' | translate}}</h1>
    <h1 data-ng-hide="create">{{originalPolicy.name|capitalize}}<i class="pficon pficon-delete clickable" data-ng-show="!create"
                                                         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' | translate}} <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 data-ng-blur="checkNewNameAvailability()">
                </div>
                <kc-tooltip>{{:: 'authz-policy-name.tooltip' | translate}}</kc-tooltip>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label" for="description">{{:: 'description' | translate}} </label>
                <div class="col-sm-6">
                    <input class="form-control" type="text" id="description" name="description" data-ng-model="policy.description">
                </div>
                <kc-tooltip>{{:: 'authz-policy-description.tooltip' | translate}}</kc-tooltip>
            </div>
            <div class="form-group clearfix">
                <label class="col-md-2 control-label" for="policies">{{:: 'authz-policy-apply-policy' | translate}} <span class="required">*</span></label>
                <div class="col-sm-6">
                    <table class="table table-striped table-bordered" style="margin-top: 0px" id="selected-policies">
                        <thead>
                            <tr>
                                <th class="kc-table-actions" colspan="2">
                                    <div class="form-inline col-md-12" style="width: 107%">
                                        <div class="form-group" style="width: 100%">
                                            <div class="input-group" style="width: 100%">
                                                <input type="hidden" ui-select2="policiesUiSelect" id="policies" data-ng-change="selectPolicy(selectedPolicy);" data-ng-model="selectedPolicy" data-placeholder="{{:: 'authz-select-a-policy' | translate}}..." data-ng-required="!selectedPolicies || selectedPolicies.length == 0"/>
                                            </div>
                                        </div>
                                    </div>
                                </th>
                                <th class="kc-table-actions">
                                    <div class="pull-right" style="width: 100%">
                                        <select id="create-policy" class="form-control" ng-model="policyType"
                                                ng-options="p.name for p in policyProviders track by p.type"
                                                data-ng-change="addPolicy(policyType);"
                                                data-ng-hide="historyBackOnSaveOrCancel">
                                            <option value="" disabled selected>{{:: 'authz-create-policy' | translate}}...</option>
                                        </select>
                                    </div>
                                </th>
                            </tr>
                            <tr data-ng-hide="!selectedPolicies || selectedPolicies.length == 0">
                                <th>{{:: 'name' | translate}}</th>
                                <th>{{:: 'description' | translate}}</th>
                                <th width="20%">{{:: 'actions' | translate}}</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr ng-repeat="policy in selectedPolicies">
                                <td data-ng-hide="historyBackOnSaveOrCancel"><a href="" data-ng-click="detailPolicy(policy)">{{policy.name}}</a></td>
                                <td data-ng-show="historyBackOnSaveOrCancel">{{policy.name}}</td>
                                <td>{{policy.description}}</td>
                                <td class="kc-action-cell" ng-click="removePolicy(selectedPolicies, policy);" style="vertical-align: middle">
                                    {{:: 'remove' | translate}}
                                </td>
                            </tr>
                            <tr data-ng-show="!selectedPolicies || selectedPolicies.length == 0">
                                <td class="text-muted" colspan="3">{{:: 'authz-no-policies-assigned' | translate}}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <kc-tooltip>{{:: 'authz-policy-apply-policy.tooltip' | translate}}</kc-tooltip>
            </div>
            <div class="form-group clearfix">
                <label class="col-md-2 control-label" for="policy.decisionStrategy">{{:: 'authz-policy-decision-strategy' | translate}}</label>
                <div class="col-sm-2">
                    <select class="form-control" id="policy.decisionStrategy"
                            data-ng-model="policy.decisionStrategy"
                            ng-change="selectDecisionStrategy()">
                        <option value="UNANIMOUS">{{:: 'authz-policy-decision-strategy-unanimous' | translate}}</option>
                        <option value="AFFIRMATIVE">{{:: 'authz-policy-decision-strategy-affirmative' | translate}}</option>
                        <option value="CONSENSUS">{{:: 'authz-policy-decision-strategy-consensus' | translate}}</option>
                    </select>
                </div>

                <kc-tooltip>{{:: 'authz-policy-decision-strategy.tooltip' | translate}}</kc-tooltip>
            </div>
            <div class="form-group clearfix">
                <label class="col-md-2 control-label" for="logic">{{:: 'authz-policy-logic' | translate}}</label>

                <div class="col-sm-1">
                    <select class="form-control" id="logic" name="logic"
                            data-ng-model="policy.logic">
                        <option value="POSITIVE">{{:: 'authz-policy-logic-positive' | translate}}</option>
                        <option value="NEGATIVE">{{:: 'authz-policy-logic-negative' | translate}}</option>
                    </select>
                </div>

                <kc-tooltip>{{:: 'authz-policy-logic.tooltip' | translate}}</kc-tooltip>
            </div>
            <input type="hidden" data-ng-model="policy.type"/>
        </fieldset>

        <div class="form-group" data-ng-show="access.manageAuthorization">
            <div class="col-md-10 col-md-offset-2">
                <button kc-save data-ng-disabled="!changed || (selectedPolicies == null || selectedPolicies.length == 0)">{{:: 'save' | translate}}</button>
                <button kc-reset data-ng-disabled="!changed">{{:: 'cancel' | translate}}</button>
            </div>
        </div>
    </form>
</div>

<kc-menu></kc-menu>