<div class="row insights_widget" id="SectionScanResultsFileLocker">
	<div class="col">
		<div class="card card-scan_results">

			<div class="card-header">
				<h5 class="card-title">{{ scan.strings.title }}</h5>
				<h6 class="card-subtitle text-muted">{{ scan.strings.subtitle }}</h6>
			</div>

			<div class="card-body">

				{% if scan.flags.is_restricted %}
					{% include '/wpadmin_pages/insights/scans/results/common_unavailable.twig' %}
				{% else %}
					{% if scan.flags.is_enabled %}
						<div class="col mt-3 mb-3">
							 <div class="input-group m-auto mt-3 mb-3">
								 <div class="input-group-prepend">
									 <label class="input-group-text" for="FileLockerFileSelect">
										 Select File To Review
									 </label>
								 </div>
								<select class="custom-select mw-100" id="FileLockerFileSelect">
									<option selected value="-">--</option>
									{% for lock_key, file_lock in scan.vars.file_locks.bad %}
										<option value="{{ lock_key }}" class="text-danger">{{ file_lock.file }}</option>
									{% endfor %}
									{% for lock_key, file_lock in scan.vars.file_locks.good %}
										<option value="{{ lock_key }}" class="text-success">{{ file_lock.file }}</option>
									{% endfor %}
								</select>
							 </div>
						</div>

						<div class="col">
							<div id="FileLockerDiffContents" class="w-100">
								<div class="alert alert-success">
									<p class="m-0">{{ scan.strings.please_select }}</p>
								</div>
							</div>
						</div>
					{% else %}
						{% include '/wpadmin_pages/insights/scans/results/common_disabled.twig' %}
					{% endif %}
				{% endif %}
			</div>

			<div class="card-footer">
				<div class="row">
					<div class="col-sm-6">
					</div>
					<div class="col-sm-6 text-right">
						<a href="{{ scan.hrefs.options }}"
						   class="btn btn-sm btn-outline-dark">{{ strings.options }} &rarr;</a>
					</div>
				</div>
			</div>

		</div>
	</div>
</div>

{% if not scan.flags.is_restricted %}
<script type="text/javascript">
	jQuery( '#FileLockerFileSelect' ).on( 'change', function ( e ) {
		iCWP_WPSF_BodyOverlay.show();
		let ajax_vars ={{ scan.ajax.filelocker_showdiff|raw }};
		ajax_vars.rid = jQuery( this ).val();
		jQuery.post( ajaxurl, ajax_vars,
			function ( oResponse ) {
				jQuery( '#FileLockerDiffContents' ).html( oResponse.data.html );
			}
		).fail(
			function () {
			}
		).always( function () {
				iCWP_WPSF_BodyOverlay.hide();
			}
		);
	} );
	jQuery( document ).on( 'submit', 'form.filelocker_fileaction', function ( evt ) {
		evt.preventDefault();
		iCWP_WPSF_BodyOverlay.show();
		let ajax_vars ={{ scan.ajax.filelocker_fileaction|raw }};
		let $oButton = jQuery( 'input[type=submit]', this );
		ajax_vars.confirmed = jQuery( 'input[type=checkbox]', this ).is( ':checked' ) ? 1 : 0;
		ajax_vars.rid = $oButton.data( 'rid' );
		ajax_vars.file_action = $oButton.data( 'action' );

		jQuery.post( ajaxurl, ajax_vars,
			function ( oResponse ) {
				let sMessage = '';
				if ( oResponse === null || typeof oResponse.data === 'undefined'
					|| typeof oResponse.data.message === 'undefined' ) {
					sMessage = oResponse.success ? 'Success' : 'Failure';
				}
				else {
					sMessage = oResponse.data.message;
				}
				iCWP_WPSF_Toaster.showMessage( sMessage, oResponse.success );
				if ( oResponse.success ) {
					setTimeout( function () {
						location.reload();
					}, 500 );
				}
			}
		).fail(
			function () {
			}
		).always( function () {
				iCWP_WPSF_BodyOverlay.hide();
			}
		);
		return false;
	} );
</script>
{% endif %}