<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.id}}">General</a></li>
                    <li class="active" data-ng-show="realm.social"><a href="#/realms/{{realm.id}}/social-settings">Social</a></li>
                    <li><a href="#/realms/{{realm.id}}/roles">Roles</a></li>
                    <li><a href="#/realms/{{realm.id}}/required-credentials">Credentials</a></li>
                    <li><a href="#/realms/{{realm.id}}/token-settings">Token</a></li>
                </ul>
            </div>
            <div id="content">
                <ol class="breadcrumb">
                    <li><a href="#/realms/{{realm.id}}">{{realm.realm}}</a></li>
                    <li><a href="#/realms/{{realm.id}}">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 for p in unsetProviders"></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" placeholder="Key" value="{{pId}}" readonly>
                                        </div>
                                    </td>
                                    <td>
                                        <input class="input-small" type="text" placeholder="Key" ng-model="realm.socialProviders[pId+'.key']"
                                               ng-class="{'dirty': saveClicked}" required>
                                    </td>
                                    <td>
                                        <input class="input-small" type="text" placeholder="Secret" ng-model="realm.socialProviders[pId+'.secret']"
                                               ng-class="{'dirty': saveClicked}" 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" data-ng-click="save()" class="primary" data-ng-show="changed">Save
                            changes
                        </button>
                        <button type="submit" data-ng-click="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 class="btn" 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;
    }
</style>