define(["itemShortcuts","connectionManager","serverNotifications","events","globalize","emby-button","browser"],function(itemShortcuts,connectionManager,serverNotifications,events,globalize,EmbyButton,browser){"use strict";function onClick(e){var itemInfo=function(button){if(button.hasAttribute("data-owned"))return itemShortcuts.getItemFromChildNode(button,!0);var id=button.getAttribute("data-id"),serverId=button.getAttribute("data-serverid");return{Id:id,ServerId:serverId}}(this),apiClient=connectionManager.getApiClient(itemInfo);"true"!==this.getAttribute("data-played")?(apiClient.markPlayed(apiClient.getCurrentUserId(),itemInfo.Id),setState(this,!0)):(apiClient.markUnplayed(apiClient.getCurrentUserId(),itemInfo.Id),setState(this,!1))}function onUserDataChanged(e,apiClient,userData){userData.ItemId===this.getAttribute("data-id")&&setState(this,userData.Played)}function setState(button,played,updateAttribute){var icon=button.querySelector("i");played?icon&&icon.classList.add("playstatebutton-icon-played"):icon&&icon.classList.remove("playstatebutton-icon-played"),!1!==updateAttribute&&button.setAttribute("data-played",played)}function clearEvents(button){var instance,name,handler;button.removeEventListener("click",onClick),(handler=(instance=button)[name="UserDataChanged"])&&(events.off(serverNotifications,name,handler),instance[name]=null)}function bindEvents(button){var instance,name,localHandler;button.addEventListener("click",onClick),button.hasAttribute("data-owned")||(name="UserDataChanged",localHandler=onUserDataChanged.bind(instance=button),events.on(serverNotifications,name,localHandler),instance[name]=localHandler)}var EmbyPlaystateButton=function(){babelHelpers.inherits(EmbyPlaystateButton,EmbyButton);var _super=_createSuper(EmbyPlaystateButton);function EmbyPlaystateButton(){var _this;babelHelpers.classCallCheck(this,EmbyPlaystateButton);var self=_this=_super.call(this);return babelHelpers.possibleConstructorReturn(_this,self)}return babelHelpers.createClass(EmbyPlaystateButton,[{key:"connectedCallback",value:function(){EmbyButton.prototype.connectedCallback.call(this),bindEvents(this)}},{key:"disconnectedCallback",value:function(){EmbyButton.prototype.disconnectedCallback.call(this),clearEvents(this)}},{key:"setItem",value:function(item){item?(function(button){var title=globalize.translate("Played");button.title=title,button.setAttribute("aria-label",title);var text=button.querySelector(".button-text");text&&(text.innerHTML=title)}(this),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"))}}]),EmbyPlaystateButton}();return EmbyPlaystateButton.getHtml=function(played,buttonClass,iconClass){iconClass=iconClass||"",played&&(iconClass+=" playstatebutton-icon-played");var title=globalize.translate("Played");return'<button title="'+title+'" aria-label="'+title+'" tabindex="-1" is="emby-playstatebutton" data-owned="true" type="button" data-action="none" class="'+buttonClass+'" data-played="'+played+'"><i class="md-icon '+iconClass+'">&#xE5CA;</i></button>'},customElements.define("emby-playstatebutton",EmbyPlaystateButton,{extends:"button"}),EmbyPlaystateButton});