"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[15605],{15605:function(t,e,a){a.r(e),a(69703),a(78557);var i=a(5898),r=a(67430),s=a(4935),n=a(10353),l=a(10736),u=a(44797),d=a(53678);function c(){var t=this,e=t.getAttribute("data-id"),a=t.getAttribute("data-serverid"),i=r.tF.getApiClient(a),s="true"===this.getAttribute("data-isfavorite"),n=i.getCurrentUserId();i.updateFavoriteStatus(n,e,!s).then((function(e){o(t,e.Likes,e.IsFavorite),d.q.invalidateQueries({queryKey:["User",n,"Items"]})}))}function o(t,e,a,i){var r=t.querySelector(".material-icons");a?(r&&(r.classList.add("favorite"),r.classList.add("ratingbutton-icon-withrating")),t.classList.add("ratingbutton-withrating")):(r&&(r.classList.add("favorite"),r.classList.remove("ratingbutton-icon-withrating")),t.classList.remove("ratingbutton-withrating")),!1!==i&&(t.setAttribute("data-isfavorite",a),t.setAttribute("data-likes",null===e?"":e)),b(t,a)}function b(t,e){t.title=e?i.Ay.translate("Favorite"):i.Ay.translate("AddToFavorites");var a=t.querySelector(".button-text");a&&(a.innerText=t.title)}function v(t){var e;t.removeEventListener("click",c),null===(e=t._unsubscribeUserData)||void 0===e||e.call(t),t._unsubscribeUserData=null}function h(t){v(t),t.addEventListener("click",c);var e=t.dataset.serverid,a=r.tF.getApiClient(e);t._unsubscribeUserData=null==a?void 0:a.subscribe([s.De.UserDataChanged],(function(e){return function(t,e,a){var i,r=t.MessageType,s=t.Data,n=a.dataset.id,d=(null!==(i=null==s?void 0:s.UserDataList)&&void 0!==i?i:[]).find((function(t){return t.ItemId===n}));d&&o(a,d.Likes,d.IsFavorite),u.A.trigger(l.A,r,[e,s])}(e,a,t)}))}var A=Object.create(n.A);A.createdCallback=function(){n.A.createdCallback&&n.A.createdCallback.call(this)},A.attachedCallback=function(){n.A.attachedCallback&&n.A.attachedCallback.call(this);var t=this.getAttribute("data-id"),e=this.getAttribute("data-serverid");if(t&&e){var a=this.getAttribute("data-likes");o(this,a="true"===a||"false"!==a&&null,"true"===this.getAttribute("data-isfavorite"),!1),h(this)}else b(this)},A.detachedCallback=function(){n.A.detachedCallback&&n.A.detachedCallback.call(this),v(this)},A.setItem=function(t){if(t){this.setAttribute("data-id",t.Id),this.setAttribute("data-serverid",t.ServerId);var e=t.UserData||{};o(this,e.Likes,e.IsFavorite),h(this)}else this.removeAttribute("data-id"),this.removeAttribute("data-serverid"),this.removeAttribute("data-likes"),this.removeAttribute("data-isfavorite"),v(this)},document.registerElement("emby-ratingbutton",{prototype:A,extends:"button"})}}]);