import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var dT="clpp.ima.AdsManagerFactory",eT=function(a){a=a.K;const b=new google.ima.AdsRenderingSettings;b.restoreCustomPlaybackStateOnAdBreakComplete=!1;typeof a.bitrate===_.t&&(b.bitrate=a.bitrate);b.enablePreloading=typeof a.enablePreloading===_.Lc?a.enablePreloading:!0;typeof a.loadVideoTimeout===_.t&&(b.loadVideoTimeout=a.loadVideoTimeout);Array.isArray(a.mimeTypes)&&(b.mimeTypes=a.mimeTypes);typeof a.playAdsAfterTime===_.t&&(b.playAdsAfterTime=a.playAdsAfterTime);typeof a.useStyledLinearAds===
_.Lc&&(b.useStyledLinearAds=a.useStyledLinearAds);b.uiElements=Array.isArray(a.uiElements)?a.uiElements:[];return b},fT=function(a){return!1===a.K.disableCustomPlayback&&a.a.isCustomPlaybackUsed()&&_.vk()||_.yk()},gT=function(a){const b=a.a,c=a.H,d=google.ima.AdEvent.Type;c.on(b,d.AD_BREAK_READY,a.Ua.bind(a));c.on(b,d.LOADED,a.ba.bind(a));c.on(b,d.CONTENT_PAUSE_REQUESTED,a.rc.bind(a));c.on(b,d.STARTED,a.ia.bind(a));c.on(b,d.LOG,a.Db.bind(a));c.on(b,d.AD_PROGRESS,a.da.bind(a));c.on(b,d.AD_BUFFERING,
a.bb.bind(a));c.on(b,d.FIRST_QUARTILE,a.V.bind(a));c.on(b,d.MIDPOINT,a.jc.bind(a));c.on(b,d.THIRD_QUARTILE,a.za.bind(a));c.on(b,d.PAUSED,a.kc.bind(a));c.on(b,d.RESUMED,a.lc.bind(a));c.on(b,d.CLICK,a.S.bind(a));c.on(b,d.SKIPPED,a.fa.bind(a));c.on(b,d.IMPRESSION,a.X.bind(a));c.on(b,d.COMPLETE,a.Cb.bind(a));c.on(b,d.CONTENT_RESUME_REQUESTED,a.uc.bind(a))},hT=function(a,b){const c=b?a.Ja.create(b.getErrorCode()):null;a.m.onError(new _.I(1,9,10003,{errorType:c},b))},iT=function(a){return _.x(function*(){yield a.m.detach();
var b=a.m;b.a&&b.a.stopForwardingEventsTo(b)})},jT=function(a,b,c){c=c&&c.getAd();let d=null;c&&(d={ad:new W(c,a.G,a.F)});a.m.trigger(new _.F(b,d))},kT=function(a){a.B=null;jT(a,_.lc);a.m.getSurface().hide(a.P)},lT=function(a){return _.x(function*(){return new Promise(b=>{a.H.on(a.m,_.Kf,()=>{a.m.getState()===_.Vo&&b()})})})},mT=function(a){_.qp(a.A,{visibility:"visible"})},oT=function(a){return _.x(function*(){a.R.initialize();const b=!!a.m.getConfiguration().muted;(yield a.L.canPlay(b))||fT(a)?
(fT(a)&&(yield iT(a)),nT(a)):(jT(a,_.Jc),a.g.warn(_.ja))})},pT=function(a,b){return _.x(function*(){a.R.initialize();yield b.play();nT(a)})},nT=function(a){a.a.init(a.A.offsetWidth,a.A.offsetHeight,google.ima.ViewMode.NORMAL);a.a.start();a.M=!0},qT=function(){return!window.google||!google.ima||!google.ima.AdsLoader},W=class{constructor(a,b,c){this.a=a;this.f=a.getAdPodInfo();this.j=b;this.h=c}ob(){return"Google IMA SDK"}pb(){return google.ima.VERSION}ub(){return 0}getId(){return this.a.getAdId()}getCreativeId(){return this.a.getCreativeId()}Qb(){return""}getApiFramework(){return this.a.getApiFramework()}getAdSystem(){return this.a.getAdSystem()}getAdvertiserName(){return this.a.getAdvertiserName()}getTitle(){return this.a.getTitle()}getDuration(){return this.a.getDuration()}getPosition(){return 0}getSkipTimeOffset(){return this.a.getSkipTimeOffset()}Tb(){return this.f?
this.f.getIsBumper():!1}qb(){let a=null;const b=this.a,c=Object.keys(b).find(d=>typeof b[d]===_.Ce&&typeof b[d].clickThroughUrl===_.Nf);c&&(a=b[c].clickThroughUrl);return a}getMediaUrl(){return this.a.getMediaUrl()}fb(){return this.a.getVastMediaWidth()}eb(){return this.a.getVastMediaHeight()}Oa(){return this.a.getVastMediaBitrate()}Pa(){return this.h?2:this.j?1:0}getPodIndex(){return this.f?this.f.getPodIndex():0}Hb(){return this.f?this.f.getTimeOffset():0}sb(){return this.f?this.f.getAdPosition():
1}gb(){return this.f?this.f.getTotalAds():1}getWrapperAdIds(){return this.a.getWrapperAdIds()}canSeek(){return!1}getWrapperAdSystems(){return this.a.getWrapperAdSystems()}getWrapperCreativeIds(){return this.a.getWrapperCreativeIds()}Sb(){return null}};W.prototype.getVideoElement=W.prototype.Sb;W.prototype.getWrapperCreativeIds=W.prototype.getWrapperCreativeIds;W.prototype.getWrapperAdSystems=W.prototype.getWrapperAdSystems;W.prototype.canSeek=W.prototype.canSeek;W.prototype.getWrapperAdIds=W.prototype.getWrapperAdIds;
W.prototype.getSequenceLength=W.prototype.gb;W.prototype.getPositionInSequence=W.prototype.sb;W.prototype.getPodTimeOffset=W.prototype.Hb;W.prototype.getPodIndex=W.prototype.getPodIndex;W.prototype.getPodType=W.prototype.Pa;W.prototype.getMediaBitrate=W.prototype.Oa;W.prototype.getMediaHeight=W.prototype.eb;W.prototype.getMediaWidth=W.prototype.fb;W.prototype.getMediaUrl=W.prototype.getMediaUrl;W.prototype.getClickThroughUrl=W.prototype.qb;W.prototype.isBumper=W.prototype.Tb;
W.prototype.getSkipTimeOffset=W.prototype.getSkipTimeOffset;W.prototype.getPosition=W.prototype.getPosition;W.prototype.getDuration=W.prototype.getDuration;W.prototype.getTitle=W.prototype.getTitle;W.prototype.getAdvertiserName=W.prototype.getAdvertiserName;W.prototype.getAdSystem=W.prototype.getAdSystem;W.prototype.getApiFramework=W.prototype.getApiFramework;W.prototype.getSourceId=W.prototype.Qb;W.prototype.getCreativeId=W.prototype.getCreativeId;W.prototype.getId=W.prototype.getId;
W.prototype.getTechnology=W.prototype.ub;W.prototype.getAdManagerVersion=W.prototype.pb;W.prototype.getAdManagerName=W.prototype.ob;var rT=class{create(a){const b=google.ima.AdError.ErrorCode;switch(a){case b.VAST_LOAD_TIMEOUT:case b.VAST_MEDIA_LOAD_TIMEOUT:case b.FAILED_TO_REQUEST_ADS:return 0;case b.VIDEO_PLAY_ERROR:return 1;default:return 2}}};var sT=class{constructor(a){this.a=a}getCuePoints(){return this.a}Kb(){return 0<=this.a.indexOf(0)||0===this.a.length}Jb(){return 0<=this.a.indexOf(-1)}};sT.prototype.hasPostroll=sT.prototype.Jb;sT.prototype.hasPreroll=sT.prototype.Kb;sT.prototype.getCuePoints=sT.prototype.getCuePoints;var tT=class{constructor(a){var b=a.jd("ima");if(!b)throw Error("IMA plugin not created.");var c=b.Pc(),d=b.h;b=b.a;if(!c||!d||!b)throw Error("IMA plugin not initialized.");const e=a.getSurface().getMedia();if(!e)throw Error("Missing media element.");this.m=a;this.A=e;a=this.m.getConfiguration();a=_.Xg(a.ima||{});this.K=a=_.Wg({disableCustomPlayback:!1},a);this.P=c;this.R=d;this.w=b;this.L=new _.Hv;this.g=new _.S("clpp.ima");this.j=this.a=null;this.f=new _.bn;this.M=!1;this.H=new _.Nt;this.Ja=new rT;
this.B=null;this.J=this.F=this.G=!1;this.I=this.C=null;c=this.H;d=google.ima.AdErrorEvent.Type.AD_ERROR;c.one(this.w,google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,this.oc.bind(this));c.on(this.w,d,this.mc.bind(this));c.on(this.m,_.Sd,this.pc.bind(this))}oc(a){this.a=a.getAdsManager(this.A,eT(this));this.a.isCustomPlaybackUsed()&&!fT(this)?(this.g.warn("IMA plugin is disabled for this platform with single video element. Disposing."),this.m.onError(new _.I(1,9,10002)),this.h()):(this.j=new _.Fv(this.m.getSurface(),
(b,c,d)=>{this.a.resize(b,c,d?google.ima.ViewMode.FULLSCREEN:google.ima.ViewMode.NORMAL)}),a=this.a.getCuePoints(),this.C=new sT(a),this.m.trigger(new _.F(_.oc,{adsTimeline:this.C})),gT(this));this.f.resolve()}mc(a){hT(this,a.getError());this.f.resolve()}rc(a){const b=this;return _.x(function*(){b.J=!0;fT(b)?(b.I=b.m.getPosition(),yield iT(b)):(yield b.m.pause(),_.qp(b.A,{visibility:_.$d}));jT(b,_.Rb,a);b.j.start()})}Ua(){const a=this;return _.x(function*(){a.a.start()})}ba(a){a.getAd().isLinear()?
jT(this,_.ac,a):(this.a.discardAdBreak(),this.G||(this.G=!0,this.m.play()))}ia(a){this.B=a.getAd().getDuration();jT(this,_.jc,a);this.m.getSurface().show(this.P)}Db(a){a=a.getAdData();hT(this,a?a.adError:null);kT(this)}da(a){jT(this,_.dc,a)}bb(a){jT(this,_.Tb,a)}V(a){jT(this,_.Wb,a)}jc(a){jT(this,_.bc,a)}za(a){jT(this,_.mc,a)}kc(a){jT(this,_.cc,a)}lc(a){jT(this,_.ec,a)}S(a){this.pause();jT(this,_.Ub,a)}fa(a){jT(this,_.fc,a);kT(this)}X(a){jT(this,_.$b,a)}Cb(a){jT(this,_.Vb,a);kT(this)}uc(){const a=
this;return _.x(function*(){a.G=!0;if(fT(a)&&null!==a.I){var b=a.m;b.a&&b.a.forwardEventsTo(b);yield _.as(a.m);!a.F&&a.I&&(yield lT(a),yield a.m.seek(a.I))}else{if(!a.J)return a.m.play();mT(a)}a.J=!1;a.j&&a.j.stop();a.F||(yield a.m.play());jT(a,_.Sb)})}pc(){this.F=!0;this.w.contentComplete()}load(){const a=this;return _.x(function*(){var b=a.m;const c=a.K;try{if(typeof c.adTagUrl!==_.Nf)throw new _.I(1,9,10001,{missingKeys:"adTagUrl"});}catch(f){return b.onError(f),a.f.resolve(),a.f}if(!c.adTagUrl)return a.f.resolve(),
a.f;b=yield a.L.canPlay(!1);const d=yield a.L.canPlay(!0),e=new google.ima.AdsRequest;e.adTagUrl=c.adTagUrl;e.setAdWillAutoPlay(b);e.setAdWillPlayMuted(d);a.w.getSettings().setAutoPlayAdBreaks(!1);a.w.requestAds(e);return a.f})}start(a){const b=this;return _.x(function*(){b.a&&b.C&&!b.M?b.C.Kb()?yield oT(b):yield pT(b,a):yield a.play()})}o(){}l(){return!0}resume(){this.a&&this.a.resume()}pause(){this.a&&this.a.pause()}skip(){this.a&&this.a.skip()}getVolume(){return this.a?this.a.getVolume():1}setVolume(a){this.a&&
this.a.setVolume(a)}getPosition(){if(!this.a||null===this.B)return-1;const a=this.a.getRemainingTime();return 0>a?0:this.B-a}h(){this.a&&(this.a.destroy(),this.a=null);mT(this);this.H.release();this.j&&(this.j.stop(),this.j=null);return Promise.resolve()}};tT.prototype.getPosition=tT.prototype.getPosition;tT.prototype.setVolume=tT.prototype.setVolume;tT.prototype.getVolume=tT.prototype.getVolume;tT.prototype.skip=tT.prototype.skip;tT.prototype.pause=tT.prototype.pause;tT.prototype.resume=tT.prototype.resume;var uT=class extends _.Pv{constructor(){super();this.a=this.h=this.f=null}onPlayerCreated(a){if(qT())return a.onError(new _.I(1,9,1E4));this.f=_.op(_.Cd,{"class":"clpp-ima clpp-hidden"});a.getSurface().addElementToContainer(this.f);this.h=new google.ima.AdDisplayContainer(this.f,a.getSurface().getMedia());this.a=new google.ima.AdsLoader(this.h);this.a.getSettings().setPlayerType(_.qa);this.a.getSettings().setPlayerVersion(_.ea);this.a.getSettings().setAutoPlayAdBreaks(!0)}onPlayerWillDestroy(a){this.a&&
(this.a.destroy(),this.a=null);this.h&&(this.h.destroy(),this.h=null);this.f&&(a.getSurface().removeElementFromContainer(this.f),this.f=null)}xh(){return this.a}vh(){return this.h}Pc(){return this.f}id(){return"ima"}};_.z("clpp.ima.ImaPlugin",uT);uT.prototype.getAdContainer=uT.prototype.Pc;uT.prototype.getAdDisplayContainer=uT.prototype.vh;uT.prototype.getAdsLoader=uT.prototype.xh;uT.Id="ima";uT.isSdkMissing=qT;_.Ir(new class{create(){return new uT}});_.mp(new class{constructor(){this.Ra=new _.S(dT)}name(){return dT}a(a,b){return a.namespace()===_.dd?!1:qT()?(this.Ra.warn("IMA SDK is not loaded."),!1):!(!b||!b.ima)}create(a){return new tT(a)}});};f.call(g, window);