define(["exports","./../../shortcuts.js","./../../emby-apiclient/connectionmanager.js","./../../emby-apiclient/events.js","./../../common/globalize.js","./../../common/input/api.js","./../emby-button/emby-button.js"],function(_exports,_shortcuts,_connectionmanager,_events,_globalize,_api,_embyButton){function showToast(options){Emby.importModule("./modules/toast/toast.js").then(function(toast){return toast(options)})}function onClick(e){e.preventDefault();var e=function(button){if(button.hasAttribute("data-owned"))return _shortcuts.default.getItemFromChildNode(button,!0);var id=button.getAttribute("data-id"),button=button.getAttribute("data-serverid");return{Id:id,ServerId:button}}(this),id=e.Id,e=e.ServerId;id&&e&&!function(apiClient,itemId,isFavorite){var newValue=!isFavorite;apiClient.updateFavoriteStatus(apiClient.getCurrentUserId(),[itemId],newValue).then(function(){showToast(newValue?{text:_globalize.default.translate("Favorited"),icon:"&#xe87D;"}:{text:_globalize.default.translate("Unfavorited"),icon:"&#xe87D;",iconStrikeThrough:!0})})}(_connectionmanager.default.getApiClient(e),id,"true"===this.getAttribute("data-isfavorite"))}function onUserDataChanged(e,apiClient,userData){userData.ItemId===this.getAttribute("data-id")&&setState(this,userData.IsFavorite)}function setState(button,isFavorite,updateAttribute){!function(button,isFavorite){isFavorite=isFavorite?_globalize.default.translate("HeaderRemoveFromFavorites"):_globalize.default.translate("HeaderAddToFavorites"),button.title=isFavorite,button.setAttribute("aria-label",isFavorite),isFavorite=button.querySelector(".button-text");isFavorite&&(isFavorite.innerHTML=_globalize.default.translate("Favorite"))}(button,isFavorite);var icon=button.querySelector("i")||button;isFavorite?icon&&(icon.innerHTML="&#xe87D;",icon.classList.add("ratingbutton-icon-withrating","md-icon-fill")):icon&&(icon.innerHTML="&#xe87D;",icon.classList.remove("ratingbutton-icon-withrating","md-icon-fill")),!1!==updateAttribute&&button.setAttribute("data-isfavorite",isFavorite)}function clearEvents(button){var name,handler;button.removeEventListener("click",onClick),(handler=(button=button)[name="UserDataChanged"])&&(_events.default.off(_api.default,name,handler),button[name]=null)}function bindEvents(button){var name,handler;button.addEventListener("click",onClick),button.hasAttribute("data-owned")||(name="UserDataChanged",handler=(handler=onUserDataChanged).bind(button=button),_events.default.on(_api.default,name,handler),button[name]=handler)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var EmbyRatingButton=function(_EmbyButton){function EmbyRatingButton(){var _this;_this=_EmbyButton.call(this)||this;return babelHelpers.possibleConstructorReturn(_this,_this)}return babelHelpers.inherits(EmbyRatingButton,_EmbyButton),babelHelpers.createClass(EmbyRatingButton,[{key:"connectedCallback",value:function(){_embyButton.default.prototype.connectedCallback.call(this),bindEvents(this)}},{key:"disconnectedCallback",value:function(){_embyButton.default.prototype.disconnectedCallback.call(this),clearEvents(this)}},{key:"setItem",value:function(item){item?(this.setAttribute("data-id",item.Id),this.setAttribute("data-serverid",item.ServerId),setState(this,(item.UserData||{}).IsFavorite)):(this.removeAttribute("data-id"),this.removeAttribute("data-serverid"),this.removeAttribute("data-isfavorite"))}}])}(_embyButton.default);EmbyRatingButton.getHtml=function(isFavorite,buttonClass,iconClass,buttonType){iconClass=iconClass||"",isFavorite&&(iconClass+=" ratingbutton-icon-withrating md-icon-fill"),buttonType=buttonType||"paper-icon-button-light",buttonClass?buttonClass+=" md-icon "+buttonType:buttonClass="md-icon "+buttonType,iconClass&&(buttonClass+=" "+iconClass);buttonType=isFavorite?_globalize.default.translate("HeaderRemoveFromFavorites"):_globalize.default.translate("HeaderAddToFavorites");return'<button title="'+buttonType+'" aria-label="'+buttonType+'" tabindex="-1" is="emby-ratingbutton" data-owned="true" type="button" data-action="none" class="'+buttonClass+'" data-isfavorite="'+isFavorite+'">&#xe87D;</button>'},customElements.define("emby-ratingbutton",EmbyRatingButton,{extends:"button"}),_exports.default=EmbyRatingButton});