<div class="bs-sidebar col-sm-3 " data-ng-include data-src="'partials/realm-menu.html'"></div>
<div id="content-area" class="col-sm-9" role="main">
    <ul class="nav nav-tabs nav-tabs-pf">
        <li><a href="#/realms/{{realm.realm}}">General</a></li>
        <li data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
        <li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
        <li><a href="#/realms/{{realm.realm}}/default-roles">Default Roles</a></li>
        <li class="active"><a href="#/realms/{{realm.realm}}/required-credentials">Credentials</a></li>
        <li><a href="#/realms/{{realm.realm}}/token-settings">Token</a></li>
        <li><a href="#/realms/{{realm.realm}}/keys-settings">Keys</a></li>
        <li><a href="#/realms/{{realm.realm}}/smtp-settings">Email</a></li>
    </ul>

    <div id="content">
        <ol class="breadcrumb">
            <li><a href="#/realms/{{realm.realm}}">{{realm.realm}}</a></li>
            <li><a href="#/realms/{{realm.realm}}">Settings</a></li>
            <li class="active">Required Credentials</li>
        </ol>
        <h2><span>{{realm.realm}}</span> Credentials</h2>
        <form class="form-horizontal" name="realmForm" novalidate>
            <fieldset class="border-top">
                <legend uncollapsed><span class="text">Realm Credentials Settings</span></legend>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="user" class="control-label two-lines">Required User Credentials</label>

                    <div class="col-sm-4">
                        <input id="user" type="text" ui-select2="userCredentialOptions" ng-model="realm.requiredCredentials" placeholder="Type a role and enter">
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="application" class="control-label two-lines">Required Application Credentials</label>

                    <div class="col-sm-4">
                        <input id="application" type="text" ui-select2="userCredentialOptions" ng-model="realm.requiredApplicationCredentials" placeholder="Type a role and enter">
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="col-sm-2 control-label" for="oauth" class="control-label two-lines">Required OAuth Credentials</label>

                    <div class="col-sm-4">
                        <input id="oauth" type="text" ui-select2="userCredentialOptions" ng-model="realm.requiredOAuthClientCredentials" placeholder="Type a role and enter">
                    </div>
                </div>
            </fieldset>
            <fieldset class="border-top">
                <legend uncollapsed><span class="text">Realm Password Policy</span></legend>
                <div class="form-group clearfix">
                    <table class="table">
                        <caption class="hidden">Table of Password Policies</caption>
                        <thead>
                        <tr ng-show="(allPolicies|remove:policy:'name').length > 0">
                            <th colspan="5" class="rcue-table-actions">
                                <div class="actions">
                                    <div class="select-rcue">
                                        <select ng-model="selectedPolicy"
                                                ng-options="(p.name|capitalize) for p in (allPolicies|remove:policy:'name')"
                                                data-ng-change="addPolicy(selectedPolicy); selectedPolicy = null">
                                            <option value="" disabled selected>Add policy...</option>
                                        </select>
                                    </div>
                                </div>
                            </th>
                        </tr>
                        <tr>
                            <th>Policy Type</th>
                            <th>Policy Value</th>
                            <th>Actions</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr ng-repeat="p in policy">
                            <td>
                                <div class="clearfix">
                                    <input class="input-small disabled" type="text" value="{{p.name|capitalize}}" readonly>
                                </div>
                            </td>
                            <td>
                                <input ng-model="p.value" type="number" placeholder="No value assigned" class="input-small" min="1" max="50">
                            </td>
                            <td>
                                <div class="action-div"><i class="icon-question" popover="{{policyMessages[name]}}"
                                                           popover-placement="left" popover-trigger="mouseenter"></i></div>
                                <div class="action-div"><i class="icon-remove" ng-click="removePolicy($index)"></i></div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </fieldset>
            <div class="pull-right form-actions">
                <button kc-reset data-ng-show="changed">Clear changes</button>
                <button kc-save data-ng-show="changed">Save</button>
            </div>
        </form>
    </div>
</div>


<!-- TODO remove once this page is properly styled -->
<style type="text/css">
    .realm-policy .actions > div {
        display: inline-block;
        overflow: hidden;
    }

    .realm-policy td {
        font-size: 10px;
    }

    .realm-policy .action-div {
        display: inline-block;
        margin: 5px;
    }

    .realm-policy .icon-remove, .realm-policy .icon-question {
        cursor: pointer;
    }

</style>