import{r as i,e as o,h as l}from"./p-a89095f5.js";import{j as d,l as v}from"./p-2a0c7fc9.js";import{s as n}from"./p-188ef7e9.js";import"./p-86bd3473.js";import"./p-65879f9e.js";import"./p-d7f93824.js";import"./p-60cf0cc2.js";const t=class{constructor(l){i(this,l),this.floodteamCloseModal=o(this,"floodteamCloseModal",7),this.service={},this.scopeToServiceMap={},this.jobId=void 0,this.job=void 0,this.currentExpanded=void 0}async onSuccess(i){var o,l,d,v,t,s,u,e,h;if("findJob"===(null===(o=null==i?void 0:i.detail)||void 0===o?void 0:o.endpoint)&&this.jobId===(null===(v=null===(d=null===(l=null==i?void 0:i.detail)||void 0===l?void 0:l.data)||void 0===d?void 0:d.job)||void 0===v?void 0:v.id)){for(const i of(null===(t=null==n?void 0:n.job)||void 0===t?void 0:t.services)||[])this.scopeToServiceMap[`${this.jobId}-${null===(s=null==i?void 0:i.service)||void 0===s?void 0:s.id}`]=i;for(const i of(null===(u=null==n?void 0:n.job)||void 0===u?void 0:u.sites)||[])for(const o of(null==i?void 0:i.services)||[])this.scopeToServiceMap[`${null==i?void 0:i.id}-${null===(e=null==o?void 0:o.service)||void 0===e?void 0:e.id}`]=o;this.scopeToServiceMap={...this.scopeToServiceMap}}else["editScopeService","addScopeService","deleteScopeService"].includes(null===(h=null==i?void 0:i.detail)||void 0===h?void 0:h.endpoint)&&this.accordionEl.requestAccordionToggle(null,!1)}getAutoFillValue(i,o,l={},n){var t,s,u,e,h,r,c;let a=n;try{a=(null===(s=null===(t=this.scopeToServiceMap)||void 0===t?void 0:t[i])||void 0===s?void 0:s[o])||(null===(e=null===(u=this.service)||void 0===u?void 0:u.autofill)||void 0===e?void 0:e[o])&&(null===(h=null==d?void 0:v.apply)||void 0===h?void 0:h.call(d,null===(c=null===(r=this.service)||void 0===r?void 0:r.autofill)||void 0===c?void 0:c[o],l||{}))||n}catch(i){console.log(`Error applying json logic to ${o}: `,this.service.id,i)}return a}render(){var i,o,d,v,t,s,u,e,h,r,c,a,p,$,f,m,j,S;const b="general"===(null===(d=null===(o=null===(i=this.service)||void 0===i?void 0:i.tab)||void 0===o?void 0:o.toLowerCase)||void 0===d?void 0:d.call(o)),y={service:this.service,job:this.job};return[l("ion-header",null,l("ion-toolbar",{class:"ion-padding-start"},l("h4",null,(null===(v=this.service)||void 0===v?void 0:v.name)||"No Name Given"),l("ion-buttons",{slot:"end"},l("ion-button",{onClick:()=>this.floodteamCloseModal.emit()},l("ion-icon",{slot:"icon-only",name:"close-circle-outline"}))))),l("ion-content",null,l("ion-accordion-group",{ref:i=>this.accordionEl=i,value:this.currentExpanded},b?l("floodteam-form-site-service",{isGeneral:!0,serviceId:null===(t=this.service)||void 0===t?void 0:t.id,jobId:this.jobId,notes:(null===(e=null===(s=this.scopeToServiceMap)||void 0===s?void 0:s[`${this.jobId}-${null===(u=this.service)||void 0===u?void 0:u.id}`])||void 0===e?void 0:e.notes)||null,siteServiceId:(null===(c=null===(h=this.scopeToServiceMap)||void 0===h?void 0:h[`${this.jobId}-${null===(r=this.service)||void 0===r?void 0:r.id}`])||void 0===c?void 0:c.id)||null,amount:this.getAutoFillValue(`${this.jobId}-${null===(a=this.service)||void 0===a?void 0:a.id}`,"amount",y,0),price:this.getAutoFillValue(`${this.jobId}-${null===(p=this.service)||void 0===p?void 0:p.id}`,"price",y,null===(f=null===($=this.service)||void 0===$?void 0:$.prices)||void 0===f?void 0:f.default),quantity:this.getAutoFillValue(`${this.jobId}-${null===(m=this.service)||void 0===m?void 0:m.id}`,"quantity",y,1),unit:null===(j=this.service)||void 0===j?void 0:j.unit}):((null===(S=n.job)||void 0===S?void 0:S.sites)||[]).map((i=>{var o,d,v,n,t,s,u,e,h,r,c,a,p;return l("floodteam-form-site-service",{siteId:null==i?void 0:i.id,jobId:this.jobId,serviceId:null===(o=this.service)||void 0===o?void 0:o.id,site:i,notes:(null===(n=null===(d=this.scopeToServiceMap)||void 0===d?void 0:d[`${null==i?void 0:i.id}-${null===(v=this.service)||void 0===v?void 0:v.id}`])||void 0===n?void 0:n.notes)||null,siteServiceId:(null===(u=null===(t=this.scopeToServiceMap)||void 0===t?void 0:t[`${null==i?void 0:i.id}-${null===(s=this.service)||void 0===s?void 0:s.id}`])||void 0===u?void 0:u.id)||null,amount:this.getAutoFillValue(`${null==i?void 0:i.id}-${null===(e=this.service)||void 0===e?void 0:e.id}`,"amount",{...y,site:i},0),price:this.getAutoFillValue(`${null==i?void 0:i.id}-${null===(h=this.service)||void 0===h?void 0:h.id}`,"price",{...y,site:i},null===(c=null===(r=this.service)||void 0===r?void 0:r.prices)||void 0===c?void 0:c.default),quantity:this.getAutoFillValue(`${null==i?void 0:i.id}-${null===(a=this.service)||void 0===a?void 0:a.id}`,"quantity",{...y,site:i},1),name:null==i?void 0:i.name,unit:null===(p=this.service)||void 0===p?void 0:p.unit})}))))]}};export{t as modal_scope_service}