define(["exports","./../modules/common/globalize.js","./../modules/loading/loading.js","./../modules/common/datetime.js","./../modules/tabbedview/basetab.js","./../components/accessschedule/accessschedule.js","./../modules/formhelper.js","./../modules/emby-elements/emby-checkbox/emby-checkbox.js","./../modules/emby-elements/emby-button/emby-button.js","./../modules/emby-elements/emby-button/paper-icon-button-light.js","./../modules/emby-elements/emby-select/emby-select.js","./../modules/listview/listview.js"],function(_exports,_globalize,_loading,_datetime,_basetab,_accessschedule,_formhelper,_embyCheckbox,_embyButton,_paperIconButtonLight,_embySelect,_listview){function loadUser(instance,page,user,allParentalRatings){!function(page,user){for(var items=[{name:_globalize.default.translate("Books"),value:"Book"},{name:_globalize.default.translate("Games"),value:"Game"},{name:_globalize.default.translate("OptionBlockChannelContent"),value:"ChannelContent"},{name:_globalize.default.translate("LiveTV"),value:"LiveTvChannel"},{name:_globalize.default.translate("Movies"),value:"Movie"},{name:_globalize.default.translate("Music"),value:"Music"},{name:_globalize.default.translate("Trailers"),value:"Trailer"},{name:_globalize.default.translate("TVShows"),value:"Series"}],html=(html="")+('

'+_globalize.default.translate("HeaderBlockItemsWithNoRating")+"

")+'
',i=0,length=items.length;i"+item.name+""}html+="
",page.querySelector(".blockUnratedItems").innerHTML=html}(page,user),instance.tags=user.Policy.BlockedTags,loadBlockedTags(page,instance.tags),function(allParentalRatings,page){for(var rating,html="",ratings=(html+="",[]),i=0,length=allParentalRatings.length;i"+rating.Name+"";page.querySelector(".selectMaxParentalRating").innerHTML=html}(allParentalRatings,page);var ratingValue="";if(user.Policy.MaxParentalRating)for(var i=0,length=allParentalRatings.length;i=rating.Value&&(ratingValue=rating.Value)}page.querySelector(".selectMaxParentalRating").value=ratingValue,page.querySelector(".selectTagMode").value=user.Policy.IsTagBlockingModeInclusive?"include":"",user.Policy.IsAdministrator?page.querySelector(".accessScheduleSection").classList.add("hide"):page.querySelector(".accessScheduleSection").classList.remove("hide"),page.querySelector(".selectMultiRestrictionMode").value=user.Policy.AllowTagOrRating?"any":"all",instance.schedules=user.Policy.AccessSchedules||[],renderAccessSchedule(page,instance.schedules),_loading.default.hide(),onValueChange.call(instance)}function loadBlockedTags(page,tags){tags=(tags=tags.map(function(h){var li='
';return(li+='
')+'
'+h+"
"+"
"+('')+"
"}).join(""))&&"
"+tags+"
";page.querySelector(".blockedTags").innerHTML=tags}function renderAccessSchedule(page,schedules){var html="",index=0;html+=schedules.map(function(a){var itemHtml="",itemHtml=(itemHtml=(itemHtml=(itemHtml=(itemHtml+='
')+'
'+'
')+function(dayOfWeek){for(var date=new Date;0")+('
'+getDisplayTime(a.StartHour)+" - "+getDisplayTime(a.EndHour)+"
"))+"
"+('');return index++,itemHtml+="
"}).join(""),page.querySelector(".accessScheduleList").innerHTML=html}function saveUser(user,page){user.Policy.MaxParentalRating=page.querySelector(".selectMaxParentalRating").value||null,user.Policy.IsTagBlockingModeInclusive="include"===page.querySelector(".selectTagMode").value,user.Policy.AllowTagOrRating="any"===page.querySelector(".selectMultiRestrictionMode").value,user.Policy.BlockUnratedItems=Array.prototype.filter.call(page.querySelectorAll(".chkUnratedItem"),function(i){return i.checked}).map(function(i){return i.getAttribute("data-itemtype")}),user.Policy.AccessSchedules=getSchedulesFromPage(page),user.Policy.BlockedTags=function(page){return Array.prototype.map.call(page.querySelectorAll(".blockedTag"),function(elem){return elem.getAttribute("data-tag")})}(page),ApiClient.updateUserPolicy(user.Id,user.Policy).then(function(){_loading.default.hide(),_formhelper.default.handleConfigurationSavedResponse()})}function getDisplayTime(hours){var minutes=0,pct=hours%1;return pct&&(minutes=parseInt(60*pct)),_datetime.default.getDisplayTime(new Date(2e3,1,1,hours,minutes,0,0))}function getSchedulesFromPage(page){return Array.prototype.map.call(page.querySelectorAll(".liSchedule"),function(elem){return{DayOfWeek:elem.getAttribute("data-day"),StartHour:elem.getAttribute("data-start"),EndHour:elem.getAttribute("data-end")}})}function showBlockedTagPopup(instance,page){var options;options={label:_globalize.default.translate("LabelTag")},Emby.importModule("./modules/prompt/prompt.js").then(function(prompt){return prompt(options)}).then(function(value){var tags=instance.tags;-1===tags.indexOf(value)&&(tags.push(value),loadBlockedTags(page,tags))})}function onValueChange(){var view=this.view,selectMaxParentalRating=view.querySelector(".selectMaxParentalRating"),selectTagMode=(selectMaxParentalRating.value?view.querySelector(".blockUnratedItems").classList.remove("hide"):view.querySelector(".blockUnratedItems").classList.add("hide"),view.querySelector(".selectTagMode"));selectMaxParentalRating.value&&"include"===selectTagMode.value?view.querySelector(".fldMultiRestrictionMode").classList.remove("hide"):view.querySelector(".fldMultiRestrictionMode").classList.add("hide")}function ParentalControlTab(view,params,options){_basetab.default.apply(this,arguments),this.apiClient=ApiClient,view.addEventListener("change",onValueChange.bind(this));var instance=this;view.querySelector(".btnAddSchedule").addEventListener("click",function(){var page,schedule,index;page=view,schedule={},index=-1,_accessschedule.default.show({schedule:schedule=schedule||{}}).then(function(updatedSchedule){var schedules=getSchedulesFromPage(page);schedules[index=-1===index?schedules.length:index]=updatedSchedule,renderAccessSchedule(page,schedules)})}),view.querySelector(".btnAddBlockedTag").addEventListener("click",function(){showBlockedTagPopup(instance,view)}),view.querySelector(".blockedTags").addEventListener("click",function(e){var tag,e=e.target.closest(".btnDeleteTag");e&&(tag=e.getAttribute("data-tag"),instance.tags=instance.tags.filter(function(t){return t!==tag}),loadBlockedTags(view,instance.tags))}),view.querySelector(".accessScheduleList").addEventListener("click",function(e){e=e.target.closest(".btnDeleteAccessScheduleItem");e&&!function(instance,page,index){(instance=instance.schedules).splice(index,1),renderAccessSchedule(page,instance)}(instance,view,parseInt(e.getAttribute("data-index")))}),view.querySelector(".userParentalControlForm").addEventListener("submit",function(e){var page=this.view,userId=(_loading.default.show(),params.userId);return ApiClient.getUser(userId,!1).then(function(result){saveUser(result,page)}),e.preventDefault(),e.stopPropagation(),!1}.bind(this));for(var btns=view.querySelectorAll(".userEditTabButton"),i=0,length=btns.length;i