<?
require_once(__DIR__."/include/header.php");
$r = json_decode($_REQUEST['PLACEMENT_OPTIONS']);
$ID = '';
if($r->ENTITY_ID){
	$ID = $r->ENTITY_ID;
}elseif($r->ID){
	$ID = $r->ID;
}
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="//api.bitrix24.com/api/v1/"></script>
<style>
	body {
		font-family: Arial;
		font-size: 14px;
		line-height: 16px;
		font-weight: 400;
		background-color: #fff;
		box-sizing: border-box;
		margin: 0;
	}
	.wrapper {
		width: 100%;
		height: 100%;
		min-height: 100vh;
		display: flex;
		justify-content: center;
		align-content: center;
		align-items: center;
	}
	.button {
		margin-left: 50px;
		min-width: 250px;
		height: 45px;
		line-height: 40px;
		background-color: #25cbff;
		color: #fff;
		cursor: pointer;
		border: 1px solid #25cbff;
	}
	.button:hover {
		background-color: #23b6e4;
	}
	.loading {
		width: 126px;
		height: 126px;
	}
	.loading img {
		animation-name: rotation;
		animation-duration: 2s;
		animation-iteration-count: infinite;
		animation-timing-function: linear;
	}
	.result {
		display: none;
	}
	@keyframes rotation {
		0% {
			transform: rotate(0deg);
		}
		100% {
			transform: rotate(-360deg);
		}
	}
</style>
<script>
	$(function () {
		var quote_id = $('.wrapper').data('id');
		if(quote_id !== ''){
			document.body.style.cursor='wait';
			$.post("https://app.appliedphysicsinc.com/export_to_excel_app/handler.php", {
				'form_submit': true,
				'quote_id': quote_id
			}, function (data) {
				document.body.style.cursor='default';
				if (data) {
					$('.loading').fadeOut(400);
					setTimeout(() => {
						$(".result").append(data);
						$('.result').fadeIn(500);
						setTimeout(() => {
							BX24.closeApplication();
						}, 3000);
					}, 500);
				}
			});
		}
	});
</script>
<div class="wrapper" data-id="<?=$ID?>">
	<?php
	/*
	<button class="export_excel button" data-id="<?=$ID?>">Add Excel file to timeline</button>
	<br><br>
	*/
	?>
	<div class="loading"><img src="images/loading.png"></div>
	<div class="result"></div>
</div>
<?
require_once("include/footer.php");
?>