import{r as i,d as o,h as l}from"./p-f8363b1b.js";import{j as d,l as v}from"./p-c2fbed0d.js";import{s as n}from"./p-c78d1e1b.js";import"./p-80de33dc.js";import"./p-3775d1fc.js";import"./p-5717491f.js";import"./p-de14d315.js";const t=class{constructor(l){i(this,l),this.fireenjinFetch=o(this,"fireenjinFetch",7),this.service={},this.scopeToServiceMap={}}async onSuccess(i){var o,l,d,v,t,s,e,r,u;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===(r=null==o?void 0:o.service)||void 0===r?void 0:r.id}`]=o}else["editScopeService","addScopeService","deleteScopeService"].includes(null===(u=null==i?void 0:i.detail)||void 0===u?void 0:u.endpoint)&&this.accordionEl.requestAccordionToggle(null,!1)}getAutoFillValue(i,o,l={},n){var t,s,e,r,u,c,a;let h=n;try{h=(null===(s=null===(t=this.scopeToServiceMap)||void 0===t?void 0:t[i])||void 0===s?void 0:s[o])||(null===(r=null===(e=this.service)||void 0===e?void 0:e.autofill)||void 0===r?void 0:r[o])&&(null===(u=null==d?void 0:v.apply)||void 0===u?void 0:u.call(d,null===(a=null===(c=this.service)||void 0===c?void 0:c.autofill)||void 0===a?void 0:a[o],l||{}))||n}catch(i){console.log(`Error applying json logic to ${o}: `,this.service.id,i)}return h}render(){var i,o,d,v,t,s,e,r,u,c,a,h,p,m,f;const $="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)),b={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},$?l("floodteam-form-site-service",{isGeneral:!0,serviceId:null===(t=this.service)||void 0===t?void 0:t.id,jobId:this.jobId,siteServiceId:(null===(r=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===r?void 0:r.id)||null,amount:this.getAutoFillValue(`${this.jobId}-${null===(u=this.service)||void 0===u?void 0:u.id}`,"amount",b,0),price:this.getAutoFillValue(`${this.jobId}-${null===(c=this.service)||void 0===c?void 0:c.id}`,"price",b,null===(h=null===(a=this.service)||void 0===a?void 0:a.prices)||void 0===h?void 0:h.default),quantity:this.getAutoFillValue(`${this.jobId}-${null===(p=this.service)||void 0===p?void 0:p.id}`,"quantity",b,1),unit:null===(m=this.service)||void 0===m?void 0:m.unit}):((null===(f=n.job)||void 0===f?void 0:f.sites)||[]).map((i=>{var o,d,v,n,t,s,e,r,u,c;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,siteServiceId:(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.id)||null,amount:this.getAutoFillValue(`${null==i?void 0:i.id}-${null===(t=this.service)||void 0===t?void 0:t.id}`,"amount",{...b,site:i},0),price:this.getAutoFillValue(`${null==i?void 0:i.id}-${null===(s=this.service)||void 0===s?void 0:s.id}`,"price",{...b,site:i},null===(r=null===(e=this.service)||void 0===e?void 0:e.prices)||void 0===r?void 0:r.default),quantity:this.getAutoFillValue(`${null==i?void 0:i.id}-${null===(u=this.service)||void 0===u?void 0:u.id}`,"quantity",{...b,site:i},1),name:null==i?void 0:i.name,unit:null===(c=this.service)||void 0===c?void 0:c.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}