<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">
    <data-kc-navigation data-kc-current="social" data-kc-realm="realm.realm" data-kc-social="realm.social"></data-kc-navigation>
    <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">Social</li>
        </ol>
        <h2><span>{{realm.realm}}</span> Social Providers Settings</h2>

        <div class="alert alert-info alert-dismissable">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">
                <span class="pficon pficon-close"></span>
            </button>
            <span class="pficon pficon-info"></span>
            <strong>Social Callback URL:</strong> {{callbackUrl}}</p>
        </div>

        <form name="realmForm" novalidate>
            <fieldset>
                <div>
                    <table class="table">
                        <caption class="hidden">Table of social providers</caption>
                        <thead>
                        <tr>
                            <th colspan="5" class="kc-table-actions">
                                <div class="pull-right">
                                    <div class="select-kc">
                                        <select ng-model="newProviderId"
                                                ng-options="(p|capitalize) for p in (allProviders|remove:configuredProviders)"
                                                data-ng-change="addProvider(newProviderId); newProviderId = null">
                                            <option value="" disabled selected>Add provider...</option>
                                        </select>
                                    </div>
                                </div>
                            </th>
                        </tr>
                        <tr ng-show="configuredProviders.length > 0">
                            <th>Provider</th>
                            <th>Key <span class="required">*</span></th>
                            <th>Secret <span class="required">*</span></th>
                            <th colspan="1">Actions</th>
                        </tr>
                        </thead>
                        <tbody ng-show="configuredProviders.length > 0">
                        <tr ng-repeat="pId in configuredProviders">
                            <td>
                                <div class="clearfix">
                                    <input class="form-control input-small disabled" type="text" value="{{pId|capitalize}}" readonly>
                                </div>
                            </td>
                            <td>
                                <input class="form-control" type="text" placeholder="Key" ng-model="realm.socialProviders[pId+'.key']"
                                       ng-class="{'dirty': postSaveProviders.indexOf(pId) > -1}" required>
                            </td>
                            <td>
                                <input class="form-control" type="text" placeholder="Secret" ng-model="realm.socialProviders[pId+'.secret']"
                                       ng-class="{'dirty': postSaveProviders.indexOf(pId) > -1}" required>
                            </td>
                            <td>
                                <div class="action-div"><i class="pficon pficon-delete" ng-click="removeProvider(pId)"></i></div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </fieldset>

            <div class="pull-right form-actions">
                <button type="submit" kc-reset data-ng-show="changed">Clear changes</button>
                <button type="submit" kc-save class="primary" data-ng-show="changed">Save changes</button>
            </div>
        </form>
    </div>
</div>
</div>

<!-- TODO remove once this page is properly styled -->
<style type="text/css">
    .social-provider input.ng-invalid.dirty,
    .social-provider input.ng-invalid.ng-dirty {
        background-color: #FFEEEE;
    }

    .social-provider .actions > div {
        display: inline-block;
        overflow: hidden;
    }

    .social-provider td {
        font-size: 10px;
    }

    .social-provider .action-div {
        display: inline-block;
        margin: 5px;
    }

    .social-provider .icon-remove, .social-provider .icon-question {
        cursor: pointer;
    }
</style>