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 _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(_isNativeReflectConstruct=function(){return!!t})()}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 t,o,e;babelHelpers.classCallCheck(this,EmbyRatingButton),t=this,o=EmbyRatingButton,o=babelHelpers.getPrototypeOf(o),o=babelHelpers.possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],babelHelpers.getPrototypeOf(t).constructor):o.apply(t,e));return babelHelpers.possibleConstructorReturn(o,o)}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){iconClass=iconClass||"",isFavorite&&(iconClass+=" ratingbutton-icon-withrating md-icon-fill"),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});