// source --> https://pflegegeldrechner.net/wp-content/plugins/simple-sidebar/js/scrpt.js?ver=7.0.2 
jQuery(document).ready(function($) {
	
	$('#ppb').fadeIn(2000);
	
	$(window).scroll(function() {
	
    if ($(this).scrollTop() > 600 /* || $(this).scrollDown() > 1 */ )
	
     {
        $('#ppb').hide();
		$('.Sidebar-Btn').fadeIn(1000);
		$('.Sidebar-Btn').removeClass('hideSidebar-Btn');
				
		// Resize the widget box
		
		var default_lenght = 10; // calculation +8px / 10px padding
		
		var item1_width = $('.item1').width();
		var item1_content_width = $('.item1_content').width();
		
		//alert(item1_width);
		
		if (default_lenght < item1_width) {
			
			function chngSizeOftheDiv() {
				
			var diff_width = default_lenght - item1_content_width + ( default_lenght * -1 ) + (-15) + 'px';

			//$('.Sidebar-Btn').removeClass("Sidebar-Btn_left"); /* regarding of position add the appropriate value wit createElement */

			/* try to use JS with if Class exists then remove */
				
			var cssValue = document.querySelector(':root');

			// Create a function for setting a width variable value
			function myFunction_set_automatic_width() {
				
				  var newCssValue = diff_width;
				  // Set the value of variable --dynamic-width-value to another value 
				  cssValue.style.setProperty('--dynamic-width-value', newCssValue);
			  
			}

			myFunction_set_automatic_width();
			
			}
						
			chngSizeOftheDiv();
		}
		
     }
	
});

// Close the popup_box
 
 $(document).on('click', '#close-btn', function(){

	$('#ppb').fadeOut(1000);
 
 });
 
 // Close info box on click
 
	 $(document).on('click', '#warning', function() {
		
		$(this).fadeOut(1000);
		
	});  

// CSS var for changing widget color

		var cssVal = document.querySelector(':root');
		
		// Create a function for setting a color variable value
		function setColor() {
				
			var setClr = $('.Sidebar-Btn').data('color-val');
			
			var newCssVal = setClr;
			// Set the value of variable --dynamic-color-value to another value 
			cssVal.style.setProperty('--dynamic-color-value', newCssVal);

		}
		
		setColor();

// CSS var for changing hover-effect color of the widget

		var cssHovVal = document.querySelector(':root');
		
		// Create a function for setting a color variable value
		function setHovColor() {
			
			var setHovClr = $('.Sidebar-Btn').data('hov-color-val');
			
			var newCssHovVal = setHovClr;
			// Set the value of variable --dynamic-color-value to another value 
			cssHovVal.style.setProperty('--dynamic-hov-color-value', newCssHovVal);

		}
		
		setHovColor();
		
// CSS var for changing TEXT color of the widget

		var cssTxtVal = document.querySelector(':root');
		
		// Create a function for setting a color variable value
		function setTxtColor() {
			
			var setTxtClr = $('.txt_clr').data('txt-color');
			
			var newCssTxtVal = setTxtClr;
			// Set the value of variable --dynamic-color-value to another value 
			cssTxtVal.style.setProperty('--dynamic-txt-color-value', newCssTxtVal);

		}
		
		setTxtColor();
		
// CSS var for changing Font Family

		var cssFontVal = document.querySelector(':root');
		
		// Create a function for setting a color variable value
		function setFontArt() {
			
			var setFont = $('.font_art').data('font-art');
			
			var newCssFontVal = setFont;
			// Set the value of variable --dynamic-font-art-value to another value 
			cssFontVal.style.setProperty('--dynamic-font-art-value', newCssFontVal);

		}
		
		setFontArt();
	
// End

	// Modal box for choosing between calculators
	const modal = document.getElementById("mdRechBox");
	const openModalBtns = document.getElementsByClassName("sdbOpenButton");
	const closeModalBtn = document.getElementById("clsMdl");
	
	const showStndCalc = document.getElementById('showTheCalc');

	// Open modal for each button/link
	Array.from(openModalBtns).forEach((link) => {
	  link.addEventListener("click", (event) => {
		event.preventDefault(); // Prevent default navigation behavior
		modal.style.display = "flex"; // Show the modal
	  });
	});
	
	// Close modal after choosing the Calculator
	
	if (showStndCalc) {
	  showStndCalc.addEventListener("click", () => {
		modal.style.display = "none"; // Hide the modal
	  });
	}
	
	// Close modal

	if(closeModalBtn) {
		closeModalBtn.addEventListener("click", () => {
		  modal.style.display = "none"; // Hide the modal
		});
	}

	// Close modal when clicking outside the content
	window.addEventListener("click", (event) => {
	  if (event.target === modal) {
		modal.style.display = "none";
	  }
	});
	
	// Hack to remove empty <p> tags from inside of the sidbar HTML probably added by wordpress autoformatting in case of <a> alements
    $('.sdbOpenButton p:empty').remove();

 });