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")):icon&&(icon.innerHTML="&#xE87D;",icon.classList.remove("ratingbutton-icon-withrating")),!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){babelHelpers.inherits(EmbyRatingButton,_EmbyButton);var _super=_createSuper(EmbyRatingButton);function EmbyRatingButton(){var _this;babelHelpers.classCallCheck(this,EmbyRatingButton),_this=_super.call(this);return babelHelpers.possibleConstructorReturn(_this,_this)}return 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"))}}]),EmbyRatingButton}(_embyButton.default);EmbyRatingButton.getHtml=function(isFavorite,buttonClass,iconClass){iconClass=iconClass||"",isFavorite&&(iconClass+=" ratingbutton-icon-withrating"),buttonClass?buttonClass+=" md-icon paper-icon-button-light":buttonClass="md-icon paper-icon-button-light",iconClass&&(buttonClass+=" "+iconClass);iconClass=isFavorite?_globalize.default.translate("HeaderRemoveFromFavorites"):_globalize.default.translate("HeaderAddToFavorites");return'<button title="'+iconClass+'" aria-label="'+iconClass+'" 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});