<?php
    $_product = $block->getProduct();
    $blockData = $this->getData();
    $builderHelper = $this->helper('MGS\Fbuilder\Helper\Data');
    $themeSettingConfig = $this->helper('MGS\ThemeSettings\Helper\Config');
?>

<?php if ($_product->getSpecialPrice() && $_product->getSpecialToDate() && $_product->getSpecialFromDate()): ?>

    <?php $specialFromDate = date('m/d/y h:i:s A', strtotime($_product->getSpecialFromDate())); ?>
    <?php $now = date('m/d/y h:i:s A', strtotime($builderHelper->getCurrentDateTime())) ?>
    <?php $endTime = str_replace(' 00:00:00', '', $_product->getSpecialToDate()) ?>

    <?php if (strtotime($_product->getSpecialFromDate()) <= strtotime($builderHelper->getCurrentDateTime()) && strtotime($_product->getSpecialToDate()) > strtotime($builderHelper->getCurrentDateTime())): ?>
        <div class="product-detail-deals margin-top25 1231">
            <div class="hurry-text">
                <?php echo __('Hurry! Only %1 left in stock', $themeSettingConfig->getStockQty($_product->getId())); ?>
            </div>
            <div class="deal-timer">
                <div id="quickview-deal-timer-<?php echo $_product->getId(); ?>" class="countdown"></div>
                <div class="time-note">
                    <span class="days"><?= __('Days'); ?></span>
                    <span class="hours"><?= __('Hours'); ?></span>
                    <span class="mins"><?= __('Mins'); ?></span>
                    <span class="secs"><?= __('Secs'); ?></span>
                </div>
            </div>
        </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(); ?> = "quickview-deal-timer-<?php echo $_product->getId(); ?>";
            CountBack(gsecs<?php echo $_product->getId(); ?>,"quickview-deal-timer-<?php echo $_product->getId(); ?>", <?php echo $_product->getId(); ?>);
        </script>
    <?php endif ?>
<?php endif ?>
