define(["exports","./../../browser.js","./../../shortcuts.js","./../../emby-apiclient/connectionmanager.js","./../../common/input/api.js","./../../emby-apiclient/events.js","./../../common/globalize.js","./../../dom.js","./../../layoutmanager.js","./../../common/datetime.js","./../../focusmanager.js","./../../loading/loading.js","./../../common/usersettings/usersettings.js","./gridrowrenderer.js","./../emby-button/emby-button.js","./../emby-scroller/emby-scroller.js","./../emby-button/paper-icon-button-light.js","./../../common/methodtimer.js","./../emby-itemscontainer/emby-itemscontainer.js","./../../common/inputmanager.js","./../../common/playback/playbackmanager.js"],function(_exports,_browser,_shortcuts,_connectionmanager,_api,_events,_globalize,_dom,_layoutmanager,_datetime,_focusmanager,_loading,_usersettings,_gridrowrenderer,_embyButton,_embyScroller,_paperIconButtonLight,_methodtimer,_embyItemscontainer,_inputmanager,_playbackmanager){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,require(["css!modules/emby-elements/guide/guide.css","programStyles","material-icons","flexStyles"]);var cellDurationMs=18e5,msPerMinute=6e4,msPerPage=288e5,startId=Date.now();function normalizeDateToTimeslot(value,roundUp){var delta=value%cellDurationMs;return roundUp&&delta&&(value+=cellDurationMs),value-=delta}function onSettingsButtonClick(e){var instance=this;require(["guide-settings-dialog"],function(guideSettingsDialog){guideSettingsDialog.show({categoryOptions:instance.categoryOptions,positionTo:e.target,positionY:"bottom",positionX:"right"},_connectionmanager.default.getApiClient(instance.options.serverId)).then(function(){instance.refresh()})})}function onDateButtonClick(e){!function(options){return Emby.importModule("./modules/actionsheet/actionsheet.js").then(function(ActionSheet){return ActionSheet.show(options)})}({items:function(instance){for(var items=[],start=new Date(instance._startDateMs),end=new Date(instance._endDateMs),nowHours=(today=new Date).getHours(),nowMinutes=30<=today.getMinutes()?30:0,nowHours=(start.setHours(nowHours,nowMinutes,0,0),end.setHours(0,0,0,0),start.getTime()>=end.getTime()&&end.setDate(start.getDate()+1),start=new Date(Math.max(today,start)),instance.scroller),nowMinutes=instance.scroller.getScrollWidth(),today=(nowMinutes-=getChannelCellWidth(instance),instance._startDateMs),instance=instance._endDateMs,nowHours=Math.abs(nowHours.getScrollLeft())/nowMinutes*(instance-today),date=(nowHours+=today,new Date(nowHours));start<=end;)items.push({name:_datetime.default.toLocaleDateString(start,{weekday:"long",month:"short",day:"numeric"}),value:start.getTime().toString(),selected:date.getDate()===start.getDate()&&date.getMonth()===start.getMonth()&&date.getFullYear()===start.getFullYear()}),start.setDate(start.getDate()+1),start.setHours(0,0,0,0);return items}(this),positionTo:e.target,title:_globalize.default.translate("HeaderSelectDate"),positionY:"bottom",hasItemSelectionState:!0}).then(function(value){scrollToTimeMs(this,value,!1,!0)}.bind(this))}function scrollToTimeMs(instance,value,exactTime,autoFocus){value=parseInt(value);var startDate,endDate,date=new Date,value=(date.setTime(value),instance.scroller),scrollWidth=instance.scroller.getScrollWidth();scrollWidth&&(scrollWidth-=getChannelCellWidth(instance),startDate=instance._startDateMs,endDate=instance._endDateMs,exactTime||(exactTime=Math.abs(value.getScrollLeft())/scrollWidth*(endDate-startDate),exactTime+=startDate,exactTime=new Date(exactTime),date.setHours(exactTime.getHours(),exactTime.getMinutes()+1,0,0)),date.setTime(normalizeDateToTimeslot(date.getTime())),exactTime=Math.max(date.getTime()-startDate,0)/(endDate-startDate),value.scrollToPosition({left:exactTime*scrollWidth*value.getScrollLeftMultiplier(),behavior:"instant"}),onScroll.call(instance,{currentTarget:instance.scroller,target:instance.scroller,autoFocus:autoFocus}))}var InsetInlineStartProp=CSS.supports("inset-inline-start","0")?"insetInlineStart":"left",BorderInlineStartWidthProp=CSS.supports("border-inline-start-width","0")?"borderInlineStartWidth":"borderLeftWidth";function setPaddingInlineStart(elem,value){(elem._paddingInlineStart||"0")!==value&&(elem._paddingInlineStart=value,elem.style[InsetInlineStartProp]=value)}function getChannelCellWidth(instance){var channelCellWidth=instance.channelCellWidth;return channelCellWidth||(channelCellWidth=instance.firstChannelCell.offsetWidth,instance.channelCellWidth=channelCellWidth),channelCellWidth}function getTimeBlockStart(instance,scrollLeft,scrollWidth){var startDate=instance._startDateMs,instance=instance._endDateMs,scrollLeft=scrollWidth?scrollLeft/scrollWidth*(instance-startDate):0;return(scrollLeft=Math.floor(scrollLeft))-scrollLeft%msPerPage+startDate}function getProgramFieldsProperty(){var programFields=[];return"true"===_usersettings.default.get("false"!==_usersettings.default.get("guide-indicator-4k")||"guide-indicator-hd")&&(programFields.push("IsHD"),programFields.push("Width")),programFields.length?programFields.join(","):null}function loadPrograms(instance,epgRowMap,channelIds,timeBlockStart){var promise,apiClient=_connectionmanager.default.getApiClient(instance.options.serverId),cacheKey=[apiClient.getCurrentUserId(),timeBlockStart.toString(),channelIds.join(",")].join("|"),cachedResult=(instance.programCache||(instance.programCache={}),instance.programCache[cacheKey]);return(promise=cachedResult?Promise.resolve(cachedResult):promise)||(cachedResult=timeBlockStart===getTimeBlockStart(instance,0,0)?1e3:0,timeBlockStart={UserId:apiClient.getCurrentUserId(),MaxStartDate:new Date(timeBlockStart+msPerPage).toISOString(),MinEndDate:new Date(timeBlockStart+cachedResult).toISOString(),channelIds:channelIds.join(","),ImageTypeLimit:1,SortBy:"StartDate",EnableTotalRecordCount:!1,EnableUserData:!1,Fields:getProgramFieldsProperty()},promise=apiClient.getLiveTvPrograms(timeBlockStart)),promise.then(function(result){return instance.programCache||(instance.programCache={}),instance.programCache[cacheKey]=result,function(instance,epgRowMap,programs){for(var i=0,length=programs.length;i'),newTimerId&&cell.setAttribute("data-timerid",newTimerId)}}.bind(instance),_events.default.on(_api.default,"TimerCreated",instance.onTimerCreatedFn),instance.onSeriesTimerCreatedFn=function(e,apiClient,data){}.bind(instance),_events.default.on(_api.default,"SeriesTimerCreated",instance.onSeriesTimerCreatedFn),instance.onTimerCancelledFn=function(e,apiClient,data){for(var options=this.options,data=data.Id,cells=options.element.querySelectorAll('.programCell[data-timerid="'+data+'"]'),i=0,length=cells.length;i'),this.currentTimeIndicatorDots=this.options.element.querySelectorAll(".guide-currentTimeIndicatorDot")),this.options.element.querySelector(".guideEpg-currentTimeIndicatorDot"));(_this$itemsContainer$=_this$itemsContainer$.channelCellClass||"").includes("channelCell-wide2")?(firstChannelCell.classList.add("channelCell-wide2"),firstChannelCell.classList.remove("channelCell-wide"),elem.classList.add("guideEpg-currentTimeIndicatorDot-wide2"),elem.classList.remove("guideEpg-currentTimeIndicatorDot-wide")):_this$itemsContainer$.includes("channelCell-wide")?(firstChannelCell.classList.add("channelCell-wide"),firstChannelCell.classList.remove("channelCell-wide2"),elem.classList.add("guideEpg-currentTimeIndicatorDot-wide"),elem.classList.remove("guideEpg-currentTimeIndicatorDot-wide2")):(firstChannelCell.classList.remove("channelCell-wide","channelCell-wide2"),elem.classList.remove("guideEpg-currentTimeIndicatorDot-wide","guideEpg-currentTimeIndicatorDot-wide2")),this.startCurrentTimeUpdateInterval()}.bind(instance),responses.virtualChunkSize=25,responses.getListOptions=instance.getListOptions.bind(instance),instance.itemsContainer=responses,instance.boundFocusableElements=function(newRowToFocus,activeElement,direction,focusOptions){var isRTL="rtl"===document.dir,focusedChannelCell=activeElement.closest(".channelCell"),isGoingBackHorizontally=isRTL?1===direction:0===direction;if(focusedChannelCell){if(newRowToFocus)return(_elems=newRowToFocus.querySelectorAll(".channelCell")).length?_elems:null;if(isGoingBackHorizontally)return null}newRowToFocus=newRowToFocus||activeElement.closest(".epgRow");var _elems=activeElement.closest(".programCell");if(isGoingBackHorizontally||_elems&&null!=direction&&direction<2){isGoingBackHorizontally=newRowToFocus.querySelectorAll(".programCell,.channelCell"),activeElement=Array.prototype.indexOf.call(isGoingBackHorizontally,activeElement);if(-1!==activeElement){var offset=0===direction||2===direction?-1:1,activeElement=(direction<2&&isRTL&&(offset*=-1),activeElement+offset),activeElement=Math.min(Math.max(0,activeElement),isGoingBackHorizontally.length-1);if((isGoingBackHorizontally=Array.prototype.slice.call(isGoingBackHorizontally,activeElement,activeElement+1)).length)return isGoingBackHorizontally}return null}if(offset=newRowToFocus.querySelectorAll(".programCell"),null==direction||2<=direction||focusedChannelCell&&(isRTL?0===direction:1===direction)){for(var currentPositionMs=!_elems||!(null==direction||2<=direction)||null!=focusOptions&&focusOptions.ignoreFocusedProgram?this.currentPositionMs+msPerMinute:getProgramFromProgramCell(_elems,_elems.closest(".epgRow")).StartDateLocalMs,programs=newRowToFocus.Programs||[],startIndex=0,i=0,length=programs.length;i')+getDisplayTime(startDate)+"",startDate.setTime(startDate.getTime()+cellDurationMs);return html}(nowHours,today),this.updateDateButtonText(Math.abs(this.scroller.getScrollLeft())),this.itemsContainer.resume({refresh:!0}).then(function(){_loading.default.hide()})}var dateLocalOptions={weekday:"short",month:"short",day:"numeric"};function hideOrShow(elem,hide){!0===elem._showing?hide&&(elem.classList.add("hide"),elem._showing=!1):hide||(elem.classList.remove("hide"),elem._showing=!0)}function getProgramMap(epgItem){for(var programMap={},items=epgItem.Programs,i=0,length=items.length;icellDurationMs?hideOrShow(scrollWidth,!1):hideOrShow(scrollWidth,!0),_usersettings.default.guideChannelStyle()),scrollWidth={};scrollWidth.showChannelImage="name"!==scrollLeft,scrollWidth.showChannelName="image"!==scrollLeft,scrollWidth.showChannelNumber=_usersettings.default.showChannelNumberInGuide(),scrollWidth.showChannelImage&&(!scrollWidth.showChannelNumber||scrollWidth.showChannelImage&&scrollWidth.showChannelName)?startDate.classList.add("hide"):startDate.classList.remove("hide")},Guide.prototype.stopCurrentTimeUpdateInterval=function(){var interval=this.currentTimeUpdateInterval;interval&&(interval.destroy(),this.currentTimeUpdateInterval=null)},Guide.prototype.startCurrentTimeUpdateInterval=function(){var interval=this.currentTimeUpdateInterval,fn=function(){for(var dots=this.currentTimeIndicatorDots,startDateMs=this._startDateMs,endDate=this._endDateMs,now=Date.now(),pct=startDateMs&&endDate?(now-startDateMs)/(endDate-startDateMs)*100:-100,showIndicator=0<=pct&&pct<=100,displayTime=(pct=pct.toFixed(2)+"%",getDisplayTime(new Date(now))),i=0,length=dots.length;i