import{r as s,h as t,H as i,e}from"./p-ee1e0eb4.js";import{A as o}from"./p-4fba3e4c.js";import{F as n}from"./p-b8d71ff4.js";import{M as a}from"./p-1adc98f6.js";import{T as l}from"./p-7dae0f0e.js";import{S as r}from"./p-8b56f734.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 p=class{constructor(t){s(this,t)}componentDidLoad(){this.postText=this.textValue,this.ref&&this.ref.innerText&&(this.assignmentName=this.ref.innerText,console.log(this.assignmentName))}setText(s){this.postText=s}isAuthenticated(){return l.getInstance().isAuthenticated()}async submitPost(){this.postLoading=!0,this.errorMessage="",this.successMessage="";var s=this.el.getElementsByClassName("PostExternalUrl")[0],t=this.el.getElementsByClassName("IsPublic")[0],i={PostText:this.postText,IsPublic:t.checked,ExternalResourceUrl:s.value,MiniAppId:r.MY_GOALS_APP_ID,AssignmentName:this.assignmentName,AssignmentData:"",PostTextJSON:null};if((await n.getInstance().createPost(i)).Succeeded?(this.postLoading=!1,this.successMessage="Posted Successfully.",this.postText="",this.externalResourceUrl="",this.uploadedImage=""):(this.postLoading=!1,this.errorMessage="There is an error while posting to feed."),this.assignmentName){var e={AssignmentData:JSON.stringify({text:i.PostText,url:i.ExternalResourceUrl}),AssignmentName:this.assignmentName};await o.getInstance().createAssignment(e)}}async uploadImage(s){this.uploadImageLoading=!0;var t=s.target.files;let i=await a.getInstance().uploadImage(t);i.Succeeded?(console.log(i),this.uploadImageLoading=!1,this.uploadedImage=i.Data.length>0?i.Data[0].FullImageUrl:"",this.externalResourceUrl=i.Data.length>0?i.Data[0].FullImageUrl:""):(this.uploadImageLoading=!1,this.errorMessage="There is an error while uploading an image.")}selectFile(){this.el.querySelector("#fileInput").click()}renderUserInfo(){let s=l.getInstance().getAuthUserSync();return s&&s.JWToken?t("ion-avatar",{class:"header-avatar",slot:"end"},t("img",s.PhotoUrl?{src:s.PhotoUrl}:{src:"/assets/img/user.png"})):t("ion-button",{slot:"end",href:"/login"},"Login to Post")}render(){const s=this.renderUserInfo();return t(i,null,t("div",{class:"assignment-name",ref:s=>this.ref=s},t("slot",null)),t("ion-card",null,t("ion-item",{class:"header",lines:"full"},s),t("ion-card-content",null,t("form",null,t("ion-list",null,t("ion-item",{class:"padding"},t("ion-textarea",{class:"PostText",required:!0,placeholder:"Post Text",name:"PostText",value:this.postText})),t("ion-item",{class:"padding"},t("ion-input",{class:"PostExternalUrl",required:!0,type:"text",placeholder:"URL",name:"ExternalResourceUrl",value:this.externalResourceUrl})),this.uploadedImage?t("ion-item",{class:"ion-padding",lines:"none"},t("img",{class:"uploaded-image",src:this.uploadedImage})):"",t("ion-item",{lines:"none"},t("input",{type:"file",id:"fileInput",onChange:s=>this.uploadImage(s),style:{display:"none"},accept:"image/*"}),this.uploadImageLoading?t("ion-spinner",{color:"primary"}):"",t("ion-button",{slot:"start",onClick:()=>this.selectFile()},t("ion-icon",{name:"add"}),"Upload Image")),t("div",{class:"public-post-toggle"},t("ion-toggle",{class:"IsPublic",color:"primary",name:"IsPublic"}),t("div",null,"Public Post")),t("div",{class:"post-footer-container"},t("div",{class:"post-footer"},t("div",null,t("div",{class:"error"},this.errorMessage),t("div",{class:"success"},this.successMessage)),t("div",null,this.postLoading?t("ion-spinner",{color:"primary"}):""),t("ion-button",{slot:"end",size:"default",onClick:()=>this.submitPost(),disabled:this.postLoading||!this.isAuthenticated()},"Post"))))))))}get el(){return e(this)}};p.style=":host{display:block}.post-footer-container{display:flex;justify-content:flex-end}.post-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}.public-post-toggle{display:flex;justify-content:flex-end;align-items:center}.assignment-name{display:none}";export{p as sparkle_feed_post}