import { db } from './firebase.js'; import { collection, addDoc } from "https://www.gstatic.com/firebasejs/9.22.1/firebase-firestore.js"; window.submitAduan = async function(e) { e.preventDefault(); const nama = document.getElementById('namaPelapor').value.toUpperCase(); const hp = document.getElementById('nomorHp').value; const kategori = document.getElementById('kategoriAduan').value; const isi = document.getElementById('isiAduan').value.toUpperCase(); const numPadded = String(Math.floor(100 + Math.random() * 900)); const romanMonths = ["I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII"]; const now = new Date(); const romanMonth = romanMonths[now.getMonth()]; const year = now.getFullYear(); const noAduan = `${numPadded}/ADUAN/${romanMonth}/${year}`; try { await addDoc(collection(db, "aduan"), { noAduan: noAduan, nama: nama, hp: hp, kategori: kategori, isi: isi, status: "ADUAN SEDANG DIPROSES", created_at: new Date() }); } catch (err) { console.error("Gagal mengirim aduan ke Firebase:", err); } document.getElementById('noAduanTeks').innerText = noAduan; document.getElementById('modalAduan').classList.remove('hidden'); document.getElementById('formAduan').reset(); toggleKategori(); }