<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-share-alt"></i> Share Item <small>{{cipher.name}}</small></h4>
</div>
<form name="form" ng-submit="form.$valid && submit(model)" api-form="submitPromise" autocomplete="off">
    <div class="modal-body">
        <p>Choose an organization that you wish to share this item with.</p>
        <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>
        <p ng-show="loading">Loading...</p>
        <div ng-show="!loading && !organizations.length" class="callout callout-default">
            <h4><i class="fa fa-info-circle"></i> No Organizations</h4>
            <p>You do not belong to any organizations. Organizations allow you to share items with other Bitwarden users.</p>
            <a ng-click="createOrg()" class="btn btn-default btn-flat">
                Create an Organization
            </a>
        </div>
        <div ng-show="!loading && organizations.length">
            <div class="form-group">
                <label for="organization">Organization</label> <span>*</span>
                <select id="organization" name="Organization" ng-model="model.organizationId" class="form-control"
                        ng-change="orgChanged()">
                    <option ng-repeat="org in organizations | orderBy: ['name']" value="{{org.id}}">{{org.name}}</option>
                </select>
            </div>
            <h4 ng-hide="!loadingCollections && !orgCollections.length">Collection Access</h4>
            <div ng-show="loadingCollections && !orgCollections.length">
                <p>Loading...</p>
            </div>
            <div ng-show="!loadingCollections && !orgCollections.length" class="callout callout-default">
                <h4><i class="fa fa-info-circle"></i> No Collections</h4>
                <p>You do not have write access to any collections for this organization.</p>
            </div>
            <div class="table-responsive" ng-show="orgCollections.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>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="collection in orgCollections =
                        (collections | filter: { organizationId: model.organizationId } | 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" ng-click="toggleCollectionSelection(collection.id)">
                                {{collection.name}}
                            </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>Save
        </button>
        <button type="button" class="btn btn-default btn-flat" ng-click="close()">Close</button>
    </div>
</form>
