// source --> https://www.greenbalance.com.ua/wp-content/plugins/woocommerce/assets/js/frontend/password-strength-meter.min.js?ver=10.9.4 
jQuery(function(s){"use strict";var r={init:function(){s(document.body).on("keyup change","form.register #reg_password, form.checkout #account_password, form.edit-account #password_1, form.lost_reset_password #password_1",this.strengthMeter),s("form.checkout #createaccount").trigger("change")},strengthMeter:function(){var e,t=s("form.register, form.checkout, form.edit-account, form.lost_reset_password"),a=s('button[type="submit"]',t),o=s("#reg_password, #account_password, #password_1",t),d=o.val(),n=!t.is("form.checkout");r.includeMeter(t,o),e=r.checkPasswordStrength(t,o),wc_password_strength_meter_params.stop_checkout&&(n=!0),d.length>0&&e<wc_password_strength_meter_params.min_password_strength&&-1!==e&&n?a.attr("disabled","disabled").addClass("disabled"):a.prop("disabled",!1).removeClass("disabled")},includeMeter:function(r,e){var t=r.find(".woocommerce-password-strength");if(""===e.val())t.hide(),s(document.body).trigger("wc-password-strength-hide"),e.removeAttr("aria-describedby");else if(0===t.length){t='<div id="password_strength" class="woocommerce-password-strength" role="alert"></div>';(r=e.parent()).is(".password-input")?r.after(t):e.after(t),e.attr("aria-describedby","password_strength"),s(document.body).trigger("wc-password-strength-added")}else t.show(),s(document.body).trigger("wc-password-strength-show")},checkPasswordStrength:function(s,r){var e=s.find(".woocommerce-password-strength"),t=s.find(".woocommerce-password-hint"),a='<small class="woocommerce-password-hint">'+wc_password_strength_meter_params.i18n_password_hint+"</small>",o=wp.passwordStrength.meter(r.val(),wp.passwordStrength.userInputDisallowedList()),d="";if(e.removeClass("short bad good strong"),t.remove(),e.is(":hidden"))return o;switch(o<wc_password_strength_meter_params.min_password_strength&&(d=" - "+wc_password_strength_meter_params.i18n_password_error),o){case 0:e.addClass("short").html(pwsL10n.short+d),e.after(a);break;case 1:case 2:e.addClass("bad").html(pwsL10n.bad+d),e.after(a);break;case 3:e.addClass("good").html(pwsL10n.good+d);break;case 4:e.addClass("strong").html(pwsL10n.strong+d);break;case 5:e.addClass("short").html(pwsL10n.mismatch)}return o}};r.init()});
// source --> https://www.greenbalance.com.ua/wp-content/plugins/blonwe-core/woocommerce-filter/single-ajax/js/single-ajax.js?ver=1.0 
(function ($) {
  "use strict";

	$(document).on('blonweSinglePageInit', function () {
		woocommerceSingleAjax();
	});

	function woocommerceSingleAjax() {
		// Klb Notice
		$('body').append('<div class="klb-notice-ajax"></div>');

		$(".single-product form.cart").addClass("single-ajax");
		
		$(".product:not(.product-type-external) form.cart").submit(function() { 
			var val = $("button[type=submit][clicked=true]").val();
		});
		$(".product:not(.product-type-external) form.cart button[type=submit]").click(function() {
			$("button[type=submit]", $(this).parents("form")).removeAttr("clicked");
			$(this).attr("clicked", "true");
		});

		// AJax single add to cart
		$('.product:not(.product-type-external) .product-detail form.cart, .single .product:not(.product-type-external) form.cart').on('submit', function(e) {

			if($('button[type=submit][clicked=true]').attr('id') == 'buynow'){
				return;
			}

			e.preventDefault();

			var form = $(this);
			$('form.cart button.single_add_to_cart_button').append('<svg class="loader-image preloader added" width="65px" height="65px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg"><circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle></svg>')

			var formData = new FormData(form[0]);
			formData.append('add-to-cart', form.find('[name=add-to-cart]').val() );

			// Ajax action.
			$.ajax({
				url: wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'blonwe_add_to_cart' ),
				data: formData,
				type: 'POST',
				processData: false,
				contentType: false,
				complete: function( response ) {
					response = response.responseJSON;

					// Redirect to cart option
					if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) {
						window.location = wc_add_to_cart_params.cart_url;
						return;
					}

					if ( ! response ) {
						return;
					}

					if ( response.error && response.product_url ) {
						window.location = response.product_url;
						return;
					}

					var $thisbutton = form.find('.single_add_to_cart_button'); //
					// $thisbutton = null; // uncomment this if you don't want the 'View cart' button

					// Trigger event so themes can refresh other areas.
					$( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $thisbutton ] );

					$(response.fragments.notices_html).appendTo('.klb-notice-ajax').delay(3000).fadeOut(300, function(){ $(this).remove();});

					//Close icon
					$('.woocommerce-message, .woocommerce-error').append('<div class="klb-notice-close"><i class="klb-icon-xmark-thin"></i></div>');
					$('.klb-notice-close').on('click', function(){
						$(this).closest('.woocommerce-message, .woocommerce-error').remove();
					});

					$('.product-detail form.cart.single-ajax button svg, .single-product-sticky .product-inner form.cart.single-ajax button svg').remove();
				},
				dataType: 'json'
			});
		});
	}
	
	$(document).ready(function() {
		woocommerceSingleAjax();
	});
	
}(jQuery));