/*
Theme Name: Hello Elementor Child
Template: hello-elementor
Version: 1.0
Text Domain: hello-elementor-child
*/
document.addEventListener('DOMContentLoaded', function() {
    const searchInput = document.querySelector('.live-search-form input[type="search"]');
    
    if (searchInput) {
        let timeout = null;
        
        searchInput.addEventListener('input', function(e) {
            clearTimeout(timeout);
            const query = e.target.value;
            
            // حداقل ۲ کاراکتر تایپ شده باشد
            if (query.length < 2) return;

            // تاخیر کوتاه برای جلوگیری از ارسال درخواست‌های زیاد هنگام تایپ سریع
            timeout = setTimeout(function() {
                // ارسال درخواست AJAX به وردپرس یا دریافت نتایج
                fetch(`/wp-json/wp/v2/posts?search=${encodeURIComponent(query)}`)
                    .then(response => response.json())
                    .then(data => {
                        console.log('نتایج پیدا شده:', data);
                        // اینجا می‌توانید باکس نتایج را زیر input بنشانید
                    });
            }, 400);
        });
    }
});
