<?php if(!is_null($selfActiveTimer) && in_array('tasks', user_modules())): ?>

    <span class="border rounded f-14 py-2 px-2 d-none d-sm-block mr-3">
        <span id="active-timer" class="mr-2"><?php echo e($selfActiveTimer->timer); ?></span>

        <?php if(is_null($selfActiveTimer->activeBreak)): ?>
            <a href="javascript:;" class="pause-active-timer mr-1 border-right" data-url="<?php echo e(url()->current()); ?>"
                data-toggle="tooltip" data-original-title="<?php echo e(__('modules.timeLogs.pauseTimer')); ?>"
                data-time-id="<?php echo e($selfActiveTimer->id); ?>">
                <i class="fa fa-pause-circle text-primary"></i>
            </a>
        <?php else: ?>
            <a href="javascript:;" class="resume-active-timer mr-1 border-right" data-url="<?php echo e(url()->current()); ?>"
                data-toggle="tooltip" data-original-title="<?php echo e(__('modules.timeLogs.resumeTimer')); ?>"
                data-time-id="<?php echo e($selfActiveTimer->activeBreak->id); ?>">
                <i class="fa fa-play-circle text-primary"></i>
            </a>
        <?php endif; ?>
        <a href="javascript:;" class="stop-active-timer" id="stop-active-timer" data-toggle="tooltip"
            data-original-title="<?php echo e(__('modules.timeLogs.stopTimer')); ?>" data-url="<?php echo e(url()->current()); ?>"
            data-time-id="<?php echo e($selfActiveTimer->id); ?>">
            <i class="fa fa-stop-circle text-danger"></i>
        </a>

    </span>

    <?php if(is_null($selfActiveTimer->activeBreak)): ?>
        <a href="javascript:;"
            class='btn-danger btn btn-sm rounded mr-3 f-14 py-2 px-2 stop-active-timer d-block d-sm-none mr-2'
            data-time-id="<?php echo e($selfActiveTimer->id); ?>" data-url="<?php echo e(url()->current()); ?>" id="stop-active-timer">
            <?php echo e(__('modules.timeLogs.stopTimer')); ?>

        </a>
    <?php endif; ?>
<?php endif; ?>

<script>
    var $worked = $("#active-timer");
    var activeBreak = "<?php echo e(!is_null($selfActiveTimer) && !is_null($selfActiveTimer->activeBreak)); ?>";

    function updateTimerTask() {
        var myTime = $worked.html();
        var ss = myTime.split(":");

        var hours = ss[0];
        var mins = ss[1];
        var secs = ss[2];
        secs = parseInt(secs) + 1;

        if (secs > 59) {
            secs = '00';
            mins = parseInt(mins) + 1;
        }

        if (mins > 59) {
            secs = '00';
            mins = '00';
            hours = parseInt(hours) + 1;
        }

        if (hours.toString().length < 2) {
            hours = '0' + hours;
        }
        if (mins.toString().length < 2) {
            mins = '0' + mins;
        }
        if (secs.toString().length < 2) {
            secs = '0' + secs;
        }
        var ts = hours + ':' + mins + ':' + secs;

        $worked.html(ts);

        if (runTimeClock) {
            return setTimeout(updateTimerTask, 1000);
        }
    }

    if ($('#active-timer').length && activeBreak != '1') {
        runTimeClock = true;
        setTimeout(updateTimerTask, 1000);
    } else {
        runTimeClock = false;
    }
        document.addEventListener("visibilitychange", function() {
            if (document.visibilityState === "visible") {
                var url = "<?php echo e(route('timelogs.timer_data')); ?>";
                    $.easyAjax({
                    url: url,
                    container: '#startTimerForm',
                    type: "GET",
                    blockUI: true,
                    success: function (response) {
                        if (response.status == 'success') {
                            $('#active-timer').html(response.data.timer);
                        }
                    }
                });
            }
        });

<?php if(!is_null($selfActiveTimer)): ?>
    $('.stop-active-timer').click(function(){
        var url = "<?php echo e(route('timelogs.stopper_alert', ':id')); ?>?via=timelog";
        var id = "<?php echo e($selfActiveTimer->id); ?>";
        url = url.replace(':id', id);
        $(MODAL_LG + ' ' + MODAL_HEADING).html('...');
        $.ajaxModal(MODAL_LG, url);
    })
<?php endif; ?>

</script>
<?php /**PATH /home/smartdigitants/public_html/oneops.co.uk/oneops.ai/resources/views/sections/timer_clock.blade.php ENDPATH**/ ?>