// source --> https://colantuono.com.ar/wp-content/plugins/woocommerce/assets/js/frontend/cart-fragments.min.js?ver=10.7.0 
jQuery(function(e){if("undefined"==typeof wc_cart_fragments_params)return!1;var t=!0,r=wc_cart_fragments_params.cart_hash_key;try{t="sessionStorage"in window&&null!==window.sessionStorage,window.sessionStorage.setItem("wc","test"),window.sessionStorage.removeItem("wc"),window.localStorage.setItem("wc","test"),window.localStorage.removeItem("wc")}catch(f){t=!1}function n(){t&&sessionStorage.setItem("wc_cart_created",(new Date).getTime())}function o(e){t&&(localStorage.setItem(r,e),sessionStorage.setItem(r,e))}var a={url:wc_cart_fragments_params.wc_ajax_url.toString().replace("%%endpoint%%","get_refreshed_fragments"),type:"POST",data:{time:(new Date).getTime()},timeout:wc_cart_fragments_params.request_timeout,success:function(r){r&&r.fragments&&(e.each(r.fragments,function(t,r){e(t).replaceWith(r)}),t&&(sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(r.fragments)),o(r.cart_hash),r.cart_hash&&n()),e(document.body).trigger("wc_fragments_refreshed"))},error:function(){e(document.body).trigger("wc_fragments_ajax_error")}};function s(){e.ajax(a)}if(t){var i=null;e(document.body).on("wc_fragment_refresh updated_wc_div",function(){s()}),e(document.body).on("added_to_cart removed_from_cart",function(e,t,a){var s=sessionStorage.getItem(r);null!==s&&s!==undefined&&""!==s||n(),sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(t)),o(a)}),e(document.body).on("wc_fragments_refreshed",function(){clearTimeout(i),i=setTimeout(s,864e5)}),e(window).on("storage onstorage",function(e){r===e.originalEvent.key&&localStorage.getItem(r)!==sessionStorage.getItem(r)&&s()}),e(window).on("pageshow",function(t){t.originalEvent.persisted&&(e(".widget_shopping_cart_content").empty(),e(document.body).trigger("wc_fragment_refresh"))});try{var c=JSON.parse(sessionStorage.getItem(wc_cart_fragments_params.fragment_name)),_=sessionStorage.getItem(r),g=Cookies.get("woocommerce_cart_hash"),m=sessionStorage.getItem("wc_cart_created");if(null!==_&&_!==undefined&&""!==_||(_=""),null!==g&&g!==undefined&&""!==g||(g=""),_&&(null===m||m===undefined||""===m))throw"No cart_created";if(m){var d=1*m+864e5,w=(new Date).getTime();if(d<w)throw"Fragment expired";i=setTimeout(s,d-w)}if(!c||!c["div.widget_shopping_cart_content"]||_!==g)throw"No fragment";e.each(c,function(t,r){e(t).replaceWith(r)}),e(document.body).trigger("wc_fragments_loaded")}catch(f){s()}}else s();Cookies.get("woocommerce_items_in_cart")>0?e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show():e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").hide(),e(document.body).on("adding_to_cart",function(){e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show()}),"undefined"!=typeof wp&&wp.customize&&wp.customize.selectiveRefresh&&wp.customize.widgetsPreview&&wp.customize.widgetsPreview.WidgetPartial&&wp.customize.selectiveRefresh.bind("partial-content-rendered",function(){s()})});
// source --> https://colantuono.com.ar/wp-content/plugins/wc-dynamic-pricing-and-discounts/rightpress/jquery-plugins/rightpress-helper/rightpress-helper.js?ver=1029 
/**
 * RightPress Javascript Helper Functions
 */

