define(["dom","events","userSettings","globalize","navDrawerContent","css!./navdrawer","scrollStyles"],function(dom,events,userSettings,globalize,navDrawerContent){"use strict";var instance,mask,navDrawerElement=document.querySelector(".mainDrawer"),DrawerStates_Closed=0,DrawerStates_Open=1,DrawerStates_Docked=2;function onMainDrawerClick(e){e.target.closest(".btnPinNavDrawer")&&instance.togglePinState()}function setPinIcon(icon){var btnPinNavDrawerIcon=navDrawerElement.querySelector(".btnPinNavDrawerIcon");btnPinNavDrawerIcon&&(btnPinNavDrawerIcon.innerHTML=icon);var title,btnPinNavDrawer=navDrawerElement.querySelector(".btnPinNavDrawer");btnPinNavDrawer&&("menu_open"===icon?(title=globalize.translate("HeaderCloseSidebar"),btnPinNavDrawer.classList.remove("btnPinNavDrawer-iconpin"),btnPinNavDrawer.classList.add("btnPinNavDrawer-iconclose")):(title=globalize.translate("HeaderPinSidebar"),btnPinNavDrawer.classList.add("btnPinNavDrawer-iconpin"),btnPinNavDrawer.classList.remove("btnPinNavDrawer-iconclose")),btnPinNavDrawer.title=title,btnPinNavDrawer.setAttribute("aria-label",title))}function NavDrawer(){instance=this,navDrawerElement.classList.add("scrollY"),navDrawerElement.classList.add("hiddenScrollY-hover"),navDrawerElement.classList.add("scrollY-mini"),dom.addEventListener(navDrawerElement,"click",onMainDrawerClick,{passive:!0}),dom.addEventListener(navDrawerElement,dom.whichTransitionEvent(),onNavDrawerTransitionEnd,{passive:!0,capture:!0})}function getScrollingElement(){return document.scrollingElement||document.documentElement}function onNavDrawerTransitionEnd(e){e.target===e.currentTarget&&(this.classList.contains("drawer-open")||this.classList.add("hide"))}function onMaskTransitionEnd(e){var maskElement;e.target!==e.currentTarget||(maskElement=mask)&&maskElement.classList.contains("drawer-backdrop-fadeout")&&(maskElement.parentNode.removeChild(maskElement),mask=null)}return NavDrawer.prototype.open=function(isDocked){navDrawerContent.onBeforeOpen(),isDocked?(navDrawerElement.classList.add("drawer-docked"),setPinIcon("menu_open")):(navDrawerElement.classList.remove("drawer-docked"),setPinIcon("view_sidebar")),navDrawerElement.style.willChange="transform";var newDrawerState=this.drawerState=isDocked?DrawerStates_Docked:DrawerStates_Open;navDrawerElement.classList.remove("hide"),navDrawerElement.offsetWidth,navDrawerElement.classList.add("drawer-open"),isDocked?this.hideMask():(this.showMask(),getScrollingElement().classList.add("withDialogOpen")),events.trigger(this,"drawer-state-change",[newDrawerState])},NavDrawer.prototype.close=function(){var currentDrawerState=this.drawerState;currentDrawerState&&(navDrawerElement.style.willChange="transform");var newDrawerState=this.drawerState=DrawerStates_Closed;navDrawerElement.classList.remove("drawer-open","drawer-docked"),this.hideMask(),getScrollingElement().classList.remove("withDialogOpen"),currentDrawerState===DrawerStates_Docked&&navDrawerElement.classList.add("hide"),setPinIcon("view_sidebar"),events.trigger(this,"drawer-state-change",[newDrawerState])},NavDrawer.prototype.toggle=function(){this.drawerState?this.close():this.open()},NavDrawer.prototype.togglePinState=function(){this.drawerState===DrawerStates_Open?(userSettings.drawerStyle("docked"),this.open(!0)):(userSettings.drawerStyle("closed"),this.close())},NavDrawer.prototype.showMask=function(){mask=mask||function(instance){var mask=document.createElement("div");return mask.className="drawer-backdrop",dom.addEventListener(mask,dom.whichAnimationEvent(),onMaskTransitionEnd,{passive:!0,capture:!0}),dom.addEventListener(mask,"click",instance.close.bind(instance),{passive:!0}),document.body.appendChild(mask),mask}(this)},NavDrawer.prototype.hideMask=function(){mask&&mask.classList.add("drawer-backdrop-fadeout")},new NavDrawer});