const firebaseConfig = {
    apiKey: "AIzaSyCwq4ME-3FLXWzk2Q2E09JloDV4WvOv8AU",
    authDomain: "hirringpeoples.firebaseapp.com",
    databaseURL: "https://hirringpeoples-default-rtdb.firebaseio.com",
    projectId: "hirringpeoples",
    storageBucket: "hirringpeoples.appspot.com",
    messagingSenderId: "696339411830",
    appId: "1:696339411830:web:64ff8dc17fb7024152c057",
    measurementId: "G-RCPW8TJ8G2"
};

firebase.initializeApp(firebaseConfig);

var contactFormDb = firebase.database().ref('hirringpeople');

document.getElementById('frmCareerss').addEventListener('submit', submitForm);

function submitForm(e) {
    e.preventDefault();
    var Name = getElementVal('Name');
    var FatherName = getElementVal('FatherName');
    var Address = getElementVal('Address');
    var ContactNo = getElementVal('ContactNo');
    var DOB = getElementVal('DOB');
    var Qualification = getElementVal('Qualification');
    var BankAccountNo = getElementVal('BankAccountNo');
    var IFSCCode = getElementVal('IFSCCode');
    var NationalId = getElementVal('NationalId');
    var MaritalStatus = getElementVal('MaritalStatus');
    var Gender = getElementVal('Gender');

    savedmessWorkExps(Name, FatherName, Address, ContactNo, DOB, Qualification, BankAccountNo, IFSCCode, NationalId, MaritalStatus, Gender);

    document.querySelector('.alert').style.display = 'block';

    setTimeout(() => {
        document.querySelector('.alert').style.display = 'none';
    }, 2000);
    document.getElementById('frmCareerss').reset();
}

const savedmessWorkExps = (Name, FatherName, Address, ContactNo, DOB, Qualification, BankAccountNo, IFSCCode, NationalId, MaritalStatus, Gender) => {
    var newcontactform = contactFormDb.push();
    newcontactform.set({
        Name: Name,
        FatherName: FatherName,
        Address: Address,
        ContactNo: ContactNo,
        DOB: DOB,
        Qualification: Qualification,
        BankAccountNo: BankAccountNo,
        IFSCCode: IFSCCode,
        NationalId: NationalId,
        MaritalStatus: MaritalStatus,
        Gender: Gender,
    });
};

const getElementVal = (id) => {
    return document.getElementById(id).value;
};
