import{h as t,r as s,H as e,e as i}from"./p-ee1e0eb4.js";import{t as a}from"./p-ff7a8a71.js";import{F as o,f as l}from"./p-39a31e43.js";import"./p-871106e0.js";import"./p-add30d46.js";import"./p-d68092b7.js";import"./p-b06e2bef.js";import"./p-2f569553.js";import"./p-bd90903e.js";import"./p-7dae0f0e.js";import"./p-5d409601.js";const r=()=>t("div",{class:"spinner-border",role:"status"}),n=class{constructor(t){s(this,t),this.formControls={noteText:{isValid:!0,value:"",errorMessage:"",validate:t=>(console.log(t),t&&t.length>0?{valid:!0,errorMessage:""}:{valid:!1,errorMessage:"Notes is required"})}},this.submitted=!1}componentDidLoad(){this.initialValues&&this.changeFormValue("noteText",this.initialValues.NoteText)}async onSubmit(t){t.preventDefault(),this.submitted=!0;let s=!0;for(let t in this.formControls){let e=this.formControls[t];e.isValid=e.validate(e.value).valid,e.errorMessage=e.validate(e.value).errorMessage,e.isValid||(s=!1)}if(s)if(this.initialValues&&this.initialValues.Id>0){let t=await o.getInstance().updateFacilitatorNote({NoteText:this.formControls.noteText.value,Id:this.initialValues.Id});t.Succeeded?((await a.create({message:"Notes updated successfully",duration:3e3})).present(),this.dismiss()):(await a.create({message:t.Message,duration:3e3})).present()}else{let t=await o.getInstance().addFacilitatorNote({NoteText:this.formControls.noteText.value});t.Succeeded?((await a.create({message:"Notes added successfully",duration:3e3})).present(),this.dismiss()):(await a.create({message:t.Message,duration:3e3})).present()}}dismiss(t){this.el.closest("ion-modal").dismiss({dismissed:!0})}changeFormValue(t,s){this.formControls=Object.assign(Object.assign({},this.formControls),{[t]:Object.assign(Object.assign({},this.formControls[t]),{value:s,isValid:this.formControls[t].validate(s).valid,errorMessage:this.formControls[t].validate(s).errorMessage})})}render(){const s=this.formControls.noteText.isValid?"is-valid":"is-invalid";return t(e,null,t("ion-header",{translucent:!0},t("ion-toolbar",null,t("ion-title",null,"Facilitator Note"),t("ion-buttons",{slot:"end"},t("ion-button",{onClick:()=>this.dismiss()},"Close")))),t("ion-content",{class:"ion-padding"},t("form",{onSubmit:t=>this.onSubmit(t),novalidate:!0},t("div",{class:"mb-3"},t("label",{htmlFor:"validationTextarea",class:"form-label"},"Notes"),t("textarea",{class:`form-control ${this.submitted&&s}`,placeholder:"Notes",value:this.formControls.noteText.value,onChange:t=>this.changeFormValue("noteText",t.target.value)}),this.formControls.noteText.errorMessage&&t("div",{class:"invalid-feedback"},this.formControls.noteText.errorMessage)),t("div",{class:"mb-3"},l.state.notesLoading&&t(r,null),t("button",{class:"btn btn-primary",type:"submit",disabled:l.state.notesLoading},"Submit")))))}get el(){return i(this)}};n.style=":host{display:block}";export{n as sparkle_facilitator_notes_form}