// source --> https://createyou.hu/wp-content/plugins/woocommerce/assets/js/frontend/woocommerce.min.js?ver=10.8.1 
function on_keydown_remove_from_cart(e){" "===e.key&&(e.preventDefault(),e.currentTarget.click())}function focus_populate_live_region(){var e=["woocommerce-message","woocommerce-error","wc-block-components-notice-banner"].map(function(e){return"."+e+'[role="alert"]'}).join(", "),o=document.querySelectorAll(e);if(0!==o.length){var t=o[0];t.setAttribute("tabindex","-1");var n=setTimeout(function(){t.focus(),clearTimeout(n)},500)}}function refresh_sorted_by_live_region(){var e=document.querySelector(".woocommerce-result-count"),o=document.querySelector('[data-wp-interactive="woocommerce/product-filters"]');if(e&&window.location.search&&!o){var t=e.innerHTML;e.setAttribute("role","alert"),e.setAttribute("aria-hidden","true");var n=setTimeout(function(){e.setAttribute("aria-hidden","false"),e.innerHTML="",e.innerHTML=t,clearTimeout(n)},2e3)}}function on_document_ready(){focus_populate_live_region(),refresh_sorted_by_live_region()}jQuery(function(e){e(".woocommerce-ordering").on("change","select.orderby",function(){e(this).closest("form").trigger("submit")}),e("input.qty:not(.product-quantity input.qty)").each(function(){var o=parseFloat(e(this).attr("min"));o>=0&&parseFloat(e(this).val())<o&&e(this).val(o)});var o="store_notice"+(e(".woocommerce-store-notice").data("noticeId")||"");if("hidden"===Cookies.get(o))e(".woocommerce-store-notice").hide();else{function t(o){["Enter"," "].includes(o.key)&&(o.preventDefault(),e(".woocommerce-store-notice__dismiss-link").click())}e(".woocommerce-store-notice").show(),e(".woocommerce-store-notice__dismiss-link").on("click",function n(r){Cookies.set(o,"hidden",{path:"/"}),e(".woocommerce-store-notice").hide(),r.preventDefault(),e(".woocommerce-store-notice__dismiss-link").off("click",n).off("keydown",t)}).on("keydown",t)}e(".woocommerce-input-wrapper span.description").length&&e(document.body).on("click",function(){e(".woocommerce-input-wrapper span.description:visible").prop("aria-hidden",!0).slideUp(250)}),e(".woocommerce-input-wrapper").on("click",function(e){e.stopPropagation()}),e(".woocommerce-input-wrapper :input").on("keydown",function(o){var t=e(this).parent().find("span.description");if(27===o.which&&t.length&&t.is(":visible"))return t.prop("aria-hidden",!0).slideUp(250),o.preventDefault(),!1}).on("click focus",function(){var o=e(this).parent(),t=o.find("span.description");o.addClass("currentTarget"),e(".woocommerce-input-wrapper:not(.currentTarget) span.description:visible").prop("aria-hidden",!0).slideUp(250),t.length&&t.is(":hidden")&&t.prop("aria-hidden",!1).slideDown(250),o.removeClass("currentTarget")}),e.scroll_to_notices=function(o){o.length&&e("html, body").animate({scrollTop:o.offset().top-100},1e3)},e('.woocommerce form .woocommerce-Input[type="password"]').wrap('<span class="password-input"></span>'),e(".woocommerce form input").filter(":password").parent("span").addClass("password-input"),e(".password-input").each(function(){const o=e(this).find("input").attr("id");e(this).append('<button type="button" class="show-password-input" aria-label="'+woocommerce_params.i18n_password_show+'" aria-describedBy="'+o+'"></button>')}),e(".show-password-input").on("click",function(o){o.preventDefault(),e(this).hasClass("display-password")?(e(this).removeClass("display-password"),e(this).attr("aria-label",woocommerce_params.i18n_password_show)):(e(this).addClass("display-password"),e(this).attr("aria-label",woocommerce_params.i18n_password_hide)),e(this).hasClass("display-password")?e(this).siblings(['input[type="password"]']).prop("type","text"):e(this).siblings('input[type="text"]').prop("type","password"),e(this).siblings("input").focus()}),e("a.coming-soon-footer-banner-dismiss").on("click",function(o){var t=e(o.target);e.ajax({type:"post",url:t.data("rest-url"),data:{woocommerce_meta:{coming_soon_banner_dismissed:"yes"}},beforeSend:function(e){e.setRequestHeader("X-WP-Nonce",t.data("rest-nonce"))},complete:function(){e("#coming-soon-footer-banner").hide()}})}),"undefined"==typeof wc_add_to_cart_params&&e(document.body).on("keydown",".remove_from_cart_button",on_keydown_remove_from_cart),e(document.body).on("item_removed_from_classic_cart updated_wc_div",focus_populate_live_region)}),document.addEventListener("DOMContentLoaded",on_document_ready);
// source --> https://createyou.hu/wp-content/plugins/foxpost-packeta-group/public/js/foxpost-wc-shipping-modal.js?ver=1.0.20 
(function ($) {

	MT = window.MT || {};
	MT.modalWindow = MT.modalWindow || {};

	// Initialize default values
	MT.modalWindow.defaultOptions = {
		selector: {
			outer: '.f-wc-s-js-modal-window', // Outer element
			inner: '.f-wc-s-js-modal-window-in' // Inner element
		},
		extraClasses: {
			outer: '',
			inner: ''
		},
		iframeUrl: '', // Serves for show iframe
		html: '', // Modal window content
		duration: 0, // Duration of how long should be modal window visible
		animated: true, // Should be show and hide animated
		animationSpeed: 'fast', // Animation speed
		overlay: true, // Should be visible overlay
		onComplete: null
	};

	// Create global variable with custom config options
	MT.modalWindow.options = {};

	MT.modalWindow.create = function (options) {
		var $outerElement = $(options.selector.outer);
		var $innerElement = $(options.selector.inner);

		if (options.html != '') {
			$innerElement.html(options.html);
		}

		// Add extra classes if it is specified in options
		if (options.extraClasses.outer != '') {
			$outerElement.addClass(options.extraClasses.outer);
		}

		if (options.extraClasses.inner != '') {
			$outerElement.addClass(options.extraClasses.inner);
		}
	};

	MT.modalWindow.destroy = function () {
		// Remove extra classes if it is specified in options
		if (MT.modalWindow.options.extraClasses.outer != '') {
			$(MT.modalWindow.options.selector.outer).removeClass(MT.modalWindow.options.extraClasses.outer);
		}

		if (MT.modalWindow.options.extraClasses.inner != '') {
			$(MT.modalWindow.options.selector.inner).removeClass(MT.modalWindow.options.extraClasses.inner);
		}

		// Empty content of modal window
		$(MT.modalWindow.options.selector.inner).empty();

		// Empty custom config options
		MT.modalWindow.options = {};
	};

	MT.modalWindow.show = function (options) {
		MT.modalWindow.options = $.extend({}, MT.modalWindow.defaultOptions, options);
		var options = MT.modalWindow.options;

		if (!$(MT.modalWindow.options.selector.outer).is(':visible')) {
			// Function called after modal window is shown
			var onShowComplete = function () {
				if (options.overlay) {
					$('body').addClass('f-wc-s-window-activated');
					$('.f-wc-s-js-window-overlay').addClass('f-wc-s-js-modal-window-close');
				}

				if (options.onComplete !== null && typeof options.onComplete == 'function') {
					options.onComplete();
				}

				if (options.duration > 0) {
					setTimeout(function () {
						MT.modalWindow.hide();
					}, MT.modalWindow.options.duration);
				}
			};

			var showModal = function () {
				$(options.selector.outer).css('display', 'flex');
				$(options.selector.inner).show({
					duration: options.animated ? options.animationSpeed : 0,
					complete: onShowComplete
				});
			};

			// Create
			MT.modalWindow.create(options);

			if (options.iframeUrl != '') {
				// If content is iframe
				var $iframe = $('<iframe class="f-wc-s-js-modal-window-iframe"></iframe>');

				$iframe.on('load', function () {
					// Set correct width and height modal window according iframe content
					if ($(this).contents().length > 0) {
						$(options.selector.outer).css('display', 'flex');
						$(this).css({
							'height': $(this).contents().find('html')[0].scrollHeight + 'px',
							'width': $(this).contents().find('html')[0].scrollWidth + 'px',                            
						});
  
						// Handle click on close icon inside iframe
						$(this).contents().find('.f-wc-s-js-modal-window-close').click(function (event) {
							event.preventDefault();
							MT.modalWindow.hide();
						});
						$(options.selector.outer).css('display', '');
					}

					// Show modal
					showModal();
				});

				// Trigger iframe onload function
				$(options.selector.inner).append($iframe.attr('src', options.iframeUrl));
			} else {
				// If content is HTML
				showModal();
			}
		}
	};

	MT.modalWindow.hide = function (onComplete) {
		if ($(MT.modalWindow.options.selector.outer).is(':visible')) {
			var options = MT.modalWindow.options;

			// Function called after modal window is hidden
			var onHideComplete = function () {
				if (options.overlay) {
					$('body').removeClass('f-wc-s-window-activated');
					$('.f-wc-s-js-window-overlay').removeClass('f-wc-s-js-modal-window-close');
				}

				if (typeof onComplete === 'function') {
					onComplete();
				}

				// Destroy
				MT.modalWindow.destroy();

				$(options.selector.outer).css('display', '');
				$(options.selector.inner).css('display', '');
			};

			// Hide
			$(options.selector.inner).hide({
				duration: options.animated ? MT.modalWindow.options.animationSpeed : 0,
				complete: onHideComplete
			});
		}
	}

	$(document).ready(function () {
		// Initialize event for hidding modal window
		$(document).on('click', '.f-wc-s-js-modal-window-close', function (event) {
			event.preventDefault();
			if (event.target !== this) {
				return;
			}

			MT.modalWindow.hide();
		});
	});

})(jQuery);
// source --> https://createyou.hu/wp-content/plugins/foxpost-packeta-group/public/js/foxpost-wc-shipping-public.js?ver=1.0.20 
(function( $ ) {
	'use strict';

	/**
	 * All of the code for your public-facing 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.         
	 *    
	 */           
     
})( jQuery );

