<div class="modal-header">
    <button type="button" class="close" ng-click="close()" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title"><i class="fa fa-user"></i> Edit User <small>{{email}}</small></h4>
</div>
<form name="form" ng-submit="form.$valid && submit()" api-form="submitPromise" autocomplete="off">
    <div class="modal-body">
        <div class="callout callout-danger validation-errors" ng-show="form.$errors">
            <h4>Errors have occurred</h4>
            <ul>
                <li ng-repeat="e in form.$errors">{{e}}</li>
            </ul>
        </div>
        <h4>User Type</h4>
        <div class="form-group">
            <div class="radio">
                <label>
                    <input type="radio" id="user-type" ng-model="type" name="Type" value="2" ng-checked="type === 2">
                    <strong>User</strong> - A regular user with access to your organization's collections.
                </label>
            </div>
            <div class="radio">
                <label>
                    <input type="radio" ng-model="type" name="Type" value="1" ng-checked="type === 1">
                    <strong>Admin</strong> - Admins can manage collections and users for your organization.
                </label>
            </div>
            <div class="radio">
                <label>
                    <input type="radio" ng-model="type" name="Type" value="0" ng-checked="type === 0">
                    <strong>Owner</strong> - The highest access user that can manage all aspects of your organization.
                </label>
            </div>
        </div>
        <h4>Access</h4>
        <div class="radio">
            <label>
                <input type="radio" ng-model="accessAll" name="AccessAll"
                       ng-value="true" ng-checked="accessAll">
                This user can access and modify <u>all items</u>.
            </label>
        </div>
        <div class="radio">
            <label>
                <input type="radio" ng-model="accessAll" name="AccessAll"
                       ng-value="false" ng-checked="!accessAll">
                This user can access only the selected collections.
            </label>
        </div>
        <div ng-show="!accessAll">
            <div ng-show="loading && !collections.length">
                Loading collections...
            </div>
            <div ng-show="!loading && !collections.length">
                <p>No collections for your organization.</p>
            </div>
            <div class="table-responsive" ng-show="collections.length" style="margin: 0;">
                <table class="table table-striped table-hover" style="margin: 0;">
                    <thead>
                        <tr>
                            <th style="width: 40px;">
                                <input type="checkbox"
                                       ng-checked="allSelected()"
                                       ng-click="toggleCollectionSelectionAll($event)">
                            </th>
                            <th>Name</th>
                            <th style="width: 100px; text-align: center;">Read Only</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="collection in collections | orderBy: ['name']">
                            <td valign="middle">
                                <input type="checkbox"
                                       name="selectedCollections[]"
                                       value="{{collection.id}}"
                                       ng-checked="collectionSelected(collection)"
                                       ng-click="toggleCollectionSelection(collection.id)">
                            </td>
                            <td valign="middle">
                                {{collection.name}}
                            </td>
                            <td style="text-align: center;" valign="middle">
                                <input type="checkbox"
                                       name="selectedCollectionsReadonly[]"
                                       value="{{collection.id}}"
                                       ng-disabled="!collectionSelected(collection)"
                                       ng-checked="collectionSelected(collection) && selectedCollections[collection.id].readOnly"
                                       ng-click="toggleCollectionReadOnlySelection(collection.id)">
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button type="submit" class="btn btn-primary btn-flat" ng-disabled="form.$loading">
            <i class="fa fa-refresh fa-spin loading-icon" ng-show="form.$loading"></i>Submit
        </button>
        <button type="button" class="btn btn-default btn-flat" ng-click="close()">Close</button>
    </div>
</form>
