import{j as n,c as I,z as N,Z as S,T as x,$ as b,I as j}from"./index-CmAiVN5e.js";import{r as _}from"./vendor-animations-CsoOZIH8.js";import{d as v,e as y,f as A}from"./validators-3vU18RTh.js";function C(e,l){return Array.from({length:l},(c,r)=>r+e)}const E="pin-field",L=`${E}_bc_`,T=`${E}_size_`,R="Backspace",z="pinField_",h=e=>e.length>0?e[e.length-1]:e,g=e=>{const l=_.useRef(null),c=e.customPrefix??z,r=s=>{if(s&&l.current){const t=document.getElementById(`${c}${e.index+1}`);t instanceof HTMLInputElement&&t.focus()}},f=s=>{if(l.current&&s.key===R&&e.value===""){const t=document.getElementById(`${c}${e.index-1}`);t instanceof HTMLInputElement&&t.focus()}},m=s=>{switch(e.type){case"en":A(s.target.value)&&e.setValue(h(s.target.value))&&r(s.target.value);break;case"number":y(s.target.value)&&e.setValue(h(s.target.value))&&r(s.target.value);break;case"letter":v(s.target.value)&&e.setValue(h(s.target.value))&&r(s.target.value);break}};return n.jsx("input",{id:`${c}${e.index}`,ref:l,value:e.value,type:"text",inputMode:e.type==="number"?"numeric":"text",autoFocus:e.autoFocus,placeholder:e.placeholder,autoComplete:"off",onKeyDown:f,onChange:m,"aria-label":e.ariaLabel,"aria-required":e.ariaRequired,className:I(E,`${L}${e.borderColor??"primary"} ${T}${e.size}`)})},o="safe-code-input",V=`${o}_size_`,$=2,F=(e,l)=>{const{t:c}=N(),r=_.useRef(null),f=e.codeLength;_.useImperativeHandle(l,()=>({scrollIntoView:t=>{var u;return(u=r.current)==null?void 0:u.scrollIntoView(t)}}));const m=(t,u)=>{const a=u.toUpperCase();if(a){const i=t>0?e.code[t-1]===a:!1,d=t<e.code.length-1?e.code[t+1]===a:!1;if(i||d)return!1}return e.setCode(t,a),!0},s=()=>{const t=!!(f-$);return n.jsxs("div",{ref:r,className:`${o}__code`,children:[n.jsxs("div",{className:`${o}__code-block`,children:[n.jsx(x,{size:"s",color:"brand",children:c("sendDonation:safeBlock:letters")}),n.jsxs("div",{className:`${o}__letters`,children:[C(0,$).map((u,a)=>n.jsx(b,{children:()=>{var i;return n.jsx(g,{index:a,placeholder:"*",value:(i=e.code)==null?void 0:i[a],setValue:d=>m(a,d),borderColor:"brand",type:"en",autoFocus:a===0,size:e.size,ariaRequired:!0})}},a)),t&&n.jsx(j,{type:"rectangle"})]})]}),t&&n.jsxs("div",{className:`${o}__code-block`,children:[n.jsx(x,{size:"s",color:"primary",children:c("sendDonation:safeBlock:numbers")}),n.jsx("div",{className:`${o}__numbers`,children:C(0,f).map((u,a)=>a<$?null:n.jsx(b,{children:()=>{var i;return n.jsx(g,{index:a,placeholder:"*",value:(i=e.code)==null?void 0:i[a],setValue:d=>m(a,d),borderColor:"secondary",type:"number",size:e.size})}},a))})]})]})};return n.jsx(S,{className:I(o,`${V}${e.size??"s"}`),title:e.title,hintText:e.hintText,errorText:e.errorText,withHintIcon:!0,children:s()})},w=_.forwardRef(F);export{g as P,w as S,C as r};