// source --> https://www.ytviews.in/wp-content/plugins/woocommerce-multi-currency/js/woocommerce-multi-currency.min.js?ver=2.1.21 
jQuery(document).ready(function(e){"use strict";e(document.body).on("updated_checkout",function(c,t){t.hasOwnProperty("wmc_update_checkout")&&t.wmc_update_checkout&&e(document.body).trigger("update_checkout")}),e(document.body).on("payment_method_selected",function(c,t){"ppcp-gateway"===e('.woocommerce-checkout input[name="payment_method"]:checked').val()&&e(document.body).trigger("update_checkout")}),window.woocommerce_multi_currency={init:function(){this.design(),this.checkPosition(),"1"===wooMultiCurrencyParams.enableCacheCompatible&&(this.cacheCompatible(),this.ajaxComplete())},disableCurrentCurrencyLink(){e(".wmc-active a").on("click",function(e){e.preventDefault(),e.stopImmediatePropagation()})},design:function(){jQuery(window).width()<=768?jQuery(".woocommerce-multi-currency.wmc-sidebar").on("click",function(){jQuery(this).toggleClass("wmc-hover"),jQuery(this).hasClass("wmc-hover")?jQuery("html").css({overflow:"hidden"}):jQuery("html").css({overflow:"visible"})}):(jQuery(".woocommerce-multi-currency.wmc-sidebar").on("mouseenter",function(){jQuery(this).addClass("wmc-hover")}),jQuery(".woocommerce-multi-currency.wmc-sidebar").on("mouseleave",function(){jQuery(this).removeClass("wmc-hover")}))},checkPosition:function(){jQuery(".woocommerce-multi-currency .wmc-currency-wrapper").on("mouseenter",function(){this.getBoundingClientRect().top/e(window).height()>.5?e(".woocommerce-multi-currency .wmc-sub-currency").addClass("wmc-show-up"):e(".woocommerce-multi-currency .wmc-sub-currency").removeClass("wmc-show-up")})},cacheCompatible(){if("undefined"!=typeof wc_checkout_params&&1===parseInt(wc_checkout_params.is_checkout))return;let c=[],t=e(".wmc-cache-pid");t.length&&t.each(function(t,r){c.push(e(r).data("wmc_product_id"))});let r=e(".variations_form");r.length&&r.each(function(t,r){let a=e(r).data("product_variations");a.length&&a.forEach(e=>{c.push(e.variation_id)})});let a=e(".woocommerce-multi-currency.wmc-shortcode").not(".wmc-list-currency-rates"),o=[];a.map(function(){let c=e(this);o.push({layout:c.data("layout"),flag_size:c.data("flag_size")})}),c.length&&(c=[...new Set(c)]);let n=[];e(".wmc-cache-value").each(function(c,t){n.push({value:e(t).data("value"),currency:e(t).data("currency")})}),n=[...new Set(n.map(JSON.stringify))].map(JSON.parse),e.ajax({url:wooMultiCurrencyParams.ajaxUrl,type:"POST",data:{action:"wmc_get_products_price",pids:c,shortcodes:o,wmc_current_url:e(".wmc-current-url").val(),exchange:n},success(c){if(c.success){let t=c.data.prices||"",r=c.data.current_currency||"",n=c.data.exchange||"";if(o.length>0&&o.length===c.data.shortcodes.length)for(let e=0;e<o.length;e++)a.eq(e).replaceWith(c.data.shortcodes[e]);if("1"!==wooMultiCurrencyParams.switchByJS&&e(".wmc-currency a").unbind(),r&&(e(".wmc-sidebar .wmc-currency").removeClass("wmc-active"),e(`.wmc-sidebar .wmc-currency[data-currency=${r}]`).addClass("wmc-active"),e(".wmc-price-switcher .wmc-current-currency i").removeClass().addClass("vi-flag-64 flag-"+c.data.current_country),e(".wmc-price-switcher .wmc-currency").show(),e(`.wmc-price-switcher .wmc-currency[data-currency=${r}]`).hide(),e(`select.wmc-nav option[data-currency=${r}]`).prop("selected",!0)),t){for(let c in t)e(`.wmc-cache-pid[data-wmc_product_id=${c}]`).replaceWith(t[c]);e(".variations_form").each((c,r)=>{let a=e(r).data("product_variations");a&&(a.map(e=>{let c=e.variation_id;return e.price_html=t[c],e}),e(r).data("product_variations",a))})}if(n)for(let c in n)n[c].currency?e(`.wmc-cache-value[data-value=${n[c].value}][data-currency=${n[c].currency}]`).replaceWith(n[c].shortcode):e(`.wmc-cache-value[data-value=${n[c].value}][data-currency='']`).replaceWith(n[c].shortcode);jQuery(document.body).trigger("wmc_cache_compatible_finish",[c.data])}}})},ajaxComplete(){e(document).on("append.infiniteScroll",()=>{this.cacheCompatible()})}},woocommerce_multi_currency.init()});
// source --> https://www.ytviews.in/wp-content/plugins/recaptcha-woo/js/rcfwc.js?ver=1.0 
/* Woo Checkout */
jQuery( document ).ready(function() {
    jQuery( document.body ).on( 'update_checkout updated_checkout applied_coupon_in_checkout removed_coupon_in_checkout checkout_error', function() {
        if(jQuery('.g-recaptcha').length > 0) {
            if (typeof grecaptcha !== "undefined" && typeof grecaptcha.reset === "function") {
                var count = 0;
                jQuery(".g-recaptcha").each(function () {
                    grecaptcha.reset(count);
                    count++;
                });
            }
        }
    });
});

/* Woo Checkout Block */
(function() {
    document.addEventListener('DOMContentLoaded', function() {
        // Global callbacks used by auto-rendered v2 widgets in the block checkout
        window.rcfwcRecaptchaCallback = function(token) {
            try {
                if (typeof wp !== 'undefined' && wp.data) {
                    wp.data.dispatch('wc/store/checkout').__internalSetExtensionData('rcfwc', { token: token });
                }
            } catch (e) {}
        };
        window.rcfwcRecaptchaExpired = function() {
            try {
                if (typeof wp !== 'undefined' && wp.data) {
                    wp.data.dispatch('wc/store/checkout').__internalSetExtensionData('rcfwc', { token: '' });
                }
            } catch (e) {}
        };

        // Try to render explicitly if needed once the blocks mount/update
        if (typeof wp !== 'undefined' && wp.data) {
            var unsubscribe = wp.data.subscribe(function() {
                var el = document.getElementById('g-recaptcha-woo-checkout');
                if (!el) {
                    return;
                }
                // If already rendered (has inner HTML/iframe), stop listening
                if (el.innerHTML && el.innerHTML.trim() !== '') {
                    unsubscribe && unsubscribe();
                    return;
                }
                // Render explicitly with callbacks if the API is ready
                if (typeof grecaptcha !== 'undefined' && typeof grecaptcha.render === 'function') {
                    try {
                        grecaptcha.render(el, {
                            sitekey: el.getAttribute('data-sitekey'),
                            callback: rcfwcRecaptchaCallback,
                            'expired-callback': rcfwcRecaptchaExpired
                        });
                    } catch (e) {
                        // Ignore if already rendered or API not ready
                    }
                    unsubscribe && unsubscribe();
                }
            }, 'wc/store/cart');
        }
    });
})();