(function(f){var m=window.AmazonUIPageJS||window.P,r=m._namespace||m.attributeErrors,d=r?r("IVMTwisterPriceFetcherAssets",""):m;d.guardFatal?d.guardFatal(f)(d,window):d.execute(function(){f(d,window)})})(function(f,m,r){f.declare("ivm-twister-constants",{VERSION_FOR_COUNTRY_DIMENSION_NAME:"version_for_country",IVM_TWISTER_SELECTION_CHANGED:"ivm:twister:selection_changed",IVM_TWISTER_FETCH_PRICES_REQUESTED:"ivm:twister:fetch_prices_requested",IVM_TWISTER_FETCH_PRICES_SUCCEEDED:"ivm:twister:fetch_prices_succeeded",
IVM_TWISTER_FETCH_PRICES_FAILED:"ivm:twister:fetch_prices_failed",IVM_TWISTER_FETCH_PRICES_LATENCY:"ivm:twister:fetch_prices_latency",IVM_TWISTER_INVALID_SEL_INFO_VALID_COMBINATIONS_STRING:"ivm:twister:invalid_sel_info_valid_combinations_string",IVM_TWISTER_SWATCH_NOT_FOUND:"ivm:twister:swatch_not_found",IVM_TWISTER_SWATCH_PRICE_INITIALIZE_FAILED:"ivm:twister:swatch_price_initialize_failed",IVM_TWISTER_SWATCH_PRICE_UPDATE_FAILED:"ivm:twister:swatch_price_update_failed",IVM_TWISTER_ATTRIBUTION:"ivm-twister",
IVM_TWISTER_VARIATION_CHANGE_EVENT:"VARIATION_CHANGE",IVM_HELPER_LINK_ID:"ivm-explain-modal-link",IVM_TWISTER_SELECTED_SWATCH_CLASS:"swatchSelect",IVM_TWISTER_SWATCH_PRICE_SPAN_CLASS:"twisterSwatchPrice",IVM_TWISTER_SWATCH_PRICE_WRAPPER_CLASS:"twisterSwatchPriceWrapper",VERSION_FOR_COUNTRY_SWATCH_SELECTOR:"div#variation_version_for_country li",VERSION_FOR_COUNTRY_SWATCH_TEXT_SELECTOR:".twisterTextDiv .a-size-base",IVM_TWISTER_PRICE_SEPARATOR:" - ",IVM_TWISTER_DIM_COMBINATION_SEPARATOR:":"});"use strict";
f.when("A","jQuery","ivm-twister-constants").register("ivm-twister-helper",function(d,e,a){return{isIvmFeatureEnabled:function(){var b=e("#"+a.IVM_HELPER_LINK_ID);return null!==b&&0<b.length}}});"use strict";f.when("A","jQuery","ivm-twister-constants","ivm-twister-helper","ivm-twister-price-updater","ivm-twister-csm-counters","ivm-twister-csm-latency-counter","twisterModule").register("ivm-twister-controller",function(d,e,a,b,c,k,h,l){d.on(a.IVM_TWISTER_SELECTION_CHANGED,function(b){k.incrementCounter(a.IVM_TWISTER_SELECTION_CHANGED,
1);var g=l.getState();g&&h.markStart(a.IVM_TWISTER_FETCH_PRICES_LATENCY,g.current_asin);c.clearIvmTwisterPrices();d.trigger(a.IVM_TWISTER_FETCH_PRICES_REQUESTED,b);k.incrementCounter(a.IVM_TWISTER_FETCH_PRICES_REQUESTED,1)});d.on(a.IVM_TWISTER_FETCH_PRICES_FAILED,function(b){var g=l.getState();g&&h.markEnd(a.IVM_TWISTER_FETCH_PRICES_LATENCY,g.current_asin);k.incrementCounter(a.IVM_TWISTER_FETCH_PRICES_FAILED,1);f.log("Received "+a.IVM_TWISTER_FETCH_PRICES_FAILED+". Message: "+b+".","ERROR",a.IVM_TWISTER_ATTRIBUTION)});
d.on(a.IVM_TWISTER_FETCH_PRICES_SUCCEEDED,function(b){var g=l.getState();g&&h.markEnd(a.IVM_TWISTER_FETCH_PRICES_LATENCY,g.current_asin);k.incrementCounter(a.IVM_TWISTER_FETCH_PRICES_SUCCEEDED,1);c.showIvmTwisterPrices(b)});return{twisterSelectionChangedHandler:function(c,g,p){if(b.isIvmFeatureEnabled()){var q=p.dimensionInfo;if(!(2>q.length)){var t=!1,h=!1;q.forEach(function(a){a.dimKey===c?t=!0:1<a.size&&(h=!0)});if(t&&h){g=e.map(g,function(a){return a.dimKey===c?"[^d+$]":a.val});g=new RegExp(g.join(":"),
"g");q=p.validCombinatonString;for(var n=[],l;l=g.exec(q);)n.push(l[0]);if(0===n.length)f.log("ivm-twister-controller::twisterSelectionChangedHandler: Found no asinKeys for regexp: "+g+", validCombinatonString: "+q,"ERROR",a.IVM_TWISTER_ATTRIBUTION),k.incrementCounter(a.IVM_TWISTER_INVALID_SEL_INFO_VALID_COMBINATIONS_STRING,1);else{var m=p.dimCombinations;p=e.map(n,function(a){return m[a]});d.trigger(a.IVM_TWISTER_SELECTION_CHANGED,p)}}}}}}});"use strict";f.when("A").register("ivm-twister-csm-counters",
function(d){var e=function(a){return ue.count(a)||0},a=function(a,c){ue.count(a,c)};return{getCounter:e,setCounter:a,incrementCounter:function(b,c){c=c||1;a(b,e(b)+c)}}});"use strict";f.when("A","ivm-twister-csm-counters").register("ivm-twister-csm-latency-counter",function(d,e){var a={};return{markStart:function(b,c){null!=b&&(b in a||(a[b]={}),null!=c&&(a[b][c]=Date.now()))},markEnd:function(b,c){if(null!=b&&a[b]&&c in a[b]){var d=Date.now()-a[b][c];delete a[b][c];e.setCounter(b,d)}}}});f.when("A",
"jQuery","cf","ivm-twister-price-updater").execute("ivm-twister-initialize-price-slots",function(d,e,a,b){b.initializeIvmPriceSlots()});f.when("A","jQuery","ivm-twister-constants","ivm-twister-controller","desktop-twister").execute("ivm-twister-initial-price-fetch",function(d,e,a,b,c){b.twisterSelectionChangedHandler(a.VERSION_FOR_COUNTRY_DIMENSION_NAME,c.tsm.currentState().selected().selInfo,c.tvm)});"use strict";f.when("A","jQuery","ivm-twister-constants","ivm-twister-controller","desktop-twister").register("ivm-twister-passive-view-registration",
function(d,e,a,b,c){this.initialize=function(){c.registerPassive({viewAttribution:a.IVM_TWISTER_ATTRIBUTION,viewName:"VersionForCountryAsinsAfterSelectionChanged"},{updateView:function(d,e){d===a.IVM_TWISTER_VARIATION_CHANGE_EVENT&&b.twisterSelectionChangedHandler(a.VERSION_FOR_COUNTRY_DIMENSION_NAME,e.selected().selInfo,c.tvm)}})};this.initialize()});"use strict";f.when("A","jQuery","ivm-twister-constants","desktop-twister").register("ivm-twister-price-fetcher",function(d,e,a,b){function c(b){try{if(!b.ASIN)throw Error("ASIN not set in callback from slotsDimSum");
var c=b.Value.content.twisterSlotDiv;if(!c)throw Error("Invalid ASIN slot in callback from slotsDimSum");var f=e(e.parseXML("\x3civmRoot\x3e"+c+"\x3c/ivmRoot\x3e")).find(".twisterSwatchPrice");var k=f.length?d.trim(f.text()):!1;k&&d.trigger(a.IVM_TWISTER_FETCH_PRICES_SUCCEEDED,[{asin:b.ASIN,price:k}])}catch(g){d.trigger(a.IVM_TWISTER_FETCH_PRICES_FAILED,{asins:[b.ASIN],error:g})}}d.on(a.IVM_TWISTER_FETCH_PRICES_REQUESTED,function(e){try{e.length&&b.slotsDimSum.get(e,c)}catch(h){d.trigger(a.IVM_TWISTER_FETCH_PRICES_FAILED,
{asins:e,error:h})}})});"use strict";f.when("A","jQuery","ivm-twister-constants","ivm-twister-csm-counters","ivm-twister-helper","desktop-twister").register("ivm-twister-price-updater",function(d,e,a,b,c,k){var h=function(c,e){b.incrementCounter(c,1);f.log(e,"ERROR",a.IVM_TWISTER_ATTRIBUTION)},l=function(b,c){var d=e("\x3cspan/\x3e",{class:a.IVM_TWISTER_SWATCH_PRICE_WRAPPER_CLASS,html:a.IVM_TWISTER_PRICE_SEPARATOR});d.append(e("\x3cspan/\x3e",{class:a.IVM_TWISTER_SWATCH_PRICE_SPAN_CLASS,html:c}));
b.append(d)},m=function(b,c,d){b.forEach(function(b){b=b.trim().split(a.IVM_TWISTER_DIM_COMBINATION_SEPARATOR)[c];b=e(a.VERSION_FOR_COUNTRY_SWATCH_SELECTOR+":eq("+b+")").find(a.VERSION_FOR_COUNTRY_SWATCH_TEXT_SELECTOR);if(null===b||0===b.length)return h(a.IVM_TWISTER_SWATCH_NOT_FOUND,"Could not find IVM swatch to clear price with selector '"+a.VERSION_FOR_COUNTRY_SWATCH_SELECTOR+" "+a.VERSION_FOR_COUNTRY_SWATCH_TEXT_SELECTOR+"', for asin: "+d.asin+"."),!1;var g=d.price,f=b.find("."+a.IVM_TWISTER_SWATCH_PRICE_WRAPPER_CLASS);
null===f||0===f.length?l(b,g):(0===b.parents("."+a.IVM_TWISTER_SELECTED_SWATCH_CLASS).length&&f.find("."+a.IVM_TWISTER_SWATCH_PRICE_SPAN_CLASS).html(g),f.show())})};return{initializeIvmPriceSlots:function(){if(c.isIvmFeatureEnabled()){var b=e(a.VERSION_FOR_COUNTRY_SWATCH_SELECTOR+" "+a.VERSION_FOR_COUNTRY_SWATCH_TEXT_SELECTOR);null!==b&&0<b.length&&b.each(function(){var b=e(this);try{var c=b.contents().get(0).nodeValue.trim(),d=/\s-\s[\D]*\d[\d,.]*[\D]*/g,f=c.match(d),g=b.find("."+a.IVM_TWISTER_SWATCH_PRICE_WRAPPER_CLASS);
null!==f&&(b.contents().get(0).nodeValue=c.replace(d,""),null!==g&&0!==g.length||l(b,f[0].replace(/^\s-\s/g,"")))}catch(u){h(a.IVM_TWISTER_SWATCH_PRICE_INITIALIZE_FAILED,"Price initialize failed for: "+b.text().trim()+". Message: "+u.message+". Stack: "+u.stack)}})}},clearIvmTwisterPrices:function(){e(a.VERSION_FOR_COUNTRY_SWATCH_SELECTOR+" "+a.VERSION_FOR_COUNTRY_SWATCH_TEXT_SELECTOR+" ."+a.IVM_TWISTER_SWATCH_PRICE_WRAPPER_CLASS).each(function(){e(this).hide()})},showIvmTwisterPrices:function(b){b.forEach(function(b){try{var c=
k.tvm,d=Object.keys(c.dimCombinations).filter(function(a){return c.dimCombinations[a]===b.asin}),e=c.dimInfoMap[a.VERSION_FOR_COUNTRY_DIMENSION_NAME].dimOrder}catch(n){return h(a.IVM_TWISTER_SWATCH_PRICE_UPDATE_FAILED,"Price update failed for ASIN: "+b.asin+". Message: "+n.message+". Stack: "+n.stack),!1}m(d,e,b)})}}})});