import{r as i,d as o,B as t,h as n}from"./p-03169580.js";import{s as e}from"./p-ac5f2e11.js";import"./p-59c95c5f.js";import"./p-c9699503.js";import"./p-bd8b186e.js";import"./p-795b799a.js";import"./p-3a8e6af1.js";function l(i){const o={amountDeducted:(i===null||i===void 0?void 0:i.amountDeducted)||0,amountOwed:(i===null||i===void 0?void 0:i.amountOwed)||0,amountPaid:(i===null||i===void 0?void 0:i.amountPaid)||0,general:0,levels:{},sites:{}};for(const t of(i===null||i===void 0?void 0:i.services)||[]){o.general=o.general+((t===null||t===void 0?void 0:t.total)||0)}for(const t of(i===null||i===void 0?void 0:i.sites)||[]){if(!o.sites[t===null||t===void 0?void 0:t.id])o.sites[t.id]=0;if(!o.levels[(t===null||t===void 0?void 0:t.level)||0])o.levels[(t===null||t===void 0?void 0:t.level)||0]=0;for(const i of(t===null||t===void 0?void 0:t.services)||[]){o.sites[t.id]=o.sites[t.id]+((i===null||i===void 0?void 0:i.total)||0);o.levels[(t===null||t===void 0?void 0:t.level)||0]=o.levels[(t===null||t===void 0?void 0:t.level)||0]+((i===null||i===void 0?void 0:i.total)||0)}}return o}const d="app-scope ion-infinite-scroll-content{display:none}";let s=class{constructor(t){i(this,t);this.fireenjinTrigger=o(this,"fireenjinTrigger",7);this.fireenjinSubmit=o(this,"fireenjinSubmit",7);this.fireenjinFetch=o(this,"fireenjinFetch",7);this.floodteamOpenModal=o(this,"floodteamOpenModal",7);this.floodteamOpenPopover=o(this,"floodteamOpenPopover",7);this.invoiceType="Water Remediation";this.attachments=[]}async fetchJob(){if(!this.jobId)return;this.fireenjinFetch.emit({endpoint:"findJob",params:{id:this.jobId,withPayments:false,withUsers:true,withSites:true,withPayModel:true,withPhotos:true,withEfiles:true,withPayables:false,withReadings:true}})}async openSendEfileModal(i){var o;i.preventDefault();i.stopPropagation();this.floodteamOpenModal.emit({component:"modal-send-email",cssClass:"modal-send-email",componentProps:{templateFilter:i=>{var o,t;return!(i===null||i===void 0?void 0:i.partial)&&((t=(o=i===null||i===void 0?void 0:i.tags)===null||o===void 0?void 0:o.includes)===null||t===void 0?void 0:t.call(o,"job"))},attachments:this.attachments,users:((o=this.job)===null||o===void 0?void 0:o.users)||[]}})}async sendEmail(i,o){var t;i.preventDefault();i.stopPropagation();if(!((t=e===null||e===void 0?void 0:e.session)===null||t===void 0?void 0:t.uid))return;this.fireenjinSubmit.emit({endpoint:"sendTemplateEmail",data:{templateId:"0xtJNtGRrT3GIosbN7iP",userIds:[o],data:{app:{url:window.location.origin},job:this.job}}})}async generatePdf(i,o=null){this.fireenjinSubmit.emit({endpoint:"generatePdf",data:{filename:o,jobId:this.jobId,templateId:i}})}async send(i){this.generatePdf("tA7FCnTudK0Sd887IeuU","Invoice PDF");this.openSendEfileModal(i)}onSuccess(i){var o,t,n;if(((o=i===null||i===void 0?void 0:i.detail)===null||o===void 0?void 0:o.endpoint)==="findJob"){this.job=(n=(t=i===null||i===void 0?void 0:i.detail)===null||t===void 0?void 0:t.data)===null||n===void 0?void 0:n.job}}onChange(i){var o,t;if(((o=i===null||i===void 0?void 0:i.target)===null||o===void 0?void 0:o.name)==="type"){this.invoiceType=((t=i===null||i===void 0?void 0:i.target)===null||t===void 0?void 0:t.value)||"Water Remediation"}}async componentDidLoad(){if(!(t===null||t===void 0?void 0:t.isBrowser))return;this.fireenjinTrigger.emit({name:"subscribe",payload:{collection:"jobs",id:this.jobId,callback:()=>{this.fetchJob()}}});this.fetchJob()}disconnectedCallback(){this.fireenjinTrigger.emit({name:"unsubscribe",payload:{collection:"jobs",id:this.jobId}})}render(){return[n("ion-content",{class:"ion-padding"},n("floodteam-title-bar",{back:`/jobs/${this.jobId}`},n("ion-text",{onClick:i=>this.floodteamOpenPopover.emit({event:i,component:"popover-invoice-select",componentProps:{value:this.invoiceType}}),style:{display:"flex",alignItems:"end",cursor:"pointer"}},this.invoiceType,n("ion-icon",{name:"chevron-down"})),n("ion-buttons",{slot:"end"},n("ion-button",{fill:"clear",onClick:i=>this.send(i)},"Send"),n("ion-button",{fill:"outline",onClick:()=>this.floodteamOpenModal.emit({component:"modal-render-template",componentProps:{templateId:"tA7FCnTudK0Sd887IeuU",headerTitle:"Invoice",data:{job:this.job,totals:l(this.job)}}})},"Preview"))),n("floodteam-form-scope",{job:this.job,jobId:this.jobId})),n("floodteam-navigation-footer",null)]}};s.style=d;export{s as app_scope};
//# sourceMappingURL=p-f611f0b7.entry.js.map