<div class="bs-sidebar col-md-3 clearfix" data-ng-include data-src="resourceUrl + '/partials/realm-menu.html'"></div>
<div id="content-area" class="col-md-9" role="main">
    <kc-navigation-client></kc-navigation-client>
    <div id="content">
        <ol class="breadcrumb" data-ng-show="create">
            <li><a href="#/realms/{{realm.realm}}/clients">Clients</a></li>
            <li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}">{{client.clientId}}</a></li>
            <li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/roles">Roles</a></li>
            <li class="active">Add role</li>
        </ol>

        <ol class="breadcrumb" data-ng-hide="create">
            <li><a href="#/realms/{{realm.realm}}/clients">Clients</a></li>
            <li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}">{{client.clientId}}</a></li>
            <li><a href="#/realms/{{realm.realm}}/clients/{{client.id}}/roles">Roles</a></li>
            <li class="active">{{role.name}}</li>
        </ol>

        <h2 data-ng-hide="create" class="pull-left"><span>{{client.clientId}}</span> {{role.name}} Client Role</h2>
        <h2 data-ng-show="create" class="pull-left"><span>{{client.clientId}}</span> Add Client Role</h2>
        <p class="subtitle" data-ng-show="create"><span class="required">*</span> Required fields</p>

        <form class="form-horizontal" name="realmForm" novalidate kc-read-only="!access.manageClients">
            
            <fieldset class="border-top">
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="name">Role name <span class="required" data-ng-show="create">*</span></label>

                    <div class="col-sm-4">
                        <input class="form-control" type="text" id="name" name="name" data-ng-model="role.name" autofocus
                               required data-ng-readonly="!create">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="description">Description </label>

                    <div class="col-sm-4">
                        <textarea  class="form-control" rows="5" cols="50" id="description" name="description" data-ng-model="role.description"></textarea>
                        <!-- Replaced by the textarea above <input type="text" id="description" name="description" data-ng-model="role.description" autofocus
                                                               required> -->
                    </div>
                </div>
                <div class="form-group clearfix block" data-ng-hide="create">
                    <label class="col-sm-2 control-label" for="compositeSwitch" class="control-label">Composite Roles</label>
                    <div class="col-sm-4">
                        <input ng-model="compositeSwitch" name="compositeSwitch" id="compositeSwitch" ng-disabled="compositeSwitchDisabled" onoffswitch />
                    </div>
                    <span tooltip-placement="right" tooltip="When this role is (un)assigned to a user any role associated with it will be (un)assigned implicitly." class="fa fa-info-circle"></span>
                </div>
            </fieldset>

            <fieldset data-ng-show="!create && (compositeSwitch || role.composite)">
                <legend uncollapsed><span class="text">Composite Realm Roles</span> </legend>
                <div class="form-group col-sm-10">
                    <div class="controls changing-selectors">
                        <div class="select-title">
                            <label class="control-label" for="available">Available Roles <span tooltip-placement="right" tooltip="Realm level roles associated with this composite role." class="fa fa-info-circle"></span></label>
                            <select id="available" class="form-control" multiple size="5"
                                    ng-multiple="true"
                                    ng-model="selectedRealmRoles"
                                    ng-options="r.name for r in realmRoles">
                            </select>
                        </div>
                        <div class="middle-buttons kc-vertical">
                            <button class="btn btn-default" type="submit" ng-click="addRealmRole()" tooltip="Associate role" tooltip-placement="right">
                                <span class="kc-icon-arrow-right">Move right</span>
                            </button>
                            <button class="btn btn-default" type="submit" ng-click="deleteRealmRole()" tooltip="Disassociate role" tooltip-placement="left">
                                <span class="kc-icon-arrow-left">Move left</span>
                            </button>
                        </div>
                        <div class="select-title">
                            <label class="control-label" for="assigned">Associated Roles  <span tooltip-placement="right" tooltip="Realm level roles associated with this composite role." class="fa fa-info-circle"></span></label>
                            <select id="assigned" class="form-control" multiple size=5
                                    ng-multiple="true"
                                    ng-model="selectedRealmMappings"
                                    ng-options="r.name for r in realmMappings">
                            </select>
                        </div>
                    </div>
                </div>
            </fieldset>

            <fieldset ng-show="clients.length > 0 && !create && (compositeSwitch || role.composite)">
                <legend uncollapsed><span class="text">Composite Client Roles</span> </legend>
                <div class="form-group input-select">
                    <label class="col-sm-2 control-label" for="clients">Client <span tooltip-placement="right" tooltip="Select an client to view/modify roles associated with this composite." class="fa fa-info-circle"></span></label>
                    <div class="col-sm-4">
                        <div class="input-group">
                            <div class="select-kc">
                                <select id="clients" name="clients" ng-change="changeClient()" ng-model="compositeClient" ng-options="c.clientId for c in clients">
                                    <option value="" selected> Select a Client...</option>
                                </select>
                            </div>

                        </div>
                    </div>
                </div>
                <div class="form-group" ng-show="compositeClient">
                    <div class="controls changing-selectors client col-sm-10">
                        <div class="select-title">
                            <label class="control-label" for="available-client">Available Roles <span tooltip-placement="right" tooltip="Roles from this client that you can associate to this composite role." class="fa fa-info-circle"></span></label>
                            <select id="available-client" class="form-control" multiple size="5"
                                    ng-multiple="true"
                                    ng-model="selectedClientRoles"
                                    ng-options="r.name for r in clientRoles">
                            </select>
                        </div>
                        <div class="middle-buttons kc-vertical">
                            <button class="btn btn-default" type="submit" ng-click="addClientRole()" tooltip="Associate role" tooltip-placement="right">
                                <span class="kc-icon-arrow-right">Move right</span>
                            </button>
                            <button class="btn btn-default" type="submit" ng-click="deleteClientRole()" tooltip="Disassociate role" tooltip-placement="left">
                                <span class="kc-icon-arrow-left">Move left</span>
                            </button>
                        </div>
                        <div class="select-title">
                            <label class="control-label" for="assigned-client">Associated Roles <span tooltip-placement="right" tooltip="Client roles associated with this composite role." class="fa fa-info-circle"></span></label>
                            <select id="assigned-client" class="form-control" multiple size=5
                                    ng-multiple="true"
                                    ng-model="selectedClientMappings"
                                    ng-options="r.name for r in clientMappings">
                            </select>
                        </div>
                    </div>
                </div>
            </fieldset>

            <div class="pull-right form-actions" data-ng-show="create && access.manageClients">
                <button kc-cancel data-ng-click="cancel()">Cancel</button>
                <button kc-save data-ng-show="changed">Save</button>
            </div>
            <div class="pull-right form-actions" data-ng-show="!create && access.manageClients">
                <button kc-reset data-ng-show="changed">Clear changes</button>
                <button kc-save  data-ng-show="changed">Save</button>
                <button kc-delete data-ng-click="remove()" data-ng-hide="changed">Delete</button>
            </div>

        </form>
    </div>
</div>