(("undefined"!=typeof self?self:this).webpackJsonp__wix_instagram_business=("undefined"!=typeof self?self:this).webpackJsonp__wix_instagram_business||[]).push([[66],{1048:function(t,i,e){"use strict";e.r(i);var s=e(1),o=e(9),n=e(15),a=e(130),r={SCROLL:"SCROLL",CLICKED:"CLICKED",HOVERED:"HOVERED",ENDED:"ENDED",INIT_SCROLL:"INIT_SCROLL"},l=function(){function t(t){var i=this;this.scrollBase=0,this.videoItems=[],this.currentPlayingIdx=-1,this.currentItemCount=0,this.playing=!1,this.updateGalleryStructure=this.updateGalleryStructure.bind(this),this.initializePlayState=this.initializePlayState.bind(this),this.onScroll=this.onScroll.bind(this),this.handleEvent=this.handleEvent.bind(this),this.play=this.play.bind(this),this.stop=this.stop.bind(this),this.isVisible=this.isVisible.bind(this),this.isCurrentVideoStillVisible=this.isCurrentVideoStillVisible.bind(this),this.videoPlay=void 0,this.itemClick=void 0,this.setPlayingVideos=t.setPlayingVideos,this.lastVideoPlayed=-1,this.videoRatingMap=new Map,this.trigger=Object.assign.apply(Object,Object(s.__spreadArrays)([{}],Object.keys(r).map((function(t){var e;return(e={})[t]=function(e){return i.handleEvent({eventName:t,eventData:e})},e}))))}return t.prototype.updateGalleryStructure=function(t){var i=this,e=t.galleryStructure,s=t.galleryWidth,o=t.scrollBase,n=t.videoPlay,a=t.videoLoop,r=t.itemClick,l=t.scrollDirection;this.galleryWidth=s,this.scrollBase=o,this.videoPlay=n,this.videoLoop=a,this.itemClick=r,this.scrollDirection=l,this.currentItemCount=e.galleryItems.length,this.videoItems=[],e.galleryItems.forEach((function(t){("video"===t.type||"image"===t.type&&(t.id.includes("_placeholder")||t.isVideoPlaceholder))&&(i.videoRatingMap.has(t.id)||i.videoRatingMap.set(t.id,t.idx),i.videoItems.push(t))}))},t.prototype.handleEvent=function(t){var i=t.eventName,e=t.eventData;switch(i){case r.SCROLL:this.onScroll(e);break;case o.a.events.ITEM_ACTION_TRIGGERED:this.itemClicked(e.idx);break;case o.a.events.VIDEO_PAUSED:this.currentPlayingIdx===e.idx&&this.stop(e.idx);break;case o.a.events.HOVER_SET:this.itemHovered(e);break;case o.a.events.VIDEO_ENDED:this.videoEnded(e.idx);break;case o.a.events.VIDEO_PLAYED:this.videoPlayed(e.idx);break;case o.a.events.VIDEO_ERROR:this.videoErrorReported()}},t.prototype.itemHovered=function(t){"hover"===this.videoPlay&&this.IdxExistsInVideoItems(t)&&this.play(t)},t.prototype.itemClicked=function(t){"onClick"===this.videoPlay&&this.IdxExistsInVideoItems(t)&&(this.currentPlayingIdx===t?this.stop():this.play(t))},t.prototype.onScroll=function(t){var i=this,e=t.top,s=t.left;this.top=e>=0?e:this.top,this.left=s>=0?s:this.left,-1===this.currentPlayingIdx||this.isCurrentVideoStillVisible({top:this.top,left:this.left})||this.stop(this.videoItems.findIndex((function(t){return t.idx===i.currentPlayingIdx}))),this.autoPlayNextVideoByRating({top:this.top,left:this.left})},t.prototype.videoEnded=function(t){var i=this.videoItems.findIndex((function(i){return i.idx===t}));this.stop(i);var e={top:this.top,left:this.left};this.autoPlayNextVideoByRating(e)},t.prototype.videoPlayed=function(t){this.currentPlayingIdx!==t&&this.play(t),this.lastVideoPlayed=t},t.prototype.videoErrorReported=function(){this.stop()},t.prototype.initializePlayState=function(){this.autoPlayNextVideoByRating({top:this.top,left:this.left})},t.prototype.autoPlayNextVideoByRating=function(t){var i=this,e=t.top,s=t.left;if(this.shouldAutoPlay()){var o={idx:-1,rating:1/0},n={idx:-1,rating:1/0};if(this.videoItems.some((function(t){if(i.isVisible(t,{top:e,left:s})){var a=i.videoRatingMap.get(t.id);return a<=n.rating?(o.idx=n.idx,o.rating=n.rating,n.idx=t.idx,n.rating=a):a<=o.rating&&(o.idx=t.idx,o.rating=a),!1}return n.idx>=0})),n.idx>=0)if(this.allowedLoop()||n.idx!==this.lastVideoPlayed)this.play(n.idx);else{if(!(o.idx>=0))return;this.play(o.idx)}else this.lastVideoPlayed=-2}},t.prototype.calculateCurrentItemPlacement=function(){var t=this;return this.videoItems.findIndex((function(i){return i.idx===t.currentPlayingIdx}))},t.prototype.play=function(t){this.setPlayingIdx(t),this.playing=!0},t.prototype.stop=function(t){if(t>=0){var i=this.videoRatingMap.get(this.videoItems[t].id)+this.currentItemCount;this.videoRatingMap.set(this.videoItems[t].id,i)}this.setPlayingIdx(-1),this.playing=!1},t.prototype.onPlayingIdxChange=function(){this.setPlayingVideos(this.currentPlayingIdx)},t.prototype.setPlayingIdx=function(t){this.currentPlayingIdx!==t&&(this.currentPlayingIdx=t,this.onPlayingIdxChange())},t.prototype.isCurrentVideoStillVisible=function(t){var i=t.top,e=t.left,s=this.calculateCurrentItemPlacement(),o=this.videoItems[s];return!!o&&this.isVisible(o,{top:i,left:e})},t.prototype.isVisible=function(t,i){var e,s=i.top,r=i.left,l={offsetTop:this.scrollBase||0,scrollY:s,scrollLeft:r},d=(t.offset.top-t.offset.bottom)/2,h=(t.offset.left-t.offset.right)/2,p=Object(a.c)({target:l,scrollBase:this.scrollBase,top:t.offset.top,bottom:t.offset.top+t.style.height,screenHeight:n.a&&n.a.innerHeight,padding:d});return e=this.scrollDirection===o.a.scrollDirection.VERTICAL||Object(a.b)({target:l,left:t.offset.left,right:t.offset.left+t.style.width,screenWidth:this.galleryWidth||n.a&&n.a.innerWidth,padding:h}),p&&e},t.prototype.shouldAutoPlay=function(){return"auto"===this.videoPlay},t.prototype.allowedLoop=function(){return!0===this.videoLoop},t.prototype.IdxExistsInVideoItems=function(t){return this.videoItems.some((function(i){return i.idx===t}))},t}();i.default=l}}]); //# sourceMappingURL=vendors~proGallery_videoScrollHelper.chunk.min.js.map