(function () {

    'use strict';

    /**
     * Register functions
     */
    jQuery.extend({

        rightpress: {

            /**
             * Attempt to sanitize JSON response
             * For use as jQuery Ajax dataFilter
             * Response must start with {"result and end with ]}
             */
            sanitize_json_response: function(response) {

                try {

                    // Attempt to parse JSON
                    jQuery.parseJSON(response);

                    // Parsing succeeded
                    return response;
                }
                catch (e) {

                    // Attempt to fix malformed JSON string
                    var valid_response = response.match(/{"result.*]}/);

                    // Check if we were able to fix it
                    if (valid_response !== null) {
                        return valid_response[0];
                    }
                }
            },

            /**
             * Safely parse JSON Ajax response
             */
            parse_json_response: function (response, return_raw_data) {

                // Check if we need to return parsed object or potentially fixed raw data
                var return_raw_data = (typeof return_raw_data !== 'undefined') ?  return_raw_data : false;

                try {

                    // Attempt to parse data
                    var parsed = jQuery.parseJSON(response);

                    // Return appropriate value
                    return return_raw_data ? response : parsed;
                }
                catch (e) {

                    // Attempt to fix malformed JSON string
                    var regex = return_raw_data ? /{"result.*"}]}/ : /{"result.*"}/;
                    var valid_response = response.match(regex);

                    // Check if we were able to fix it
                    if (valid_response !== null) {
                        response = valid_response[0];
                    }
                }

                // Second attempt to parse response data
                return return_raw_data ? response : jQuery.parseJSON(response);
            },

            /**
             * Add nested object value
             */
            add_nested_object_value: function (object, path, value) {

                var last_key_index = path.length - 1;

                for (var i = 0; i < last_key_index; ++ i) {

                    var key = jQuery.isNumeric(path[i]) ? parseInt(path[i]) : path[i];

                    if (jQuery.isNumeric(path[i + 1])) {
                        if (typeof object[key] === 'undefined') {
                            object[key] = [];
                        }
                    }
                    else if (!(key in object)) {
                        object[key] = {};
                    }

                    object = object[key];
                }

                object[path[last_key_index]] = value;
            },

            /**
             * Nested object key existence check
             */
            object_key_check: function (object /*, key_1, key_2... */) {

                var keys = Array.prototype.slice.call(arguments, 1);
                var current = object;

                // Iterate over keys
                for (var i = 0; i < keys.length; i++) {

                    // Check if current key exists
                    if (typeof current[keys[i]] === 'undefined') {
                        return false;
                    }

                    // Check if all but last keys are for object
                    if (i < (keys.length - 1) && typeof current[keys[i]] !== 'object') {
                        return false;
                    }

                    // Go one step down
                    current = current[keys[i]];
                }

                // If we reached this point all keys from path
                return true;
            },

            /**
             * Clear field value
             */
            clear_field_value: function (field) {

                if (field.is('select')) {
                    field.prop('selectedIndex', 0);
                    if (field.hasClass('rightpress_select2')) {
                        field.val('').change();
                    }
                }
                else if (field.is(':radio, :checkbox')) {
                    field.removeAttr('checked');
                }
                else {
                    field.val('');
                }
            },

            /**
             * Check if field is multiselect
             */
            field_is_multiselect: function (field) {
                return (field.is('select') && typeof field.attr('multiple') !== 'undefined' && field.attr('multiple') !== false);
            },

            /**
             * Check if field is empty, i.e. does not contain text, is not checked, value is not selected etc.
             *
             * Accepts jQuery object with multiple elements for checkbox/radio sets and single element for all other input types
             *
             * TODO: REVIEW IF THIS IS OK, NEVER USED/TESTED THIS
             */
            field_is_empty: function (field) {

                // Multiple inputs - set of checkboxes or radio buttons
                if (field.length > 1) {

                    // No inputs can be checked
                    return !field.filter(':checked').length;
                }
                // No inputs
                else if (field.length < 1) {

                    // We should never end up here but lets treat this as empty just in case
                    return true;
                }
                // Single input
                else {

                    // Get field value
                    var value = field.val();

                    // Multiselect
                    if (jQuery.rightpress.field_is_multiselect(field)) {

                        // Default to empty array
                        value = value || [];

                        // No options can be selected
                        return !value.length;
                    }
                    // Radio or checkbox inputs
                    else if (field.is(':radio, :checkbox')) {

                        // Field must not be checked
                        return !field.is(':checked');
                    }
                    // Regular select fields and other inputs
                    else {

                        // Check if value is empty string or null
                        return (value === '' || value === null || value === undefined);
                    }
                }
            },

            /**
             * Get current page url with appended extra query var
             */
            get_current_url_with_query_var: function(key, value) {

                // Get current url
                var url = window.location.href;

                // Check if current url has query string
                var has_query = url.indexOf('?') > -1;

                // Get operator symbol
                var operator = has_query ? '&' : '?';

                // Append extra var if it does not exist yet
                // Note: This function currently does not check for differences in values
                if (!has_query || (url.indexOf(('?' + key + '=')) === -1 && url.indexOf(('&' + key + '=')) === -1)) {
                    url += operator + key + '=' + value;
                }

                // Return url
                return url;
            },

            /**
             * Serialize form including disabled inputs defined by selector
             */
            serialize_including_disabled: function(form, selector) {

                // Get disabled inputs and enable them
                var disabled = form.find(':input:disabled').filter(selector).removeAttr('disabled');

                // Serialize form
                var serialized = form.serialize();

                // Enable previously disabled inputs
                disabled.attr('disabled', 'disabled');

                // Return serialized data
                return serialized;
            },

            /**
             * Serialize form including disabled inputs defined by selector
             */
            escape_html: function(html) {
                return document.createElement('div').appendChild(document.createTextNode(html)).parentNode.innerHTML;
            }
    }

    });

}());
// source --> https://colantuono.com.ar/wp-content/plugins/wc-dynamic-pricing-and-discounts/rightpress/jquery-plugins/rightpress-live-product-update/rightpress-live-product-update.js?ver=1029 
/**
 * RightPress Live Product Update
 */

