<div id="space-permission-modal" class="modal" tabindex="-1" role="dialog">
	<div class="modal-dialog modal-80">
		<div class="modal-content">
			<div class="modal-header">Space Permissions</div>
			<div class="modal-body" style="overflow-x: auto;">
				<div class="space-admin table-responsive">

					<table class="table table-hover permission-table mb-3">
						<thead>
							<tr>
								<th></th>
								<th colspan="3">Spaces</th>
								<th colspan="9" class="text-info">Documents</th>
							</tr>
							<tr>
								<th></th>
								<th>View</th>
								<th>Manage</th>
								<th>Owner</th>
								<th class="text-info">Create</th>
								<th class="text-info">Edit</th>
								<th class="text-info">Delete</th>
								<th class="text-info">Move</th>
								<th class="text-info">Copy</th>
								<th class="text-info">Templates</th>
								<th class="text-info">Approval</th>
								<th class="text-info">Lifecycle</th>
								<th class="text-info">Versions</th>
							</tr>
						</thead>
						<tbody>
							{{#each spacePermissions as |permission|}}
								<tr>
									<td>
										{{#if (eq permission.who "role")}}
											<span class="button-icon-blue button-icon-small align-middle">
												<i class="material-icons">people</i>
											</span>
											<span class="color-blue">&nbsp;{{permission.name}}
												<small class="form-text text-muted d-inline-block">({{permission.members}})</small>
											</span>
										{{else}}
											{{#if (eq permission.whoId constants.EveryoneUserId)}}
												<span class="button-icon-green button-icon-small align-middle">
													<i class="material-icons">language</i>
												</span>
												<span class="color-green">&nbsp;{{permission.name}}</span>
											{{else}}
												<span class="button-icon-gray button-icon-small align-middle">
													<i class="material-icons">person</i>
												</span>
												<span class="">&nbsp;{{permission.name}}
													{{#if (eq permission.whoId session.user.id)}}
														<small class="form-text text-muted d-inline-block">(you)</small>
													{{/if}}
												</span>
											{{/if}}
										{{/if}}
									</td>
									<td>{{input type="checkbox" id=(concat 'space-role-view-' permission.whoId) checked=permission.spaceView}}</td>
									<td>{{input type="checkbox" id=(concat 'space-role-manage-' permission.whoId) checked=permission.spaceManage}}</td>
									<td>{{input type="checkbox" id=(concat 'space-role-owner-' permission.whoId) checked=permission.spaceOwner}}</td>
									<td>{{input type="checkbox" id=(concat 'doc-role-add-' permission.whoId) checked=permission.documentAdd}}</td>
									<td>{{input type="checkbox" id=(concat 'doc-role-edit-' permission.whoId) checked=permission.documentEdit}}</td>
									<td>{{input type="checkbox" id=(concat 'doc-role-delete-' permission.whoId) checked=permission.documentDelete}}</td>
									<td>{{input type="checkbox" id=(concat 'doc-role-move-' permission.whoId) checked=permission.documentMove}}</td>
									<td>{{input type="checkbox" id=(concat 'doc-role-copy-' permission.whoId) checked=permission.documentCopy}}</td>
									<td>{{input type="checkbox" id=(concat 'doc-role-template-' permission.whoId) checked=permission.documentTemplate}}</td>
									<td>{{input type="checkbox" id=(concat 'doc-role-approve-' permission.whoId) checked=permission.documentApprove}}</td>
									<td>{{input type="checkbox" id=(concat 'doc-role-lifecycle-' permission.whoId) checked=permission.documentLifecycle}}</td>
									<td>{{input type="checkbox" id=(concat 'doc-role-version-' permission.whoId) checked=permission.documentVersion}}</td>
								</tr>
							{{/each}}
						</tbody>
					</table>

					<div class="container-fluid">
						<div class="row justify-content-center">
							<div class="col-6">
								<div class="form-group">
									{{focus-input id="user-search" type="text" class="form-control mousetrap" placeholder="Search users..." value=searchText key-up=(action 'onSearch')}}
									<small class="form-text text-muted">firstname, lastname, email</small>
								</div>
								{{#each filteredUsers as |user|}}
									<div class="row my-3">
										<div class="col-10">{{user.fullname}}</div>
										<div class="col-2 text-right">
											<button class="btn btn-primary" {{action 'onAdd' user}}>Add</button>
										</div>
									</div>
								{{/each}}
							</div>
						</div>
					</div>

				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Cancel</button>
				<button type="button" class="btn btn-success" onclick= {{action 'setPermissions'}}>Save</button>
			</div>
		</div>
	</div>
</div>