
((r,a)=>{function e(t,e,i){var s;void 0===i&&(i=o),(s=new Date).setTime(s.getTime()+i),i="expires="+s.toUTCString(),document.cookie=t+"="+e+"; "+i+"; path=/"}function s(t){for(var e=t+"=",i=decodeURIComponent(document.cookie).split(";"),s=0;s<i.length;s++){for(var o=i[s];" "===o.charAt(0);)o=o.substring(1);if(0===o.indexOf(e))return o.substring(e.length,o.length)}return""}var o,n,t,c,_,d,h,p;function l(){return this instanceof l?t||((t=this).COOKIE_NAME="wc_prl_deployments_clicked",this.cookie_raw="",void(this.clicks=[])):new l}function u(){return this instanceof u?d||((d=this).COOKIE_NAME="wc_prl_recently_viewed",this.cookie_raw="",this.viewed_ids=[],this.viewed_cat_ids=[],void(this.viewed_tag_ids=[])):new u}(WC_PRL=a.WC_PRL||{}).$window=r(a),WC_PRL.params=a.wc_prl_params,WC_PRL.cookies=WC_PRL.cookies||{},WC_PRL.cookies.model=(o=1e3*WC_PRL.params.shopping_session_seconds,{set:e,get:s,remove:function(t){document.cookie=t+"=; expires=Thu, Jan 01 1970 00:00:00 UTC;path=/"},refresh:function(t){e(t,s(t))}}),WC_PRL.cookies.clicks=(n=WC_PRL.cookies.model,c=WC_PRL.params.clicks_max_cookie_num,l.prototype.init=function(){this.cookie_raw=n.get(this.COOKIE_NAME),""!==this.cookie_raw&&(this.clicks=this.cookie_raw.split(","),n.set(this.COOKIE_NAME,this.clicks.join(",")))},l.prototype.is_clicked=function(t){return-1!==this.clicks.indexOf(t)},l.prototype.add=function(t){this.is_clicked(t)||(this.clicks.length>c-1&&this.clicks.splice(0,1),this.clicks.push(t),n.set(this.COOKIE_NAME,this.clicks.join(",")))},l),WC_PRL.cookies.recently_viewed=(_=WC_PRL.cookies.model,h=WC_PRL.params.recently_views_max_cookie_num,u.prototype.init=function(){var t;this.cookie_raw=_.get(this.COOKIE_NAME),""!==this.cookie_raw&&((t=this.cookie_raw.split(",")).length&&(this.viewed_ids=r.map(t[0].split("|"),function(t){return parseInt(t,10)}),1<t.length&&(this.viewed_cat_ids=r.map(t[1].split("|"),function(t){return parseInt(t,10)})),2<t.length)&&(this.viewed_tag_ids=r.map(t[2].split("|"),function(t){return parseInt(t,10)})),this.save())},u.prototype.add_product_id=function(t){this.viewed_ids.length>h&&this.viewed_ids.shift(),t=parseInt(t,10);var e=this.viewed_ids.indexOf(t);-1<e&&this.viewed_ids.splice(e,1),this.viewed_ids.push(t)},u.prototype.add_category_id=function(t){this.viewed_cat_ids.length>h&&this.viewed_cat_ids.shift(),t=parseInt(t,10);var e=this.viewed_cat_ids.indexOf(t);-1<e&&this.viewed_cat_ids.splice(e,1),this.viewed_cat_ids.push(t)},u.prototype.add_tag_id=function(t){this.viewed_tag_ids.length>h&&this.viewed_tag_ids.shift(),t=parseInt(t,10);var e=this.viewed_tag_ids.indexOf(t);-1<e&&this.viewed_tag_ids.splice(e,1),this.viewed_tag_ids.push(t)},u.prototype.save=function(){var t=this.viewed_ids.join("|"),e=this.viewed_cat_ids.join("|"),i=this.viewed_tag_ids.join("|");this.cookie_raw=t,e&&(this.cookie_raw+=","+e),i&&(this.cookie_raw+=","+i),_.set(this.COOKIE_NAME,this.cookie_raw)},u),WC_PRL.Deployment=(()=>{function e(t){return this instanceof e?!!t.length&&(this.id=null,this.engine_id=null,this.location_hash=null,this.source_hash=null,void(this.$deployment=t)):new e(t)}return WC_PRL.params,e.prototype.get_id=function(){var t;return this.id||(t=this.$deployment.attr("id"),t=parseInt(t.match(/([0-9]+)$/g),10),this.id=t),this.id},e.prototype.get_engine_id=function(){var t;return this.engine_id||(t=parseInt(this.$deployment.data("engine"),10),this.engine_id=t),this.engine_id},e.prototype.get_location_hash=function(){var t;return this.location_hash||(t=this.$deployment.data("location-hash"),this.location_hash=t),this.location_hash},e.prototype.get_source_hash=function(){var t;return this.source_hash||(t=this.$deployment.data("source-hash"),this.source_hash=t),this.source_hash},e.prototype.setup_events=function(){var e=this,i=WC_PRL.cookies.clicks();this.$deployment.on("click","a",function(){var t=r(this);t.attr("href")&&(t=(t=t.parent().attr("class").match(/post-([0-9-]+)\s?/g))instanceof Array?parseInt(t.pop().replace("post-","").trim(),10):0)&&(t=[e.get_id(),t],e.get_source_hash()&&t.push(e.get_source_hash()),t=t.join("_"),i.add(t))})},e})(),WC_PRL.tracking=(p=WC_PRL.cookies.recently_viewed(),{add_deployment_events:function(t=void 0){var e,i;"no"!==WC_PRL.params.tracking_enabled&&(t=t&&t.length?t:r(".wc-prl-recommendations:not(.placeholder)")).length&&(e="yes"===WC_PRL.params.ajax_add_to_cart,i=r(document.body).hasClass("woocommerce-checkout"),t.each(function(){var t=r(this);new WC_PRL.Deployment(t).setup_events(),e&&i&&t.on("click","a.add_to_cart_button",function(){r(document.body).one("added_to_cart",function(){r(document.body).trigger("update_checkout")})})}))},maybe_track_product_view:function(){if(r("body.single-product").length){var t,e=r("#wc-prl-recommendations-tracking-data").first();if(e.length)if(t=e.data("product-id")){p.init();var e=e.attr("class"),s=e.match(/wc-prl-cat-([0-9-]+)\s?/g);if(s&&s instanceof Array){var o=s.pop().replace("wc-prl-cat-","").trim().split("-");for(i in o)p.add_category_id(o[i])}s=e.match(/wc-prl-tag-([0-9-]+)\s?/g);if(s&&s instanceof Array){var n=s.pop().replace("wc-prl-tag-","").trim().split("-");for(i in n)p.add_tag_id(n[i])}p.add_product_id(t),p.save()}else a.console.warn("Could not parse the product id. Tracking bypassed...");else a.console.warn("Could not parse the product id. Tracking bypassed...")}}}),WC_PRL.template={render_placeholders:function(t){var e,i,s,o;(t=t||r(".wc-prl-ajax-placeholder")).length&&(o=[],t.each(function(){var t=r(this).attr("id");o.push(t)}),i=o,t.each(function(){var t=r(this).attr("data-env");try{s=JSON.parse(t)}catch(t){s=!1}if(s)return!1}),e=s,i={locations:i.join(","),product:e.product||"",archive:e.archive||"",order:e.order||"",current_url:a.location.href},WC_PRL.$window.trigger("wc_prl_deployments_before_render"),r.post(woocommerce_params.wc_ajax_url.toString().replace("%%endpoint%%","woocommerce_prl_print_location"),i,function(e){for(var i in"failure"===e.result&&a.console.error("PRL Deployment Render Error: ",e),e.html)e.html[i]&&t.each(function(){var t=r(this);if(i==t.attr("id"))return t.replaceWith(e.html[i]),!1});WC_PRL.$window.trigger("wc_prl_deployments_after_render"),"yes"===WC_PRL.params.tracking_enabled&&WC_PRL.tracking.add_deployment_events()}))}},"yes"===WC_PRL.params.tracking_enabled&&WC_PRL.cookies.clicks().init(),r(function(){WC_PRL.tracking.maybe_track_product_view();var t=r(".wc-prl-ajax-placeholder");t.length?WC_PRL.template.render_placeholders(t):"yes"===WC_PRL.params.tracking_enabled&&WC_PRL.tracking.add_deployment_events()})})(jQuery,window);