!function(){"use strict";if(window._veesual_cta_async&&window._veesual_cta_async.isLoaded)return;var e=!!window.location.search.match(/(\?|&)_veesual_cta_debug(=|&|$)/)||!1,t=window,i=t.document,a=i.location,n=navigator;function o(e,i,a){t.addEventListener?e.addEventListener(i,a,!1):t.attachEvent&&e.attachEvent("on"+i,a)}function s(t,i){e&&"object"==typeof console&&(void 0!==i?console.log("[Veesual] "+t,i):console.log("[Veesual] "+t))}function c(t){e&&console&&console.log&&(console.log(t),console.log(t.stack))}function l(){var e,t,i,a;for(s("start pushHandling"),e=0;e<arguments.length;e++)try{s("start Try "+(t=arguments[e].shift())),(i=this)[a=t]&&"function"==typeof i[a]?(this[t].apply(this,arguments[e]),s("Executed "+t)):s("Method "+t+" not found")}catch(e){c(e)}}function r(e,t){"a"===e.tagName.toLowerCase()&&t(e);const i=e.getElementsByTagName("a");for(let e=0;e<i.length;e++)t(i[e])}var d=[],u=!1,f={},p={};const _=(new Date).valueOf();var v=function(){this.init()},h=v.prototype;h.init=function(){},h.isLoaded=function(){return!0},h.callOnCTALoad=function(e){if(u)!0!==e&&e();else{if(!0===e){for(var t=0;t<d.length;t++)d[t]();return d=[],void(u=!0)}d.push(e)}},h.addJsFallbackListener=function(e,t,n,c,l={},r={}){o(e,"click",(function(n){i.veesual_js_fallback={};for(const e of["experience_id","garment_id","module"])r[e]&&(i.veesual_js_fallback[e]=r[e]);for(const e of["cta_location","cta_version"])l[e]&&(i.veesual_js_fallback[e]=l[e]);i.veesual_js_fallback.referrer=a.href;try{i.veesual_js_fallback.origin=new URL(e.getAttribute("href"),i.baseURI).href}catch(n){i.veesual_js_fallback.origin=e.getAttribute("href")}s(`CTA ${t} got clicked with ${JSON.stringify(i.veesual_js_fallback)}`)}))};let y=[];h.addSwitchModelListener=function(e,n,c,l,r={},d={}){r.module&&"switch_model"==r.module&&o(e,"click",(function(e){e.preventDefault(),s(`CTA ${n} got clicked`);if(!i.getElementById("veesual_switch_model_js")){s(`CTA ${n} loading Switch Model JS`);const e=i.createElement("script");r.api_prefix&&"/v1/eileenfisher"===r.api_prefix&&a.host.match(/^www\./)?e.src=`https://eileenfisher.switch-model.veesual.ai/static/js/tag.js?v=${_}`:e.src=`https://switch-model.veesual.ai/static/js/tag.js?v=${_}`,e.id="veesual_switch_model_js",i.head.appendChild(e)}!function(){const e=d.experience_id?{experience_id:d.experience_id}:{},i={focus:d.garment_type};for(const e of["garment_id","look_id","mode","primary_color","locale"])d[e]&&(i[e]=d[e]);i.look_id||(i[`${d.garment_type.toLowerCase()}_garment_id`]=d.garment_id);const a=new CustomEvent("veesual_switch_model_event",{detail:{config:Object.assign({api_key:l,domain:c},i,e,r)}});Array.isArray(y)?(y.push(a),t.dispatchEvent(new CustomEvent("veesual_switch_model_init"))):t.dispatchEvent(a)}()}))};let b={},A={};h.nextApiCall=function(e){const t=b[e];b[e]=void 0,"function"==typeof t&&t()},h.apiCall=function(e,t,i,a,n){const o=this,s=JSON.stringify({apiBaseUrl:e,apiPrefix:t,apiPublicKey:i,params:a});if(void 0===b[s])if(b[s]=!0,void 0!==A[s]){const{code:e,parsed:t}=A[s];n(e,t),this.nextApiCall(s)}else this.doApiCall(e,t,i,a,(function(e,t){A[s]={code:e,parsed:t},n(e,t),o.nextApiCall(s)}));else if("function"==typeof b[s]){const c=b[s];b[s]=function(){o.apiCall(e,t,i,a,n),c()}}else b[s]=function(){o.apiCall(e,t,i,a,n)}},h.doApiCall=function(e,t,i,a,n){var o=new XMLHttpRequest;o.open("POST",`${e}${t}/cta`),o.setRequestHeader("Content-Type","application/json;charset=UTF-8"),o.setRequestHeader("Authorization",`Bearer ${i}`),o.onload=function(){let e=null;try{e=JSON.parse(o.responseText)}catch(e){c(e)}n(o.status,e)},o.send(JSON.stringify(a))};let m={};h.nextCreateCTA=function(e){const t=m[e];m[e]=void 0,"function"==typeof t&&t()},h.createCTA=function(e,t,i,a,n={}){const o=this;Array.isArray(e)?e.forEach((function(e){o.createCTA(e,t,i,a,n)})):void 0===m[e]?(m[e]=!0,this.doCreateCTA(e,t,i,a,n,(function(){o.nextCreateCTA(e)}))):m[e]=function(){o.createCTA(e,t,i,a,n)}};let g={};if(h.doCreateCTA=function(e,o,l,d,u={},_=null){const v=this;let h=JSON.stringify(u);const y=e+"|"+h,b=i.getElementById(e);if(!b)return"function"==typeof _&&_(),s(`CTA ${e} does not exist`);if(b.getAttribute("data-params")===h)return"function"==typeof _&&_(),s(`CTA ${e} already linked to params (${h})`);if(void 0!==f[y]){b.outerHTML=f[y],"function"==typeof u.callback&&u.callback(p[y]);const t=i.getElementById(e);if(t)try{const i=JSON.parse(t.getAttribute("data-response"));r(t,(function(t){u.module&&"switch_model"==u.module?v.addSwitchModelListener(t,e,o,d,u,i):v.addJsFallbackListener(t,e,o,d,u,i)}))}catch(e){c(e)}return"function"==typeof _&&_(),s(`CTA ${e} is loading cache (${y})`)}b.setAttribute("data-domain",o),b.setAttribute("data-params",h),b.setAttribute("data-loaded","0");const A=u.api_base_url||"https://api.veesual.ai",m=u.api_prefix||"/v1/default",C={domain:o,tag_version:l,url:a.href,device:Math.min(t.screen.width,t.screen.height)<768||n.userAgent.indexOf("Mobi")>-1?"mobile":"desktop"};for(let e in u)-1===["api_base_url","api_prefix","callback"].indexOf(e)&&(C[e]=u[e]);if(u.api_prefix){const a=t.MutationObserver||t.WebKitMutationObserver;if("/v1/laredoute"==u.api_prefix&&!C.product_external_variant_id){const t=document.getElementById("veesualContainer");if(t&&(C.product_external_variant_id=t.getAttribute("data-current-colour"),h=JSON.stringify(Object.assign({},u,{product_external_variant_id:C.product_external_variant_id})),b.setAttribute("data-params",h),!g["laredoute:"+e])){new a((function(t,i){t.forEach((function(t){"attributes"===t.type&&v.createCTA(e,o,l,d,u)}))})).observe(t,{attributes:!0}),g["laredoute:"+e]=!0}}if("/v1/gemo"==u.api_prefix){const t=document.getElementById("content");if(t&&!g["gemo:"+e]){new a((function(t,a){const n=i.getElementById(e);n&&"1"!==n.getAttribute("data-loaded")&&v.createCTA(e,o,l,d,u)})).observe(t,{subtree:!0,attributes:!0,childList:!0}),g["gemo:"+e]=!0}}}this.apiCall(A,m,d,C,(function(t,i){if(b.getAttribute("data-params")!==h)return void("function"==typeof _&&_());const n=a.search.match(/(\?|&)_veesual_cta_force(=|&|$)/);if(s("CTA response"+(n?" (forced)":""),i),200===t&&null!==i&&i.ready||n){const t=function(e,t){let i=e.getAttribute("href");if(""!==i){i=i.replace(/#[^/?]+/,"");for(const e of["cta_location","cta_version","module"])u[e]&&(t[e]=u[e]);for(const e of["experience_id","garment_id","module","cta_location","cta_version"]){if(!t[e]&&!n)continue;const a=encodeURIComponent(t[e]||"__FORCED__"),o=new RegExp(`(#(/[^?]*)??(.*&)?)${e}(=[^&]*)?`).exec(i);o?i=i.replace(o[0],`${o[1]}${e}=${a}`):i.includes("#")?i+=(i.match(/#.*\?/)?"&":"?")+`${e}=${a}`:i+=`#?${e}=${a}`}e.setAttribute("href",i)}};"function"==typeof u.callback&&u.callback(i),r(b,(function(a){t(a,i),u.module&&"switch_model"==u.module?v.addSwitchModelListener(a,e,o,d,u,i):v.addJsFallbackListener(a,e,o,d,u,i)}));const a="undefined"!=typeof getComputedStyle?getComputedStyle(b):b.style;if("none"===a.display){const e=b.getAttribute("data-display");b.setAttribute("data-display-hide",a.display),b.style.display=null!==e?e:"block"}"0"===a.opacity&&(b.setAttribute("data-opacity-hide",a.opacity),b.style.opacity="1"),"hidden"!==a.visibility&&"collapse"!==a.visibility||(b.setAttribute("data-visibility-hide",a.visibility),b.style.visibility="visible")}else for(let e of["display","opacity","visibility"])null!==b.getAttribute(`data-${e}-hide`)&&(b.style[e]=b.getAttribute(`data-${e}-hide`));b.setAttribute("data-response",JSON.stringify(i)),b.setAttribute("data-loaded","1"),f[y]=b.outerHTML,p[y]=i,"function"==typeof _&&_()}))},h.enableAnalytics=function(){const e=new CustomEvent("veesual_enable_analytics");Array.isArray(y)?(y.push(e),t.dispatchEvent(new CustomEvent("veesual_switch_model_init"))):t.dispatchEvent(e),s("CTA received enableAnalytics")},h.disableAnalytics=function(){const e=new CustomEvent("veesual_disable_analytics");Array.isArray(y)?(y.push(e),t.dispatchEvent(new CustomEvent("veesual_switch_model_init"))):t.dispatchEvent(e),s("CTA received disableAnalytics")},h.push=l,h.isLoaded=h.isLoaded,h.callOnCTALoad=h.callOnCTALoad,h.addSwitchModelListener=h.addSwitchModelListener,h.createCTA=h.createCTA,h.enableAnalytics=h.enableAnalytics,h.disableAnalytics=h.disableAnalytics,!window._veesual_cta_async||!window._veesual_cta_async.isLoaded){o(t,"veesual_switch_model_initiated",(function(){if(Array.isArray(y)){s("CTA received Switch Model JS initiated");const e=y;y=!1,e.forEach((function(e){t.dispatchEvent(e)}))}}));var C=t._veesual_cta_async,w=new v;t._veesual_cta_async=w,l.apply(w,C),w.callOnCTALoad(!0)}}();