define(["itemShortcuts","browser","connectionManager","serverNotifications","events","globalize","emby-button"],function(itemShortcuts,browser,connectionManager,serverNotifications,events,globalize,EmbyButton){"use strict";function onClick(e){var button=this,itemInfo=function(button){if(button.hasAttribute("data-owned"))return itemShortcuts.getItemFromChildNode(button,!0);var id=button.getAttribute("data-id"),serverId=button.getAttribute("data-serverid");return{Id:id,ServerId:serverId}}(button),id=itemInfo.Id,serverId=itemInfo.ServerId;id&&serverId&&function(apiClient,itemId,isFavorite){return apiClient.updateFavoriteStatus(apiClient.getCurrentUserId(),itemId,!isFavorite)}(connectionManager.getApiClient(serverId),id,"true"===this.getAttribute("data-isfavorite")).then(function(userData){setState(button,userData.Likes,userData.IsFavorite)})}function onUserDataChanged(e,apiClient,userData){userData.ItemId===this.getAttribute("data-id")&&setState(this,userData.Likes,userData.IsFavorite)}function setState(button,likes,isFavorite,updateAttribute){var icon=button.querySelector("i");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 instance,name,handler;button.removeEventListener("click",onClick),(handler=(instance=button)[name="UserDataChanged"])&&(events.off(serverNotifications,name,handler),instance[name]=null)}function bindEvents(button){var instance,name,localHandler;button.addEventListener("click",onClick),button.hasAttribute("data-owned")||(name="UserDataChanged",localHandler=onUserDataChanged.bind(instance=button),events.on(serverNotifications,name,localHandler),instance[name]=localHandler)}var EmbyRatingButton=function(){babelHelpers.inherits(EmbyRatingButton,EmbyButton);var _super=_createSuper(EmbyRatingButton);function EmbyRatingButton(){var _this;babelHelpers.classCallCheck(this,EmbyRatingButton);var self=_this=_super.call(this);return babelHelpers.possibleConstructorReturn(_this,self)}return babelHelpers.createClass(EmbyRatingButton,[{key:"connectedCallback",value:function(){EmbyButton.prototype.connectedCallback.call(this),bindEvents(this)}},{key:"disconnectedCallback",value:function(){EmbyButton.prototype.disconnectedCallback.call(this),clearEvents(this)}},{key:"setItem",value:function(item){item?(function(button){var title=globalize.translate("Favorite");button.title=title,button.setAttribute("aria-label",title);var text=button.querySelector(".button-text");text&&(text.innerHTML=title)}(this),this.setAttribute("data-id",item.Id),this.setAttribute("data-serverid",item.ServerId),setState(this,0,(item.UserData||{}).IsFavorite)):(this.removeAttribute("data-id"),this.removeAttribute("data-serverid"),this.removeAttribute("data-likes"),this.removeAttribute("data-isfavorite"))}}]),EmbyRatingButton}();return EmbyRatingButton.getHtml=function(isFavorite,buttonClass,iconClass){var icon;iconClass=iconClass||"",icon=(isFavorite&&(iconClass+=" ratingbutton-icon-withrating"),"&#xE87D;");var title=globalize.translate("Favorite");return'<button title="'+title+'" aria-label="'+title+'" tabindex="-1" is="emby-ratingbutton" data-owned="true" type="button" data-action="none" class="'+buttonClass+'" data-isfavorite="'+isFavorite+'"><i class="md-icon '+iconClass+'">'+icon+"</i></button>"},customElements.define("emby-ratingbutton",EmbyRatingButton,{extends:"button"}),EmbyRatingButton});