(function () {

    'use strict';

    /**
     * Delay helper
     */
    var delay = (function(){

        var timers = {};

        return function(callback, ms, unique){
            clearTimeout(timers[unique]);
            timers[unique] = setTimeout(callback, ms);
        };
    })();

    /**
     * Register plugin
     */
    jQuery.fn.rightpress_live_product_update = function(params) {

        var self = this;
        var form = this.closest('.product').find('form.cart');

        // Unique id for each instance
        var unique = Math.random().toString(36).slice(2);

        // On input change
        form.find(':input').on('change keyup', function() {
            queue();
        });

        // Allow inputs to be attached on the fly
        form.on('rightpress_live_product_update_attach_input', function(event, element) {
            jQuery(element).find(':input').on('change keyup', function() {
                queue();
            });
        });

        // On variation select and our custom event
        form.on('found_variation, rightpress_live_product_update_trigger', function() {
            queue();
        });

        // Trigger now
        queue();

        /**
         * Make Ajax call
         */
        function call()
        {
            // Serialize form data
            var form_data = form.serialize();

            // Get product id
            var product_id = params.product_id !== undefined ? params.product_id : form.find('button[type="submit"][name="add-to-cart"]').val();

            // Add product id
            if (product_id) {
                form_data += (form_data !== '' ? '&' : '') + 'rightpress_reference_product_id=' + product_id;
            }

            // Compile a list of field names so that even empty fields (checkboxes, file uploads etc) are submitted
            form.find('input, textarea, select').each(function() {
                if (jQuery(this).is(':visible') && typeof jQuery(this).prop('name') !== 'undefined') {
                    form_data += (form_data !== '' ? '&' : '') + 'rightpress_complete_input_list[]=' + jQuery(this).prop('name');
                }
            });

            // Send request
            jQuery.ajax({
                type: 'POST',
                url: params.ajax_url,
                context: self,
                data: {
                    action: params.action,
                    data:   form_data
                },
                dataType: 'json',
                dataFilter: jQuery.rightpress.sanitize_json_response,
                beforeSend: params.before_send,
                success: params.response_handler
            });
        }

        /**
         * Queue call
         * Waits for 500 ms before actually executing, cancels any pending processes
         */
        function queue()
        {
            delay(function() {
                call();
            }, 500, unique);
        }


    };

}());