<div id="wrapper" class="container social-provider">
    <div class="row">
        <div class="bs-sidebar col-md-3 clearfix" data-ng-include data-src="'partials/realm-menu.html'"></div>
        <div id="content-area" class="col-md-9" role="main">
            <div class="top-nav" data-ng-hide="createRealm">
                <ul class="rcue-tabs">
                    <li><a href="#/realms/{{realm.realm}}">General</a></li>
                    <li class="active" data-ng-show="realm.social"><a href="#/realms/{{realm.realm}}/social-settings">Social</a></li>
                    <li data-ng-show="realm.registrationAllowed"><a href="#/realms/{{realm.realm}}/registration-settings">Registration</a></li>
                    <li><a href="#/realms/{{realm.realm}}/roles">Roles</a></li>
                    <li><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">SMTP</a></li>
                </ul>
            </div>
            <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>
                <form name="realmForm" novalidate>
                    <fieldset>
                        <div>
                            <table>
                                <caption class="hidden">Table of social providers</caption>
                                <thead>
                                <tr>
                                    <th colspan="5" class="rcue-table-actions">
                                        <div class="actions">
                                            <div class="select-rcue">
                                                <select ng-model="newProviderId"
                                                        ng-options="p as allProviders[p] for p in unsetProviders"
                                                        placeholder="Please select"></select>
                                            </div>
                                            <div>
                                                <button ng-click="addProvider()" ng-disabled="">Add Provider</button>
                                            </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="input-small disabled" type="text" value="{{allProviders[pId]}}" readonly>
                                        </div>
                                    </td>
                                    <td>
                                        <input class="input-small" type="text" placeholder="Key" ng-model="realm.socialProviders[pId+'.key']"
                                               ng-class="{'dirty': postSaveProviders.indexOf(pId) > -1}" required>
                                    </td>
                                    <td>
                                        <input class="input-small" 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="icon-question" ng-click="openHelp(pId)"></i></div>
                                        <div class="action-div"><i class="icon-remove" ng-click="removeProvider(pId)"></i></div>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </fieldset>
                    <div class="form-actions">
                        <button type="submit" kc-save class="primary" data-ng-show="changed">Save
                            changes
                        </button>
                        <button type="submit" kc-reset data-ng-show="changed">Clear changes
                        </button>
                    </div>
                </form>
            </div>
        </div>
        <div id="container-right-bg"></div>
    </div>
</div>

<div modal="providerHelpModal" close="closeHelp()" options="opts">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h3>Configure {{helpPId}}</h3>
            </div>
            <div class="modal-body">
                <div ng-include src="'partials/provider/'+ helpPId +'-help.html'"></div>
            </div>
            <div class="modal-footer">
                <button ng-click="closeHelp()">Close</button>
            </div>
        </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>