import{I as c}from"./globals.js";import{o as n,c as u,j as f,f as l,k as h,S as p,a as o,t as d,n as v,_}from"./index.js";import{a as m}from"./Button.js";/* empty css                                          */const y={key:0,class:"input-field__icon"},I=["type"],F={key:1,class:"input-field__placeholder"},E={key:2,class:"input-field__fast-enter-hint"},b={class:"input-field__fast-enter-hint-left"},g={class:"input-field__fast-enter-hint-right"},k={key:3,class:"input-field__enter-icon",src:m};function w(e,t,r,S,a,s){return n(),u("div",{class:v(["input-field",s.classes]),onClick:t[5]||(t[5]=i=>s.isMobile&&s.focusInput()),onTouchend:t[6]||(t[6]=(...i)=>s.focusInput&&s.focusInput(...i))},[r.data.icon?(n(),u("div",y,[f(e.$slots,"default")])):l("",!0),h(o("input",{ref:"input",type:s.validGamefaceInputType,"onUpdate:modelValue":t[0]||(t[0]=i=>a.value=i),onMousedown:t[1]||(t[1]=(...i)=>e.onInputMouseDown&&e.onInputMouseDown(...i)),onInput:t[2]||(t[2]=(...i)=>s.validateInput&&s.validateInput(...i)),onFocus:t[3]||(t[3]=(...i)=>s.onFocus&&s.onFocus(...i)),onBlur:t[4]||(t[4]=(...i)=>s.onBlur&&s.onBlur(...i))},null,40,I),[[p,a.value]]),String(a.value).length?l("",!0):(n(),u("div",F,d(r.data.placeholder),1)),String(a.value).length&&a.currentFastEnterHint.length&&a.inputIsFocused?(n(),u("div",E,[o("div",b,d(a.value),1),o("div",g,d(a.currentFastEnterHint.slice(a.value.length).replace(/\s/g," ")),1)])):l("",!0),r.isShowEnterIcon?(n(),u("img",k)):l("",!0)],34)}const C={props:{data:{type:Object,default:()=>({failure:!1,icon:!1,success:!1,disabled:!1,value:"",placeholder:"",type:"text"})},autofocus:{type:Boolean,default:!1},fastEnterHints:{type:Array,default:()=>[]},validateSuccessCallback:{type:Function,default:()=>!1},validateFailureCallback:{type:Function,default:()=>!1},isShowEnterIcon:{type:Boolean,default:!0}},data(){return{value:"",inputIsFocused:!1,currentFastEnterHint:"",validatedFailure:!1,validatedSuccess:!1}},computed:{classes(){return{"input-field_success":this.validatedSuccess||this.data.success,"input-field_failure":this.validatedFailure||this.data.failure,"input-field_icon":this.data.icon,"input-field_focused":this.inputIsFocused,"input-field_disabled":this.data.disabled,"input-field_hoverable":!this.isMobile}},validGamefaceInputType(){return this.data.type==="password"?"password":""},isMobile(){return this.$root.isMobile}},created(){this.value=this.data.value,document.addEventListener("keyup",this.onKeyUp)},mounted(){this.autofocus&&this.focusInput()},unmounted(){document.removeEventListener("keyup",this.onKeyUp)},methods:{validateInput(){if(this.data.type==="number"){let e=this.value.toString().replace(/\D/g,"");e=isNaN(parseInt(e))?0:Math.min(parseInt(e),c),this.value=e}if(this.data.type==="name"||this.data.type==="code"){const e=this.data.type==="name"?/^[a-zA-Z]*$/:/^[0-9]$/;this.value=this.value.trim().split("").filter(t=>e.test(t)).join("").slice(0,40)}this.data.type==="code"&&(this.value=this.value.slice(0,6)),this.$emit("update",this.value),this.updateCurrentFastEnterHint()},onFocus(){this.$emit("focus"),this.inputIsFocused=!0},onBlur(){this.$emit("blur"),this.validatedFailure=this.validateFailureCallback(this.value),this.validatedSuccess=this.validateSuccessCallback(this.value),this.inputIsFocused=!1},updateCurrentFastEnterHint(){if(["number","code"].includes(this.data.type))return;const e=this.fastEnterHints.find(t=>t.toLowerCase().startsWith(this.value.toLowerCase()));this.currentFastEnterHint=e||""},onKeyUp(e){if(e.keyCode===window.KEY_CODE_TAB||e.keyCode===window.KEY_CODE_ARROW_RIGHT){if(!this.inputIsFocused||!this.currentFastEnterHint.length)return;this.value=this.currentFastEnterHint,this.$nextTick(()=>this.$refs.input.setSelectionRange(this.value.length,this.value.length))}e.keyCode===window.KEY_CODE_ENTER&&this.$refs.input.blur()},focusInput(){this.$refs.input.focus()}},watch:{"data.value"(){this.value=this.data.value}}},T=_(C,[["render",w]]);export{T as I};
