define(["browser","dom","layoutManager","css!./emby-checkbox"],function(browser,dom,layoutManager){"use strict";function onKeyDown(e){return browser.tizen&&32===e.keyCode?(e.preventDefault(),this.checked=!this.checked,this.dispatchEvent(new CustomEvent("change",{bubbles:!0})),!1):13===e.keyCode?(e.preventDefault(),this.checked=!this.checked,this.dispatchEvent(new CustomEvent("change",{bubbles:!0})),!1):void 0}var enableRefreshHack=!!(browser.tizen||browser.orsay||browser.operaTv||browser.web0s||browser.netcast);function forceRefresh(loading){var elem=this.parentNode;setTimeout(function(){elem.classList.add("forceRefresh"),setTimeout(function(){elem.classList.remove("forceRefresh")},20)},!0===loading?500:0)}function onInit(){this.hasInit||(this.hasInit=!0)}function _connectedCallback(){if("true"!==this.getAttribute("data-embycheckbox")){this.setAttribute("data-embycheckbox","true"),this.classList.add("emby-checkbox"),layoutManager.tv&&this.classList.add("emby-checkbox-tv");var labelElement=this.parentNode;labelElement.classList.add("emby-checkbox-label");var labelTextElement=labelElement.querySelector("span"),outlineClass="checkboxOutline",customClass=this.getAttribute("data-outlineclass");customClass&&(outlineClass+=" "+customClass);var checkHtml='<i class="md-icon checkboxIcon checkboxIcon-checked">'+(this.getAttribute("data-checkedicon")||"&#xE5CA;")+"</i>",uncheckedHtml='<i class="md-icon checkboxIcon checkboxIcon-unchecked">'+(this.getAttribute("data-uncheckedicon")||"")+"</i>",focusHelperHtml="";"false"!==this.getAttribute("data-focushelper")&&(focusHelperHtml+='<span class="emby-checkbox-focushelper"></span>'),focusHelperHtml+='<span class="'+outlineClass+'">'+checkHtml+uncheckedHtml+"</span>",labelElement.insertAdjacentHTML("beforeend",focusHelperHtml),labelTextElement&&labelTextElement.classList.add("checkboxLabel"),this.addEventListener("keydown",onKeyDown),enableRefreshHack&&(forceRefresh.call(this,!0),dom.addEventListener(this,"click",forceRefresh,{passive:!0}),dom.addEventListener(this,"blur",forceRefresh,{passive:!0}),dom.addEventListener(this,"focus",forceRefresh,{passive:!0}),dom.addEventListener(this,"change",forceRefresh,{passive:!0}))}}function _disconnectedCallback(){this.removeEventListener("keydown",onKeyDown),dom.removeEventListener(this,"click",forceRefresh,{passive:!0}),dom.removeEventListener(this,"blur",forceRefresh,{passive:!0}),dom.removeEventListener(this,"focus",forceRefresh,{passive:!0}),dom.removeEventListener(this,"change",forceRefresh,{passive:!0})}if(window.customElements){var EmbyCheckbox=function(_HTMLInputElement){function EmbyCheckbox(){var _this;babelHelpers.classCallCheck(this,EmbyCheckbox);var self=_this=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(EmbyCheckbox).call(this));return onInit.call(self),babelHelpers.possibleConstructorReturn(_this,self)}return babelHelpers.inherits(EmbyCheckbox,_HTMLInputElement),babelHelpers.createClass(EmbyCheckbox,[{key:"connectedCallback",value:function(){onInit.call(this),_connectedCallback.call(this)}},{key:"disconnectedCallback",value:function(){_disconnectedCallback.call(this)}}]),EmbyCheckbox}(babelHelpers.wrapNativeSuper(HTMLInputElement));customElements.define("emby-checkbox",EmbyCheckbox,{extends:"input"})}else if(document.registerElement){var EmbyCheckboxPrototype=Object.create(HTMLInputElement.prototype);EmbyCheckboxPrototype.createdCallback=onInit,EmbyCheckboxPrototype.attachedCallback=_connectedCallback,EmbyCheckboxPrototype.detachedCallback=_disconnectedCallback,document.registerElement("emby-checkbox",{prototype:EmbyCheckboxPrototype,extends:"input"})}});