define(["exports","./../../shortcuts.js","./../../emby-apiclient/connectionmanager.js","./../../emby-apiclient/events.js","./../../common/globalize.js","./../../common/input/api.js","./../emby-button/emby-button.js","./../../layoutmanager.js"],function(_exports,_shortcuts,_connectionmanager,_events,_globalize,_api,_embyButton,_layoutmanager){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),apiClient=_connectionmanager.default.getApiClient(e);"true"!==this.getAttribute("data-played")?(apiClient.markPlayed(apiClient.getCurrentUserId(),[e.Id]),setState(this,!0)):(apiClient.markUnplayed(apiClient.getCurrentUserId(),[e.Id]),setState(this,!1))}function onUserDataChanged(e,apiClient,userData){userData.ItemId===this.getAttribute("data-id")&&setState(this,userData.Played)}function setState(button,played,updateAttribute){!function(button,played){played=played?_globalize.default.translate("HeaderMarkUnplayed"):_globalize.default.translate("HeaderMarkPlayed"),button.title=played,button.setAttribute("aria-label",played),played=button.querySelector(".button-text");played&&(played.innerHTML=_globalize.default.translate("Played"))}(button,played);var icon=button.querySelector("i")||button;played?icon&&icon.classList.add("playstatebutton-icon","playstatebutton-icon-played"):icon&&(icon.classList.add("playstatebutton-icon"),icon.classList.remove("playstatebutton-icon-played")),!1!==updateAttribute&&button.setAttribute("data-played",played)}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 EmbyPlaystateButton=function(_EmbyButton){function EmbyPlaystateButton(){var _this;_this=_EmbyButton.call(this)||this;return babelHelpers.possibleConstructorReturn(_this,_this)}return babelHelpers.inherits(EmbyPlaystateButton,_EmbyButton),babelHelpers.createClass(EmbyPlaystateButton,[{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&&item.UserData.Played)):(this.removeAttribute("data-id"),this.removeAttribute("data-serverid"),this.removeAttribute("data-played"))}}])}(_embyButton.default);EmbyPlaystateButton.getHtml=function(played,buttonClass,iconClass,buttonType){iconClass?iconClass+=" playstatebutton-icon":iconClass="playstatebutton-icon",played&&(iconClass+=" playstatebutton-icon-played"),buttonType=buttonType||"paper-icon-button-light",buttonClass?buttonClass+=" md-icon "+buttonType:buttonClass="md-icon "+buttonType,iconClass&&(buttonClass+=" "+iconClass),_layoutmanager.default.tv||(buttonClass+=" button-hoverable");buttonType=played?_globalize.default.translate("HeaderMarkUnplayed"):_globalize.default.translate("HeaderMarkPlayed");return'<button title="'+buttonType+'" aria-label="'+buttonType+'" tabindex="-1" is="emby-playstatebutton" data-owned="true" type="button" data-action="none" class="'+buttonClass+'" data-played="'+played+'">&#xe86c;</button>'},customElements.define("emby-playstatebutton",EmbyPlaystateButton,{extends:"button"}),_exports.default=EmbyPlaystateButton});