<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/resource">{{::
            'authz-resources' | 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="6">
                <div class="form-inline">
                    {{:: 'filter' | translate}}:&nbsp;&nbsp;
                    <div class="form-group">
                        <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('resourceSearch').click()">
                            <div class="input-group-addon">
                                <i class="fa fa-search" id="resourceSearch" type="submit"
                                   data-ng-click="firstPage()"></i>
                            </div>
                        </div>
                        <div class="input-group">
                            <input type="text" placeholder="{{:: 'type' | translate}}" data-ng-model="query.type"
                                   class="form-control search"
                                   onkeydown="if (event.keyCode == 13) document.getElementById('resourceSearch').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-uri' | translate}}" data-ng-model="query.uri"
                                   class="form-control search"
                                   onkeydown="if (event.keyCode == 13) document.getElementById('resourceSearch').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-owner' | translate}}"
                                   data-ng-model="query.owner" class="form-control search"
                                   onkeydown="if (event.keyCode == 13) document.getElementById('resourceSearch').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('resourceSearch').click()">
                            <div class="input-group-addon">
                                <i class="fa fa-search" type="submit" data-ng-click="firstPage()"></i>
                            </div>
                        </div>
                    </div>
                    <div class="pull-right">
                        <a id="createResource" class="btn btn-default"
                           href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/resource/create">{{::
                            'create' | translate}}</a>
                    </div>
                </div>
            </th>
        </tr>
        <tr data-ng-hide="resources.length == 0">
            <th width="1%"></th>
            <th>{{:: 'name' | translate}}</th>
            <th>{{:: 'type' | translate}}</th>
            <th>{{:: 'authz-uris' | translate}}</th>
            <th>{{:: 'authz-owner' | translate}}</th>
            <th width="11%" style="text-align: center">{{:: 'actions' | translate}}</th>
        </tr>
        </thead>
        <tfoot data-ng-show="resources && (resources.length >= query.max || query.first > 0)">
        <tr>
            <td colspan="6">
                <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="resources.length < query.max">{{::
                        'next-page' | translate}}
                    </button>
                </div>
            </td>
        </tr>
        </tfoot>
        <tbody>
        <tr ng-repeat-start="resource in resources | filter:search | orderBy:'name'" data-ng-click="showDetails(resource, $event);" style="cursor: pointer;">
            <td>
                <span ng-if="!resource.details || !resource.details.loaded" class="fa fa-angle-right"></span>
                <span ng-if="resource.details && resource.details.loaded" class="fa fa-angle-right fa-angle-down"></span>
            </td>
            <td>
                <a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/resource/{{resource._id}}">{{resource.name}}</a>
            </td>
            <td>
                <span data-ng-show="resource.type">{{resource.type}}</span>
                <span data-ng-show="!resource.type">{{:: 'authz-no-type-defined' | translate}}</span>
            </td>
            <td>
                <span data-ng-show="resource.uris.length == 0">{{:: 'authz-no-uri-defined' | translate}}</span>
                <span data-ng-show="resource.uris.length == 1">{{resource.uris[0]}}</span>
                <span data-ng-show="resource.uris.length > 1">{{resource.uris.length}} {{:: 'authz-uris' | translate}}</span>
            </td>
            <td>{{resource.owner.name}}</td>
            <td align="center">
                <div class="dropdown dropdown-kebab-pf">
                    <button class="btn btn-default" ng-click="createPolicy(resource);">{{:: 'authz-create-permission' | translate}}
                    </button>
                    <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"
                            aria-haspopup="true" aria-expanded="true">
                        <span class="fa fa-ellipsis-v"></span></button>
                    <ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownKebabRight">
                        <li><a href="" ng-click="delete(resource);">{{:: 'delete' | translate}}</a></li>
                    </ul>
                </div>
            </td>
        </tr>
        <tr ng-if="resource.details && resource.details.loaded" ng-repeat-end="">
            <td colspan="6" style="background-color: #ffffff">
                <div class="list-group-item-container container-fluid">
                    <div class="close" data-ng-click="showDetails(resource, $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>{{:: 'authz-scopes' | translate}}</dt>
                                <dd>
                                    <span data-ng-show="resource.scopes && !resource.scopes.length">{{:: 'authz-no-scopes-assigned' | translate}}</span>
                                    <span ng-repeat="scope in resource.scopes" data-ng-show="resource.scopes.length > 0"><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/scope/{{scope.id}}">{{scope.name}}</a>{{$last ? '' : ', '}} </span>
                                </dd>
                                <dt>{{:: 'authz-associated-permissions' | translate}}</dt>
                                <dd>
                                    <span data-ng-show="resource.policies && !resource.policies.length">{{:: 'authz-no-permission-assigned' | translate}}</span>
                                    <span ng-repeat="policy in resource.policies" data-ng-show="resource.policies.length > 0"><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/authz/resource-server/permission/{{policy.type}}/{{policy.id}}">{{policy.name}}</a>{{$last ? '' : ', '}}</span>
                                </dd>
                                <dt>{{:: 'authz-uris' | translate}}</dt>
                                <dd>
                                    <span data-ng-show="resource.uris && !resource.uris.length">{{:: 'authz-no-uri-defined' | translate}}</span>
                                    <span ng-repeat="uri in resource.uris" data-ng-show="resource.uris.length > 0">{{uri}}{{$last ? '' : ', '}}</span>
                                </dd>
                            </dl>
                        </div>
                    </div>
                </div>
            </td>
        </tr>
        <tr data-ng-show="(resources | filter:search).length == 0">
            <td class="text-muted" colspan="6" data-ng-show="search.name">{{:: 'no-results' | translate}}</td>
            <td class="text-muted" colspan="6" data-ng-hide="search.name">{{:: 'authz-no-resources-available' |
                translate}}
            </td>
        </tr>
        </tbody>
    </table>
</div>

<kc-menu></kc-menu>
