<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>
    </ol>

    <kc-tabs-resource-server></kc-tabs-resource-server>

    <table class="table table-striped table-bordered">
        <thead>
            <tr>
                <th class="kc-table-actions" colspan="5">
                    <div class="form-inline">
                        <div class="form-group">
                            {{:: 'filter' | translate}}:&nbsp;&nbsp;
                            <div class="input-group">
                                <input type="text" placeholder="{{:: 'name' | translate}}" data-ng-model="query.name" class="form-control search" onkeydown="if (event.keyCode == 13) document.getElementById('policySearch').click()">
                                <div class="input-group-addon">
                                    <i class="fa fa-search" id="policySearch" type="submit" data-ng-click="firstPage()"></i>
                                </div>
                            </div>
                            <div class="input-group">
                                <input type="text" placeholder="{{:: 'authz-resource' | translate}}" data-ng-model="query.resource" class="form-control search" onkeydown="if (event.keyCode == 13) document.getElementById('policySearch').click()">
                                <div class="input-group-addon">
                                    <i class="fa fa-search" type="submit" data-ng-click="firstPage()"></i>
                                </div>
                            </div>
                            <div class="input-group">
                                <input type="text" placeholder="{{:: 'authz-scope' | translate}}" data-ng-model="query.scope" class="form-control search" onkeydown="if (event.keyCode == 13) document.getElementById('policySearch').click()">
                                <div class="input-group-addon">
                                    <i class="fa fa-search" type="submit" data-ng-click="firstPage()"></i>
                                </div>
                            </div>
                            <div class="input-group">
                                <select class="form-control search" data-ng-model="query.type"
                                        ng-options="p.type as p.name for p in policyProviders track by p.type" data-ng-change="firstPage()">
                                    <option value="" selected ng-click="query.type = ''">{{:: 'authz-all-types' | translate}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="pull-right">
                            <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);">
                                <option value="" disabled selected>{{:: 'authz-create-policy' | translate}}...</option>
                            </select>
                        </div>
                    </div>
                </th>
            </tr>
            <tr data-ng-hide="policies.length == 0">
                <th width="1%"></th>
                <th>{{:: 'name' | translate}}</th>
                <th>{{:: 'description' | translate}}</th>
                <th width="7%">{{:: 'type' | translate}}</th>
                <th width="6%" style="text-align: center;">{{:: 'actions' | translate}}</th>
            </tr>
        </thead>
        <tfoot data-ng-show="policies && (policies.length >= query.max || query.first > 0)">
        <tr>
            <td colspan="5">
                <div class="table-nav">
                    <button data-ng-click="firstPage()" class="first" ng-disabled="query.first == 0">{{:: 'first-page' | translate}}</button>
                    <button data-ng-click="previousPage()" class="prev" ng-disabled="query.first == 0">{{:: 'previous-page' | translate}}</button>
                    <button data-ng-click="nextPage()" class="next" ng-disabled="policies.length < query.max">{{:: 'next-page' | translate}}</button>
                </div>
            </td>
        </tr>
        </tfoot>
        <tbody>
            <tr ng-repeat-start="policy in policies | filter: {name: search.name, type: search.type} | orderBy:'name'" data-ng-click="showDetails(policy, $event);" style="cursor: pointer">
                <td>
                    <span ng-if="!policy.details || !policy.details.loaded" class="fa fa-angle-right"></span>
                    <span ng-if="policy.details && policy.details.loaded" class="fa fa-angle-right fa-angle-down"></span>
                </td>
                <td><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/policy/{{policy.type}}/{{policy.id}}">{{policy.name}}</a></td>
                <td>{{policy.description}}</td>
                <td>{{policy.type}}</td>
                <td align="center">
                    <div class="dropdown dropdown-kebab-pf">
                        <button class="btn btn-default" ng-click="delete(policy);">{{:: 'delete' | translate}}
                        </button>
                    </div>
                </td>
            </tr>
            <tr ng-if="policy.details && policy.details.loaded" ng-repeat-end="">
                <td colspan="5" style="background-color: #ffffff">
                    <div class="list-group-item-container container-fluid">
                        <div class="close" data-ng-click="showDetails(policy, $event);" style="padding-top: 10px">
                            <span class="pficon pficon-close"></span>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <dl class="dl-horizontal">
                                    <dt>Dependent Policies</dt>
                                    <dd>
                                        <span data-ng-show="policy.dependentPolicies && !policy.dependentPolicies.length">{{:: 'authz-no-policies-available' | translate}}</span>
                                        <span ng-repeat="dep in policy.dependentPolicies" data-ng-show="policy.dependentPolicies.length > 0"><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/{{dep.type == 'scope' || dep.type == 'resource' ? 'permission' : 'policy'}}/{{dep.type}}/{{dep.id}}">{{dep.name}}</a>{{$last ? '' : ', '}}</span>
                                    </dd>
                                </dl>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
            <tr data-ng-show="(policies | filter:search).length == 0">
                <td class="text-muted" colspan="3" data-ng-show="search.name">{{:: 'no-results' | translate}}</td>
                <td class="text-muted" colspan="3" data-ng-hide="search.name">{{:: 'authz-no-policies-available' | translate}}</td>
            </tr>
        </tbody>
    </table>
</div>

<kc-menu></kc-menu>