const e=e=>e>=200&&e<=204,t=(e,t,s,n)=>{const{status:r,responseText:i}=e,o=t(r);let a={};try{a=JSON.parse(i)}catch(l){a=i}var c;o?s({status:r,data:a,headers:(c=e.getAllResponseHeaders(),c.split("\n").reduce((e,t)=>{const s=t.indexOf(":"),n=t.substr(0,s).trim().toLowerCase(),r=t.substr(s+1).trim();return n&&(e[n]=e[n]?`${e[n]}, ${r}`:r),e},{}))}):n({status:r,data:a,message:`Request failed with status code ${r}`})};var s=()=>{let s=null;const n=(n,r,i,{headers:o={},validateStatus:a=e,withCredentials:c=!1,cancelLast:l=!1,onUploadProgress:d=(()=>{})})=>{l&&null!==s&&s.abort();const h=((e,t,s,n,r,i)=>{const o=new XMLHttpRequest;return o.open(e,t,!0),Object.keys(n).forEach(e=>{o.setRequestHeader(e,n[e])}),o.withCredentials=r,o.upload&&o.upload.addEventListener("progress",i),o.send(((e,t)=>["POST","PUT","PATCH"].includes(e)?"object"!=typeof t||t instanceof Blob||t instanceof FormData?t:JSON.stringify(t):null)(e,s)),o})(n,r,i,o,c,d);return s=h,((e,s)=>new Promise((n,r)=>{e.readyState===XMLHttpRequest.DONE?t(e,s,n,r):e.onreadystatechange=()=>{e.readyState===XMLHttpRequest.DONE&&(t(e,s,n,r),e.onreadystatechange=null)}}))(h,a)};return{request:n,get(e,t={}){return n("GET",e,{},t)},post(e,t,s){return n("POST",e,t,s)},put(e,t,s){return n("PUT",e,t,s)},patch(e,t,s){return n("PATCH",e,t,s)},delete(e,t={}){return n("DELETE",e,{},t)}}};const{assign:n}=Object;function r(e){return Array.isArray(e)}function i(e){return"object"==typeof e&&!r(e)&&null!==e}function o(e){return"string"==typeof e}function a(e){return void 0===e}function c(e){return"function"==typeof e}function l(e){return null===e||"object"!=typeof e||0===Object.keys(e).length}function d(e,t){return Array.from(e,t)}function h(e,t,s){return d(e.querySelectorAll(t),s)}function u(e,t,...s){return n(e.createElement(t),...s)}function m(e=""){return e.includes("/metrum/")}function g(e=""){return e.split("/metrum/")[1].split("/")[0]}function p(){}function b(e,t,s){let n;return function(...r){const i=this,o=s&&!n;return clearTimeout(n),n=setTimeout(()=>{n=null,s||e.apply(i,r)},t),o&&e.apply(i,r),n}}function f(e,t){return e.concat(t)}const v=/Version\/[\d.]+.*Safari/,y=/iPhone|iPad|iPod|Android/i,x=e=>(t,s)=>Object.assign({},t,{},e(s)),E=(e,t,s)=>e.addEventListener(t,s),w=()=>(new Date).getTime();function C(e){return``}const P=e=>e.opbox||{};class S{constructor({targetWindow:e}={}){this.targetWindow=e}get document(){return this.targetWindow.document}}class k extends Error{constructor(e){super(e),this.message=e,this.name="PageRenderingError"}}class A{constructor({data:e,headers:t}={}){this.data=e,this.headers=t}get valid(){return i(this.data)}}const T=["OK","DATA_SOURCE_ERRORS"];class N extends A{get valid(){return super.valid&&i(this.headers)&&i(this.renderingResult)&&T.indexOf(this.renderingStatus)>=0}get renderingResult(){return this.data.pageRenderingResult}get renderingStatus(){return this.data.renderingStatus}get renderingContext(){return JSON.parse(this.headers["page-context"])}}class I{constructor(e={}){this.dataSources=e}resolve(e,t){const{value:s}=e;if("DATA_SOURCE"===e.type){const e=this.dataSources[s];return Object.assign({},e&&e.data&&{[t]:e.data},{},e&&!l(e.metadata)&&{[`${t}.$meta`]:e.metadata})}return{[t]:s}}}class O{constructor(e={},t={}){const{boxes:s=[],dataSources:n=[],parameters:r=[],locale:i,pageUrl:o,canonicalUrl:a}=e,{edgeHost:c,env:l,isDirect:d,renderDateTime:h}=t;this.boxes=s,this.dataSources=n,this.context={locale:i,pageUrl:o,canonicalUrl:a,edgeHost:c,env:l,isDirect:d,renderDateTime:h},this.parameters=r,this.parameterResolver=new I(this.resolvedDataSources)}get resolvedDataSources(){return this.dataSources.reduce((e,t)=>n(e,{[t.name]:t}),{})}get resolvedMeta(){const e=Object.keys(this.context).reduce((e,t)=>n(e,{[`$page.${t}`]:this.context[t]}),{}),t=this.parameters.reduce((e,t)=>n(e,this.parameterResolver.resolve(t,t.name)),{});return Object.assign({},e,{},t)}get resolved(){return{boxes:this.boxes,dataSources:this.resolvedDataSources,meta:this.resolvedMeta}}}class V{constructor({boxes:e={},boxNameToIdMap:t={},dataSources:s={},meta:n={}}={}){this.boxes=e,this.boxNameToIdMap=t,this.dataSources=s,this.meta=n,this.parameterResolver=new I(this.dataSources)}get resolved(){return{boxes:this.resolvedBoxes,boxNameToIdMap:this.boxNameToIdMap,dataSources:this.dataSources,meta:this.meta}}get resolvedBoxes(){return function(e=this,t,s){const n={};return Object.keys(e).forEach(r=>{n[r]=t.call(s,e[r],r,e)}),n}(this.boxes,e=>{const t=Object.keys(e).reduce((t,s)=>{const r=this.parameterResolver.resolve(e[s],s);return n(t,r)},{});return n(t,this.pageProperties)})}get pageProperties(){return Object.keys(this.meta).filter(e=>0===e.indexOf("$page.")).reduce((e,t)=>n(e,{[t]:this.meta[t]}),{})}}function M(e){return e>=200&&e<300||502===e}class R{constructor({httpClient:e,reportError:t,targetWindow:s=window,subtreeRenderCallback:n}){this.httpClient=e,this.reportError=t,this.targetWindow=s,this.subtreeRenderCallback=n}getPageData(e){const t={headers:{Accept:"application/vnd.opbox-web.v2+json"},cancelLast:!0,validateStatus:M};return this.httpClient.get(e,t).then(e=>{const t=new A(e);if(!t.valid)throw new k("Opbox response is invalid.");return new V(t.data)})}getPageRenderingResult(e){const t={headers:{Accept:"application/vnd.opbox-web.v3+json"},cancelLast:!0,validateStatus:M};return this.httpClient.get(e,t).then(e=>(e=>{const t=new N(e);if(!t.valid)throw new k("Page rendering response is invalid.");const{renderingResult:s,renderingContext:n}=t;return new O(s,n)})(e))}renderSubtree({boxId:e,additionalQueryParameters:t={}}={}){if(!e){const e="Missing 'boxId' property!";return this.reportError(Error(e)),Promise.reject(e)}return this.httpClient.get(((e,t={})=>{const s=new URL(e.href);return s.search=((e,t)=>{return s=Object.assign({},(e=>{const t={};return new URLSearchParams(e).forEach((e,s)=>{t[s]=e}),t})(e.search),{},t),new URLSearchParams(s).toString();var s})(s,t),s.toString()})(this.targetWindow.location,t),{headers:{Accept:"application/vnd.opbox-web.subtree+json","x-box-id":e},cancelLast:!1,validateStatus:M}).then(({data:t})=>this.subtreeRenderCallback({boxId:e,data:t}))}createAPI(){return{getData:this.getPageData.bind(this),renderSubtree:this.renderSubtree.bind(this)}}}class W{constructor({meta:e={}}={},t){this.appContext=t,this.meta=e}updateMetaRobots(){const e=this.appContext.document.querySelector('head meta[name="robots"]');e&&this.meta&&e.setAttribute("content",[this.meta.noindexCondition?"noindex":"index",this.meta.nofollowCondition?"nofollow":"follow"].join(", "))}render(){this.updateMetaRobots()}}class j{constructor({appContext:e,analytics:t,updateComponentCallback:s=p,beforeUpdateComponentCallback:n=p}){this.appContext=e,this.rawData=new V,this.listeners={},this.analytics=t,this.updateComponentCallback=s,this.beforeUpdateComponentCallback=n}registerListener(e,t=p,s=p){if(this.rawData.boxes[e]){const s=this.rawData.resolved.boxes[e];setTimeout(()=>{t(s)},0)}this.listeners[e]={onChange:t,onProgress:s}}triggerChangeListener(e){this.rawData=e;const{boxes:t,boxNameToIdMap:s,meta:n}=this.rawData.resolved;Object.entries(t).forEach(([e,t])=>{a(t)||this.updateComponentCallback(e,t)}),Object.keys(s).forEach(e=>{const n=t[s[e]];if(!a(n)){const t=this.listeners[e];t&&c(t.onChange)&&setTimeout(()=>t.onChange(n),0)}});const{defaultCustomParams:r}=n;this.analytics&&this.analytics.updateCustomParams(r),new W({meta:n},this.appContext).render()}triggerProgressListener(){this.beforeUpdateComponentCallback(),Object.keys(this.listeners).forEach(e=>{const t=this.listeners[e];t&&c(t.onProgress)&&setTimeout(()=>t.onProgress(),0)})}}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var L,B=(((e,t)=>{e.exports=(()=>{function e(e){return e instanceof Object&&e.constructor===Object}function t(s,n){var r=s,i=n;e(s)||(r={}),e(n)||(i={});var o=Object.keys(r),a=Object.keys(i),c={};return o.forEach(s=>{-1!==a.indexOf(s)?null===r[s]?c[s]=i[s]:e(r[s])&&e(i[s])?c[s]=t(r[s],i[s]):c[s]=i[s]:c[s]=r[s]}),a.forEach(e=>{-1===o.indexOf(e)&&(c[e]=i[e])}),c}return function(s){var n=s;e(s)||(n={});for(var r=arguments.length,i=Array(r>1?r-1:0),o=1;o{e(s)&&(n=t(n,s))}),n}})()})(L={exports:{}}),L.exports);const U=e=>h(e,"[data-analytics-enabled]"),H=e=>{const t=h(e,"[data-analytics-proxied]").reduce((e,t)=>{const s=U(t).filter(t=>!e.includes(t));return s.length?f(e,s):e},[]);return U(e).filter(e=>!t.includes(e))},D=(e,t,s,n)=>e>0?e({width:e.innerWidth,height:e.innerHeight});class q{constructor({targetWindow:e,boxes:t=[],significantElementSizePercentage:s=.75,timeoutValue:n=500,debounceTimeoutValue:r=20}){this.targetWindow=e,this.config={timeoutValue:n,debounceTimeoutValue:r,significantElementSizePercentage:s},this.resetState(),this.boxes=t.length?t:H(e.document),this.visibleElements=[],this.scrollHandlerWithContext=this.scrollHandler.bind(this),this.scrollEndHandler=b(this.resetCurrentlyVisibleElementsAfterScroll,this.config.debounceTimeoutValue),this.resizeEndHandler=b(this.resizeHandler.bind(this),this.config.debounceTimeoutValue),this.resetCurrentlyVisibleElementsOnTimeout=function(e,t,s){let n;return function(...s){const r=this;return new Promise(i=>{clearTimeout(n),n=setTimeout(()=>{n=null,i(e.apply(r,s))},t)})}}(this.resetCurrentlyVisibleElements.bind(this),this.config.debounceTimeoutValue),this.markCurrentlyVisibleElementsAsSeenOnTimeout=b(this.markCurrentlyVisibleElementsAsSeen.bind(this),this.config.timeoutValue)}setUserViewport(){this.state.userViewport=$(this.targetWindow)}resetState(){const e=(new Date).getTime();this.state={isScrolling:!1,scrollStartTime:e,counterStartTime:e,userViewport:$(this.targetWindow)}}createEvent(e){let t;try{t=this.targetWindow.document.createEvent("CustomEvent"),t.initCustomEvent(e,!0,!0,{})}catch(s){t=new CustomEvent(e,{cancelable:!0,bubbles:!0})}return t}isSignificantPartOfElementVisible(e){const t=e.right-e.left,s=e.bottom-e.top,n=D(e.left,e.right,this.state.userViewport.width,t);return D(e.top,e.bottom,this.state.userViewport.height,s)*n/(t*s)>this.config.significantElementSizePercentage}putVisibleElementsToBuffer(){let e=!1;const t=this.visibleElements.slice();this.visibleElements=[];for(let n=0;nnull!==e),H(this.targetWindow.document).forEach(this.addBox.bind(this)))}markElementAsSeen(e,t){if(!e)return;const s=parseInt(e.getAttribute("data-visible-for"),10)||0;(!e.getAttribute("data-seen")&&s+t)>=this.config.timeoutValue&&(e.setAttribute("data-seen",!0),e.dispatchEvent(this.createEvent("boxView"))),e.setAttribute("data-visible-for",s+t)}markPreviouslyVisibleElementsAsSeen(){const e=(new Date).getTime();this.visibleElements.forEach(t=>{this.markElementAsSeen(t,e-this.state.counterStartTime)})}markPreviouslyVisibleElementsAsSeenAfterScroll(){this.visibleElements.forEach(e=>{this.markElementAsSeen(e,this.state.scrollStartTime-this.state.counterStartTime)})}markCurrentlyVisibleElementsAsSeen(){this.visibleElements.forEach(e=>{this.markElementAsSeen(e,this.config.timeoutValue)})}resetCurrentlyVisibleElements(){this.markPreviouslyVisibleElementsAsSeen(),this.putVisibleElementsToBuffer(),this.markCurrentlyVisibleElementsAsSeenOnTimeout(),this.resetState()}resetCurrentlyVisibleElementsAfterScroll(){this.markPreviouslyVisibleElementsAsSeenAfterScroll(),this.putVisibleElementsToBuffer(),this.markCurrentlyVisibleElementsAsSeenOnTimeout(),this.resetState()}scrollHandler(){this.state.isScrolling||(this.state.scrollStartTime=(new Date).getTime(),this.state.isScrolling=!0),clearTimeout(this.markCurrentlyVisibleElementsAsSeenOnTimeout()),this.scrollEndHandler()}resizeHandler(){this.setUserViewport(),this.resetCurrentlyVisibleElements()}addBox(e){-1===this.boxes.indexOf(e)&&this.boxes.push(e)}isBoxInViewport(e){return-1!==this.visibleElements.indexOf(e)}clearAttributes(e){this.boxes.forEach(t=>{t&&t.matches(e)&&(t.removeAttribute("data-seen"),t.removeAttribute("data-visible-for"))})}markBoxAsRendered(e,t=""){return t&&this.clearAttributes(t),e.getAttribute("data-analytics-enabled")&&this.addBox(e),H(e).forEach(this.addBox.bind(this)),this.resetCurrentlyVisibleElementsOnTimeout()}markBoxAsVisible(e,t=!1){this.addBox(e),t?this.markElementAsSeen(e,this.config.timeoutValue):this.resetCurrentlyVisibleElementsOnTimeout()}recursivelyMarkBoxAsVisible(e){this.addBox(e),H(e).forEach(e=>{this.addBox(e)}),this.resetCurrentlyVisibleElementsOnTimeout()}removeBox(e){this.boxes=this.boxes.filter(t=>t!==e),this.visibleElements=this.visibleElements.filter(t=>t!==e)}markBoxAsHidden(e){this.removeBox(e),this.resetCurrentlyVisibleElementsOnTimeout()}unmountNode(e){U(e).forEach(e=>this.removeBox(e))}recursivelyMarkBoxAsHidden(e){this.removeBox(e),H(e).forEach(e=>{this.removeBox(e)}),this.resetCurrentlyVisibleElementsOnTimeout()}trackBoxScroll(e){e.addEventListener("scroll",this.scrollHandlerWithContext)}initialize(){this.targetWindow.addEventListener("scroll",this.scrollHandlerWithContext),this.targetWindow.addEventListener("resize",this.resizeEndHandler),this.resetCurrentlyVisibleElements()}createAPI(){return{markBoxAsRendered:this.markBoxAsRendered.bind(this),markBoxAsVisible:this.markBoxAsVisible.bind(this),recursivelyMarkBoxAsVisible:this.recursivelyMarkBoxAsVisible.bind(this),markBoxAsHidden:this.markBoxAsHidden.bind(this),recursivelyMarkBoxAsHidden:this.recursivelyMarkBoxAsHidden.bind(this),trackBoxScroll:this.trackBoxScroll.bind(this),isBoxInViewport:this.isBoxInViewport.bind(this)}}}class z{constructor({targetWindow:e,onCycleComplete:t}){this.window=e,this.document=this.window.document,this.onCycleComplete=t,this.initTimeStamp=null,this.engagementCycleStartTime=null,this.engagementTime=0,this.maxScrollBottom=this.getScrollBottom(),this.previousInteractionTime=null,this.handleInteraction=this.handleInteraction.bind(this),this.refreshEngagementCycle=this.refreshEngagementCycle.bind(this)}getTimeSpentOnPage(){return w()-this.initTimeStamp}updateEngagementTime(e){if(!this.previousInteractionTime)return;let t;if(this.previousInteractionTimethis.maxScrollBottom&&(this.maxScrollBottom=e)}getScrollBottom(){const{innerHeight:e,scrollY:t}=this.window;return e+(t||this.document.documentElement.scrollTop)}getPageHeight(){const{body:e,documentElement:t}=this.document;return Math.max(e.scrollHeight,e.offsetHeight,t.clientHeight,t.scrollHeight,t.offsetHeight)}endCycle(e){this.updateEngagementTime(e),this.engagementTime>0&&this.onCycleComplete({engagementTime:this.getEngagementTimeWithLimit(),scrollBottom:this.maxScrollBottom,pageHeight:this.getPageHeight()});const t=e-2e3;this.previousInteractionTime{const s={};for(let r=0;rs?s.toUpperCase():t.toLowerCase()))]=i.value)}var n;return s},_=({contextNode:e,customParams:t={}})=>{const s=F(e,"data-analytics-view-opbox-custom-"),n=Object.keys(s).length?{_opbox:s}:{};return B(F(e,"data-analytics-view-custom-"),n,t)},J=({contextNode:e,coordinates:t={},destinationUrl:s="",customParams:n={},isNewTab:r})=>{const i=r?{isNewTab:r}:{},o=Object.assign({},F(e,"data-analytics-click-opbox-custom-"),{destinationUrl:s},i,{},t);return B(F(e,"data-analytics-click-custom-"),{_opbox:o},n)},X=({contextNode:e,customParams:t={}})=>{const s=F(e,"data-analytics-interaction-custom-"),n=F(e,"data-analytics-interaction-opbox-custom-"),r=Object.keys(n).length?{_opbox:n}:{};return B(s,r,t)};function Y(e,t,s){return e.addEventListener(t,s),{remove(){e.removeEventListener(t,s)}}}class G{constructor({targetWindow:e,config:t,cookieMonsterClient:s,boxViewsMarker:n,sendPerformanceMetrics:r}){const{cookieMonster:{boxViewDisabled:i,isEngagementMeasuringEnabled:o,defaultCustomParams:a={}}={}}=t;this.targetWindow=e,this.document=this.targetWindow.document,this.boxViewDisabled=i,this.isEngagementMeasuringEnabled=o,this.cookieMonsterClient=s,this.boxViewsMarker=n,this.defaultCustomParams=a,this.eventCallbacks=[],this.sendPerformanceMetrics=r||p,this.engagementObserver=new z({targetWindow:e,onCycleComplete:this.sendPingEvent.bind(this)});const c=(({navigator:{userAgent:e=""}={}}={})=>e)(e);this.isMobile=(e=>!!e.match(y))(c),this.isSafari=(e=>!!e.match(v))(c),this.isFirefox=(e=>e.toLowerCase().includes("firefox"))(c)}initialize(){this.cookieMonsterClient.initialize(),this.isEngagementMeasuringEnabled&&this.engagementObserver.initialize(),this.eventHandlers=[Y(this.document,"change",this.handleChange.bind(this)),Y(this.document,"click",this.handleClick.bind(this)),Y(this.document,"mousedown",this.handleLinkClick.bind(this)),Y(this.document,"submit",this.handleSubmit.bind(this)),Y(this.document,"contextmenu",this.handleClick.bind(this)),Y(this.document,"boxView",this.handleBoxView.bind(this)),Y(this.targetWindow,"DOMContentLoaded",this.detectAdblock.bind(this))]}teardown(){this.eventHandlers.forEach(e=>{e.remove()})}sendEvent({contextNode:e,action:t,label:s="",value:n,customParams:r={}}={}){if(!e||!t)return{};const i=e.closest("[data-analytics-category]").getAttribute("data-analytics-category"),o=e.closest("[data-box-name]").getAttribute("data-box-name"),a=e.closest("[data-box-id]"),c=a&&a.getAttribute("data-box-id"),l=(e=>{const t=e.closest("[data-analytics-tags]");return t?((e,t)=>{const s=e.split(","),n=t.split(","),r=s.concat(n);return r.filter((e,t)=>e&&r.indexOf(e)===t)})(t.closest("[data-item]")?(e=>{const t=e&&e.closest("[data-box-name][data-analytics-tags]");return t&&t.getAttribute("data-analytics-tags")||""})(t):"",t.getAttribute("data-analytics-tags")||""):[]})(e),d=(e=>{const t=e.closest("[data-analytics-groups]");if(t){let e=decodeURIComponent(t.getAttribute("data-analytics-groups"));try{e=JSON.parse(e)}catch(s){return console.log(`JSON.parse error! Can not convert ${e} to JSON.`),[]}return e}return[]})(e),h=l.length?{analyticsTags:l}:{},u=d.length?{groups:d}:{},m=Object.assign({},h,{},u,{},c?{boxName:o,boxId:c}:{boxName:o}),g={category:i,action:t,label:s,value:n,customParams:B(Object.assign({},r),{_opbox:m},this.defaultCustomParams.ev)};return this.cookieMonsterClient.send("event",g),this.eventCallbacks.length&&this.eventCallbacks.forEach(e=>e(g)),g}sendPingEvent({engagementTime:e,scrollBottom:t,pageHeight:s}={}){this.cookieMonsterClient.send("event",{category:"Engagement",label:"ping",customParams:{et:e,sb:t,ph:s}})}sendClickEvent(e){this.sendEvent(Object.assign({},e,{action:"click"}))}sendContextmenuEvent(e){this.sendEvent(Object.assign({},e,{action:"contextmenu"}))}sendBoxInteractionEvent(e){this.sendEvent(Object.assign({},e,{action:"boxInteraction"}))}sendItemViewEvent(e){this.sendEvent(Object.assign({},e,{action:"itemView"}))}sendBoxViewEvent(e){this.sendEvent(Object.assign({},e,{action:"boxView"}))}sendFormSubmitEvent(e){this.sendEvent(Object.assign({},e,{action:"submit"}))}detectAdblock(){const e=u(this.document,"div",{innerHTML:" ",className:"adsbox"});this.document.body.appendChild(e),this.targetWindow.setTimeout(()=>{const t=0!==e.offsetHeight;this.cookieMonsterClient.send("event",{category:"clearPV",action:t,customParams:this.defaultCustomParams.ev}),this.document.body.removeChild(e)},100)}handleClick(e){this.handleBoxInteraction(e),this.handleLinkClick(e)}handleBoxInteraction(e){if("function"!=typeof e.target.closest)return;const t=e.target.closest("[data-analytics-interaction]");if(!t)return;const s=X({contextNode:t}),n=t.getAttribute("data-analytics-interaction-label")||"",r=t.getAttribute("data-analytics-interaction-value")||t.textContent.trim();this.sendBoxInteractionEvent({contextNode:t,label:n,value:r,customParams:s})}shouldHandleBoxInteraction(e){return"mousedown"===e.type&&!this.isMobile&&(this.isSafari||this.isFirefox)&&"select-one"===e.target.type}handleLinkClick(e){if("function"!=typeof e.target.closest)return;if(this.shouldHandleBoxInteraction(e))return void this.handleBoxInteraction(e);const t=e.target.closest("a");if(!t||!t.hasAttribute("data-analytics-clickable"))return;const s=t.getAttribute("data-analytics-click-label")||"",n=t.getAttribute("data-analytics-click-value")||t.textContent.trim(),r="_blank"===t.getAttribute("target"),i=t.getAttribute("href"),o=e.pageX?{pageX:e.pageX,pageY:e.pageY}:{};"click"!==e.type||0!==e.button?"contextmenu"!==e.type?"mousedown"===e.type&&1===e.button&&this.sendClickEvent({contextNode:t,label:s,value:n,customParams:J({contextNode:t,coordinates:o,destinationUrl:i,isNewTab:!0})}):this.sendContextmenuEvent({contextNode:t,label:s,value:n,customParams:J({contextNode:t,coordinates:o,destinationUrl:i})}):this.sendClickEvent({contextNode:t,label:s,value:n,customParams:J({contextNode:t,coordinates:o,destinationUrl:i,isNewTab:r||e.metaKey||e.ctrlKey})})}handleChange(e){const t=e.target;if("select-one"===t.type&&t&&t.hasAttribute("data-analytics-selectable")){const{value:e}=t.options[t.selectedIndex],s=F(t,"data-analytics-select-custom-");this.sendEvent({contextNode:t,action:"change",value:e,customParams:s})}}handleSubmit(e){const t=e.target;if(!t||"FORM"!==t.nodeName||!t.hasAttribute("data-analytics-submittable"))return;const s=t.getAttribute("action");let n=d(t.elements).filter(e=>e.name).map(e=>({name:e.name,value:e.value})).sort((e,t)=>e.name.toLowerCase().localeCompare(t.name.toLowerCase())).map(e=>`${e.name}=${e.value}`).join("&");n=n?`?${n}`:"";let r=n?s+n:s;r=encodeURI(r),this.sendFormSubmitEvent({contextNode:t,value:r,label:"submitForm"})}markParentBoxAsVisible(e){const t=e.parentNode&&e.parentNode.closest("[data-analytics-enabled]");this.boxViewsMarker&&t&&!t.hasAttribute("data-seen")&&this.boxViewsMarker.markBoxAsVisible(t,!0)}handleBoxView(e){const t=e.target;if(!t||!t.hasAttribute("data-analytics-enabled")||this.boxViewDisabled&&!t.hasAttribute("data-item")||d(t.childNodes).some(e=>e.classList&&e.classList.contains("opbox-fragment")))return;const s=t.getAttribute("data-analytics-view-value")||"",n=t.getAttribute("data-analytics-view-label")||"";let r=_({contextNode:t});if(t.firstChild&&t.firstChild.nodeType===Node.ELEMENT_NODE&&(r=Object.assign({},r,{},F(t.firstChild,"data-analytics-view-custom-"))),t.hasAttribute("data-item"))return this.markParentBoxAsVisible(t),void this.sendItemViewEvent({contextNode:t,label:n,value:s,customParams:r});r=Object.assign({},r,{},(e=>{if(!e)return{};const t=e.getAttribute("data-analytics-box-view-custom-params");if(!t)return{};let s={};try{s=JSON.parse(decodeURIComponent(t))}catch(n){console.log(n)}return s})(t)),this.sendBoxViewEvent({contextNode:t,value:s,customParams:r})}sendPageViewProxy(){this.sendPerformanceMetrics(),this.cookieMonsterClient.sendPageView(this.defaultCustomParams.pv),this.cookieMonsterClient.updateReferrer()}sendEventProxy(e,t,s,n){return e.nodeType===Node.ELEMENT_NODE?this.sendEvent({contextNode:e,action:t,value:s,customParams:n}):this.sendEvent(e)}sendItemViewEventProxy({contextNode:e,label:t,value:s,customParams:n}){this.sendItemViewEvent({contextNode:e,label:t,value:s,customParams:_({contextNode:e,customParams:n})})}sendClickEventProxy({contextNode:e,label:t,value:s,customParams:n,destinationUrl:r,isNewTab:i}){if(i&&"boolean"!=typeof i)throw Error("isNewTab property must be boolean");this.sendClickEvent({contextNode:e,label:t,value:s,customParams:J({contextNode:e,destinationUrl:r,customParams:n,isNewTab:i})})}sendContextmenuEventProxy({contextNode:e,label:t,value:s,customParams:n,destinationUrl:r}){this.sendContextmenuEvent({contextNode:e,label:t,value:s,customParams:J({contextNode:e,destinationUrl:r,customParams:n})})}sendBoxInteractionEventProxy({contextNode:e,label:t,value:s,customParams:n}){this.sendBoxInteractionEvent({contextNode:e,label:t,value:s,customParams:X({contextNode:e,customParams:n})})}updateCustomParams({pv:e={},ev:t={}}){i(e)&&i(t)?this.defaultCustomParams={pv:e,ev:t}:console.log("Can not update custom params with non-object arguments!")}registerEventCallback(e){e&&!this.eventCallbacks.includes(e)&&this.eventCallbacks.push(e)}createAPI(){return{sendPageView:this.sendPageViewProxy.bind(this),sendEvent:this.sendEventProxy.bind(this),sendItemViewEvent:this.sendItemViewEventProxy.bind(this),sendClickEvent:this.sendClickEventProxy.bind(this),sendContextmenuEvent:this.sendContextmenuEventProxy.bind(this),sendBoxInteractionEvent:this.sendBoxInteractionEventProxy.bind(this),registerEventCallback:this.registerEventCallback.bind(this)}}}function K(e,t,s=null){e&&c(e[t])&&e[t](s)}function Q(e){return!i(e)||"clientImplementationVersion"in e?e:Object.assign(e,{clientImplementationVersion:""})}function Z(e,t){return""===t?e:`${e}@${t}`}class ee{constructor({targetWindow:e,services:t,reportError:s,unmountNodeCallback:n,mountNodeCallback:r}={}){this.targetWindow=e,this.services=t,this.implementations=new Map,this.instances=new Map,this.reportError=s,this.unmountNodeCallback=n,this.mountNodeCallback=r}unmountNode(e){this.unmountNodeCallback(e),h(e,"[data-prototype-id]").concat([e]).forEach(e=>{const t=e.getAttribute("data-box-id")||e.getAttribute("data-box-name");K(this.instances.get(t),"onUnmount"),this.instances.set(t,null)})}mountNode(e){h(e,"[data-prototype-id]").concat([e]).forEach(e=>{const t=e.getAttribute("data-prototype-id"),s=e.getAttribute("data-civ")||"";this.registerInstancesForPrototype(t,s,[e])}),this.mountNodeCallback(e)}isPrototypeObjectValid(e){const{prototypeName:t,clientImplementationVersion:s}=e;return"prototypeName"in e?""===t?(this.reportError(Error('Property "prototypeName" cannot be empty string')),!1):o(t)?!!o(s)||(this.reportError(Error(`Property "clientImplementationVersion" must be string but got ${typeof s}`)),!1):(this.reportError(Error(`Property "prototypeName" must be string but got ${typeof t}`)),!1):(this.reportError(Error('Property "handledPrototype" must have "prototypeName" field')),!1)}containsValidPrototypes(e){return 0===e.length?(this.reportError(Error("Empty handledPrototypes list")),!1):!e.filter(e=>!this.isPrototypeObjectValid(e)).length}isPrototypeValid(e){return r(e)?this.containsValidPrototypes(e):i(e)?this.isPrototypeObjectValid(e):(this.reportError(Error('"handledPrototype" argument must be an object or an array')),!1)}isImplementationValid(e){return c(e)?e.prototype.onUpdate&&!c(e.prototype.onUpdate)?(this.reportError(Error(`"onUpdate" property must be a function or undefined but got ${typeof e.prototype.onUpdate}`)),!1):!!c(e.prototype.onMount)||(this.reportError(Error('"implementation" class has to have "onMount" method')),!1):(this.reportError(Error('"implementation" must be a class')),!1)}registerInstancesForPrototype(e,t,s){const n=this.implementations.get(Z(e,t));n&&this.registerInstances(s,this.services.getServicesForComponent(e),n)}registerImplementationAndInstances({prototypeName:e,clientImplementationVersion:t},s){const n=Z(e,t),r=""===t;this.implementations.has(n)?this.reportError(Error(`${e} ${r?"":`with ${t} client implementation version `}already registered!`)):(this.implementations.set(n,s),this.registerInstancesForPrototype(e,t,h(this.targetWindow.document,`[data-prototype-id="${e}"]${r?"":`[data-civ="${t}"]`}`)))}updateComponentCallback(e,t){K(this.instances.get(e),"onUpdate",t)}beforeUpdateComponentCallback(){this.instances.forEach(e=>K(e,"beforeOnUpdate"))}getSerializedPropsFromNode(e){if(!e)return{};try{return JSON.parse(e.textContent)}catch(t){return this.reportError(t),{}}}getSerializedPropsForBox(e,t){const s=[e?`[data-serialize-box-id="${e}"]`:null,t?`[data-serialize-box-name="${t}"]`:null].filter(Boolean).join(", "),n=this.targetWindow.document.querySelector(s);return n?this.getSerializedPropsFromNode(n):{}}registerInstances(e,t,s){e.forEach(e=>{const n=e.getAttribute("data-box-name"),r=e.getAttribute("data-box-id"),i=this.getSerializedPropsForBox(r,n),o=new s({baseNode:e,props:i,services:t}),a=r||n;this.instances.set(a,o),o.onMount()})}register(e,t){const s=(e=>r(e)?e.map(Q):Q(e))(e);this.isPrototypeValid(s)&&this.isImplementationValid(t)&&(r(s)?s.forEach(e=>{this.registerImplementationAndInstances(e,t)}):this.registerImplementationAndInstances(s,t))}createPublicAPI(){return{register:this.register.bind(this)}}createPrivateAPI(){return{updateComponentCallback:this.updateComponentCallback.bind(this),beforeUpdateComponentCallback:this.beforeUpdateComponentCallback.bind(this),unmountNode:this.unmountNode.bind(this),mountNode:this.mountNode.bind(this)}}}const te=()=>Promise.reject(Error("missing edge host"));class se{constructor({httpClient:e,config:t={}}){this.edgeHost=t.edgeHost,this.httpClient=e,this.defaultRequestSettings={headers:{"Content-type":"application/vnd.allegro.public.v1+json",Accept:"application/vnd.allegro.public.v1+json","Accept-Language":t.language}}}prepareRequestSettings(e={}){if(e.disableDefaultHeaders)return e;const t=this.normalizeSettings(e);return B({},this.defaultRequestSettings,t)}normalizeSettings(e){if(!e||!e.headers)return e;const t=function e(t,s){return Object.keys(t).reduce((n,r)=>{const i=t[r],o="object"==typeof i?e(i,s):i;return n[s.find(e=>r.toLowerCase()===e.toLowerCase())||r]=o,n},{})}(e.headers,Object.keys(this.defaultRequestSettings.headers));return n(e,{headers:t})}prepareRequestUrl(e){return this.edgeHost+e}get(e,t){return this.httpClient.get(this.prepareRequestUrl(e),this.prepareRequestSettings(t))}put(e,t,s){return this.httpClient.put(this.prepareRequestUrl(e),t,this.prepareRequestSettings(s))}post(e,t,s){return this.httpClient.post(this.prepareRequestUrl(e),t,this.prepareRequestSettings(s))}patch(e,t,s){return this.httpClient.patch(this.prepareRequestUrl(e),t,this.prepareRequestSettings(s))}delete(e,t){return this.httpClient.delete(this.prepareRequestUrl(e),this.prepareRequestSettings(t))}createAPI(){return this.edgeHost?{get:this.get.bind(this),put:this.put.bind(this),post:this.post.bind(this),patch:this.patch.bind(this),delete:this.delete.bind(this)}:{get:te,put:te,post:te,patch:te,delete:te}}}class ne{constructor({targetWindow:e,alias:t="cm",config:s={},isExternal:n=!1}){const{cookieMonster:{host:r,account:i,defaultCustomParams:o={},referrer:a=document.referrer}}=s;this.targetWindow=e,this.document=this.targetWindow.document,this.alias=t,this.host=r,this.account=i,this.isExternal=n,this.defaultCustomParams=o,this.referrer=a}initialize(){if(this.isExternal)return this.loadExternal(),void this.callCookieMonster.call(this,"create",this.account);this.host&&this.account&&!this.isLoaded()?(this.load(),this.callCookieMonster.call(this,"create",this.account),this.sendPageView(),this.updateReferrer()):this.updateReferrer()}load(){this.isLoaded()||((e,t,s,n,r)=>{e["cm.analytics.object"]=r,e[r]=e[r]||((...t)=>{(e[r].q=e[r].q||[]).push(t)});const i=u(t,"script",{src:n}),o=t.getElementsByTagName("script")[0];o.parentNode.insertBefore(i,o)})(this.targetWindow,this.document,0,this.host,this.alias)}loadExternal(){this.isLoaded()||((e,t)=>{e["cm.analytics.object"]=t,e[t]=e[t]||((...s)=>{(e[t].q=e[t].q||[]).push(s)})})(this.targetWindow,this.alias)}send(...e){this.callCookieMonster.call(this,this.sendCommand(),...e)}sendPageView(e=this.defaultCustomParams.pv||{}){this.send("pageview",{customParams:e,referrer:this.referrer})}updateReferrer(){this.referrer=window.location.href}callCookieMonster(...e){this.isLoaded()&&this.targetWindow[this.alias].apply(null,e)}isLoaded(){return"function"==typeof this.targetWindow[this.alias]}sendCommand(){return`send@${this.account}`}}var re=e=>t=>{0===t.status||(e.newrelic?(console.error(`Reporting error to newrelic: ${t.message}`),e.newrelic.noticeError(t)):console.error(`Error: ${t.message}`))};const ie=e=>{const{origin:t,pathname:s,search:n}=e;return`${t}${s}${n}`};class oe{constructor({targetWindow:e,opboxWebClient:t,rawDataListenersRegistry:s}){this.targetWindow=e,this.opboxWebClient=t,this.rawDataListenersRegistry=s,this.history=[e.location.pathname],this.recentlyFetchedURL=ie(e.location)}initialize(){this.targetWindow.onpopstate=e=>this.handlePopState(e),this.targetWindow.history.replaceState({opboxjs:!0},"")}isInternalNavigation(e){return this.history.find(t=>t===e)}navigateRelative(e){const{pathname:t,search:s}=this.targetWindow.location,n=t+s,r=t+((e,t)=>{function s(e){const t=/([^&=]+)=?([^&]*)/g,s={},n=e.substring(e.indexOf("?")+1,e.length);let r;for(;r=t.exec(n);)i=s,o=decodeURIComponent(r[1]),a=decodeURIComponent("string"===r[1]?r[2].replace(/\+/g," "):r[2]),void 0===i[o]?i[o]=[a]:i[o].push(a);var i,o,a;return s}const n=s(e);let r;const i=((e,t)=>{for(let s=0,{length:n}=e;s{return s=e,n=t.name,r=t.value,void(s[n]=Array.isArray(r)?r:[r]);var s,n,r})}function a(e){return Object.keys(e).map(t=>e[t].map(e=>[t,e])).reduce(f,[]).reduce((e,[t,s])=>null!=s?`${e}${(e?"&":"?")+encodeURIComponent(t)}=${encodeURIComponent(s)}`:e,"")}return i&&0===i.value.indexOf("http")?(r=2===i.value.split("?").length?s(i.value.split("?")[1]):[],o(r),i.value=i.value.split("?")[0]+a(r)):o(n),a(n)})(s,e);return this.changeUrl(r),this.history.push(t),this.targetWindow.performance.mark("clientSideNavigationStart"),r!==n&&this.fetch(r),r}refreshPage(){const{pathname:e,search:t}=this.targetWindow.location,s=e+t;this.fetch(s)}changeUrl(e){return this.targetWindow.history.pushState("","",e)}handlePopState(e){const{pathname:t}=e.target.location,s=ie(e.target.location);this.isInternalNavigation(t)&&this.recentlyFetchedURL!==s&&this.refreshPage()}fetch(e){this.recentlyFetchedURL=ie(this.targetWindow.location),this.rawDataListenersRegistry.triggerProgressListener(),this.opboxWebClient.getPageData(e).then(e=>this.rawDataListenersRegistry.triggerChangeListener(e)).catch(re)}}const ae="opboxAnimationTimerInterval";function ce(e,t,s,n,{duration:r=500,onFinish:i}={}){if("function"!=typeof n)return null;const o=(e=>e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||(e=>{setTimeout(e,1e3/60)}))(e),a=Date.now(),c=s-t;let l=!1;const d=()=>{const e=Date.now()-a;if(l||e>=r)"function"==typeof i&&i(),l=!1;else{const i=((s=Math.min(e/r,1))<.5?8*s*s*s*s:1-8*--s*s*s*s)*c+t;n(i),o(d)}var s};return d(),{stop(){l=!0}}}function le(e,t=0,{duration:s=500}={}){const n=e.pageYOffset,r=Math.max(0,t),i=e.document.body.scrollHeight;function o(){e[ae]&&"function"==typeof e[ae].stop&&(e[ae].stop(),e[ae]=null)}o(),e[ae]=ce(e,n,t,t=>{e.scrollTo(0,Math.round(t)),(t=>{const s=t===r||t===r,n=e.innerHeight+t>=i;return s||n})(t)&&o()},{duration:s})}function de(e,t){return s=>{if(!e.has(s))return Promise.reject(Error(`Service ${s} is not registered`));const n=e.get(s);return n.fetchIfNotFetched(t),n.promise}}class he{constructor({prototypeName:e,servicesRegistry:t,targetWindow:s}){this.services=new Map,this.targetWindow=s,t.forEach((t,s)=>{t.components.some(t=>t.prototypeName===e)&&this.services.set(s,t)}),this.get=de(this.services,this.targetWindow)}has(e){return this.services.has(e)}}function ue(e,t,{inHead:s=!1,referenceNode:n=null}={}){return r=>{if(l(r))return null;const i=u(e.document,"link",r,{rel:t});if(n)((e,t)=>{e.parentNode.insertBefore(t,e.nextSibling)})(n,i);else{const t=s?"head":"body";e.document[t].appendChild(i)}return i}}var me=["spinner","button","link","badge","brand","card","chart","desk","divider","heading","hint","icon","indicator","input","list","marker","notification","placeholder","price","progress","table","dropdown","breadcrumb","accordion","attachment","carousel","chip","choice","dialog","field","image-tile","input-group","message","modal","pagination","range","select","slider","soap","stepper","tabs","typography","color","grid","align","border","box-sizing","display","flex","height","margin","padding","position","utils","visibility","white-space","width","zindex","calendar","navigation-tiles","pin","player-video","sheet"],ge=(e,t,s)=>{const n=ue(e,"stylesheet",{inHead:!0,referenceNode:s})({type:"text/css",href:t});return new Promise((e,t)=>{n.addEventListener("error",t),n.addEventListener("load",e)})};const pe=e=>({href:t})=>-1!==t.indexOf(e);let be;function fe(e,t){return t.filter(t=>{return!e.find((s=t,e=>s.url?s.url===e.url||s.url===e.href||s.url===e.src:!!s.code&&s.code===e.code));var s})}function ve(e,t){const s=(e=>h(e,'link[type="text/css"],style',e=>({href:e.href,code:e.innerHTML,node:e,isMetrum:m(e.href)})).filter(({href:e,code:t})=>e||t))(e.document),n=fe(s,t);be=be&&!be.forceRefresh?be:(e=>{const t=(e=>d(e.document.styleSheets).find(({href:e})=>e&&e.includes("/metrum-bundle/")))(e),s=!!t;let n=[];return{isMetrumBundleEnabled:s,inject(r){if(!s)return Promise.resolve();const[i,o]=((e,t)=>t.reduce(([t,s],n)=>(e.includes(n)||s.push(n),t.push(n),[t,s]),[[],[]]))(n,r);return n=i,o.length?((e,t)=>{const s=u(e,"iframe",{style:"display:none"}),n=()=>e.body.removeChild(s);e.body.appendChild(s);const{contentDocument:r,contentWindow:i}=s;return r.open("text/html","replace"),r.write(t.map(C).join("")),r.close(),new Promise(e=>{const t=()=>{i.removeEventListener("load",t),e([d(r.styleSheets),n])};i.addEventListener("load",t)})})(e.document,o).then(([e,s])=>{e.forEach(e=>{if(((e,t)=>t.rules.length>0&&d(e.rules).findIndex(e=>e.cssText===t.rules[0].cssText)>-1)(t,e))return;const s=g(e.href),n=((e,t)=>d(e.rules).findIndex(e=>e.selectorText===`._${t}_e_`))(t,s),r=n>0?n:t.rules.length,i=d(e.rules);for(let o=0;om(n.url)&&i?(t.metrumStyles.push(n.url),t):(t.injectedStyles.push(((e,t,{url:s,code:n})=>m(s)?((e,t,s,n)=>{const r=g(s);return n.includes(r)?ge(e,s,((e,t,s)=>{const n=e.filter(({isMetrum:e})=>e),r=t.slice(0,t.indexOf(s)).reverse().find(e=>n.find(pe(e))),i=r?n.find(pe(r)).node:null;return!i&&n.length?n[0].node.previousElementSibling:!i&&e.length?e[0].node.previousElementSibling:i})(t,n,r)):Promise.resolve()})(e,t,s,me):s?ge(e,s):n?((e,t)=>{const s=u(e.document,"style",{innerHTML:t});return e.document.head.appendChild(s),Promise.resolve()})(e,n):Promise.reject())(e,s,n)),t),{metrumStyles:[],injectedStyles:[]});return a.push(r(o)),Promise.all(a)}function ye(e,t){const s=(e=>d(e.document.getElementsByTagName("script"),({src:e,innerHTML:t,nonce:s})=>({src:e,code:t,nonce:s})))(e),n=(e=>(e.find(({nonce:e})=>!!e)||{}).nonce)(s),r=fe(s,t);return Promise.all(r.map(((e,t)=>{const s=re(e),n=(e=>"noModule"in e.document.createElement("script"))(e);return({url:r,code:i,attributes:o,type:a,async:c})=>r||i?new Promise(l=>{const d=!r&&!!i,h="module"===a,m=u(e.document,"script");let g;const p=e=>{l(),e.message||(e.message=`Error while loading script: ${r}`),s(e),m.removeEventListener("error",p)},b=()=>{l(),m.removeEventListener("error",p),m.removeEventListener("load",b)};if(!h||n){if(o){if(o.nomodule&&n)return void l();Object.entries(o).forEach(([t,s])=>{"data-serialize-box-id"!==t&&"data-serialize-box-name"!==t||(g=e.document.querySelector(`[${t}="${s}"]`)),m.setAttribute(t,s)})}t&&m.setAttribute("nonce",t),c&&m.setAttribute("async","async"),a&&(m.type=a),d?(m.innerHTML=i,l()):(m.src=r,m.addEventListener("load",b),m.addEventListener("error",p)),g?g.parentNode.replaceChild(m,g):e.document.body.appendChild(m)}else l()}):Promise.resolve()})(e,n)))}function xe(e,t){const{svgColorMatrixFilters:s="",assets:{scripts:n=[],styles:r=[],prefetches:i=[],preloads:o=[]}}=t;return(({document:e},t)=>{if(!t)return;const s=e.querySelector("#svg-color-matrix-filters"),n=u(e,"div",{innerHTML:t}).querySelector("svg");s?h(n,"filter",e=>{s.querySelector(`#${e.getAttribute("id")}`)||s.appendChild(e)}):e.body.insertBefore(n,e.body.firstChild)})(e,s),((e,t)=>{t.forEach(ue(e,"preload"))})(e,o),((e,t)=>{t.forEach(ue(e,"prefetch"))})(e,i),Promise.all([ye(e,n),ve(e,r)])}class Ee{constructor({assetUrl:e,components:t,reportError:s}){this.assetUrl=e,this.components=t,this.reportError=s,this.implementation=null,this.status=0,this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}registerImplementation(e){try{this.implementation=new e,this.status=2,this.resolve(this.implementation)}catch(t){this.handleError(t)}}fetchIfNotFetched(e){0===this.status&&(this.status=1,ye(e,[{url:this.assetUrl}]).catch(e=>{this.handleError(e)}))}handleError(e){this.reportError(e),this.status=2,this.reject()}}class we{constructor({targetWindow:e,reportError:t}){this.targetWindow=e,this.servicesRegistry=new Map;const s=this.targetWindow.document.querySelector('[data-config="services"]');if(s)try{JSON.parse(s.textContent).forEach(([e,{assetUrl:s,components:n}])=>{const r=new Ee({assetUrl:s,components:n,reportError:t});this.servicesRegistry.set(e,r)})}catch(n){t(n)}this.dangerouslyGet=de(this.servicesRegistry,this.targetWindow)}getServicesForComponent(e){return new he({prototypeName:e,servicesRegistry:this.servicesRegistry,targetWindow:this.targetWindow})}register({serviceName:e},t){this.servicesRegistry.get(e).registerImplementation(t)}createAPI(){return{register:this.register.bind(this),__dangerouslyGet__:this.dangerouslyGet.bind(this)}}}const Ce=()=>Date.now();class Pe{constructor({localStorage:e,reportError:t,ttlMs:s=2592e6,key:n="opbox.preferences",timeProvider:r=Ce}){this.writeToStorage=this.writeToStorage.bind(this),this.loadPreferences=this.loadPreferences.bind(this),this.cleanupPreferences=this.cleanupPreferences.bind(this),this.savePreferences=this.savePreferences.bind(this),this.storage=(e=>{try{const t="test_preferences_storage";return e.setItem(t,t),e.getItem(t),e.removeItem(t),!0}catch(t){return!1}})(e)?e:{setItem(){},getItem(){return{}}},this.ttlMs=s,this.key=n,this.timeProvider=r,this.reportError=t}savePreferences(e){const t=this.loadPreferences(),s=this.timeProvider(),n=e.reduce(x(({name:e,value:t})=>({[e]:{value:t,timestamp:s}})),t);this.writeToStorage(n)}writeToStorage(e){try{this.storage.setItem(this.key,JSON.stringify(e))}catch(t){this.reportError(t)}}loadPreferences(){try{return JSON.parse(this.storage.getItem(this.key))||{}}catch(e){return this.reportError(e),{}}}cleanupPreferences(){const e=this.loadPreferences(),t=this.timeProvider(),s=Object.entries(e).reduce(x(([e,s])=>s.timestamp+this.ttlMs>t?{[e]:s}:{}),{});this.writeToStorage(s)}}const Se={withCredentials:!0,headers:{"Content-type":"application/vnd.allegro.internal.v1+json",Accept:"application/vnd.allegro.internal.v1+json"}};class ke{constructor({edgeClient:e,localStorage:t,ttlMs:s,reportError:n}){this.edgeClient=e,this.storage=new Pe({localStorage:t,ttlMs:s,reportError:n}),this.setPreference=this.setPreference.bind(this),this.getPreference=this.getPreference.bind(this),this.getPreferences=this.getPreferences.bind(this),this.getPreferencesFromLocalStorageOrDefaults=this.getPreferencesFromLocalStorageOrDefaults.bind(this)}setPreference(e,t){const s={name:e,value:t};return this.storage.savePreferences([s]),this.edgeClient.post("/preferences",s,Se)}getPreference(e,t){return"string"==typeof e||e instanceof String?this.getPreferences({[e]:t}).then(t=>t[e]):Promise.reject(Error("illegal argument type provided as preference name"))}getPreferences(e){if("object"!=typeof e)return Promise.reject(Error("illegal argument type provided as preferences"));const t=`/preferences?name=${Object.keys(e).join(",")}`;return this.edgeClient.get(t,Se).then(e=>(this.storage.savePreferences(e.data.preferences),e.data.preferences.reduce(x(({name:e,value:t})=>({[e]:t})),{}))).catch(()=>this.getPreferencesFromLocalStorageOrDefaults(e))}getPreferencesFromLocalStorageOrDefaults(e){this.storage.cleanupPreferences();const t=this.storage.loadPreferences();return Object.entries(e).reduce(x(([e,s])=>({[e]:e in t?t[e].value:s})),{})}createAPI(){return{set:this.setPreference,get:this.getPreference,getMany:this.getPreferences}}}var Ae=({targetWindow:e,unmountNodeCallback:t,mountNodeCallback:s,injectAssets:n=xe})=>{function r(t){return e.document.querySelector(`[data-box-id="${t}"]`)}return({boxId:i,data:o})=>{const{htmlString:a}=o;return a?n(e,o).then(()=>{const n=u(e.document,"div",{innerHTML:a}),o=r(i);t(o),o.parentNode.replaceChild(n.firstElementChild,o),s(r(i))}):Promise.resolve()}};const Te=new class{constructor(e,t,s){this.targetWindow=e;const n=(e=>P(e).config)(this.targetWindow),r=new S({targetWindow:e}),i=new ne({targetWindow:e,config:n}),o=new q({targetWindow:e}),a=new G({targetWindow:e,config:n,cookieMonsterClient:i,boxViewsMarker:o,sendPerformanceMetrics:this.sendPerformanceMetrics.bind(this)}),c=re(e),l=new we({targetWindow:e,reportError:c}),d=(e=>{const t=new ee(e);return{public:Object.assign({init:(s=e.targetWindow,({prototypeName:e},t)=>{e&&t({domNodes:h(s.document,`[data-prototype-id="${e}"]`)})})},t.createPublicAPI()),private:t.createPrivateAPI()};var s})({targetWindow:e,services:l,reportError:c,unmountNodeCallback:o.unmountNode.bind(o),mountNodeCallback:o.markBoxAsRendered.bind(o)}),u=new j({appContext:r,analytics:a,updateComponentCallback:d.private.updateComponentCallback,beforeUpdateComponentCallback:d.private.beforeUpdateComponentCallback}),m=new R({httpClient:t,reportError:c,subtreeRenderCallback:Ae({targetWindow:e,unmountNodeCallback:d.private.unmountNode,mountNodeCallback:d.private.mountNode})});this.config=n,this.cookieMonsterClient=i,this.boxViewsMarker=o,this.analytics=a,this.services=l,this.componentAPI=d,this.rawDataListenersRegistry=u,this.opboxWebClient=m,this.reportError=c,this.navigation=new oe({targetWindow:e,opboxWebClient:m,rawDataListenersRegistry:u}),this.edgeClient=new se({httpClient:s,config:n}),this.preferencesClient=new ke({edgeClient:this.edgeClient,localStorage:this.targetWindow.localStorage,reportError:this.reportError}),this.uiTools=(e=>{const t=t=>"string"!=typeof t?null:e.document.querySelector(`a[name="${t}"]`),s=t=>{const s=e.pageYOffset||e.document.documentElement.scrollTop||0;return t?t.getBoundingClientRect().top+s:null};return{getBoxAnchorNode:t,getTopOffset:s,scrollTo(n,{animate:r=!0}={}){const i={duration:r?500:0};if("number"==typeof n)return void le(e,n,i);const o=t(n);if(o){const t=s(o);le(e,t,i)}},tween(...t){ce(e,...t)}}})(e),this.analytics.initialize(),this.navigation.initialize(),this.boxViewsMarker.initialize()}get API(){return{analytics:this.analytics.createAPI(),boxViewsMarker:this.boxViewsMarker.createAPI(),component:this.componentAPI.public,onData:this.rawDataListenersRegistry.registerListener.bind(this.rawDataListenersRegistry),changeParams:this.navigation.navigateRelative.bind(this.navigation),refreshPage:this.navigation.refreshPage.bind(this.navigation),tween:this.uiTools.tween,scrollTo:this.uiTools.scrollTo,page:this.opboxWebClient.createAPI(),edge:this.edgeClient.createAPI(),preferences:this.preferencesClient.createAPI(),onDomReady:this.domReadyHelper.bind(this),loaded:!0,performance:P(this.targetWindow).performance,services:this.services.createAPI(),reportError:this.reportError}}domReadyHelper(e){"loading"===this.targetWindow.document.readyState?this.targetWindow.document.addEventListener("DOMContentLoaded",e):this.targetWindow.setTimeout(e,0)}broadcastAPILoadEvent(){const e=((e,t)=>{const s=this.targetWindow.document.createEvent("CustomEvent");return s.initCustomEvent("opboxAPILoaded",!0,!0,{}),s})();this.targetWindow.dispatchEvent(e)}attach(){const e=P(this.targetWindow),t=this.API;var s,r;e&&(function e(t,s,n,...r){if(c(t)&&c(s)){if(!t.__queue__)return;o=t.__queue__,a=s,o.forEach(({args:e,reject:t,resolve:s})=>{const n=((e,t)=>{try{return e(...t)}catch(s){return void console.error(s)}})(a,e);n&&c(n.then)&&c(s)&&c(t)&&n.then(s,t)}),n(s,...r)}else i(t)&&i(s)&&Object.keys(t).forEach(i=>{e(t[i],s[i],n,...r.concat(i))});var o,a}(e,t,(t,...s)=>{return r=this.targetWindow,i=function e(t,s,...n){if(0===n.length)return s;const r=n,i=r.shift();return(t="object"!=typeof t?{}:t)[i]=e(t[i],s,...r),t}(e,t,...s),r.opbox=r.opbox||{},void n(r.opbox,i);var r,i}),s=e,r=Object.keys(t).concat("initialized","config"),Object.keys(s).forEach(e=>{r.includes(e)||delete s[e]}),Object.freeze(e)),(({navigator:{serviceWorker:e},location:{href:t}},s)=>{e&&(((e,t,s)=>{"function"==typeof e.addEventListener&&e.addEventListener("message",e=>{"installed"===e.data&&t("event","PWA","serviceworker-registered",null,s)})})(e,s,t),((e,t)=>{if("function"!=typeof e.getRegistrations)return Promise.resolve();const s=e=>e.unregister().then(t=>t?e.active.scriptURL:"");e.getRegistrations().then(e=>Promise.all(e.map(s))).then(e=>{const s=e.filter(Boolean);s.length>0&&t("event","PWA","serviceworker-unregistered",null,s.join(","))})})(e,s))})(this.targetWindow,this.cookieMonsterClient.send.bind(this.cookieMonsterClient)),this.broadcastAPILoadEvent(),t.performance.markTimeToInteractive("opbox-web-browser")}sendPerformanceMetrics(){this.targetWindow.pinter&&this.targetWindow.pinter.sendUserTimings&&this.targetWindow.pinter.sendUserTimings()}run(){this.attach()}}(window,s(),s());Te.run(),Te.attach.bind(Te);