// source --> https://votrecoachpatissier.fr/wp-content/plugins/woocommerce-subscriptions-pro/common/js/woocommerce-subscriptions-pro-common.js?ver=2.5.5 
(function( $ ) {
	'use strict';

	/**
	 * All of the code for your common JavaScript source
	 * should reside in this file.
	 *
	 * Note: It has been assumed you will write jQuery code here, so the
	 * $ function reference has been prepared for usage within the scope
	 * of this function.
	 *
	 * This enables you to define handlers, for when the DOM is ready:
	 *
	 * $(function() {
	 *
	 * });
	 *
	 * When the window is loaded:
	 *
	 * $( window ).load(function() {
	 *
	 * });
	 *
	 * ...and/or other possibilities.
	 *
	 * Ideally, it is not considered best practise to attach more than a
	 * single DOM-ready or window-load handler for a particular page.
	 * Although scripts in the WordPress core, Plugins and Themes may be
	 * practising this, we should strive to set a better example in our own work.
	 */

	$('form.cart').on('submit', function() {
		var type = null;
		if ( $('input[name="wps_type_selection"][value="one_time"]').is(':checked')) {
			type = 'one_time';
		} else if( $('input[name="wps_type_selection"][value="subscribe"]').is(':checked') ) {
			type = 'subscribe';
		}
		$('<input>').attr({
			type: 'hidden',
			name: 'wps_type_selection',
			value: type
		}).appendTo($(this));
	});

	$(document ).on('submit', 'form.cart' ,function() {
		var type = null;
		if ( $('input[name="wps_type_selection"][value="one_time"]').is(':checked')) {
			type = 'one_time';
		} else if( $('input[name="wps_type_selection"][value="subscribe"]').is(':checked') ) {
			type = 'subscribe';
		}
		$('<input>').attr({
			type: 'hidden',
			name: 'wps_type_selection',
			value: type
		}).appendTo($(this));
	});

	$(document).ready(function() {
		if ( $('.wps_sfw_check_simple_cart_subscription_purchase').length > 0 ) {
			$('.wps_sfw_check_simple_cart_subscription_purchase').prop('checked', true);
		} else {
			setTimeout(() => {
				$('.wps_sfw_check_simple_cart_subscription_purchase').prop('checked', true);
			}, 100);
		}
	});
	
	$( document ).on( 'click', '.wps_wsp_get_edit_form', function(e){
		e.preventDefault();
		
		const subscription_id = $(this).data( 'subscription_id' );
		const data = {
			action:'wps_wsp_get_subscription_edit_form',
			nonce : wsp_common_param.nonce,
			subscription_id : subscription_id,
		};
	
		$.ajax(
			{
				url: wsp_pro_public_param.ajaxurl,
				type: "POST",
				data: data,
				success: function(response)
				{
					if ( response ) {
						$( '.subscription-edit-container' ).removeClass( 'wps-not-content' );
						$( '.subscription-edit-container' ).addClass( 'wps-has-content' );
	
						$( '.subscription-edit-container' ).html( response );
					}
				}
			}
		);
	});
	
	$( document ).on('submit', '#wps-wps-subscription-edit-form',function(event) {
		event.preventDefault(); // Prevent the default form submission
		
		// Serialize form data
		var formData = $(this).serialize();
	
		console.log(formData);
		$.ajax({
			url: wsp_pro_public_param.ajaxurl, // Replace with the URL to handle the form submission
			type: 'POST',
			dataType: 'json',
			data: {
				action: 'wps_wsp_update_subscription', // The custom action name
				form_data: formData,
				nonce : wsp_common_param.nonce,
			},
			success: function(response) {
				console.log(response);

				if ( response.status ) {
					alert(wsp_common_param.update_success );
				} else {
					alert(wsp_common_param.update_error );
				}
				window.location.reload();
			},
			error: function(xhr, status, error) {
			  // Handle error
			}
		});
	});

	$( document ).on( 'click', '.wps-wsp-close-popup', function(){
		$( '.subscription-edit-container' ).addClass( 'wps-not-content' );
		$( '.subscription-edit-container' ).removeClass( 'wps-has-content' );
		$( '.subscription-edit-container' ).empty();
	});
})( jQuery );
// source --> https://votrecoachpatissier.fr/wp-content/plugins/woocommerce/assets/js/js-cookie/js.cookie.min.js?ver=2.1.4-wc.10.6.2 
/*! js-cookie v3.0.5 | MIT */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self,function(){var n=e.Cookies,o=e.Cookies=t();o.noConflict=function(){return e.Cookies=n,o}}())}(this,function(){"use strict";function e(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)e[o]=n[o]}return e}return function t(n,o){function r(t,r,i){if("undefined"!=typeof document){"number"==typeof(i=e({},o,i)).expires&&(i.expires=new Date(Date.now()+864e5*i.expires)),i.expires&&(i.expires=i.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var c="";for(var u in i)i[u]&&(c+="; "+u,!0!==i[u]&&(c+="="+i[u].split(";")[0]));return document.cookie=t+"="+n.write(r,t)+c}}return Object.create({set:r,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var t=document.cookie?document.cookie.split("; "):[],o={},r=0;r<t.length;r++){var i=t[r].split("="),c=i.slice(1).join("=");try{var u=decodeURIComponent(i[0]);if(o[u]=n.read(c,u),e===u)break}catch(f){}}return e?o[e]:o}},remove:function(t,n){r(t,"",e({},n,{expires:-1}))},withAttributes:function(n){return t(this.converter,e({},this.attributes,n))},withConverter:function(n){return t(e({},this.converter,n),this.attributes)}},{attributes:{value:Object.freeze(o)},converter:{value:Object.freeze(n)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"})});