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 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 t,o,e;babelHelpers.classCallCheck(this,EmbyPlaystateButton),t=this,o=EmbyPlaystateButton,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(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){iconClass?iconClass+=" playstatebutton-icon":iconClass="playstatebutton-icon",played&&(iconClass+=" playstatebutton-icon-played"),buttonClass?buttonClass+=" md-icon paper-icon-button-light":buttonClass="md-icon paper-icon-button-light",iconClass&&(buttonClass+=" "+iconClass);iconClass=played?_globalize.default.translate("HeaderMarkUnplayed"):_globalize.default.translate("HeaderMarkPlayed");return'<button title="'+iconClass+'" aria-label="'+iconClass+'" 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});