<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>
        <li data-ng-show="create">{{:: 'authz-add-resource' | translate}}</li>
        <li data-ng-hide="create">{{originalResource.name}}</li>
    </ol>

    <h1 data-ng-show="create">{{:: 'authz-add-resource' | translate}}</h1>
    <h1 data-ng-hide="create">{{originalResource.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" data-ng-show="create">*</span></label>
                <div class="col-sm-6">
                    <input class="form-control" type="text" id="name" name="name" data-ng-model="resource.name" autofocus required data-ng-blur="checkNewNameAvailability()">
                </div>
                <kc-tooltip>{{:: 'authz-resource-name.tooltip' | translate}}</kc-tooltip>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label" for="name">{{:: 'displayName' | translate}} <span class="required" data-ng-show="create">*</span></label>
                <div class="col-sm-6">
                    <input class="form-control" type="text" id="displayName" name="displayName" data-ng-model="resource.displayName">
                </div>
                <kc-tooltip>{{:: 'authz-resource-name.tooltip' | translate}}</kc-tooltip>
            </div>
            <div class="form-group" data-ng-hide="create">
                <label class="col-md-2 control-label" for="resource.owner.name">{{:: 'authz-owner' | translate}} </label>
                <div class="col-sm-6">
                    <input class="form-control" type="text" id="resource.owner.name" name="name" data-ng-model="resource.owner.name" autofocus disabled>
                </div>
                <kc-tooltip>{{:: 'authz-resource-owner.tooltip' | translate}}</kc-tooltip>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label" for="type">{{:: 'type' | translate}} </label>
                <div class="col-sm-6">
                    <input class="form-control" type="text" id="type" name="name" data-ng-model="resource.type" autofocus>
                </div>
                <kc-tooltip>{{:: 'authz-resource-type.tooltip' | translate}}</kc-tooltip>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label" for="newUri">{{:: 'authz-uri' | translate}} </label>
                <div class="col-sm-6">
                    <div class="input-group" ng-repeat="(i, uri) in resource.uris track by $index">
                        <input class="form-control" ng-model="resource.uris[i]">
                        <div class="input-group-btn">
                            <button class="btn btn-default" type="button" data-ng-click="deleteUri($index)"><span class="fa fa-minus"></span></button>
                        </div>
                    </div>

                    <div class="input-group">
                        <input class="form-control" ng-model="newUri" id="newUri">
                        <div class="input-group-btn">
                            <button class="btn btn-default" type="button" data-ng-click="newUri.length > 0 && addUri()"><span class="fa fa-plus"></span></button>
                        </div>
                    </div>
                </div>
                <kc-tooltip>{{:: 'authz-resource-uri.tooltip' | translate}}</kc-tooltip>
            </div>
            <div class="form-group clearfix">
                <label class="col-md-2 control-label" for="scopes">{{:: 'authz-scopes' | translate}}</label>

                <div class="col-md-6">
                    <input type="hidden" ui-select2="scopesUiSelect" id="scopes" data-ng-model="resource.scopes" data-placeholder="{{:: 'authz-select-scope' | translate}}..." multiple/>
                </div>

                <kc-tooltip>{{:: 'authz-resource-scopes.tooltip' | translate}}</kc-tooltip>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label" for="iconUri">{{:: 'authz-icon-uri' | translate}} </label>
                <div class="col-sm-6">
                    <input class="form-control" type="text" id="iconUri" name="name" data-ng-model="resource.icon_uri" autofocus>
                </div>
                <kc-tooltip>{{:: 'authz-icon-uri.tooltip' | translate}}</kc-tooltip>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label" for="resource.ownerManagedAccess">{{:: 'authz-resource-user-managed-access-enabled' | translate}}</label>
                <div class="col-md-6">
                    <input ng-model="resource.ownerManagedAccess" id="resource.ownerManagedAccess" onoffswitch />
                </div>
                <kc-tooltip>{{:: 'authz-resource-user-managed-access-enabled.tooltip' | translate}}</kc-tooltip>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">{{:: 'authz-resource-attributes' | translate}}</label>
                <div class="col-md-6">
                    <table class="table table-striped table-bordered">
                        <thead>
                        <tr>
                            <th>{{:: 'key' | translate}}</th>
                            <th>{{:: 'value' | translate}}</th>
                            <th>{{:: 'actions' | translate}}</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr ng-repeat="(key, value) in resource.attributes | toOrderedMapSortedByKey">
                            <td>{{key}}</td>
                            <td><input ng-model="resource.attributes[key]" class="form-control" type="text" name="{{key}}" id="attribute-{{key}}" /></td>
                            <td class="kc-action-cell" id="removeAttribute" data-ng-click="removeAttribute(key)">{{:: 'delete' | translate}}</td>
                        </tr>
                        <tr>
                            <td><input ng-model="newAttribute.key" class="form-control" type="text" id="newAttributeKey" /></td>
                            <td><input ng-model="newAttribute.value" class="form-control" type="text" id="newAttributeValue" /></td>
                            <td class="kc-action-cell" id="addAttribute" data-ng-click="addAttribute()" data-ng-disabled="!newAttribute.key.length || !newAttribute.value.length">{{:: 'add' | translate}}</td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <kc-tooltip>{{:: 'authz-resource-attributes.tooltip' | translate}}</kc-tooltip>
            </div>
        </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">{{:: 'save' | translate}}</button>
                <button kc-reset data-ng-disabled="!changed">{{:: 'cancel' | translate}}</button>
            </div>
        </div>
    </form>
</div>

<kc-menu></kc-menu>