!function(e){"function"==typeof define&&define.amd?define(e):e()}(function(){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var B=require("tslib"),F=B.__importStar(require("react")),J=require("react-gesture-responder"),K=require("react-spring"),Q=require("./use-measure"),U=B.__importDefault(require("use-scroll-lock")),V=require("./use-previous");exports.default=F.forwardRef(function(e,n){var t=e.children,r=e.id,o=e.value,u=e.onRequestChange,i=(e.focusOnChange,e.enableScrollLock),a=void 0===i||i,s=e.enableGestures,l=void 0===s||s,f=e.enableMouse,c=void 0!==f&&f,d=e.lazyLoad,v=void 0!==d&&d,m=e.onSetLazy,h=e.animationConfig,y=void 0===h?{tension:190,friction:20,mass:.4}:h,p=e.onTerminationRequest,S=e.onMoveShouldSet,g=e.style,x=B.__rest(e,["children","id","value","onRequestChange","focusOnChange","enableScrollLock","enableGestures","enableMouse","lazyLoad","onSetLazy","animationConfig","onTerminationRequest","onMoveShouldSet","style"]),_=F.useRef(null),b=F.useState(!1),w=b[0],R=b[1],q=F.useState(function(){return new Set(m?m(o):[o])}),M=q[0],C=q[1],G=Q.useMeasure(_).width,E=F.useRef(new Map),L=V.usePrevious(o),k=F.useRef(null);function D(e){var n=E.current.get(e);n&&n.focus()}U.default(w&&a),F.useEffect(function(){k.current="number"==typeof L&&L!==o?o:null},[L,o]),F.useImperativeHandle(n,function(){return{focus:function(e){D(e||o)}}});var z=K.useSpring(function(){return{x:-100*o,config:y}}),T=z[0].x,N=z[1];function O(){"number"==typeof k.current&&D(k.current)}var j=t.filter(function(e){return null!==e}),A=j.length-1,H=0;function I(e){return 0<e&&e<=A}function P(e){var n=G/2;Math.abs(e)>n?e<0&&o<A?u(o+1):0<e&&H<o?u(o-1):N({x:-100*o}):N({x:-100*o,onRest:O})}F.useEffect(function(){N({x:-100*o,onRest:O}),M.add(o)},[o]);var X=J.useGestureResponder({onTerminationRequest:p,onStartShouldSet:function(){return!1},onMoveShouldSet:function(e,n){e.initial,e.xy;var t=e.initialDirection;if(!l)return!1;var r=0!=t[0];return S?S(e,n,r):r},onGrant:function(){R(!0)},onMove:function(e){var n=e.delta,t=e.direction,r=n[0];N({x:r/G*100+-100*o,immediate:!0,onRest:function(){}}),function(n){if(I(n)){var e=n;m&&(e=m(n));var t=Array.isArray(e)?e:[e],r=new Set(M);t.forEach(function(e){!M.has(e)&&I(n)&&r.add(e)}),C(r)}}(0<t[0]?o-1:o+1)},onRelease:function(e){var n=e.delta,t=e.velocity,r=e.direction,i=n[0];return R(!1),.2<t&&0<r[0]&&H<o?u(o-1):.2<t&&r[0]<0&&o<A?u(o+1):void P(i)},onTerminate:function(e){var n=e.delta;R(!1),P(n[0])}},{uid:r,enableMouse:c}).bind;return F.createElement("div",B.__assign({},X,{ref:_,className:"Gesture-view",style:B.__assign({display:"flex",flexDirection:"column",overflow:"hidden",width:"100%"},g)},x),F.createElement(K.animated.div,{className:"Gesture-view__animated-container",style:{flexDirection:"row",direction:"ltr",willChange:"transform",minHeight:0,flex:1,display:"flex",transform:T.interpolate(function(e){return"translateX("+function(e,n){if(0<e)return.3*e;if(e<n){var t=e-n;return e-.7*t}return e}(e,-100*A)+"%)"})}},j.map(function(e,n){var t={key:n,tabIndex:o===n?0:-1,style:{display:"flex",flexDirection:"column",width:"100%",alignSelf:"stretch",justifyContent:"flex-start",flexShrink:0,height:"100%",overflow:"hidden",outline:"none"},"aria-hidden":n!==o,ref:function(e){E.current.set(n,e)}},r=!v||o===n||M.has(n);return"function"==typeof e?e(t,o===n,r):F.createElement("div",B.__assign({className:"Gesture-view__pane"},t),r&&e)})))})});
