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}))})):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){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});