!function(){"use strict";const e=()=>Object.prototype.hasOwnProperty.call(top,"ABTastyEditor"),t=t=>{const i=(()=>{if(e()||(()=>{const e=!!document.getElementById("ABTastyPreviewBar"),t=location.href.includes("ab_project=preview");return e||t})())return!1;const t=ABTasty.getTestsOnPage()[TEST_ID];return!!t&&Object.keys(t.targetings.qaParameters).length>0})(),s=window.document.cookie.includes("abTastyDebug=")||!0===window.abTastyDebug;if(i||s){const e=(()=>{const e=(()=>{const{type:e}=DATA;return`${PACKAGE.replace("@abtasty/","")}${e?`_${e}`:""}`})();return`${e.charAt(0).toUpperCase()}${e.slice(1)}`.split("-").join(" ")})();window.console.log(`%c${e} - ${i?"QA":"Debug"} Mode for campaign ${TEST_ID} %c ${t}`,"background-color: #D6FF01; color: #3100be; padding: 3px 0 3px 10px; border-radius: 5px 0 0 5px; font-weight: bold;","background-color: #3100be; color: white; padding: 3px 10px 3px 0; border-radius: 0 5px 5px 0;")}},i=e=>(e=>{if("string"!=typeof e||!e.trim().length)return null;const[t,i,s]=e.split("[]").map(e=>e.trim()),r=Boolean(s)?s:e,n=i?document.querySelector(t)?.[i]:document;return n?n.querySelector(r):null})(e),s=(e,t)=>{const s={childList:!0,subtree:!0,attributes:!0},r=()=>n.disconnect(),n=new MutationObserver(()=>{const s=i(t);return s&&!r()&&e(s)});return{clear:r,observe:e=>{const t=document.querySelector("body")||document.documentElement,i=e??t;n.observe(i,s)}}},r=()=>{},n=(t,o)=>{const l=i(t),a={selector:t,clear:r,observe:r};if(l)return setTimeout(()=>o(l),0),a;if(e())return setTimeout(()=>n(t,o),1e3),a;if(t.includes("[]"))return((e,t)=>{const[r,n]=t.split("[]").map(e=>e.trim()),o=i(r),l=o?.[n],{clear:a,observe:c}=s(e,t),u=()=>{const s=i(t);return s&&!h()&&e(s)},h=()=>{a(),o?.removeEventListener("load",u)},d=()=>{c(l),"iframe"===o?.localName&&o.addEventListener("load",u)};return d(),{selector:t,clear:h,observe:d}})(o,t);const{clear:c,observe:u}=s(o,t);return u(),{selector:t,clear:c,observe:u}};function o(e,t){const i=e.parentElement||e.getRootNode().host;return t(e)||!i?e:o(i,t)}let l=!1;const a="abtasty_executedCampaign";class c{constructor(){this.targets=[],this.existingTargets=[],this.inViewportTargets=[],this.visibilityObserver=null,this.mutationObserver=null,this.mouseOverEvent=null,this.scrollEvent=null,this.onTransitionEnd=null,this.onIframeLoad=null}transitionOverHandler(e){const t=[e,"transitionend",this.checkElements.bind(this),!0];return this.getEvents(...t)}intersectionHandler(e){e.forEach(e=>{e.isIntersecting?(this.existingTargets.forEach(t=>{t.element.isSameNode(e.target)&&(this.inViewportTargets.push(t),this.mouseOverEvent.start(),this.scrollEvent.start(),this.onTransitionEnd.start())}),this.checkElements()):this.inViewportTargets=this.inViewportTargets.filter(t=>!t.element.isSameNode(e.target)||(this.mouseOverEvent.clear(),this.scrollEvent.clear(),this.onTransitionEnd.clear(),!1))})}startVisibilityObserver(e){const t={root:e,rootMargin:"0px",threshold:.01};return this.visibilityObserver??=new IntersectionObserver(this.intersectionHandler.bind(this),t),this.visibilityObserver}startMutationObserver(e){return this.mutationObserver??=new MutationObserver(this.checkElements.bind(this)),this.mutationObserver.observe(e,{attributes:!0,childList:!0,subtree:!0}),this.mutationObserver}onMouseOver({target:e,path:t}){const i=this.inViewportTargets.find(({element:i,selector:s})=>{if(i.isSameNode(e))return!0;const[r,,n]=s.split("[]"),o=n??r,l=[...e.querySelectorAll(o)];if(l.length&&l.includes(i))return!0;if(t.includes(i))return!0;if(!e.parentElement?.children?.length)return;const a=[...e.parentElement.children],c=a.findIndex(t=>t.isSameNode(e)),u=a.filter((e,t)=>t>c);if(u.length){if(u.includes(i))return!0;if(u.some(e=>[...e.querySelectorAll(o)].includes(i)))return!0}return!1});if(i&&this.isElementVisible(i.element)){const{selector:e,element:t,uniqueId:s}=i,r=this.targets.find(t=>t.selector===e&&t.uniqueId===s);r&&r.resolve(t),this.clear(e,s)}}getEvents(e,...t){return{start:()=>e?.addEventListener(...t),clear:()=>e?.removeEventListener(...t)}}mouseOverHandler(e){const t=[e,"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0?"touchmove":"mouseover",e=>{const t=e.composedPath(),{target:i}=e;setTimeout(()=>this.onMouseOver({target:i,path:t}),50)},!0];return this.getEvents(...t)}scrollEventHandler(e){const t=[e,"scroll",(i=this.checkElements.bind(this),()=>{l||(l=!0,setTimeout(()=>{i(),l=!1},100))}),{passive:!0}];var i;return this.getEvents(...t)}isElementVisible(e){return this.isElementOpaque(e)&&this.isElementTopmost(e)}isElementOpaque(e){return"HTML"===o(e,e=>"0"===window.getComputedStyle(e).opacity).nodeName}isElementTopmost(e){const t=e.getBoundingClientRect(),i=[[t.left,t.top],[t.right,t.top],[t.left,t.bottom],[t.right,t.bottom],[t.left+t.width/2,t.top],[t.left+t.width/2,t.bottom],[t.left,t.height/2],[t.right,t.height/2],[t.left+t.left/2,t.height/2]];let s=!1,r=0;for(;!s&&r<i.length;){const t=e.getRootNode()?.elementFromPoint(...i[r]);s=e===t||t?.contains(e)||e.contains(t),r+=1}return s}checkElements(){this.targets.forEach(({selector:e,uniqueId:t})=>{const s=i(e),[r,,n]=e.split("[]"),o=n??r;s&&!this.existingTargets.find(e=>e.element.matches(o)&&e.uniqueId===t)&&(this.existingTargets.push({element:s,selector:e,uniqueId:t}),this.visibilityObserver.observe(s))}),this.existingTargets=this.existingTargets.filter(({selector:e,element:t})=>!(!i(e)||!t.isConnected)||(t&&this.visibilityObserver.unobserve(t),!1)),this.inViewportTargets=this.inViewportTargets.filter(({selector:e,element:t,uniqueId:i})=>{const[s,,r]=e.split("[]"),n=r??s;if(t.matches(n)&&this.isElementVisible(t)){const s=this.targets.find(t=>t.selector===e&&t.uniqueId===i);return s&&s.resolve(t),this.clear(e,i),!1}return!0})}onLoadIframe(e){const t=[e.defaultView.frameElement,"load",()=>this.watch(selector,resolve,uniqueId).bind(this),{passive:!0}];return this.getEvents(...t)}watch(e,t,i){this.targets.push({selector:e,resolve:t,uniqueId:i});const{clear:s}=n(e,e=>{s();const t=e.getRootNode({composed:!0}),i="body"in t?t.body:document;this.mouseOverEvent=this.mouseOverHandler(t),this.scrollEvent=this.scrollEventHandler(t),this.onTransitionEnd=this.transitionOverHandler(t),t.defaultView?.frameElement&&(this.onIframeLoad=this.onLoadIframe(t),this.onIframeLoad.start()),this.startVisibilityObserver(t),this.startMutationObserver(i),this.checkElements()})}clear(e,t){[this.targets,this.existingTargets,this.inViewportTargets]=[this.targets,this.existingTargets,this.inViewportTargets].map(i=>i.filter(({selector:i,uniqueId:s})=>i!==e&&s!==t));const s=i(e);s&&this.visibilityObserver?.unobserve(s),0===this.targets.length&&(this.mutationObserver?.disconnect(),this.onIframeLoad?.clear()),0===this.inViewportTargets.length&&(this.mouseOverEvent?.clear(),this.scrollEvent?.clear(),this.onTransitionEnd?.clear())}}let u=[];const{visibilityGoals:h}=DATA,d=`${PLUGIN_ID.split("-")[0]}_${TEST_ID}`;let m=[];const g=()=>{u=u.filter(e=>{let{visibilityTrigger:t,selector:i,uniqueId:s}=e;return t.clear(i,s),!1})},v=(e,i)=>{let{selector:s,actionTrackingName:r}=e;const o=new c;return o.watch(s,()=>(e=>{let{selector:i,actionTrackingName:s}=e;ABTastyEvent(s,null,TEST_ID),t(`Engagement goal "${s}" sent to test ${TEST_ID}.`),u=u.filter(e=>i!==e.selector&&s!==e.actionTrackingName)})({selector:s,actionTrackingName:r}),d),!i&&s.includes("[]contentDocument[]")&&((e,t)=>{n(e,i=>{const s=i.ownerDocument.defaultView.frameElement;if(!m.some(e=>{let[t]=e;return t===s})){const i=()=>{u=u.filter(i=>!(e===i.selector&&t===i.actionTrackingName&&i.visibilityTrigger.clear(e,d)));const i=h.find(i=>i.selector===e&&i.actionTrackingName===t);u.push(v(i,!0))};s.addEventListener("load",i),m.push([s,i])}})})(s,r),{selector:s,actionTrackingName:r,visibilityTrigger:o,uniqueId:d}},b=()=>{t("Widget launch"),g(),u=h.map(v)},p=e=>{let{detail:{campaignId:t}}=e;t===TEST_ID&&(b(),T())},E=()=>{window.removeEventListener(a,p),g(),window.addEventListener(a,p),m=m.filter(e=>{let[t,i]=e;return t?.removeEventListener("load",i),!1})},T=()=>document.addEventListener("abtasty_resetActionTracking",E,{once:!0});b(),T()}();
