import{r as i,d as o,h as d}from"./p-03169580.js";import{j as l,l as v}from"./p-c2fbed0d.js";import{s as t}from"./p-e1ee6da1.js";import"./p-80de33dc.js";import"./p-59c95c5f.js";import"./p-3775d1fc.js";import"./p-5717491f.js";import"./p-de14d315.js";const n=".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}";let e=class{constructor(d){i(this,d);this.fireenjinFetch=o(this,"fireenjinFetch",7);this.service={};this.scopeToServiceMap={}}async onSuccess(i){var o,d,l,v,n,e,s,r,u;if(((o=i===null||i===void 0?void 0:i.detail)===null||o===void 0?void 0:o.endpoint)==="findJob"&&this.jobId===((v=(l=(d=i===null||i===void 0?void 0:i.detail)===null||d===void 0?void 0:d.data)===null||l===void 0?void 0:l.job)===null||v===void 0?void 0:v.id)){for(const i of((n=t===null||t===void 0?void 0:t.job)===null||n===void 0?void 0:n.services)||[]){this.scopeToServiceMap[`${this.jobId}-${(e=i===null||i===void 0?void 0:i.service)===null||e===void 0?void 0:e.id}`]=i}for(const i of((s=t===null||t===void 0?void 0:t.job)===null||s===void 0?void 0:s.sites)||[]){for(const o of(i===null||i===void 0?void 0:i.services)||[]){this.scopeToServiceMap[`${i===null||i===void 0?void 0:i.id}-${(r=o===null||o===void 0?void 0:o.service)===null||r===void 0?void 0:r.id}`]=o}}}else if(["editScopeService","addScopeService","deleteScopeService"].includes((u=i===null||i===void 0?void 0:i.detail)===null||u===void 0?void 0:u.endpoint)){this.accordionEl.requestAccordionToggle(null,false)}}getAutoFillValue(i,o,d={},t){var n,e,s,r,u,c,a;let h=t;try{h=((e=(n=this.scopeToServiceMap)===null||n===void 0?void 0:n[i])===null||e===void 0?void 0:e[o])||((r=(s=this.service)===null||s===void 0?void 0:s.autofill)===null||r===void 0?void 0:r[o])&&((u=l===null||l===void 0?void 0:v.apply)===null||u===void 0?void 0:u.call(l,(a=(c=this.service)===null||c===void 0?void 0:c.autofill)===null||a===void 0?void 0:a[o],d||{}))||t}catch(i){console.log(`Error applying json logic to ${o}: `,this.service.id,i)}return h}render(){var i,o,l,v,n,e,s,r,u,c,a,h,p,m,f;const $=((l=(o=(i=this.service)===null||i===void 0?void 0:i.tab)===null||o===void 0?void 0:o.toLowerCase)===null||l===void 0?void 0:l.call(o))==="general";const b={service:this.service,job:this.job};return[d("ion-content",null,d("ion-item-divider",null,((v=this.service)===null||v===void 0?void 0:v.name)||"No Name Given"),d("ion-accordion-group",{ref:i=>this.accordionEl=i,value:this.currentExpanded},$?d("floodteam-form-site-service",{isGeneral:true,serviceId:(n=this.service)===null||n===void 0?void 0:n.id,jobId:this.jobId,siteServiceId:((r=(e=this.scopeToServiceMap)===null||e===void 0?void 0:e[`${this.jobId}-${(s=this.service)===null||s===void 0?void 0:s.id}`])===null||r===void 0?void 0:r.id)||null,amount:this.getAutoFillValue(`${this.jobId}-${(u=this.service)===null||u===void 0?void 0:u.id}`,"amount",b,0),price:this.getAutoFillValue(`${this.jobId}-${(c=this.service)===null||c===void 0?void 0:c.id}`,"price",b,(h=(a=this.service)===null||a===void 0?void 0:a.prices)===null||h===void 0?void 0:h.default),quantity:this.getAutoFillValue(`${this.jobId}-${(p=this.service)===null||p===void 0?void 0:p.id}`,"quantity",b,1),unit:(m=this.service)===null||m===void 0?void 0:m.unit}):(((f=t.job)===null||f===void 0?void 0:f.sites)||[]).map((i=>{var o,l,v,t,n,e,s,r,u,c;return d("floodteam-form-site-service",{siteId:i===null||i===void 0?void 0:i.id,jobId:this.jobId,serviceId:(o=this.service)===null||o===void 0?void 0:o.id,site:i,siteServiceId:((t=(l=this.scopeToServiceMap)===null||l===void 0?void 0:l[`${i===null||i===void 0?void 0:i.id}-${(v=this.service)===null||v===void 0?void 0:v.id}`])===null||t===void 0?void 0:t.id)||null,amount:this.getAutoFillValue(`${i===null||i===void 0?void 0:i.id}-${(n=this.service)===null||n===void 0?void 0:n.id}`,"amount",{...b,site:i},0),price:this.getAutoFillValue(`${i===null||i===void 0?void 0:i.id}-${(e=this.service)===null||e===void 0?void 0:e.id}`,"price",{...b,site:i},(r=(s=this.service)===null||s===void 0?void 0:s.prices)===null||r===void 0?void 0:r.default),quantity:this.getAutoFillValue(`${i===null||i===void 0?void 0:i.id}-${(u=this.service)===null||u===void 0?void 0:u.id}`,"quantity",{...b,site:i},1),name:i===null||i===void 0?void 0:i.name,unit:(c=this.service)===null||c===void 0?void 0:c.unit})}))))]}};e.style=n;export{e as popover_site_service};
//# sourceMappingURL=p-a7d96bca.entry.js.map