class QuixoticApp { constructor() { this.tg = window.Telegram?.WebApp; this.init(); this.bindEvents(); } init() { if (this.tg) { this.tg.ready(); this.tg.expand(); this.tg.MainButton.hide(); } this.searchInput = document.getElementById('searchInput'); this.searchBtn = document.getElementById('searchBtn'); this.loading = document.getElementById('loading'); this.results = document.getElementById('results'); this.noResults = document.getElementById('noResults'); } bindEvents() { this.searchBtn.addEventListener('click', () => this.search()); this.searchInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') { this.search(); } }); } async search() { const query = this.searchInput.value.trim(); if (!query) return; this.showLoading(); try { const response = await fetch('/api/search', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ query, userId: this.tg?.initDataUnsafe?.user?.id || 'demo' }) }); if (!response.ok) { throw new Error('Search failed'); } const data = await response.json(); this.displayResults(data.videos); } catch (error) { console.error('Search error:', error); this.showNoResults(); } } showLoading() { this.loading.classList.remove('hidden'); this.results.classList.add('hidden'); this.noResults.classList.add('hidden'); this.searchBtn.disabled = true; } hideLoading() { this.loading.classList.add('hidden'); this.searchBtn.disabled = false; } displayResults(videos) { this.hideLoading(); if (!videos || videos.length === 0) { this.showNoResults(); return; } this.results.innerHTML = videos.map(video => `