import{r as i,e as t,h as s}from"./p-a89095f5.js";import{t as o}from"./p-3e7f0e42.js";import{s as e}from"./p-188ef7e9.js";import"./p-29ec504c.js";import"./p-8cd54418.js";import"./p-d7f93824.js";import"./p-2a0c7fc9.js";import"./p-86bd3473.js";import"./p-65879f9e.js";import"./p-60cf0cc2.js";const a=class{constructor(s){i(this,s),this.fireenjinFetch=t(this,"fireenjinFetch",7),this.fireenjinSubmit=t(this,"fireenjinSubmit",7),this.forceResize=t(this,"forceResize",7),this.templateId=void 0,this.jobId=void 0,this.userId=void 0,this.loading=!1,this.signed=!1,this.template=void 0}async onChange(i){var t,s;if("signature"===(null===(t=null==i?void 0:i.target)||void 0===t?void 0:t.name)){if((await i.target.toDataURL()).length<=10)return void alert("Signature is required to submit!");this.loading=!0,this.fireenjinSubmit.emit({endpoint:"signContract",data:{jobId:this.jobId,signatures:[{data:await i.target.toDataURL(),userId:this.userId||(null===(s=null==e?void 0:e.session)||void 0===s?void 0:s.uid)}],templateId:this.templateId}})}}async onSuccess(i){var t,s,o,e;"signContract"===(null===(t=null==i?void 0:i.detail)||void 0===t?void 0:t.endpoint)?(this.presentToast(),this.loading=!1,this.signed=!0):"findTemplate"===(null===(s=i.detail)||void 0===s?void 0:s.endpoint)&&(this.template=(null===(e=null===(o=i.detail)||void 0===o?void 0:o.data)||void 0===e?void 0:e.template)?i.detail.data.template:null)}async fetchJob(){this.jobId&&this.fireenjinFetch.emit({endpoint:"findJob",params:{id:this.jobId,withPayments:!1,withUsers:!0,withSites:!1,withPayModel:!1,withPhotos:!1,withEfiles:!1,withPayables:!1,withReadings:!1}})}async presentToast(){(await o.create({message:"File(s) added successfully to Efile!",duration:2e3})).present()}componentDidLoad(){this.fetchJob(),setTimeout((()=>{this.forceResize.emit({})}),1e3)}render(){var i;return[s("ion-content",{class:"ion-padding"},s("floodteam-title-bar",{back:(null===(i=null==e?void 0:e.session)||void 0===i?void 0:i.uid)?`/jobs/${this.jobId}`:"/"},"E-Sign"),this.signed?s("div",{style:{width:"90%",maxWidth:"500px",margin:"0 auto"}},s("ion-icon",{name:"checkmark-circle",color:"success",style:{height:"150px",width:"150px",display:"block",margin:"30px auto"}}),s("h1",null,"Signature Submitted!"),s("p",null,"Thank you for your time, you can now close this browser tab.")):s("div",{class:{"is-loading":this.loading}},s("floodteam-template",{style:{padding:"60px 2em"},templateId:this.templateId,disableFrame:!0,disablePosition:!0,data:{timestamp:(new Date).toISOString(),job:e.job,user:null==e?void 0:e.profile}}),s("floodteam-signature-pad",{ref:i=>this.signaturePadEl=i}))),s("floodteam-navigation-footer",null)]}};a.style="";export{a as app_sign}