define(["exports","./../../common/globalize.js","./../../emby-apiclient/connectionmanager.js","./../emby-button/emby-button.js"],function(_exports,_globalize,_connectionmanager,_embyButton){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}))})):require(["syncDialog"],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.Id).then(function(result){!function(button,syncPercent){var icon=button.iconElement;icon||(button.iconElement=button.querySelector("i"),icon=button.iconElement),null!=syncPercent?(button.classList.add("downloadbutton-on"),icon&&icon.classList.add("downloadbutton-icon-on")):(button.classList.remove("downloadbutton-on"),icon&&icon.classList.remove("downloadbutton-icon-on")),100<=(syncPercent||0)?(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=100<=(syncPercent||0)?_globalize.default.translate("Downloaded"):null!=syncPercent?_globalize.default.translate("Downloading"):_globalize.default.translate("Download"),(syncPercent=button.querySelector(".button-text"))&&(syncPercent.innerHTML=icon),button.title=icon,button.setAttribute("aria-label",icon)}(button,result.Progress)},function(){})}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var EmbyDownloadButton=function(_EmbyButton){babelHelpers.inherits(EmbyDownloadButton,_EmbyButton);var _super=_createSuper(EmbyDownloadButton);function EmbyDownloadButton(){var _this;babelHelpers.classCallCheck(this,EmbyDownloadButton),_this=_super.call(this);return babelHelpers.possibleConstructorReturn(_this,_this)}return 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)}}]),EmbyDownloadButton}(_embyButton.default);customElements.define("emby-downloadbutton",EmbyDownloadButton,{extends:"button"}),_exports.default=EmbyDownloadButton});