define(["jquery","Logger","stage/StageEvent","core/Mediator","./SwipeRangeFactory","./SwipeDirection","./SwipeState","./PageTransformer","css!./SwipeHandler.css"],function(t,e,n,i,r,a,o,s){"use strict";return t("#page-container").on("touchmove",function(t){t.preventDefault()}),function(g,u,c){function f(){O.reset(),F=new a,A={startPage:null,targetPage:null},h=0,H=0,u.stage.trigger.unlock(g)}function d(t,e){var n=s.generatePageTransformData(_,t,e,C);n&&u.transition.transform(n)}function l(){if(!S())return!1;try{var t=k[F.get()];return!(!t||!t(_))||(e.log("SwipeHandler::startTransition: No valid swipe direction detected!"),O.setToTransition(),d(0,y),!0)}catch(t){e.error("SwipeHandler::startTransition",t)}return!1}function S(){return _?!!_.currentPage||(e.log("SwipeHandler::startTransition: No current page!"),!1):(e.error("SwipeHandler::invalid swipe range for transition!"),!1)}function p(t){return t&&t.currentPage&&t.nextPage?T(t.currentPage,t.nextPage,-1*w()):(e.log("SwipeHandler::startTransition: Could not start transition, because there is no valid target page!"),!1)}function P(t){return t&&t.currentPage&&t.previousPage?T(t.currentPage,t.previousPage,w()):(e.log("SwipeHandler::startTransition: Could not start transition, because there is no valid target page!"),!1)}function T(t,e,n){return v(t,e),O.setToTransition(),d(n,y),!0}function v(t,e){A.startPage=t,A.targetPage=e}function w(){return t(".stage").width()}function I(){return!E()&&O.isInIdleState()}function N(){return!E()&&(O.pointerIsActivatedForSliding()||O.isSliding())}function D(){return!E()&&O.isSliding()}function E(){return u.stage.trigger.isLocked(g)}var h,H,R=c.parameters,b=R.asNumber("swipeStartDistance",5),m=R.asNumber("swipeToNavigateDistance",150),y=R.asNumber("swipeTransitionDuration",300),C=R.asBool("swipeHiddenPages",!0),_=r.create(u),O=new o,F=new a,k={},A={startPage:null,targetPage:null};return function(){y<=0&&(y=1),k[F.DIRECTION.LEFT]=p,k[F.DIRECTION.RIGHT]=P}(),{onStageReady:function(){O.isInactive()&&f()},onNavigationLocked:function(t){t.actor!==g&&f()},onEnterPage:function(){f()},onTransitionFinished:function(){if(e.log("Transition ended!"),A.startPage&&A.targetPage&&A.startPage!==A.targetPage)return void u.stage.navigation.gotoPage(A.targetPage,{actorId:g,transitionType:"none"});_&&(u.transition.notifyReset(_.getPageIds()),f())},onSlideStart:function(t){I()&&(_=r.create(u),O.setToStartCondition(),h=JSON.parse(JSON.stringify(t.clientX)),i.publish(n.SWIPE_STARTED))},onSlide:function(t){if(N()){var e=JSON.parse(JSON.stringify(t.clientX)),n=e-h,i=1,r=new a(n),o=u.stage.navigation.getCurrentPage().navigationToPreviousPageIsAvailable();if(O.pointerIsActivatedForSliding()){if(0===n||n<b&&n>-b)return;if(r.isRight()&&!o)return;u.stage.trigger.lock(g)}(!_.previousPage&&e>h||!_.nextPage&&e<h)&&(i=3),F=r,n>m||n<-m?O.setToMoveToNavigateCondition():O.setToMoveCondition(),H=n/i,d(H,0)}},onSlideEnd:function(){if(i.publish(n.SWIPE_ENDED),!D())return void(O.isInTransition()||(f(),d(0,1)));l()||(O.setToTransition(),d(0,y))},isSliding:function(){return!O.isInIdleState()&&!O.isInactive()},_setSwipeState:function(t){O=t},_getSwipeState:function(){return O},_setTransitionInfo:v,_getTransitionInfo:function(){return A},_setSwipeRange:function(t){_=t},_setDirection:function(t){F=t}}}});