"use strict";var _=Object.create;var I=Object.defineProperty,ee=Object.defineProperties,te=Object.getOwnPropertyDescriptor,ne=Object.getOwnPropertyDescriptors,oe=Object.getOwnPropertyNames,T=Object.getOwnPropertySymbols,ue=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var j=(e,t,n)=>t in e?I(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,H=(e,t)=>{for(var n in t||(t={}))R.call(t,n)&&j(e,n,t[n]);if(T)for(var n of T(t))B.call(t,n)&&j(e,n,t[n]);return e},P=(e,t)=>ee(e,ne(t));var q=(e,t)=>{var n={};for(var r in e)R.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&T)for(var r of T(e))t.indexOf(r)<0&&B.call(e,r)&&(n[r]=e[r]);return n};var re=(e,t)=>{for(var n in t)I(e,n,{get:t[n],enumerable:!0})},N=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of oe(t))!R.call(e,a)&&a!==n&&I(e,a,{get:()=>t[a],enumerable:!(r=te(t,a))||r.enumerable});return e};var S=(e,t,n)=>(n=e!=null?_(ue(e)):{},N(t||!e||!e.__esModule?I(n,"default",{value:e,enumerable:!0}):n,e)),se=e=>N(I({},"__esModule",{value:!0}),e);var ce={};re(ce,{Field:()=>ie,Root:()=>ae});module.exports=se(ce);var u=S(require("react"),1);var d=S(require("react"),1),E=()=>{},le={values:[],register:E,unregister:E,getIndex:()=>-1,handleKeyDown:E,handleInput:E,handleMouseDown:E},U=(0,d.createContext)(le);function $({value:e,children:t}){return d.default.createElement(U.Provider,{value:e},t)}function z(){return(0,d.useContext)(U)}function G(...e){return t=>e.forEach(n=>{typeof n=="function"?n(t):n&&(n.current=t)})}function g(e,t){return function(n){e==null||e(n),n.defaultPrevented||t==null||t(n)}}var ae=(0,u.forwardRef)((e,t)=>{let K=e,{blurOnCompleted:n=!1,autoFocus:r=!1,defaultValue:a,value:m,transform:x=o=>o,onChange:b=()=>{},onCompleted:y=()=>{}}=K,C=q(K,["blurOnCompleted","autoFocus","defaultValue","value","transform","onChange","onCompleted"]),v=(0,u.useRef)(null),[i,V]=(0,u.useState)([]),[J,Q]=(0,u.useState)([]),c=i.length,L=m||J,w=m?b:Q;(0,u.useEffect)(()=>{if(!m){let o=a?a.slice(0,c):new Array(c).fill("");w(o)}},[c]);let M=i[0];(0,u.useEffect)(()=>{r&&(M==null||M.focus())},[r,M]);let W=(0,u.useCallback)(o=>{V(s=>[...s,o])},[]),X=(0,u.useCallback)(o=>{V(s=>s.filter(l=>l!==o))},[]),D=(0,u.useCallback)(o=>o?i.indexOf(o):-1,[i]),Y=o=>o.filter(Boolean).length===c,A=o=>{requestAnimationFrame(()=>o.select())},p=o=>{let s=Math.min(Math.max(o,0),c-1),l=i[s];l.focus(),A(l)},F=o=>{w(L.map((s,l)=>l===o?"":s))};return u.default.createElement($,{value:{register:W,unregister:X,getIndex:D,values:L,handleKeyDown:o=>{let s=o.currentTarget,l=D(s);o.key==="Backspace"&&!s.value?(o.preventDefault(),F(l-1),p(l-1)):o.key==="ArrowLeft"?(o.preventDefault(),p(l-1)):o.key==="ArrowRight"?(o.preventDefault(),p(l+1)):o.key==="ArrowUp"?(o.preventDefault(),p(0)):o.key==="ArrowDown"&&(o.preventDefault(),p(c-1))},handleInput:o=>{var k;let s=o.currentTarget,{value:l}=s,f=D(s);if(!l){F(f);return}let h=[...L];for(let Z of l){let O=x(Z);if(O&&(h[f]=O,f+=1),f>=c)break}if(w(h),Y(h)&&(y(h),n)){s.blur();return}o.nativeEvent.isComposing?((k=v.current)==null||k.focus(),setTimeout(()=>p(f),50)):p(f)},handleMouseDown:o=>{let s=o.currentTarget;s.value&&A(s)}}},u.default.createElement("div",P(H({},C),{ref:t})),u.default.createElement("input",{ref:v,"aria-hidden":"true",style:{position:"absolute",opacity:0,left:-9999,top:-9999},tabIndex:-1,onFocus:o=>o.target.value=""}))}),ie=(0,u.forwardRef)((e,t)=>{let n=(0,u.useRef)(null),{register:r,unregister:a,getIndex:m,values:x,handleKeyDown:b,handleInput:y,handleMouseDown:C}=z(),v=m(n.current);return(0,u.useEffect)(()=>{let i=n.current;return i&&r(i),()=>{i&&a(i)}},[r,a]),u.default.createElement("input",P(H({"aria-label":`Please enter OTP character ${v+1}`,type:"text",autoComplete:"one-time-code",inputMode:"numeric",value:x[v]||""},e),{onKeyDown:g(e.onKeyDown,b),onInput:g(e.onInput,y),onMouseDown:g(e.onMouseDown,C),ref:G(n,t)}))});0&&(module.exports={Field,Root}); //# sourceMappingURL=index.cjs.map