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-9e8ba117.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.fireenjinFetch=o(this,"fireenjinFetch",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,e,u,r;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===(e=null==n?void 0:n.job)||void 0===e?void 0:e.sites)||[])for(const o of(null==i?void 0:i.services)||[])this.scopeToServiceMap[`${null==i?void 0:i.id}-${null===(u=null==o?void 0:o.service)||void 0===u?void 0:u.id}`]=o;this.scopeToServiceMap={...this.scopeToServiceMap}}else["editScopeService","addScopeService","deleteScopeService"].includes(null===(r=null==i?void 0:i.detail)||void 0===r?void 0:r.endpoint)&&this.accordionEl.requestAccordionToggle(null,!1)}getAutoFillValue(i,o,l={},n){var t,s,e,u,r,c,h;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===(u=null===(e=this.service)||void 0===e?void 0:e.autofill)||void 0===u?void 0:u[o])&&(null===(r=null==d?void 0:v.apply)||void 0===r?void 0:r.call(d,null===(h=null===(c=this.service)||void 0===c?void 0:c.autofill)||void 0===h?void 0:h[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,e,u,r,c,h,a,p,m,f,$,b,g;const j="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)),k={service:this.service,job:this.job};return[l("ion-content",null,l("ion-item-divider",null,(null===(v=this.service)||void 0===v?void 0:v.name)||"No Name Given"),l("ion-accordion-group",{ref:i=>this.accordionEl=i,value:this.currentExpanded},j?l("floodteam-form-site-service",{isGeneral:!0,serviceId:null===(t=this.service)||void 0===t?void 0:t.id,jobId:this.jobId,notes:(null===(u=null===(s=this.scopeToServiceMap)||void 0===s?void 0:s[`${this.jobId}-${null===(e=this.service)||void 0===e?void 0:e.id}`])||void 0===u?void 0:u.notes)||null,siteServiceId:(null===(h=null===(r=this.scopeToServiceMap)||void 0===r?void 0:r[`${this.jobId}-${null===(c=this.service)||void 0===c?void 0:c.id}`])||void 0===h?void 0:h.id)||null,amount:this.getAutoFillValue(`${this.jobId}-${null===(a=this.service)||void 0===a?void 0:a.id}`,"amount",k,0),price:this.getAutoFillValue(`${this.jobId}-${null===(p=this.service)||void 0===p?void 0:p.id}`,"price",k,null===(f=null===(m=this.service)||void 0===m?void 0:m.prices)||void 0===f?void 0:f.default),quantity:this.getAutoFillValue(`${this.jobId}-${null===($=this.service)||void 0===$?void 0:$.id}`,"quantity",k,1),unit:null===(b=this.service)||void 0===b?void 0:b.unit}):((null===(g=n.job)||void 0===g?void 0:g.sites)||[]).map((i=>{var o,d,v,n,t,s,e,u,r,c,h,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===(e=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===e?void 0:e.id)||null,amount:this.getAutoFillValue(`${null==i?void 0:i.id}-${null===(u=this.service)||void 0===u?void 0:u.id}`,"amount",{...k,site:i},0),price:this.getAutoFillValue(`${null==i?void 0:i.id}-${null===(r=this.service)||void 0===r?void 0:r.id}`,"price",{...k,site:i},null===(h=null===(c=this.service)||void 0===c?void 0:c.prices)||void 0===h?void 0:h.default),quantity:this.getAutoFillValue(`${null==i?void 0:i.id}-${null===(a=this.service)||void 0===a?void 0:a.id}`,"quantity",{...k,site:i},1),name:null==i?void 0:i.name,unit:null===(p=this.service)||void 0===p?void 0:p.unit})}))))]}};t.style=".popover-site-service{--min-width:300px;--offset-y:-50px}popover-site-service ion-accordion-group{background:var(--background-color) !important;--ion-item-background:var(--background-color);--background:var(--background-color);background-color:var(--background-color) !important}popover-site-service ion-list ion-item{--ion-item-background:transparent}popover-site-service fireenjin-input ion-label{font-size:12px !important}";export{t as popover_site_service}