<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> Invite User</h4>
</div>
<form name="inviteForm" ng-submit="inviteForm.$valid && submit(model)" api-form="submitPromise" autocomplete="off">
    <div class="modal-body">
        <p>
            Invite a new user to your organization by entering their Bitwarden account email address below. If they do not have
            a Bitwarden account already, they will be prompted to create a new account.
        </p>
        <div class="callout callout-danger validation-errors" ng-show="inviteForm.$errors">
            <h4>Errors have occurred</h4>
            <ul>
                <li ng-repeat="e in inviteForm.$errors">{{e}}</li>
            </ul>
        </div>
        <div class="form-group" show-errors>
            <label for="emails">Email</label>
            <input type="text" id="emails" name="Emails" ng-model="model.emails" class="form-control" required api-field />
            <p class="help-block">You can invite up to 20 users at a time by comma separating a list of email addresses.</p>
        </div>
        <h4>User Type</h4>
        <div class="form-group">
            <div class="radio">
                <label>
                    <input type="radio" id="user-type" ng-model="model.type" name="Type" value="User">
                    <strong>User</strong> - A regular user with access to your organization's collections.
                </label>
            </div>
            <div class="radio">
                <label>
                    <input type="radio" ng-model="model.type" name="Type" value="Admin">
                    <strong>Admin</strong> - Admins can manage collections and users for your organization.
                </label>
            </div>
            <div class="radio">
                <label>
                    <input type="radio" ng-model="model.type" name="Type" value="Owner">
                    <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="model.accessAll" name="AccessAll"
                       ng-value="true" ng-checked="model.accessAll">
                This user can access and modify <u>all items</u>.
            </label>
        </div>
        <div class="radio">
            <label>
                <input type="radio" ng-model="model.accessAll" name="AccessAll"
                       ng-value="false" ng-checked="!model.accessAll">
                This user can access only the selected collections.
            </label>
        </div>
        <div ng-show="!model.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'] track by collection.id">
                            <td style="width: 40px;" 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="width: 100px; 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="inviteForm.$loading">
            <i class="fa fa-refresh fa-spin loading-icon" ng-show="inviteForm.$loading"></i>Send Invite
        </button>
        <button type="button" class="btn btn-default btn-flat" ng-click="close()">Close</button>
    </div>
</form>
