define(["exports","./../../common/globalize.js","./../../emby-apiclient/connectionmanager.js","./../emby-button/emby-button.js","./../../layoutmanager.js"],function(_exports,_globalize,_connectionmanager,_embyButton,_layoutmanager){function onClick(e){var options,button=this,id=button.getAttribute("data-id"),serverId=button.getAttribute("data-serverid"),type=button.getAttribute("data-itemtype"),apiClient=_connectionmanager.default.getApiClient(serverId);button.classList.contains("downloadbutton-on")?(options={text:_globalize.default.translate("ConfirmRemoveDownload"),confirmText:_globalize.default.translate("RemoveDownload"),cancelText:_globalize.default.translate("KeepDownload"),primary:"cancel"},Emby.importModule("./modules/common/dialogs/confirm.js").then(function(confirm){return confirm(options)}).then(function(){apiClient.cancelSyncItems([id]),button.dispatchEvent(new CustomEvent("download-cancel",{cancelable:!1}))})):Emby.importModule("./modules/sync/sync.js").then(function(syncDialog){syncDialog.showMenu({items:[{Id:id,Type:type,ServerId:serverId}],mode:"download",serverId:serverId}).then(function(){button.dispatchEvent(new CustomEvent("download",{cancelable:!1}))})})}function clearEvents(button){button.removeEventListener("click",onClick)}function bindEvents(button){clearEvents(button),button.addEventListener("click",onClick)}function fetchAndUpdate(button,item){_connectionmanager.default.getApiClient(item).getSyncStatus(item).then(function(result){!function(button,status){var icon=button.iconElement;icon||(button.iconElement=button.querySelector("i"),icon=button.iconElement),null!=status?(button.classList.add("downloadbutton-on"),icon&&icon.classList.add("downloadbutton-icon-on")):(button.classList.remove("downloadbutton-on"),icon&&icon.classList.remove("downloadbutton-icon-on")),"Synced"===status?(button.classList.add("downloadbutton-complete"),icon&&icon.classList.add("downloadbutton-icon-complete")):(button.classList.remove("downloadbutton-complete"),icon&&icon.classList.remove("downloadbutton-icon-complete")),icon="Synced"===status?_globalize.default.translate("Downloaded"):null!=status?_globalize.default.translate("Downloading"):_globalize.default.translate("Download"),(status=button.querySelector(".button-text"))&&(status.innerHTML=icon),button.title=icon,button.setAttribute("aria-label",icon)}(button,result.Status)},function(){})}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var EmbyDownloadButton=function(_EmbyButton){function EmbyDownloadButton(){var _this;_this=_EmbyButton.call(this)||this;return babelHelpers.possibleConstructorReturn(_this,_this)}return babelHelpers.inherits(EmbyDownloadButton,_EmbyButton),babelHelpers.createClass(EmbyDownloadButton,[{key:"connectedCallback",value:function(){_embyButton.default.prototype.connectedCallback.call(this),function(){var itemId=this.getAttribute("data-id"),serverId=this.getAttribute("data-serverid");itemId&&serverId&&bindEvents(this)}.call(this)}},{key:"disconnectedCallback",value:function(){_embyButton.default.prototype.disconnectedCallback.call(this),function(){clearEvents(this),this.iconElement=null}.call(this)}},{key:"setItem",value:function(item){!function(item){(item?(this.setAttribute("data-id",item.Id),this.setAttribute("data-serverid",item.ServerId),this.setAttribute("data-itemtype",item.Type),fetchAndUpdate(this,item),bindEvents):(this.removeAttribute("data-id"),this.removeAttribute("data-serverid"),this.removeAttribute("data-itemtype"),clearEvents))(this)}.call(this,item)}}])}(_embyButton.default);EmbyDownloadButton.getHtml=function(item,buttonClass,iconClass,buttonType){iconClass=iconClass||"",buttonType=buttonType||"paper-icon-button-light",buttonClass?buttonClass+=" md-icon "+buttonType:buttonClass="md-icon "+buttonType,_layoutmanager.default.tv||(buttonClass+=" button-hoverable");buttonType=item.SyncStatus;return null!=buttonType&&(buttonClass+=" downloadbutton-on",iconClass+=" downloadbutton-icon-on"),"Synced"===buttonType&&(buttonClass+=" downloadbutton-complete",iconClass+=" downloadbutton-icon-complete"),iconClass&&(buttonClass+=" "+iconClass),iconClass="Synced"===buttonType?_globalize.default.translate("Downloaded"):null!=buttonType?_globalize.default.translate("Downloading"):_globalize.default.translate("Download"),'<button data-id="'+item.Id+'" data-serverid="'+item.ServerId+'" data-itemtype="'+item.Type+'" title="'+iconClass+'" aria-label="'+iconClass+'" tabindex="-1" is="emby-downloadbutton" data-owned="true" type="button" data-action="none" class="'+buttonClass+'">&#xf090;</button>'},customElements.define("emby-downloadbutton",EmbyDownloadButton,{extends:"button"}),_exports.default=EmbyDownloadButton});