!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).VmaxGoogleAdDisplay=t()}(this,(function(){"use strict";function e(e,t,i,n){return new(i||(i=Promise))((function(o,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function a(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}l((n=n.apply(e,t||[])).next())}))}function t(e,t,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(e):n?n.value:t.get(e)}function i(e,t,i,n,o){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!o)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?o.call(e,i):o?o.value=i:t.set(e,i),i}function n(...e){console.error.apply(console,e)}"function"==typeof SuppressedError&&SuppressedError;var o,s,r,a,l,d,c,u,h,f,p,E,v,g,m,w,I,S,A,_,D,T,O,R;class b{constructor(e){var n;(o.add(this),s.set(this,void 0),r.set(this,void 0),a.set(this,[]),l.set(this,[]),d.set(this,[]),c.set(this,[]),u.set(this,"hidden"),h.set(this,null),f.set(this,null),p.set(this,!0),E.set(this,null),e instanceof HTMLElement)?(i(this,s,(n=t(this,o,"m",v).bind(this),new IntersectionObserver(n,{root:null,rootMargin:"0px",threshold:.5})),"f"),i(this,r,e,"f"),t(this,s,"f").observe(e),i(this,u,function(e){let t="hidden",i="visibilitychange";const n=window.document;return void 0!==n[t]?(t="hidden",i="visibilitychange"):void 0!==n.msHidden?(t="msHidden",i="msvisibilitychange"):void 0!==n.webkitHidden?(t="webkitHidden",i="webkitvisibilitychange"):void 0!==n.oHidden?(t="oHidden",i="ovisibilitychange"):void 0!==n.mozHidden?(t="mozHidden",i="mozvisibilitychange"):void 0!==n.khtmlHidden&&(t="khtmlHidden",i="khtmlvisibilitychange"),n.addEventListener(i,e,!0),t}(t(this,o,"m",g).bind(this)),"f"),function(e){window.addEventListener("focus",e),window.addEventListener("pageshow",e)}(t(this,o,"m",m).bind(this)),function(e){window.addEventListener("blur",e),window.addEventListener("pagehide",e)}(t(this,o,"m",w).bind(this)),this.check()):function(...e){console.warn.apply(console,e)}("Container must be a valid HTMLElement")}destroy(){var e;null===(e=t(this,s,"f"))||void 0===e||e.unobserve(t(this,r,"f")),i(this,a,[],"f"),i(this,l,[],"f"),i(this,d,[],"f"),i(this,c,[],"f"),i(this,h,null,"f"),i(this,f,null,"f"),i(this,p,null,"f"),clearInterval(t(this,E,"f"))}check(){t(this,o,"m",g).call(this)}enter(e){if("function"!=typeof e)throw new Error("Callback must be a function");return t(this,a,"f").push(e),this}exit(e){if("function"!=typeof e)throw new Error("Callback must be a function");return t(this,l,"f").push(e),this}enterOnce(e){if("function"!=typeof e)throw new Error("Callback must be a function");return t(this,d,"f").push(e),this}exitOnce(e){if("function"!=typeof e)throw new Error("Callback must be a function");return t(this,c,"f").push(e),this}}function k(e,t){const i=function(e,t){const i=navigator.userAgent.match(/Android/i),n=navigator.userAgent.match(/Chrome/i),o=e&&i&&n;if(!o)return!1;const s=function(e,t){try{const i=e.split("://"),n=i[0];return`intent://${i[1]}/#Intent;scheme=${n};S.browser_fallback_url=${t||""};end`}catch(e){return!1}}(e,t);return s||!1}(e,t);return i||t}function y(e){if("number"==typeof e)return e;try{const[t,i,n]=e.split(":"),o=60*parseInt(t)*60,s=60*parseInt(i);return o+s+parseInt(n)}catch(e){return function(...e){console.debug.apply(console,e)}("videoInstreamVmaxAd: Wrong time specified in vast parser",e),0}}function C(e){var t,i,n,o,s,r;const{bid:a,vast:l,hasVideoAdElement:d=!1,imaCompanions:c={companions:[],companionResourceUrls:[]}}=e,{ext:u={},w:h=null,h:f=null}=a||{},p=null!==(t=null==u?void 0:u["ad-meta"])&&void 0!==t?t:{},{id:E=null,name:v=null,"campaign-meta":g={}}=p,{id:m=null,name:w=null,marketer:I={},order:S={}}=g,{id:A=null,name:_=null,agency:D=null,brand:T=null}=I||{},{id:O=null,name:R=null}=S,b=e=>"number"==typeof e&&e>=0?e:-1,C=function(e){try{return JSON.parse(e)}catch(e){return{}}}((null==a?void 0:a.adm)||"{}"),N=(null==C?void 0:C.title)||"",P=(null==C?void 0:C.ctaText)||"",L=!!(null==C?void 0:C.linkUrl)||!!(null==C?void 0:C.linkFallback),M=k((null==C?void 0:C.linkUrl)||"",(null==C?void 0:C.linkFallback)||""),U=(null==l?void 0:l.adSystem)||"",W=(null==l?void 0:l.adTitle)||"",F=(null==l?void 0:l.description)||"",V=(null===(i=null==l?void 0:l.linear)||void 0===i?void 0:i.skipoffset)||(null==l?void 0:l.skipOffset)?b(y((null===(n=null==l?void 0:l.linear)||void 0===n?void 0:n.skipoffset)||(null==l?void 0:l.skipOffset)||"")):"",H=(null==l?void 0:l.duration)?b(y(null==l?void 0:l.duration)):"",x=!!(null==l?void 0:l.deepLinkUrl)||!!(null==l?void 0:l.clickThrough);let K=(null==l?void 0:l.companions)||[],G=(null==l?void 0:l.companionResourceUrls)||[];const j=k((null==l?void 0:l.deepLinkUrl)||"",(null==l?void 0:l.clickThrough)||""),{companions:Y=[],companionResourceUrls:X=[]}=c;Y.length&&(K=[...Y],G=[...X]);return{adId:E,adName:v,campaignId:m,campaignName:w,marketerId:A,marketerName:_,brand:T,agency:D,orderId:O,orderName:R,qualifiedSignature:(null===(r=null===(s=null===(o=null==a?void 0:a.ext)||void 0===o?void 0:o.modules)||void 0===s?void 0:s.render)||void 0===r?void 0:r.signature)||"",width:h,height:f,adSystem:U,adTitle:N||W,adDescription:F,ctaText:P,skipOffset:V,adDuration:H,isCTAAvailable:L||x,adClickUrl:M||j,companionResourceUrls:G,hasVideoAdElement:d,companions:K}}s=new WeakMap,r=new WeakMap,a=new WeakMap,l=new WeakMap,d=new WeakMap,c=new WeakMap,u=new WeakMap,h=new WeakMap,f=new WeakMap,p=new WeakMap,E=new WeakMap,o=new WeakSet,v=function(e){var n;const s=null===(n=null==e?void 0:e[0])||void 0===n?void 0:n.isIntersecting;"boolean"==typeof s&&(i(this,h,!0===s,"f"),t(this,o,"m",I).call(this))},g=function(){const e=window.document;i(this,f,!1===(null==e?void 0:e[t(this,u,"f")])||"visible"===(null==e?void 0:e.visibilityState),"f"),t(this,o,"m",I).call(this)},m=function(){i(this,f,!0,"f"),t(this,o,"m",I).call(this)},w=function(){const e=window.document;clearInterval(t(this,E,"f")),i(this,E,setTimeout((()=>{!1===(!1===(null==e?void 0:e[t(this,u,"f")])||"visible"===(null==e?void 0:e.visibilityState))&&(i(this,f,!1,"f"),t(this,o,"m",I).call(this))}),1),"f")},I=function(){const e=t(this,h,"f")&&t(this,f,"f");if(t(this,p,"f")===e)return;const n=t(this,h,"f")&&t(this,f,"f"),o=t(this,n?a:l,"f"),s=t(this,n?d:c,"f");o.forEach((e=>e())),s.forEach((e=>e())),i(this,n?d:c,[],"f"),i(this,p,e,"f")},function(e){e.AD_READY="adReady",e.AD_IMPRESSION="adImpression",e.AD_RENDERED="adRendered",e.AD_REFRESHED="adRefreshed",e.AD_ERROR="adError",e.AD_CLOSED="adClosed",e.AD_CLICKED="adClicked",e.AD_SKIPPED="adSkipped",e.AD_SKIPPABLE_STATE_CHANGE="adSkippableStateChange",e.AD_PAUSED="adPaused",e.AD_RESUMED="adResumed",e.AD_VIDEO_START="adVideoStart",e.AD_VIDEO_FIRST_QUARTILE="adVideoFirstQuartile",e.AD_VIDEO_MIDPOINT="adVideoMidpoint",e.AD_VIDEO_THIRD_QUARTILE="adVideoThirdQuartile",e.AD_VIDEO_COMPLETE="adVideoComplete",e.AD_VOLUME_CHANGED="adVolumeChanged",e.AD_MUTED="adMuted",e.AD_UNMUTED="adUnmuted",e.AD_PROGRESS="adProgress",e.AD_USER_CLOSE="adUserClose",e.AD_INSERTION_START="adInsertionStart",e.AD_INSERTION_END="adInsertionEnd",e.AD_MEDIA_EXPAND="onFullScreen",e.AD_MEDIA_COLLAPSE="onExitFullScreen"}(S||(S={})),function(e){e.PERSONAL_COMPUTER="2",e.CONNECTED_TV="3",e.PHONE="4",e.TABLET="5",e.CONNECTED_DEVICE="6",e.SET_TOP_BOX="7"}(A||(A={})),function(e){e.GEO_PROFILE="geoProfile",e.USER_PROFILE="userProfile"}(_||(_={})),function(e){e.APP_ID="appId",e.ACCOUNT_KEY="accountKey",e.SECRET_KEY="secretKey",e.SDK_INITIALIZED="sdkInitialized",e.GEO_PROFILE="geoProfile",e.USER_PROFILE="userProfile",e.IS_APP="isApp",e.SOURCE_CONFIG_DATA="sourceConfig",e.ABORT="abort",e.PRIVATE_KEY="privateKey",e.KEY_ID="keyId",e.UPS_ENDPOINT="upsEndpoint",e.UPS_XAUTH="upsXAuth",e.DGS_ENDPOINT="dgsEndpoint",e.DGS_XAUTH="dgsXAuth",e.AS_ENDPOINT="adspotEndpoint",e.AS_XAUTH="adspotXAuth",e.UPS_FIRST_FETCH_DONE="upsFirstFetchDone",e.UPS_SERVICE_CALL="UPSServiceCall",e.DGS_SERVICE_CALL="DGSServiceCall"}(D||(D={})),function(e){e.UID="uid",e.GENDER="gender",e.AGE="age",e.COUNTRY="country",e.REGION="region",e.CITY="city",e.ZIPCODE="zip",e.KEYWORDS="keywords"}(T||(T={})),function(e){e.PLAY_ONCE="play_once",e.REPEAT="repeat"}(O||(O={}));class N{constructor(){R.set(this,new Map)}static getInstance(){return N.instance}set(e,i){"object"!=typeof e?t(this,R,"f").set(e,i):Object.entries(e).forEach((([e,i])=>{t(this,R,"f").set(e,i)}))}get(e){var i;return"string"!=typeof e||0==e.length?t(this,R,"f"):null!==(i=t(this,R,"f").get(e))&&void 0!==i?i:null}get isSDKInitialized(){return Boolean(t(this,R,"f").get(D.SDK_INITIALIZED))}}R=new WeakMap,N.instance=new N;const P=N.getInstance();var L,M,U,W,F;!function(e){e.errorCode="{errorcode}",e.noFill="",e.noFillError="[nofill.error]",e.demandPartnerSDKVersion="[demand.partner.sdkversion]",e.eventName="[event.name]",e.vastErrorCode="[vast.error]",e.OmidSDKVersion="[omid.partner.sdkversion]",e.eventAttribute1="[event.attribute1]",e.eventAttribute2="[event.attribute2]",e.eventAttribute3="[event.attribute3]",e.randomCcb="[random.ccb]",e.deviceIFA="[device.ifa]"}(L||(L={}));class V{static post(t){return e(this,void 0,void 0,(function*(){const{url:e,payload:i,headers:o={},credentials:s}=t||{};let r={method:"POST",body:JSON.stringify(i)};s&&(r.credentials=s),o&&(r.headers=o);const a=new AbortController;r.signal=a.signal;return[fetch(e,r).then((e=>e.ok?e.json().catch((()=>Promise.reject(n("Invalid JSON response")))):e.text().then((t=>Promise.reject({message:`Error: ${e.status}`,status:e.status,body:t}))))).catch((e=>(function(...e){console.log.apply(console,e)}("Error in Fetch.post",e),Promise.reject(e)))),a]}))}static get(t){return e(this,arguments,void 0,(function*(e,t={}){return fetch(e,t).then((e=>e.json()))}))}static getPlainResponse(t){return e(this,arguments,void 0,(function*(e,t={}){return fetch(e,t)}))}static DeviceGeoService(){const e=P.get(D.ACCOUNT_KEY),t=P.get(D.DGS_ENDPOINT);P.get(D.DGS_XAUTH);const i=(t||"").replace("ACCOUNT_KEY",e);return M.get(i)}static UserProfileService(t){return e(this,void 0,void 0,(function*(){const e=P.get(D.ACCOUNT_KEY),i=P.get(D.UPS_ENDPOINT),n=P.get(D.UPS_XAUTH),o=(i||"").replace("ACCOUNT_KEY",e),[s]=yield M.post({url:o,headers:{"X-AUTH":n},payload:t});return s}))}static AdQuery(e){const{ACCOUNT_KEY:t,AS_ENDPOINT:i}=D,n=P.get(t)||"",o=P.get(i);return M.post({url:o.replace("ACCOUNT_KEY",n),payload:e,credentials:"include"})}static replaceAllMacros(e,t){const i=Object.keys(L);if(0===i.length)return e;const{ifa:n=""}=window.VmaxAdManager.getDevice().getPayload();return i.forEach((i=>{var o;const s=L[i];let r;r=s===L.randomCcb?Date.now().toString():s===L.deviceIFA?n:t&&(null===(o=t[s])||void 0===o?void 0:o.toString())||"";const a=new RegExp(this.escapeRegExp(s),"g");e=e.replace(a,r)})),t||i.forEach((t=>{const i=L[t],n=new RegExp(this.escapeRegExp(i),"g");e=e.replace(n,"")})),e}static escapeRegExp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}static FireTracker(i,n){return e(this,void 0,void 0,(function*(){if(!(e=i,"string"==typeof e&&e.length>0||(e=>Array.isArray(e))(i)))return Promise.reject("No url to fire tracker");var e;for(let e of i)e=this.replaceAllMacros(e,n),yield t(M,M,"m",U).call(M,e)}))}}M=V,U=function(t){return e(this,void 0,void 0,(function*(){try{const e=window.VmaxAdManager.getSite().getPayload(),{pageUrl:i,referrerUrl:o}=e,s=yield fetch(t,{method:"GET",headers:{Connection:"keep-alive","X-Requested-with":`${i}`},credentials:"include"});s.ok||n("Tracker request failed:",s.status,s.statusText)}catch(e){n("Error while firing the tracker:",e)}}))};class H{constructor(e=new Map){W.set(this,new Map),i(this,W,e,"f")}fireTracker(e,i){const n=t(this,W,"f").get(e);n&&V.FireTracker(n,i)}}W=new WeakMap,function(e){e.IMPRESSION="impressionViewable",e.REWARD_SLOT_CLOSED="rewardedSlotClosed",e.REWARD_SLOT_GRANTED="rewardedSlotGranted",e.SLOT_ONLOAD="slotOnload",e.SLOT_RENDER_ENDED="slotRenderEnded",e.SLOT_RENDER_RECIEVED="slotResponseReceived",e.SLOT_VISIBILTY_CHANGED="slotVisibilityChanged"}(F||(F={}));var x,K=F;!function(e){e.IMPRESSION="impression",e.NO_FILL="nofill",e.FILL="fill",e.CLICK="click",e.ERROR="error",e.START="start",e.FIRST_QUARTILE="firstQuartile",e.MIDPOINT="midpoint",e.THIRD_QUARTILE="thirdQuartile",e.COMPLETE="complete",e.PAUSE="pause",e.RESUME="resume",e.SKIP="skip",e.MUTE="mute",e.UNMUTE="unmute",e.SKIPPABLE_STATE_CHANGE="skippableStateChange"}(x||(x={}));var G,j,Y,X,Q,$,z,B,q,J,Z,ee,te,ie,ne,oe,se,re,ae,le,de,ce,ue,he,fe,pe,Ee=x;return j=new WeakMap,Y=new WeakMap,X=new WeakMap,Q=new WeakMap,$=new WeakMap,z=new WeakMap,B=new WeakMap,q=new WeakMap,J=new WeakMap,Z=new WeakMap,ee=new WeakMap,te=new WeakMap,ie=new WeakMap,ne=new WeakMap,oe=new WeakMap,se=new WeakMap,re=new WeakMap,ae=new WeakMap,G=new WeakSet,le=function(e){t(this,$,"f").fireTracker(Ee.NO_FILL,{[L.noFill]:e,[L.noFillError]:e})},de=function(){const{IMPRESSION:e,NO_FILL:n,FILL:o}=Ee,{burl:s="",nurl:r="",lurl:a=""}=t(this,j,"f")||{};s&&t(this,ie,"f").set(e,[s]),a&&t(this,ie,"f").set(n,[a]),r&&t(this,ie,"f").set(o,[r]),i(this,$,new H(t(this,ie,"f")),"f")},ce=function(){t(this,$,"f").fireTracker(Ee.FILL,Object.assign({},t(this,re,"f"))),i(this,B,new b(t(this,Y,"f")),"f"),t(this,B,"f").enter(t(this,J,"f")),t(this,B,"f").exit(t(this,Z,"f"))},ue=function(){var e;t(this,$,"f").fireTracker(Ee.IMPRESSION,Object.assign({},t(this,re,"f"))),null===(e=t(this,z,"f"))||void 0===e||e.AdImpression()},he=function(){return e(this,void 0,void 0,(function*(){var e;window.googletag=window.googletag||{cmd:[]},window.googletag.cmd.push((()=>{var e;i(this,se,(null===(e=window.googletag.defineSlot(t(this,ne,"f"),t(this,oe,"f"),t(this,Q,"f")))||void 0===e?void 0:e.addService(window.googletag.pubads()))||null,"f"),window.googletag.pubads().collapseEmptyDivs(),window.googletag.enableServices(),window.googletag.pubads().disableInitialLoad(),window.googletag.display(t(this,Q,"f"))})),i(this,re,{[L.demandPartnerSDKVersion]:(null===(e=window.googletag)||void 0===e?void 0:e.getVersion())||""},"f"),t(this,G,"m",fe).call(this)}))},fe=function(){window.googletag.cmd.push((()=>{window.googletag.pubads().addEventListener(K.SLOT_RENDER_RECIEVED,(e=>{e.slot.getSlotElementId()===t(this,Q,"f")&&console.debug("Google Ad Display(Slot received):",e.slot.getResponseInformation())})),window.googletag.pubads().addEventListener(K.IMPRESSION,(e=>{if(e.slot.getSlotElementId()===t(this,Q,"f")){const{advertiserId:n="",campaignId:o=""}=e.slot.getResponseInformation();i(this,ae,{adId:n,campaignId:o},"f"),t(this,G,"m",ue).call(this)}})),window.googletag.pubads().addEventListener(K.SLOT_ONLOAD,(e=>{e.slot.getSlotElementId(),console.debug("Google Ad Display(Slot loaded):",e.slot.getResponseInformation())}))}))},pe=function(e){return e.flatMap((e=>e.split("x").map((e=>parseInt(e,10)))))},class{constructor(){G.add(this),j.set(this,void 0),this.isContainerRequiredForCache=!0,Y.set(this,void 0),X.set(this,void 0),Q.set(this,`div-gpt-ad-${(new Date).getTime()}`),$.set(this,void 0),z.set(this,void 0),B.set(this,void 0),q.set(this,""),J.set(this,(()=>{})),Z.set(this,(()=>{})),ee.set(this,(()=>{})),te.set(this,(()=>{})),ie.set(this,new Map),ne.set(this,""),oe.set(this,void 0),se.set(this,void 0),this.canRefresh=!0,this.shouldProcessRefresh=!0,re.set(this,void 0),ae.set(this,void 0)}getAllSignatures(){return"nw.gambanner"}prepare(e){var n;try{const{bid:o,container:s,listeners:r}=e||{};i(this,Y,s,"f"),i(this,X,document.createElement("div"),"f"),t(this,X,"f").id=t(this,Q,"f"),t(this,Y,"f").appendChild(t(this,X,"f")),i(this,j,o,"f");const a=(null===(n=t(this,j,"f"))||void 0===n?void 0:n.adm)||"";if(!a||""===a)return Promise.reject("No ad object found");t(this,G,"m",de).call(this);const l=JSON.parse(a),{adnetwork_params:d}=l,{adsizes:c,adunitid:u}=d;i(this,ne,u,"f"),i(this,oe,t(this,G,"m",pe).call(this,c),"f"),t(this,G,"m",he).call(this);const{AdPaused:h,AdResumed:f,AdClicked:p}=r||{};return"function"==typeof h&&i(this,Z,h,"f"),"function"==typeof f&&i(this,J,f,"f"),"function"==typeof p&&i(this,ee,p,"f"),i(this,z,r,"f"),Promise.resolve()}catch(e){return console.warn(e),t(this,G,"m",le).call(this,"6"),Promise.reject(e)}}render(e){return new Promise(((e,n)=>{if(!window.googletag.pubads().getSlots().find((e=>e.getSlotElementId()===t(this,Q,"f"))))return t(this,G,"m",le).call(this,"2"),void n(new Error("Ad slot not found"));window.googletag.cmd.push((()=>{t(this,se,"f")&&window.googletag.pubads().refresh([t(this,se,"f")]),window.googletag.pubads().addEventListener(K.SLOT_RENDER_ENDED,(o=>{if(o.slot.getSlotElementId()===t(this,Q,"f")){if(console.log("google display",o),o.isEmpty)return t(this,G,"m",le).call(this,"2"),void n(new Error("Ad Empty!"));i(this,ae,{adId:(null==o?void 0:o.advertiserId)||"",campaignId:(null==o?void 0:o.campaignId)||""},"f"),t(this,G,"m",ce).call(this),e()}}))}))}))}destroy(){var e,n,o;t(this,se,"f")&&window.googletag.destroySlots([t(this,se,"f")]),null===(n=null===(e=t(this,X,"f"))||void 0===e?void 0:e.parentNode)||void 0===n||n.removeChild(t(this,X,"f")),null===(o=t(this,B,"f"))||void 0===o||o.destroy(),i(this,B,null,"f"),i(this,j,{},"f"),i(this,J,(()=>{}),"f"),i(this,Z,(()=>{}),"f"),i(this,ee,(()=>{}),"f"),i(this,$,{},"f"),i(this,ie,new Map,"f")}closeAd(){var e;return null===(e=t(this,z,"f"))||void 0===e||e.AdClosed(),this.canRefresh=!1,this.destroy(),Promise.resolve()}getVmaxAdInfo(){const e=C({bid:Object.assign(Object.assign({},t(this,j,"f")),t(this,ae,"f"))});return Object.assign({},e)}getAdMarkup(){var e;return(null===(e=t(this,j,"f"))||void 0===e?void 0:e.adm)||""}}}));