import {clpp} from "./cl.core.js";let g={};const _ = clpp._;var f=function(window){'use strict';var NU="clpp-freewheel",OU="clpp.freewheel.AdsManagerFactory",PU="freewheel",QU=function(a){switch(a){case 0:return tv.freewheel.SDK.ADUNIT_PREROLL;case 1:return tv.freewheel.SDK.ADUNIT_MIDROLL;case 2:return tv.freewheel.SDK.ADUNIT_POSTROLL;default:return""}},RU=function(a){const b=[];typeof a.networkId!==_.t&&b.push("networkId");typeof a.serverUrl!==_.Nf&&b.push("serverUrl");typeof a.profileId!==_.Nf&&b.push("profileId");typeof a.videoAssetId!==_.Nf&&typeof a.videoAssetId!==_.t&&b.push("videoAssetId");
if(b.length)throw new _.I(1,9,12001,{missingKeys:b.join(", ")});},SU=function(){return _.x(function*(){var a=new _.Hv;let b=tv.freewheel.SDK.VIDEO_ASSET_AUTO_PLAY_TYPE_NONE;const c=yield a.canPlay(!1);a=yield a.canPlay(!0);c?b=tv.freewheel.SDK.VIDEO_ASSET_AUTO_PLAY_TYPE_ATTENDED:a&&(b=tv.freewheel.SDK.VIDEO_ASSET_AUTO_PLAY_TYPE_UNATTENDED);return b})},TU=function(a){a.j.on(a.a,tv.freewheel.SDK.EVENT_REQUEST_COMPLETE,a.K.bind(a));a.j.on(a.a,tv.freewheel.SDK.EVENT_SLOT_STARTED,a.M.bind(a));a.j.on(a.a,
tv.freewheel.SDK.EVENT_SLOT_ENDED,a.L.bind(a));a.j.on(a.a,tv.freewheel.SDK.EVENT_AD,a.J.bind(a));a.j.on(a.m,_.Zf,a.I.bind(a));a.j.on(a.m,_.Kf,a.H.bind(a))},WU=function(a){return _.x(function*(){a.G.length?(UU(a),a.f=a.G.shift(),a.f.play()):(VU(a),yield a.m.a.play())})},VU=function(a){const b=a.m.jd(PU).Pc();b&&a.m.getSurface().hide(b);a.m.getSurface().showMediaElement()},UU=function(a){const b=a.m.jd(PU).Pc();b&&(a.m.getSurface().show(b),a.m.getSurface().hideMediaElement(),a.a.registerVideoDisplayBase(NU),
a.m.isMuted()?a.setVolume(0):a.setVolume(a.m.getVolume()||1))},XU=function(a){a.F.length?(UU(a),a.f=a.F.shift(),a.f.play()):VU(a)},YU=function(a,b,c){var d=null;a.a&&c&&(c.adInstance||c.slot)&&(c=(d=c.adInstance||null)?d.getSlot():c.slot,d={ad:new Y(a.a,c,d)});a.m.trigger(new _.F(b,d))},ZU=class extends _.Pv{constructor(){super();this.f=this.a=null}onPlayerCreated(a){if(window.tv&&tv.freewheel&&tv.freewheel.SDK)this.a=_.op(_.Cd,{id:NU}),this.f=_.op(_.w,{"class":_.Yc}),this.a.appendChild(this.f),a.getSurface().addElementToContainer(this.a,
!0),a.getSurface().hide(this.a);else a.onError(new _.I(1,9,12E3))}onPlayerWillDestroy(a){this.a&&(a.getSurface().removeElementFromContainer(this.a),this.f=this.a=null)}id(){return PU}Pc(){return this.a}wh(){return this.f}};_.z("clpp.freewheel.FreeWheelPlugin",ZU);ZU.prototype.getAdVideo=ZU.prototype.wh;ZU.prototype.getAdContainer=ZU.prototype.Pc;ZU.Id=PU;ZU.AD_CONTAINER_ID=NU;_.Ir(new class{create(){return new ZU}});var Y=class{constructor(a,b,c){this.h=a;this.f=b;this.a=c}ob(){return"FreeWheel AdManager SDK"}pb(){return tv.freewheel.SDK.version}ub(){return 0}getId(){return this.a?this.a.getAdId():""}getCreativeId(){const a=(this.a||{})._creativeId;return typeof a===_.Nf?a:""}Qb(){return""}getApiFramework(){return this.a?this.a.getActiveCreativeRendition().getCreativeApi():""}getAdSystem(){return""}getAdvertiserName(){return""}getTitle(){return""}getDuration(){return this.a?this.a.getActiveCreativeRendition().getDuration():
0}getPosition(){return 0}getSkipTimeOffset(){return 0}Tb(){return!1}qb(){return this.a&&this.a.getEventCallbackUrls(tv.freewheel.SDK.EVENT_AD_CLICK,tv.freewheel.SDK.EVENT_TYPE_CLICK)[0]||""}getMediaUrl(){return this.a?this.a.getActiveCreativeRendition().getPrimaryCreativeRenditionAsset().getUrl():""}fb(){return this.a?this.a.getActiveCreativeRendition().getWidth():0}eb(){return this.a?this.a.getActiveCreativeRendition().getHeight():0}Oa(){return 0}Pa(){switch(this.f.getTimePositionClass()){case tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL:return 0;
case tv.freewheel.SDK.TIME_POSITION_CLASS_POSTROLL:return 2;default:return 1}}getPodIndex(){switch(this.Pa()){case 0:return 0;case 2:return-1}return this.h.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_MIDROLL).indexOf(this.f)+1}Hb(){switch(this.Pa()){case 0:return 0;case 2:return-1;default:return this.f.getTimePosition()}}sb(){return this.a?this.f.getAdInstances().indexOf(this.a)+1:1}gb(){return this.f.getAdCount()}getWrapperAdIds(){return[]}canSeek(){return!1}getWrapperAdSystems(){return[]}getWrapperCreativeIds(){return[]}Sb(){return null}};
Y.prototype.getVideoElement=Y.prototype.Sb;Y.prototype.getWrapperCreativeIds=Y.prototype.getWrapperCreativeIds;Y.prototype.getWrapperAdSystems=Y.prototype.getWrapperAdSystems;Y.prototype.canSeek=Y.prototype.canSeek;Y.prototype.getWrapperAdIds=Y.prototype.getWrapperAdIds;Y.prototype.getSequenceLength=Y.prototype.gb;Y.prototype.getPositionInSequence=Y.prototype.sb;Y.prototype.getPodTimeOffset=Y.prototype.Hb;Y.prototype.getPodIndex=Y.prototype.getPodIndex;Y.prototype.getPodType=Y.prototype.Pa;
Y.prototype.getMediaBitrate=Y.prototype.Oa;Y.prototype.getMediaHeight=Y.prototype.eb;Y.prototype.getMediaWidth=Y.prototype.fb;Y.prototype.getMediaUrl=Y.prototype.getMediaUrl;Y.prototype.getClickThroughUrl=Y.prototype.qb;Y.prototype.isBumper=Y.prototype.Tb;Y.prototype.getSkipTimeOffset=Y.prototype.getSkipTimeOffset;Y.prototype.getPosition=Y.prototype.getPosition;Y.prototype.getDuration=Y.prototype.getDuration;Y.prototype.getTitle=Y.prototype.getTitle;Y.prototype.getAdvertiserName=Y.prototype.getAdvertiserName;
Y.prototype.getAdSystem=Y.prototype.getAdSystem;Y.prototype.getApiFramework=Y.prototype.getApiFramework;Y.prototype.getSourceId=Y.prototype.Qb;Y.prototype.getCreativeId=Y.prototype.getCreativeId;Y.prototype.getId=Y.prototype.getId;Y.prototype.getTechnology=Y.prototype.ub;Y.prototype.getAdManagerVersion=Y.prototype.pb;Y.prototype.getAdManagerName=Y.prototype.ob;var $U=class{constructor(a){this.a=a}getCuePoints(){return this.a.getTemporalSlots().map(a=>{switch(a.getTimePositionClass()){case tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL:return 0;case tv.freewheel.SDK.TIME_POSITION_CLASS_POSTROLL:return-1;default:return a.getTimePosition()}})}Kb(){return 0<this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL).length}Jb(){return 0<this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_POSTROLL).length}};
$U.prototype.hasPostroll=$U.prototype.Jb;$U.prototype.hasPreroll=$U.prototype.Kb;$U.prototype.getCuePoints=$U.prototype.getCuePoints;var aV=class{constructor(a){this.g=new _.S("clpp.freewheel.AdsManager");this.m=a;this.j=new _.Nt;this.C=new tv.freewheel.SDK.AdManager;this.f=this.a=null;this.G=[];this.B=[];this.F=[];this.A=new _.bn;this.w=null}load(){const a=this;return _.x(function*(){const b=a.m.getConfiguration().freewheel||{};try{RU(b)}catch(d){return a.m.onError(d),a.A.resolve(),a.A}a.C.setNetwork(b.networkId);a.C.setServer(b.serverUrl);a.a=a.C.newContext();a.a.setProfile(b.profileId);typeof b.siteSectionId!==_.Nf&&typeof b.siteSectionId!==
_.t||a.a.setSiteSection(b.siteSectionId);const c=yield SU();a.a.setVideoAsset(b.videoAssetId,a.m.getDuration(),void 0,void 0,c);if(Array.isArray(b.pods))for(const d of b.pods)a.a.addTemporalSlot(d.id,QU(d.type),d.position,d.slotProfile,d.cuepointSequence,d.maxDuration,d.minDuration,d.acceptContentType);b.keyValues&&typeof b.keyValues===_.Ce&&Object.keys(b.keyValues).forEach(d=>a.a.addKeyValue(d,b.keyValues[d]));a.a.setParameter(tv.freewheel.SDK.PARAMETER_EXTENSION_CONTENT_VIDEO_ENABLED,!1,tv.freewheel.SDK.PARAMETER_LEVEL_GLOBAL);
if(Array.isArray(b.parameters))for(const d of b.parameters)a.a.setParameter(d.name,d.value,d.level);TU(a);a.a.submitRequest();return a.A})}start(){const a=this;return _.x(function*(){yield WU(a)})}o(){}resume(){this.f&&this.f.resume()}pause(){this.f&&this.f.pause()}skip(){this.f&&this.f.skipCurrentAd()}getVolume(){return this.a?this.a.getAdVolume():1}setVolume(a){this.a&&this.a.setAdVolume(a)}getPosition(){return this.f?this.f.getPlayheadTime():-1}l(){return!0}h(){const a=this;return _.x(function*(){a.j.release();
a.w&&(a.w.stop(),a.w=null);VU(a);a.a&&(a.a.dispose(),a.a=null)})}K(a){if(a.success)this.G=this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL),this.B=this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_MIDROLL),this.F=this.a.getSlotsByTimePositionClass(tv.freewheel.SDK.TIME_POSITION_CLASS_POSTROLL),this.m.trigger(new _.F(_.oc,{adsTimeline:new $U(this.a)})),this.w=new _.Fv(this.m.getSurface(),(b,c)=>this.a.resize(b,c),this.m.jd(PU).f);else this.m.onError(new _.I(1,
9,10003,{errorType:0},void 0));this.A.resolve()}M(a){YU(this,_.Rb,a);this.w.start()}L(a){this.f=null;a=a.slot;YU(this,_.Sb);this.w.stop();if(a)switch(a.getTimePositionClass()){case tv.freewheel.SDK.TIME_POSITION_CLASS_PREROLL:WU(this);break;case tv.freewheel.SDK.TIME_POSITION_CLASS_MIDROLL:VU(this);this.m.play();break;case tv.freewheel.SDK.TIME_POSITION_CLASS_POSTROLL:XU(this)}}J(a){const b=a.subType;this.g.debug("ad event",b);switch(b){case tv.freewheel.SDK.EVENT_AD_IMPRESSION:YU(this,_.jc,a);YU(this,
_.$b,a);break;case tv.freewheel.SDK.EVENT_AD_IMPRESSION_END:YU(this,_.lc,a);break;case tv.freewheel.SDK.EVENT_AD_FIRST_QUARTILE:YU(this,_.Wb,a);break;case tv.freewheel.SDK.EVENT_AD_MIDPOINT:YU(this,_.bc,a);break;case tv.freewheel.SDK.EVENT_AD_THIRD_QUARTILE:YU(this,_.mc,a);break;case tv.freewheel.SDK.EVENT_AD_COMPLETE:YU(this,_.Vb,a);break;case tv.freewheel.SDK.EVENT_AD_CLICK:YU(this,_.Ub,a);break;case tv.freewheel.SDK.EVENT_AD_PAUSE:YU(this,_.cc,a);break;case tv.freewheel.SDK.EVENT_AD_RESUME:YU(this,
_.ec,a);break;case tv.freewheel.SDK.EVENT_AD_SKIPPED:YU(this,_.fc,a);break;case tv.freewheel.SDK.EVENT_AD_BUFFERING_START:YU(this,_.Tb,a);break;case tv.freewheel.SDK.EVENT_AD_BUFFERING_END:YU(this,_.dc,a);break;case tv.freewheel.SDK.EVENT_ERROR:this.m.onError(new _.I(1,9,10003,{errorType:1},{fwCode:a[tv.freewheel.SDK.INFO_KEY_ERROR_CODE],fwInfo:a[tv.freewheel.SDK.INFO_KEY_ERROR_INFO],fwModule:a[tv.freewheel.SDK.INFO_KEY_ERROR_MODULE]}))}}I(){if(!this.f){var a=this.m.getPosition();if(this.f=this.B.find(b=>
.5>Math.abs(a-b.getTimePosition()))||null){const b=this.B.findIndex(c=>c===this.f);this.B.splice(b,1);this.m.pause();UU(this);this.f.play()}}}H(a){if((a=a.detail)&&this.a)switch(a.currentState){case _.Wo:this.a.setVideoState(tv.freewheel.SDK.VIDEO_STATE_PLAYING);break;case _.Vo:this.a.setVideoState(tv.freewheel.SDK.VIDEO_STATE_PAUSED);break;case _.Lo:this.a.setVideoState(tv.freewheel.SDK.VIDEO_STATE_COMPLETED);XU(this);break;case _.To:case _.Mo:this.a.setVideoState(tv.freewheel.SDK.VIDEO_STATE_STOPPED)}}};
aV.prototype.getPosition=aV.prototype.getPosition;aV.prototype.setVolume=aV.prototype.setVolume;aV.prototype.getVolume=aV.prototype.getVolume;aV.prototype.skip=aV.prototype.skip;aV.prototype.pause=aV.prototype.pause;aV.prototype.resume=aV.prototype.resume;_.mp(new class{constructor(){this.Ra=new _.S(OU)}name(){return OU}a(a,b){return a.namespace()!==_.dd&&b&&b.freewheel?window.tv&&tv.freewheel&&tv.freewheel.SDK?!0:(this.Ra.warn("FreeWheel SDK is not loaded."),!1):!1}create(a){return new aV(a)}});};f.call(g, window);