async function submitTeacher(e) { e.preventDefault(); const email = document.getElementById('t-email').value.trim(); const password = document.getElementById('t-password').value; // 1. Register with Supabase Auth const { data: authData, error: authError } = await supabase.auth.signUp({ email, password }); if (authError) { ApexApp.showToast(authError.message, true); return; } const grades = Array.from(document.querySelectorAll('input[name="t-grades"]:checked')).map(cb => cb.value); const boards = Array.from(document.querySelectorAll('input[name="t-boards"]:checked')).map(cb => cb.value); // 2. Insert into profiles table const profileRecord = { id: authData.user.id, role: 'teacher', name: document.getElementById('t-name').value, whatsapp: document.getElementById('t-whatsapp').value, tuition_mode: document.getElementById('t-mode').value, address: document.getElementById('t-address').value || null, qualification: document.getElementById('t-qual').value, experience: Number(document.getElementById('t-exp').value), category: document.getElementById('t-category').value, grades: grades, boards: boards, non_academic_skill: document.getElementById('t-nonacad-item')?.value || null, competitive_exam: document.getElementById('t-comp-item')?.value || null, other_details: document.getElementById('t-other-text')?.value || null, fee_amount: Number(document.getElementById('t-fee').value), fee_currency: document.getElementById('t-curr').value, fee_period: document.getElementById('t-period').value, gmt_zone: document.getElementById('t-gmt').value, available_timings: document.getElementById('t-timings').value, location: document.getElementById('t-location').value, is_verified: true }; const { error: dbError } = await supabase.from('profiles').insert([profileRecord]); if (dbError) { ApexApp.showToast(dbError.message, true); return; } ApexApp.setUser(profileRecord); window.location.href = 'index.html'; } async function submitStudent(e) { e.preventDefault(); const email = document.getElementById('s-email').value.trim(); const password = document.getElementById('s-password').value; const { data: authData, error: authError } = await supabase.auth.signUp({ email, password }); if (authError) { ApexApp.showToast(authError.message, true); return; } const selectedGrade = document.querySelector('input[name="s-grade"]:checked')?.value; const profileRecord = { id: authData.user.id, role: 'student', name: document.getElementById('s-name').value, parent_name: document.getElementById('s-parent').value, whatsapp: document.getElementById('s-whatsapp').value, tuition_mode: document.getElementById('s-mode').value, address: document.getElementById('s-address').value || null, category: document.getElementById('s-category').value, grades: selectedGrade ? [selectedGrade] : [], boards: [document.getElementById('s-board')?.value || 'CBSE'], non_academic_skill: document.getElementById('s-nonacad-item')?.value || null, competitive_exam: document.getElementById('s-comp-item')?.value || null, location: document.getElementById('s-location').value, is_verified: false }; const { error: dbError } = await supabase.from('profiles').insert([profileRecord]); if (dbError) { ApexApp.showToast(dbError.message, true); return; } ApexApp.setUser(profileRecord); window.location.href = 'index.html'; }