document.querySelectorAll('.tab-btn').forEach(btn => {document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
btn.classList.add('active');
document.getElementById('tab-' + btn.dataset.tab).classList.add('active');
});
});
// STAR RATING INTERACTION
document.querySelectorAll('.star-rating').forEach(container => {
const stars = container.querySelectorAll('.star');
const label = container.querySelector('.rating-value');
let currentRating = 0;
stars.forEach(star => {
star.addEventListener('click', () => {
currentRating = parseInt(star.dataset.value);
updateStars(currentRating);
});
star.addEventListener('mouseenter', () => {
const hoverVal = parseInt(star.dataset.value);
stars.forEach(s => {
s.classList.toggle('active', parseInt(s.dataset.value) <= hoverVal);
});
});
star.addEventListener('mouseleave', () => updateStars(currentRating));
});
function updateStars(val) {
currentRating = val;
label.textContent = val + ' / 5';
stars.forEach(s => s.classList.toggle('active', parseInt(s.dataset.value) <= val));
}
});
// FILE UPLOAD FEEDBACK
const fileInput = document.getElementById('file-upload');
const fileNames = document.querySelector('.file-names');
if (fileInput) {
fileInput.addEventListener('change', () => {
fileNames.innerHTML = Array.from(fileInput.files).map(f => `
${f.name}`).join(' ');
});
}
// FORM SUBMISSION HANDLER
document.querySelectorAll('form').forEach(form => {
form.addEventListener('submit', async (e) => {
e.preventDefault();
const submitBtn = form.querySelector('button[type="submit"]');
if (!form.checkValidity()) {
form.reportValidity();
return;
}
submitBtn.classList.add('loading');
submitBtn.disabled = true;
// Simulate API call
await new Promise(resolve => setTimeout(resolve, 1200));
// Hide form, show success
document.querySelectorAll('.tab-content').forEach(t => t.classList.remove('active'));
document.querySelector('.tabs').style.display = 'none';
document.getElementById('success-state').classList.add('active');
window.scrollTo({ top: 0, behavior: 'smooth' });
});
});
// RESET FUNCTIONS
function resetForm(formId) {
const form = document.getElementById(formId);
form.reset();
document.querySelectorAll(`#${formId} .rating-value`).forEach(el => el.textContent = '0 / 5');
document.querySelectorAll(`#${formId} .star`).forEach(el => el.classList.remove('active'));
if (fileNames) fileNames.innerHTML = '';
}
function resetAll() {
document.getElementById('success-state').classList.remove('active');
document.querySelector('.tabs').style.display = 'flex';
document.querySelector('.tab-btn[data-tab="course"]').click();
document.querySelectorAll('form').forEach(f => f.reset());
document.querySelectorAll('.rating-value').forEach(el => el.textContent = '0 / 5');
document.querySelectorAll('.star').forEach(el => el.classList.remove('active'));
}