
jQuery(document).bind('gform_post_render', function(){

	mdc.autoInit();
	jQuery('.mdc-checkbox').each(function(){
        mdc.checkbox.MDCCheckbox.attachTo(this);
	})

	jQuery('.mdc-radio').each(function(){
        mdc.radio.MDCRadio.attachTo(this);
	});

	jQuery('body').on('click','.gfield_list_icons',function(){
		var parentTr = jQuery(this).parents('.gfield_list_group');
		if( parentTr.length ) {
			var siblingsTr = jQuery(parentTr).siblings('.gfield_list_group');
			siblingsTr.each( function( ) {
				var input = jQuery( this ).find('.mdc-text-field').removeAttr( 'data-mdc-auto-init-state');
			});
			window.mdc.autoInit(); // init the first created row
			return false; // break the each loop after itetrating through the first sibling;
		}
	});

	

	//ripple effect

	var btns = document.querySelectorAll('.mdc-button');
	        for (var i = 0, btn; btn = btns[i]; i++) {
	          mdc.ripple.MDCRipple.attachTo(btn);
	        }

	//keep the float above class for input fields that have placeholder

	jQuery('.mdc-text-field__input').on('blur',  function(){
		var current_field_id = jQuery(this).prop('id');
		var isOutlinedDisplay = jQuery(this).parents('.mdc-text-field--outlined').length;
		if( jQuery('#'+current_field_id).attr('placeholder') !== undefined && !isOutlinedDisplay){
			jQuery( 'label[for='+current_field_id+'].mdc-floating-label' ).addClass('mdc-floating-label--float-above');
		}
	
	});

	//keep the float above class for dropdown fields that have placeholder

	jQuery('select.mdc-select__native-control').on('blur',  function(){
		var current_field_id = jQuery(this).prop('id');
		var select_val = this.value;
		jQuery('#'+current_field_id +' option').each( function (){
			
			if( jQuery(this).hasClass('gf_placeholder') || jQuery(this).hasClass( 'stla-material-placeholder') || select_val !== ''){
			jQuery( 'label[for="'+current_field_id+'"].mdc-floating-label' ).addClass('mdc-floating-label--float-above');
		} 
		});

	});

	//set progress bar

	var determinates = document.querySelectorAll('.mdc-linear-progress');
	for (var i = 0, determinate; determinate = determinates[i]; i++) {
	  var linearProgress = mdc.linearProgress.MDCLinearProgress.attachTo(determinate);
	  linearProgress.progress = 1;
	}

	//material select
	const select = document.querySelectorAll('.mdc-select');

	for( var i = 0 ; i< select.length; i++){
		new mdc.select.MDCSelect(select[i]);
	  }

	  // console.log(mdc);
	// Switch instantiation
	const switchControl = document.querySelectorAll('.mdc-switch'); 

	for( var i = 0 ; i< switchControl.length; i++){
		new mdc.switchControl.MDCSwitch(switchControl[i]);
	  }
});



