import{r as t,i as s,h as e,H as i,e as n}from"./p-ee1e0eb4.js";import{A as r}from"./p-4fba3e4c.js";import{T as o}from"./p-7dae0f0e.js";import"./p-b06e2bef.js";import"./p-2f569553.js";import"./p-ff7a8a71.js";import"./p-871106e0.js";import"./p-add30d46.js";import"./p-d68092b7.js";import"./p-bd90903e.js";import"./p-5d409601.js";const a=class{constructor(e){t(this,e),this.formSubmitted=s(this,"formSubmitted",7),this.submitted=!0,this.assignmentLoading=!1,this.onSubmit=async t=>{t.preventDefault();const s=t.currentTarget.querySelectorAll("sparkle-input,sparkle-file-upload"),e=Array.from(s).reduce(((t,s)=>{const{name:e,type:i,value:n}=s;let r=!1;return s.querySelector("ion-item")&&(r=s.querySelector("ion-item").classList.contains("item-checkbox-checked")),e&&(t[e]="checkbox"===i?r:n),t}),{});Array.from(s).filter((t=>t.required)).every((t=>""!==t.value))?this.formSubmitted.emit(e):alert("Please fill in all required fields"),this.assignmentLoading=!0,this.errorMessage="",this.successMessage="";var i={AssignmentData:JSON.stringify(e),AssignmentName:this.name};console.log(i);try{(await r.getInstance().createAssignment(i)).Succeeded?(this.assignmentLoading=!1,this.successMessage="Assignment submitted Successfully.",this.resetForm()):(this.assignmentLoading=!1,this.errorMessage="There is an error while posting to feed.")}catch(t){this.assignmentLoading=!1}}}fileUploaded(t){console.log("fileUploaded",t)}resetForm(){const t=this.el.querySelector("form");t&&t.reset()}renderUserInfo(){let t=o.getInstance().getAuthUserSync();return t&&t.JWToken?e("ion-avatar",{class:"header-avatar",slot:"end"},e("img",t.PhotoUrl?{src:t.PhotoUrl}:{src:"/assets/img/user.png"})):e("ion-button",{slot:"end",href:"/login"},"Login to Post")}isAuthenticated(){return o.getInstance().isAuthenticated()}render(){const t=this.renderUserInfo();return e(i,null,e("ion-card",null,e("ion-item",{class:"header ion-justify-content-between",lines:"full"},e("ion-label",null,this.name),t),e("ion-card-content",null,e("form",{onSubmit:this.onSubmit},e("slot",null),e("div",{class:"assignment-footer-container"},e("div",{class:"assignment-footer"},e("div",null,e("div",{class:"error"},this.errorMessage),e("div",{class:"success"},this.successMessage)),e("div",null,this.assignmentLoading?e("ion-spinner",{color:"primary"}):""),e("ion-button",{type:"submit",slot:"end",size:"default",disabled:this.assignmentLoading||!this.isAuthenticated()},"Submit")))))))}get el(){return n(this)}};a.style=":host{display:block}.assignment-footer-container{display:flex;justify-content:flex-end}.assignment-footer{display:flex;justify-content:space-between;align-items:center}.error{color:red;margin-right:10px}.success{color:green;margin-right:10px}.uploaded-image{display:block;max-height:140px;width:auto !important}";export{a as sparkle_assignment}