import{m as s}from"./alpinejs-BkKOMYu4-v4.7.9.js";import{a as i}from"./axios-ngrFHoWO-v4.7.9.js";class n{constructor(){this.errors={}}record(t){this.errors=t}any(){return Object.keys(this.errors).length>0}has(t){return this.errors.hasOwnProperty(t)}get(t){if(this.errors[t])return this.errors[t][0]}clear(t){t!==void 0&&delete this.errors[this.normalizeKey(t)]}reset(){this.errors={}}normalizeKey(t){let e=t.replace("[]","").split("[");return e.length===1?t:e.join(".").slice(0,-1)}}window.axios=i;const a=document.querySelector('meta[name="csrf-token"]').content;i.defaults.headers.common["X-CSRF-TOKEN"]=a;i.defaults.headers.common["X-Requested-With"]="XMLHttpRequest";window.Alpine=s;s.data("App",({requirementSatisfied:o,permissionProvided:t})=>({step:1,formSubmitting:!1,animateAlert:!1,appInstalled:!1,errorMessage:null,form:{db_host:"127.0.0.1",db_port:3306,store_search_engine:"mysql"},errors:new n,get isShowPrev(){return this.step===2||this.step===3},get isPrevDisabled(){return this.formSubmitting},get isNextDisabled(){if(this.step===1)return!o||this.formSubmitting;if(this.step===2)return!t||this.formSubmitting;if(this.step===3)return this.formSubmitting},get hasErrorMessage(){return this.errorMessage!==null},prevStep(){this.isPrevDisabled||this.step>1&&this.step--},nextStep(){if(!this.isNextDisabled){if(this.step===3){this.submitForm();return}this.step++,this.focusInitialFormField()}},setErrorMessage(e){this.errorMessage=e,this.triggerAlertAnimation()},resetErrorMessage(){this.errorMessage=null},triggerAlertAnimation(){this.animateAlert=!0,setTimeout(()=>{this.animateAlert=!1},1e3)},focusInitialFormField(){this.step===3&&this.$nextTick(()=>{this.$refs.configurationForm.elements[0].focus()})},focusSearchEngineInputField(e){e!=="mysql"&&this.$nextTick(()=>{const r=this.$refs.configurationForm.elements;r[r.length-2].focus()})},focusFirstErrorField(e){[...this.$refs.configurationForm.elements].some(r=>{if(r.name===Object.keys(e)[0])return r.focus(),!0})},scrollToTop(){this.$refs.configurationContent.scroll({top:0,behavior:"auto"})},resetForm(){this.form={db_host:"127.0.0.1",db_port:3306,store_search_engine:"mysql"}},submitForm(){this.formSubmitting=!0,axios.post("/install",this.form).then(()=>{this.appInstalled=!0,this.resetForm(),this.resetErrorMessage(),this.errors.reset()}).catch(({response:e})=>{if(e.status===422){const r=e.data.errors;this.resetErrorMessage(),this.focusFirstErrorField(r),this.errors.record(r);return}this.scrollToTop(),this.setErrorMessage(e.data.message)}).finally(()=>{this.formSubmitting=!1})}}));s.start();
