(self.webpackChunk=self.webpackChunk||[]).push([[8013],{8013:function(e,t,l){"use strict";l.r(t),l.d(t,{showEditor:function(){return P}}),l(23938),l(61013),l(63238),l(61418),l(72482),l(5769);var a,n=l(83094),o=l(1115),i=l(6594),r=l(78695),s=l(53218),c=l(22155),u=l(28978),d=l(6383),v=l(53754),f=(l(78066),l(30983),l(21865),l(50447),l(56561),l(16589),l(53913));function y(e){var t=n.ZP.parentWithClass(this,"dialog"),l=t.querySelector("#selectPlaylistToAddTo").value,r=f.ZP.getApiClient(a);return l?(u.set("playlisteditor-lastplaylistid",l),function(e,t,l){var a=t.querySelector(".fldSelectedItemIds").value||"";if("queue"===l)return s.O.queue({serverId:e.serverId(),ids:a.split(",")}),t.submitted=!0,void o.default.close(t);i.ZP.show();var n=e.getUrl("Playlists/".concat(l,"/Items"),{Ids:a,userId:e.getCurrentUserId()});e.ajax({type:"POST",url:n}).then((function(){i.ZP.hide(),t.submitted=!0,o.default.close(t)}))}(r,t,l)):function(e,t){i.ZP.show();var l=e.getUrl("Playlists",{Name:t.querySelector("#txtNewPlaylistName").value,Ids:t.querySelector(".fldSelectedItemIds").value||"",userId:e.getCurrentUserId()});e.ajax({type:"POST",url:l,dataType:"json",contentType:"application/json"}).then((function(l){i.ZP.hide();var a=l.Id;t.submitted=!0,o.default.close(t),function(e,t){d.appRouter.showItem(t,e.serverId())}(e,a)}))}(r,t),e.preventDefault(),!1}function m(e){e.dispatchEvent(new CustomEvent("change",{}))}function p(e,t,a){Promise.resolve().then(l.bind(l,74227)).then((function(l){var n=a?"on":"off";l.centerFocus[n](e,t)}))}var P=function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e);var l=t.items||{};a=t.serverId;var n={removeOnClose:!0,scrollY:!1};r.Z.tv?n.size="fullscreen":n.size="small";var d=o.default.createDialog(n);d.classList.add("formDialog");var P="";return P+='<div class="formDialogHeader">',P+='<button is="paper-icon-button-light" class="btnCancel autoSize" tabindex="-1"><span class="material-icons arrow_back"></span></button>',P+='<h3 class="formDialogHeaderTitle">',P+=v.ZP.translate("HeaderAddToPlaylist"),P+="</h3>",P+="</div>",P+=function(e){var t="";t+='<div class="formDialogContent smoothScrollY" style="padding-top:2em;">',t+='<div class="dialogContentInner dialog-content-centered">',t+='<form style="margin:auto;">',t+='<div class="fldSelectPlaylist selectContainer">';var l=e.length?" autofocus":"";return t+='<select is="emby-select" id="selectPlaylistToAddTo" label="'.concat(v.ZP.translate("LabelPlaylist"),'"').concat(l,"></select>"),t+="</div>",t+='<div class="newPlaylistInfo">',t+='<div class="inputContainer">',l=e.length?"":" autofocus",t+='<input is="emby-input" type="text" id="txtNewPlaylistName" required="required" label="'.concat(v.ZP.translate("LabelName"),'"').concat(l," />"),t+="</div>",t+="</div>",t+='<div class="formDialogFooter">',t+='<button is="emby-button" type="submit" class="raised btnSubmit block formDialogFooterItem button-submit">'.concat(v.ZP.translate("Add"),"</button>"),t+="</div>",t+='<input type="hidden" class="fldSelectedItemIds" />',t+="</form>",(t+="</div>")+"</div>"}(l),d.innerHTML=P,function(e,t,l){if(e.querySelector("#selectPlaylistToAddTo").addEventListener("change",(function(){this.value?(e.querySelector(".newPlaylistInfo").classList.add("hide"),e.querySelector("#txtNewPlaylistName").removeAttribute("required")):(e.querySelector(".newPlaylistInfo").classList.remove("hide"),e.querySelector("#txtNewPlaylistName").setAttribute("required","required"))})),e.querySelector("form").addEventListener("submit",y),e.querySelector(".fldSelectedItemIds",e).value=l.join(","),l.length)e.querySelector(".fldSelectPlaylist").classList.remove("hide"),function(e,t){var l=t.querySelector("#selectPlaylistToAddTo");i.ZP.hide(),t.querySelector(".newPlaylistInfo").classList.add("hide");var n=f.ZP.getApiClient(a);n.getItems(n.getCurrentUserId(),{Recursive:!0,IncludeItemTypes:"Playlist",SortBy:"SortName",EnableTotalRecordCount:!1}).then((function(t){var a="";(!1!==e.enableAddToPlayQueue&&s.O.isPlaying()||c.Z.Manager.isSyncPlayEnabled())&&(a+='<option value="queue">'.concat(v.ZP.translate("AddToPlayQueue"),"</option>")),a+='<option value="">'.concat(v.ZP.translate("OptionNew"),"</option>"),a+=t.Items.map((function(e){return'<option value="'.concat(e.Id,'">').concat(e.Name,"</option>")})),l.innerHTML=a;var n=e.defaultValue;n||(n=u.get("playlisteditor-lastplaylistid")||""),l.value="new"===n?"":n,l.value||(l.value=""),m(l),i.ZP.hide()}))}(t,e);else{e.querySelector(".fldSelectPlaylist").classList.add("hide");var n=e.querySelector("#selectPlaylistToAddTo");n.innerHTML="",n.value="",m(n)}}(d,t,l),d.querySelector(".btnCancel").addEventListener("click",(function(){o.default.close(d)})),r.Z.tv&&p(d.querySelector(".formDialogContent"),!1,!0),o.default.open(d).then((function(){return r.Z.tv&&p(d.querySelector(".formDialogContent"),!1,!1),d.submitted?Promise.resolve():Promise.reject()}))};t.default=P}}]);