`;
}).join('');
container.innerHTML = html;
} catch (err) {
console.error("Rendering Error:", err);
}
}
function filterItems(category, element) {
filterStatus = category;
document.querySelectorAll('.filter-btn').forEach(btn => btn.classList.remove('active'));
if (element) element.classList.add('active');
generateCards();
}
function initiateQuiz() {
document.getElementById('quizStartUI').classList.add('hidden');
document.getElementById('quizEndUI').classList.add('hidden');
document.getElementById('quizPlayUI').classList.remove('hidden');
quizScore = 0;
quizIndex = 0;
activeQuizVerbs = [...verbLibrary].sort(() => 0.5 - Math.random()).slice(0, 10);
showNextQuestion();
}
function showNextQuestion() {
const v = activeQuizVerbs[quizIndex];
const isV3 = Math.random() > 0.5;
const targetLabel = isV3 ? 'V3 (Past Participle)' : 'V2 (Past Simple)';
const rightAns = isV3 ? v.v3 : v.v2;
document.getElementById('qCount').innerText = `প্রশ্ন: ${quizIndex + 1}/10`;
document.getElementById('currScore').innerText = `স্কোর: ${quizScore}`;
document.getElementById('qForm').innerText = targetLabel;
document.getElementById('qVerb').innerText = v.v1;
document.getElementById('qMean').innerText = `[${v.m1}]`;
let distractors = verbLibrary.filter(item => item.v1 !== v.v1).sort(() => 0.5 - Math.random()).slice(0, 3).map(item => isV3 ? item.v3 : item.v2);
let options = [...new Set([rightAns, ...distractors])].sort(() => 0.5 - Math.random());
while(options.length < 4) {
const rand = verbLibrary[Math.floor(Math.random()*verbLibrary.length)];
options.push(isV3 ? rand.v3 : rand.v2);
options = [...new Set(options)];
}
const container = document.getElementById('ansGrid');
container.innerHTML = options.map(opt => ``).join('');
}
function processAnswer(selected, correct) {
const btns = document.querySelectorAll('.quiz-opt');
btns.forEach(b => b.disabled = true);
if (selected === correct) {
quizScore++;
event.target.classList.add('bg-green-100', 'border-green-500', 'text-green-700');
} else {
event.target.classList.add('bg-red-100', 'border-red-500', 'text-red-700');
btns.forEach(b => { if (b.innerText.trim() === correct) b.classList.add('bg-green-100', 'border-green-500', 'text-green-700'); });
}
setTimeout(() => {
quizIndex++;
if (quizIndex < 10) { showNextQuestion(); } else { concludeQuiz(); }
}, 1000);
}
function concludeQuiz() {
document.getElementById('quizPlayUI').classList.add('hidden');
document.getElementById('quizEndUI').classList.remove('hidden');
document.getElementById('scoreVal').innerText = quizScore;
const icon = document.getElementById('endIcon');
const status = document.getElementById('endStatus');
if (quizScore === 10) { icon.innerText = "👑"; status.innerText = "ভার্ব মাস্টার!"; }
else if (quizScore >= 7) { icon.innerText = "🔥"; status.innerText = "দারুণ খেলেছেন!"; }
else { icon.innerText = "📚"; status.innerText = "আরো প্র্যাকটিস করুন!"; }
}
function initPlayground() {
const searchInput = document.getElementById('mainSearch');
if (searchInput) { searchInput.addEventListener('input', generateCards); }
generateCards();
let attempts = 0;
const heartbeat = setInterval(() => {
const container = document.getElementById('verbDisplay');
if (container && (container.innerHTML.includes('লোড হচ্ছে') || container.children.length === 0)) { generateCards(); }
attempts++;
if (attempts > 12) clearInterval(heartbeat);
}, 500);
}
if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initPlayground); } else { initPlayground(); }