<div class="grid-container-8-2">
	<div class="grid-cell-1 grid-cell-middle">
		<div class="section-heading">
			<div class="page-header">
				<span class="page-number">{{page.numbering}}</span>
				<span class="page-title">{{page.title}}</span>
			</div>
		</div>
	</div>
	<div class="grid-cell-2 grid-cell-right grid-cell-middle">
		{{#unless (eq document.protection constants.ProtectionType.Lock)}}
			<div class="section-heading no-print" id="page-toolbar-{{ page.id }}">
				<div class="section-toolbar">
					{{#if canEdit}}
						<i class="add-section dicon {{constants.Icon.Plus}}" {{action "onShowSectionWizard" page}}>
							{{#attach-tooltip showDelay=1000}}Insert section above{{/attach-tooltip}}
						</i>
						<div class="gap"/>
						<i class="dicon {{constants.Icon.Edit}}" {{action "onEdit"}} />
					{{/if}}
					{{#if hasMenuPermissions}}
						<div class="gap"/>
						<i class="dicon {{constants.Icon.Settings}}">
							{{#attach-popover class="ember-attacher-popper" hideOn="clickout click" showOn="click" isShown=false}}
								<div class="menu">
									{{#if canEdit}}
										<a class="item" href="#" id={{concat "edit-page-button-" page.id}} {{action "onEdit"}}>Edit</a>
									{{/if}}
									{{#if permissions.documentCopy}}
										<a class="item" href="#" id={{concat "copy-page-button-" page.id}} data-toggle="modal" data-target={{concat "#copy-page-modal-" page.id}} data-backdrop="static">Copy</a>
									{{/if}}
									{{#if canMove}}
										<a class="item" href="#" id={{concat "move-page-button-" page.id}} data-toggle="modal" data-target={{concat "#move-page-modal-" page.id}} data-backdrop="static">Move</a>
									{{/if}}
									{{#if permissions.documentTemplate}}
										<a class="item" href="#" id={{concat "publish-page-button-" page.id}} data-toggle="modal" data-target={{concat "#publish-page-modal-" page.id}} data-backdrop="static">Publish</a>
									{{/if}}
									{{#if canDelete}}
										<a class="item red" href="#" id={{concat "delete-page-button-" page.id}} data-toggle="modal" data-target={{concat "#delete-page-modal-" page.id}} data-backdrop="static">Delete</a>
									{{/if}}
									{{#if (and canEdit state.actionablePage)}}
										<div class="divider"></div>
										{{#unless state.indentDisabled}}
											<a class="item" href="#" id={{concat "toc-indent-button-" page.id}} {{action "pageIndent"}}>Indent</a>
										{{/unless}}
										{{#unless state.outdentDisabled}}
											<a class="item" href="#" id={{concat "toc-outdent-button-" page.id}} {{action "pageOutdent"}}>Outdent</a>
										{{/unless}}
										{{#unless state.upDisabled}}
											<a class="item" href="#" id={{concat "toc-up-button-" page.id}} {{action "pageUp"}}>Move up</a>
										{{/unless}}
										{{#unless state.downDisabled}}
											<a class="item" href="#" id={{concat "toc-down-button-" page.id}} {{action "pageDown"}}>Move down</a>
										{{/unless}}
									{{/if}}
								</div>
							{{/attach-popover}}
						</i>
					{{/if}}
				</div>
			</div>
		{{/unless}}
	</div>
</div>

{{#if permissions.documentCopy}}
	<div id={{concat "copy-page-modal-" page.id}} class="modal" tabindex="-1" role="dialog">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">Copy Section</div>
				<div class="modal-body">
					<div class="form-group">
						<label>Destination Document</label>
						{{focus-input type="text" value=docSearchFilter class="form-control" placeholder="a OR b, x AND y, 'phrase mat*'"}}
					</div>
					{{ui/ui-spacer size=100}}
					<div class="document-copy-move">
						{{#if emptySearch}}
							<p>No matching documents found.</p>
						{{/if}}
						<ul class="documents-list">
							{{#each docSearchResults key="id" as |result|}}
								<li class="document {{if result.selected "selected"}}" {{action "onSelectSearchResult" result.documentId}}>
									<div class="title">{{result.document}}</div>
									<div class="space">{{result.space}}</div>
									<div class="snippet">{{result.excerpt}}</div>
									{{#if result.selected}}
										<i class="dicon {{constants.Icon.Tick}}" />
									{{/if}}
								</li>
							{{/each}}
						</ul>
					</div>
				</div>
				<div class="modal-footer">
					{{ui/ui-button color=constants.Color.Gray light=true label=constants.Label.Cancel dismiss=true}}
					{{ui/ui-button-gap}}
					{{ui/ui-button color=constants.Color.Green light=true label=constants.Label.Copy onClick=(action "onCopyPage")}}
				</div>
			</div>
		</div>
	</div>
{{/if}}

{{#if permissions.documentMove}}
	<div id={{concat "move-page-modal-" page.id}} class="modal" tabindex="-1" role="dialog">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">Move Section</div>
				<div class="modal-body">
					<div class="form-group">
						<label>Destination Document</label>
						{{focus-input type="text" value=docSearchFilter class="form-control" placeholder="a OR b, x AND y, 'phrase mat*'"}}
					</div>
					<div class="document-copy-move">
						{{#if emptySearch}}
							<p>No matching documents found.</p>
						{{/if}}
						<ul class="documents-list">
							{{#each docSearchResults key="id" as |result|}}
								<li class="document {{if result.selected "selected"}}" {{action "onSelectSearchResult" result.documentId}}>
									<div class="title">{{result.document}}</div>
									<div class="space">{{result.space}}</div>
									<div class="snippet">{{result.excerpt}}</div>
									{{#if result.selected}}
										<i class="dicon {{constants.Icon.Tick}}" />
									{{/if}}
								</li>
							{{/each}}
						</ul>
					</div>
				</div>
				<div class="modal-footer">
					{{ui/ui-button color=constants.Color.Gray light=true label=constants.Label.Cancel dismiss=true}}
					{{ui/ui-button-gap}}
					{{ui/ui-button color=constants.Color.Green light=true label=constants.Label.Copy onClick=(action "onMovePage")}}
				</div>
			</div>
		</div>
	</div>
{{/if}}

{{#if permissions.documentDelete}}
	<div id= {{concat "delete-page-modal-" page.id}} class="modal" tabindex="-1" role="dialog">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">Delete Section</div>
				<div class="modal-body">
					<p>Are you sure you want to delete this section?</p>
					<div class="form-group">
						<div class="form-check">
							{{input type="checkbox" class="form-check-input" checked=deleteChildren  id=(concat "delete-page-check-" page.id)}}
							<label class="form-check-label" for= {{concat "delete-page-check-" page.id}}>
								Also delete child sections
							</label>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					{{ui/ui-button color=constants.Color.Gray light=true label=constants.Label.Cancel dismiss=true}}
					{{ui/ui-button-gap}}
					{{ui/ui-button color=constants.Color.Red light=true label=constants.Label.Delete onClick=(action "onDeletePage")}}
				</div>
			</div>
		</div>
	</div>
{{/if}}

{{#if permissions.documentTemplate}}
	<div id={{concat "publish-page-modal-" page.id}} class="modal" tabindex="-1" role="dialog">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">Publish Reusable Content Block</div>
				<div class="modal-body">
					<div class="form-group">
						<label for="block-title-{{page.id}}">Name</label>
						{{input id=(concat "block-title-" page.id) type="text" class="form-control mousetrap" placeholder="Enter name" value=blockTitle}}
						<small class="form-text text-muted">Provide a short title for the reusable content block</small>
					</div>
					<div class="form-group">
						<label for="block-desc-{{page.id}}">Description</label>
						{{textarea id=(concat "block-desc-" page.id) rows="3" class="form-control mousetrap" placeholder="Enter description" value=blockExcerpt}}
						<small class="form-text text-muted">Short description to help others understand the reusable content block</small>
					</div>
				</div>
				<div class="modal-footer">
					{{ui/ui-button color=constants.Color.Gray light=true label=constants.Label.Cancel dismiss=true}}
					{{ui/ui-button-gap}}
					{{ui/ui-button color=constants.Color.Green light=true label=constants.Label.Publish onClick=(action "onSavePageAsBlock")}}
				</div>
			</div>
		</div>
	</div>
{{/if}}