// ==========================================
//   useful.js — пошук відео
// ==========================================

document.addEventListener('DOMContentLoaded', () => {

  // --- VIDEO SEARCH ---
  const searchInput  = document.getElementById('videoSearch');
  const videoCards   = document.querySelectorAll('.video-card');
  const noResults    = document.getElementById('videoNoResults');

  searchInput?.addEventListener('input', () => {
    const q = searchInput.value.trim().toLowerCase();
    let visible = 0;

    videoCards.forEach(card => {
      const title = card.querySelector('.video-title')?.textContent.toLowerCase() || '';
      const desc  = card.querySelector('.video-desc')?.textContent.toLowerCase() || '';
      const match = !q || title.includes(q) || desc.includes(q);
      card.classList.toggle('hidden', !match);
      if (match) visible++;
    });

    if (noResults) {
      noResults.style.display = visible === 0 ? 'flex' : 'none';
    }
  });

});
