import{r as i,d as o,h as l}from"./p-9b6cc562.js";import{j as d,l as v}from"./p-95e9f2f6.js";import{s as t}from"./p-889c70e7.js";import"./p-86bd3473.js";import"./p-65879f9e.js";import"./p-e5527167.js";import"./p-60cf0cc2.js";const n=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,n,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===(n=null==t?void 0:t.job)||void 0===n?void 0:n.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==t?void 0:t.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;this.scopeToServiceMap={...this.scopeToServiceMap}}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={},t){var n,s,e,r,u,c,h;let a=t;try{a=(null===(s=null===(n=this.scopeToServiceMap)||void 0===n?void 0:n[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===(h=null===(c=this.service)||void 0===c?void 0:c.autofill)||void 0===h?void 0:h[o],l||{}))||t}catch(i){console.log(`Error applying json logic to ${o}: `,this.service.id,i)}return a}render(){var i,o,d,v,n,s,e,r,u,c,h,a,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===(n=this.service)||void 0===n?void 0:n.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===(a=null===(h=this.service)||void 0===h?void 0:h.prices)||void 0===a?void 0:a.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=t.job)||void 0===f?void 0:f.sites)||[]).map((i=>{var o,d,v,t,n,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===(t=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===t?void 0:t.id)||null,amount:this.getAutoFillValue(`${null==i?void 0:i.id}-${null===(n=this.service)||void 0===n?void 0:n.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})}))))]}};n.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{n as popover_site_service}