var foxpost_wc_shipping_public = {};
var MT = window.MT || {};

jQuery(document).ready(function($) {

    foxpost_wc_shipping_public = {
            init: function() {
                //console.log('foxpost_wc_shipping_public::init');
                // prevent multiple bindings when checkout refreshes
                jQuery(window).off("message.foxpost_wc_shipping");
                jQuery(window).on("message.foxpost_wc_shipping", function(e) {
                    var raw = e && e.originalEvent ? e.originalEvent.data : null;
                    if (typeof raw === 'undefined' || raw === null) return;
                    var payload = raw;
                    if (typeof raw === 'string') {
                        try {
                            payload = JSON.parse(raw);
                        } catch (err) {
                            return; // ignore non-JSON messages
                        }
                    }
                    if (typeof payload !== 'object') return;
                    var operatorId = payload.operator_id || payload.operatorId || payload.id;
                    if (!operatorId) return;

                    foxpost_wc_shipping_public.select_parcel_box(operatorId);
        			//Hide the modal window
                    if (window.MT && MT.modalWindow && typeof MT.modalWindow.hide === 'function') {
            			MT.modalWindow.hide();
                    }
                    return true;         
                });
                
           
            },                   
            show_modal: function() {
                    //console.log('foxpost_wc_shipping_public::show_modal');
            },   
            hide_modal: function() {
                    //console.log('foxpost_wc_shipping_public::hide_modal');
            },
            select_parcel_box: function(apt) {
                    //console.log('foxpost_wc_shipping_public::select_parcel_box:'+apt);
                    
                    
                    var page = 'checkout';
                    if( jQuery('body').hasClass('woocommerce-cart')) page = 'cart';   
                    var security = ''
                    var ajax_url = '';
        			//Set based on page
        			if(page == 'checkout') {
        				security = wc_checkout_params.update_order_review_nonce;
        				ajax_url = wc_checkout_params.ajax_url;
        			} else {
        				security = wc_cart_params.update_shipping_method_nonce;
        				ajax_url = wc_cart_params.ajax_url;
        			}

                    
        			//Create reuqest
        			var data = {
        				action: 'foxpost_wc_shipping_select',                   
        				security: security,
        				page: page,
                        apt: apt
        			};                     
                    
        			//Make ajax request
        			jQuery.post(ajax_url, data, function(response) {
        
        				//TODO handle error
        				if(response.success) {
        
        					// Refresh the review order section, so the selected point is visible automatically
        					jQuery('body').trigger('update_checkout');
        
        					//Update cart
        					if( jQuery('.cart_totals input.shipping_method:checked').length) {
        						jQuery('.cart_totals input.shipping_method:checked').trigger( 'change' );
        					} else {
        						jQuery('.cart_totals input.shipping_method').trigger( 'change' ); //This is when the only available option is the pont shipping one
        					}
        
        				} else {
        
        				}
        
        			});                    
                    
                    return true;
            }

    }
           
	//if( jQuery('.foxpost-wc-shipping-modal').length ) {      
		//foxpost_wc_shipping_public.init();
	//}
});