"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);function d(){var t=this,e=t.getAttribute("data-id"),a=t.getAttribute("data-serverid"),i=r.tF.getApiClient(a),s=this.getAttribute("data-likes");s="true"===s||"false"!==s&&null,function(t,e,a,i,r){return e.updateFavoriteStatus(e.getCurrentUserId(),a,!r)}(0,i,e,0,"true"===this.getAttribute("data-isfavorite")).then((function(e){c(t,e.Likes,e.IsFavorite)}))}function c(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)),o(t,a)}function o(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 b(t){var e;t.removeEventListener("click",d),null===(e=t._unsubscribeUserData)||void 0===e||e.call(t),t._unsubscribeUserData=null}function v(t){b(t),t.addEventListener("click",d);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&&c(a,d.Likes,d.IsFavorite),u.A.trigger(l.A,r,[e,s])}(e,a,t)}))}var h=Object.create(n.A);h.createdCallback=function(){n.A.createdCallback&&n.A.createdCallback.call(this)},h.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");c(this,a="true"===a||"false"!==a&&null,"true"===this.getAttribute("data-isfavorite"),!1),v(this)}else o(this)},h.detachedCallback=function(){n.A.detachedCallback&&n.A.detachedCallback.call(this),b(this)},h.setItem=function(t){if(t){this.setAttribute("data-id",t.Id),this.setAttribute("data-serverid",t.ServerId);var e=t.UserData||{};c(this,e.Likes,e.IsFavorite),v(this)}else this.removeAttribute("data-id"),this.removeAttribute("data-serverid"),this.removeAttribute("data-likes"),this.removeAttribute("data-isfavorite"),b(this)},document.registerElement("emby-ratingbutton",{prototype:h,extends:"button"})}}]);