import{r as o,d as i,B as l,h as e}from"./p-03169580.js";import{t,p as s}from"./p-c5cf028c.js";import{s as n}from"./p-81b30421.js";import"./p-4cb16df5.js";import"./p-7cbdb4ea.js";import"./p-59c95c5f.js";import"./p-c9699503.js";import"./p-bd8b186e.js";import"./p-795b799a.js";import"./p-3a8e6af1.js";const a="modal-search-users .banner{background-color:var(--ion-color-secondary)}modal-search-users h1{color:#fff}modal-search-users p{margin:0 0 15px 0;color:rgba(255, 255, 255, 0.8);font-weight:normal}@media only screen and (max-width: 800px){.modal-search-users{--width:100%;--max-width:auto}}";let r=class{constructor(l){o(this,l);this.floodteamCloseModal=i(this,"floodteamCloseModal",7);this.fireenjinFetch=i(this,"fireenjinFetch",7);var e,t;this.steps=["search","team","recent"];this.heading="Search or Add User";this.payModels=[];this.team=[];this.loading=false;this.fetchData={locationId:(t=(e=n===null||n===void 0?void 0:n.profile)===null||e===void 0?void 0:e.location)===null||t===void 0?void 0:t.id};this.selectedIds=[]}onReset(o){var i;if(((i=o.detail)===null||i===void 0?void 0:i.endpoint)==="editJob"){const o=document.querySelector("ion-modal.modal-edit-job");if(o===null||o===void 0?void 0:o.dismiss){o.dismiss()}}}async onSuccess(o){var i,l,e,t;if(((i=o.detail)===null||i===void 0?void 0:i.endpoint)==="editJob"){const o=document.querySelector("ion-modal.modal-edit-job");if(o===null||o===void 0?void 0:o.dismiss){await o.dismiss();this.presentToast()}}else if(((l=o.detail)===null||l===void 0?void 0:l.endpoint)==="listUsers"){this.team=((t=(e=o.detail)===null||e===void 0?void 0:e.data)===null||t===void 0?void 0:t.users)?o.detail.data.users:[]}}onTabClick(o){console.log(o)}async presentToast(){const o=await t.create({message:`Job has been edited successfully!`,duration:2e3});o.present()}toggleSelect(o,i){o.stopPropagation();o.preventDefault();this.selectedIds=this.selectedIds.includes(i.id)?this.selectedIds.filter((o=>i.id!==o)):[...new Set([...this.selectedIds,i.id])]}async openPopover(o,i){o.preventDefault();o.stopPropagation();const l=await s.create({component:"popover-user",cssClass:"popover-user-wrapper",componentProps:{user:i},event:o});return await l.present()}async save(){var o,i;if(!((o=this.selectedIds)===null||o===void 0?void 0:o.length))return;this.loading=true;for(const o of this.selectedIds){this.fireenjinFetch.emit({endpoint:"addUserToJob",params:{data:{userId:o,jobId:(i=n===null||n===void 0?void 0:n.job)===null||i===void 0?void 0:i.id}}})}this.loading=false;this.floodteamCloseModal.emit()}componentDidLoad(){var o,i;if(!(l===null||l===void 0?void 0:l.isBrowser))return;this.fireenjinFetch.emit({endpoint:"listUsers",params:{data:{locationId:(i=(o=n===null||n===void 0?void 0:n.profile)===null||o===void 0?void 0:o.location)===null||i===void 0?void 0:i.id,limit:15,type:"staff"}}})}render(){var o,i;return[e("ion-header",null,e("ion-toolbar",null,e("ion-title",null,this.heading),e("ion-buttons",{slot:"end"},e("ion-button",{onClick:()=>this.save(),color:"primary",fill:"solid"},"Save"),e("ion-button",{onClick:()=>this.floodteamCloseModal.emit()},e("ion-icon",{slot:"icon-only",name:"close-circle-outline"}))))),e("ion-content",{class:{"ion-padding":true,"is-loading":this.loading}},e("fireenjin-search-bar",{ref:o=>this.filterBarEl=o,paginationEl:this.paginationEl,filters:[{name:"tags",label:"Tags",icon:"pricetags",multiple:true,options:[{label:"Imported",value:"imported"},{label:"Referral",value:"referral"},{label:"Plumber",value:"plumber"},{label:"Staff",value:"staff"},{label:"Agent",value:"agent"},{label:"Property Manager",value:"property manager"},{label:"PEU",value:"peu"},{label:"CSV Import",value:"csvImport"}]},{name:"locationId",label:"Location",icon:"business",options:[...(n===null||n===void 0?void 0:n.locations)?n.locations.map((o=>({label:o.name,value:o.id}))):[],{label:"On Job",value:null}],value:(i=(o=n===null||n===void 0?void 0:n.profile)===null||o===void 0?void 0:o.location)===null||i===void 0?void 0:i.id}]}),e("fireenjin-pagination",{display:"list",ref:o=>this.paginationEl=o,disableVirtualScroll:true,listEl:({result:o})=>e("ion-item",null,e("ion-checkbox",{slot:"start",checked:this.selectedIds.includes(o.id),onClick:i=>this.toggleSelect(i,o)}),e("fireenjin-avatar",{src:o.photo,style:{marginRight:"15px"},initials:`${(o===null||o===void 0?void 0:o.firstName)?o.firstName.charAt(0):""}${(o===null||o===void 0?void 0:o.lastName)?o.lastName.charAt(0):""}`}),e("ion-label",null,e("h4",null,(o===null||o===void 0?void 0:o.firstName)||""," ",(o===null||o===void 0?void 0:o.lastName)||""),(o===null||o===void 0?void 0:o.tags)?o.tags.map((o=>e("ion-chip",null,o))):null),e("ion-button",{fill:"clear",slot:"end",color:"medium",onClick:i=>this.openPopover(i,o)},e("ion-icon",{name:"ellipsis-vertical",slot:"icon-only"}))),endpoint:"listUsers",fetchData:this.fetchData,limit:24,resultsKey:"users",removeDuplicates:true}))]}};r.style=a;export{r as modal_search_users};
//# sourceMappingURL=p-2cff9109.entry.js.map