<?php $_product = $this->getProduct() ?>
<?php $blockData = $this->getBlockData() ?>
<?php $builderHelper = $this->helper('MGS\Fbuilder\Helper\Data'); ?>
<?php if($_product->getSpecialPrice() && $_product->getSpecialToDate() && $_product->getSpecialFromDate()): ?>
	<?php $themeHelper = $this->helper('MGS\ThemeSettings\Helper\Config'); ?>
	<?php $dateTimeFormat = \Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT; ?>
	<?php $specialFromDate = date($dateTimeFormat, strtotime($_product->getSpecialFromDate())); ?>
	<?php $now = $themeHelper->getCurrentDateTime(); ?>
	<?php $endTime = date($dateTimeFormat, strtotime($_product->getSpecialToDate())); ?>
	
	<?php if($specialFromDate <= $now && $endTime > $now): ?>
		<div class="deal-timer">
			<div id="deal-timer-<?php echo $_product->getId(); ?>" class="countdown"></div>
			<?php if(($blockData['fbuilder_days']!='') && ($blockData['fbuilder_hours']!='') && ($blockData['fbuilder_minutes']!='') && ($blockData['fbuilder_seconds']!='')): ?>
				<div class="time-note">
					<span class="days"><?php echo $builderHelper->decodeHtmlTag($blockData['fbuilder_days']) ?></span>
					<span class="hours"><?php echo $builderHelper->decodeHtmlTag($blockData['fbuilder_hours']) ?></span>
					<span class="mins"><?php echo $builderHelper->decodeHtmlTag($blockData['fbuilder_minutes']) ?></span>
					<span class='secs'><?php echo $builderHelper->decodeHtmlTag($blockData['fbuilder_seconds']) ?></span>
				</div>
			<?php endif ?>
		</div>
		<script type="text/javascript">
			var dthen<?php echo $_product->getId(); ?> = new Date("<?php echo Date("m/d/y", strtotime($endTime)).' 11:59:59 PM'; ?>");
			start<?php echo $_product->getId(); ?> = "<?php echo $now; ?>";
			start_date<?php echo $_product->getId(); ?> = Date.parse(start<?php echo $_product->getId(); ?>);
			var dnow<?php echo $_product->getId(); ?> = new Date(start_date<?php echo $_product->getId(); ?>);
			ddiff = new Date((dthen<?php echo $_product->getId(); ?>)-(dnow<?php echo $_product->getId(); ?>));
			gsecs<?php echo $_product->getId(); ?> = Math.floor(ddiff.valueOf()/1000);

			var iid<?php echo $_product->getId(); ?> = "deal-timer-<?php echo $_product->getId(); ?>";
			CountBack(gsecs<?php echo $_product->getId(); ?>,"deal-timer-<?php echo $_product->getId(); ?>", <?php echo $_product->getId(); ?>);
		</script>
	<?php else:?>
		<div class="note out-time">
			<span><?= __('The product out of time deal special')?></span>
		</div>
	<?php endif ?>
<?php endif ?>