var BookingReservationForm = function(){};

/***
 * Init the form
 * @returns {undefined}
 */
BookingReservationForm.Init = function(){
    Event.AddById("btnValidReservation", "click", BookingReservationForm.SaveElement);
};

/***
* Get the Id of element 
*/
BookingReservationForm.GetId = function(){
    return Form.GetId("BookingReservationFormForm");
};

/*
* Save the Element
*/
BookingReservationForm.SaveElement = function(e){

    if(Form.IsValid("BookingReservationFormForm"))
    {
        Animation.AddLoading("BookingReservationFormForm");
        Animation.Hide("BookingReservationFormForm");
       
    let request = new Http("Booking", "SaveReservation");
        request.SetData(Form.Serialize("BookingReservationFormForm"));

        request.Post(data => {

            data = JSON.parse(data);

            if(data.status == "error"){
                Form.RenderError("BookingReservationFormForm", data.data.message);
            } else {
                Animation.RemoveLoading("BookingReservationFormForm");
                Animation.Load("BookingReservationFormForm", Language.GetCode("Booking.ReservationConfirmed"));
                Animation.Show("BookingReservationFormForm");
            }
        });
    }
};

