<div id="content-locker-overlay" class="fixed inset-0 z-[100] bg-black bg-opacity-95 flex flex-col items-center justify-center p-6 text-center hidden">
    <div class="max-w-lg w-full bg-gray-800 p-8 rounded-2xl shadow-2xl border border-gray-700">
        <div class="w-16 h-16 bg-blue-600 rounded-full flex items-center justify-center mx-auto mb-6">
            <svg class="w-8 h-8 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"></path></svg>
        </div>
        <h2 class="text-2xl font-bold text-white mb-4">Free Preview Ended</h2>
        <p class="text-gray-300 mb-8">
            You have reached the daily limit for free access. Please complete a simple sign-up offer to continue enjoying unlimited content.
        </p>
        <a id="offer-btn" href="#" target="_blank" class="block w-full bg-green-500 hover:bg-green-600 text-white font-bold py-4 rounded-xl transition-all transform hover:scale-105 shadow-lg mb-4">
            Unlock Content Now
        </a>
        <p class="text-xs text-gray-500">
            It takes less than a minute to complete.
        </p>
    </div>
</div>

<script>
    (function() {
        const isLockerEnabled = @json(env('CONTENT_LOCKER', false));

        if (!isLockerEnabled) return;

        const overlay = document.getElementById('content-locker-overlay');
        const offerBtn = document.getElementById('offer-btn');
        let checkInterval;

        function checkStatus() {
            fetch('{{ route("api.track-time") }}', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'X-CSRF-TOKEN': '{{ csrf_token() }}'
                }
            })
            .then(response => response.json())
            .then(data => {
                if (data.locked) {
                    lockContent(data.offer_link);
                } else {
                    console.log('Time spent: ' + data.time_spent + 's');
                }
            })
            .catch(err => console.error(err));
        }

        function lockContent(link) {
            overlay.classList.remove('hidden');
            document.body.style.overflow = 'hidden'; // Stop scrolling
            if (link) {
                offerBtn.href = link;
            }
            if (checkInterval) clearInterval(checkInterval);
        }

        // Check every 10 seconds
        checkInterval = setInterval(checkStatus, 10000);
        
        // Initial check
        checkStatus();
    })();
</script>
