odoo.define('booking.main', function (require) {
    

    $(document).ready(function() {
        
        $('#medical_info').hide()

        $('#booking_total_price').text(
            $('#booking_price_product').val()+' €'
            );
 
    });

    $( "#medical_concern" ).change(function() {
        
        if (this.value=='have medical concern')
        {
            
            $('#medical_info').show()
            $("medical_info_div").addClass("s_website_form_required");
            $("medical_information").prop('required',true);
        }
        else
        {
            $('#medical_info').hide()
            $("medical_info_div").removeClass("s_website_form_required");
            $("medical_information").prop('required',false);
        }


      });

    $( "#back_button2" ).click(function() {
        history.back()
      });

      $( "#back_button1" ).click(function() {
        history.back()
      });

    $(":checkbox").change(function() {
        console.log('start debug price')
        //si coche adhésion alors le statut devient membre
        if(this.value==$("#membership_product").val() && this.checked)
        {
           
            if ($("#status").val()=='not member') {$("#status2").val('member')}
         
            
        }
        //si décoche adhésion alors le statut devient non membre
        if(this.value==$("#membership_product").val() && this.checked==false)
        {
            if ($("#status").val()=='not member'){$("#status2").val('not member')}
        
        }

        

            
            //recalcul du prix total selon le status
            if ($("#status2").val()=='not member')
                {   
                    
                    $("#your_status").text('non adhérent')
                   
                    $("#price_of_the_stay").text($("#booking_price").val()+' €')
                    $("#total_price").val($("#booking_price").val())
                }
            if ($("#status2").val()=='member')
                {
                    $("#your_status").text('adhérent')
                    $("#price_of_the_stay").text($("#booking_member_price").val()+' €')
                    $("#total_price").val($("#booking_member_price").val())
                }
            if ($("#status2").val()=='super member')
                {   
                    $("#your_status").text('Adhérent de soutien')
                    $("#price_of_the_stay").text($("#booking_super_member_price").val()+' €')
                    $("#total_price").val($("#booking_super_member_price").val())
                }

            $( ":checkbox" ).each(function( index ) {
                var l=this.name.length
                var i=this.name.substring(2,l-1)
                
                if (this.value==$("#membership_product").val())
                {
                    var option_price_str='#o_standard'+i
                }
                else
                {   
                    if ($("#status2").val()=='not member')
                    {
                        var option_price_str='#o_standard'+i
                    }
                    else
                    {
                        var option_price_str='#o_'+$("#status2").val()+i
                    }
                    
                }
                
                
                option_price=$(option_price_str).val()
                if  (!option_price) option_price=0
                console.log(option_price_str+'='+option_price)
                total_price=$("#total_price").val()

                if(this.checked) {
                    
                    $("#total_price").val(parseInt(total_price)+parseInt(option_price))
                    console.log($("#total_price").val())
                    
                }
                
              });
              
             $("#booking_total_price").text($("#total_price").val()+' €');
             console.log( 'total price final='+$("#booking_total_price").text())
             console.log('end debug price')
        
    });
   

});