1import{a as Wt}from"./chunk-4JW5547L.js";import{a as co,f as mo}from"./chunk-MW4BCGBM.js";import{a as no}from"./chunk-MXV7C6QD.js";import{a as fe}from"./chunk-C472OY6Q.js";import{a as Ht}from"./chunk-UHDKYKMY.js";import{a as Kn}from"./chunk-WVDCR2J5.js";import{g as oo,j as ao}from"./chunk-FDEBVIKH.js";import{c as ro}from"./chunk-4ACG5RNN.js";import{a as io}from"./chunk-LPI52V34.js";import{a as Zn,b as eo,c as to,l as St,m as lo}from"./chunk-HWGFFUFH.js";import{b as Xn}from"./chunk-QV4OSBYG.js";import{a as Qn,b as Hn,c as $e,d as Wn,e as bt,f as vt,g as xt,h as Jn}from"./chunk-2H66A7VZ.js";import{a as yt}from"./chunk-QQAVOCLP.js";import{a as ut}from"./chunk-B7D2DWLU.js";import{a as Bn,b as zn,c as Gn,d as qn,e as jn}from"./chunk-MRZSOMOS.js";import{a as Ie}from"./chunk-WZYNORWH.js";import{a as so}from"./chunk-GGZV6UMG.js";import{b as Yn}from"./chunk-5UGC3NTR.js";import{a as Y}from"./chunk-34CAIZEC.js";import{a as $n}from"./chunk-O22NHKL2.js";import{a as Re}from"./chunk-TVP2JV4D.js";import{a as ae}from"./chunk-YXRY563P.js";import{a as mt}from"./chunk-EFXMSIQX.js";import{a as On}from"./chunk-U24WZWAH.js";import{w as An}from"./chunk-SXPXG3P7.js";import{d as Pn}from"./chunk-TQLM3XDO.js";import{a as _e}from"./chunk-J356NWY5.js";import{a as Ln}from"./chunk-63N2QQFO.js";import{a as pt,b as ht,c as gt,e as Un}from"./chunk-5PFBPAE5.js";import{a as Ct}from"./chunk-5QPJTQHP.js";import{a as gn}from"./chunk-G5WFK75M.js";import{a as Tt}from"./chunk-PLQKMNXX.js";import{a as bn,b as Ft,c as wt}from"./chunk-KC7WGNSJ.js";import{b as yi,d as Si}from"./chunk-7IAOFO6M.js";import{f as Kt,h as Sn,j as Fn,k as wn,v as Q}from"./chunk-KHUJSBOG.js";import{b as yn}from"./chunk-2C6LKFWM.js";import{c as Cn}from"./chunk-LZVL4JQH.js";import{a as H}from"./chunk-PJLIWTQI.js";import{b as fn,d as dt}from"./chunk-CU7QFI6V.js";import{a as Ue}from"./chunk-SPJNZU2P.js";import{a as _t,b as ft,c as Rn}from"./chunk-545DLHFS.js";import{b as q}from"./chunk-RND7IQSZ.js";import{a as hn,d as ct}from"./chunk-KKLQBNPD.js";import{B as xn,D as ne,E as ue,c as vn,d as B,f as K,g as de,h as Te,j as ve,k as Ae,l as ce,r as me,s as pe}from"./chunk-GHIFMYC2.js";import{C as Vn,F as Nn,d as Tn,h as In,i as Qt,s as Dn,t as En,w as kn,z as Mn}from"./chunk-VNJB24XO.js";import{a as G}from"./chunk-G3JXQVD2.js";import{a as oe}from"./chunk-55ZWMGAA.js";import{a as te,b as ie}from"./chunk-MVFLDTCZ.js";import{a as _n}from"./chunk-Y5ISLRKX.js";import{$a as Ki,$b as Ne,B as Ni,C as Li,Ca as et,Dd as pn,Ec as lt,Fc as on,Fd as un,Gc as an,Hb as ot,Ia as tt,K as Pi,Kb as Xi,La as De,Lb as Ve,Oc as Le,Pa as it,Pc as rn,Qa as Gi,Ra as qi,Rc as ln,Sb as Yi,T as Ai,Tb as at,Tc as X,U as Me,Uc as sn,Vb as rt,Vc as dn,Ya as ji,ab as Qi,bb as Hi,e as Fi,f as wi,ga as Ri,hd as Pe,i as Ti,ia as Ui,id as st,jb as nt,jc as Zi,k as Ii,ka as $i,l as Di,ma as Ze,oa as Oi,ob as Wi,oc as en,ra as Bi,sc as tn,t as Ei,td as cn,ud as we,v as ki,wb as jt,wc as Fe,x as Mi,xa as zi,xc as nn,y as Vi,zb as Ji,zd as mn}from"./chunk-Q4ADUVSE.js";import{a as R}from"./chunk-OJIK2GGX.js";import{n as xi,q as Ye,v as Se}from"./chunk-MSIUAZXA.js";import{$b as l,Ac as N,Cc as ge,Da as S,Dc as c,Eb as Z,Ec as A,Ed as vi,Fa as P,Fb as ii,Fc as x,Gb as ni,Gc as Xe,Ha as se,Hb as oi,Hc as ci,J as He,Jc as mi,Kc as pi,Lc as ui,Ob as ai,Pb as ri,Pc as _i,Qc as qt,Rb as he,Tc as j,Ub as C,Uc as be,Vb as h,Wb as We,Xb as li,Xc as fi,Yb as E,Yc as Ci,Zb as k,Zc as hi,_b as p,aa as Yt,ac as s,ad as xe,bc as g,cd as ye,eb as Bt,fd as gi,ga as Zt,hc as zt,ib as ti,ic as y,jb as r,la as F,ld as ee,mc as f,md as b,n as Qe,oc as d,od as ze,r as D,ra as u,sa as _,sd as M,t as ke,td as T,ud as bi,wc as si,xa as ei,xc as di,yc as Gt,zb as V,zc as Je}from"./chunk-NCV6CZXT.js";import{a as I,b as L}from"./chunk-QXIBXHVB.js";var It=class n{api=F(_n);uploadFile(t,e,i){let o=new FormData;return o.append("file",t),o.append("field_id",e.toString()),o.append("client_id",i.toString()),this.api.post("/v2/clientzone/uploadCustomFieldFile",o).pipe(ke(a=>({success:a.success,fileId:a.file_id,fileName:a.file_name,fileUrl:a.file_url,error:a.error})),He(a=>(console.error("File upload error:",a),Qe(()=>({success:!1,error:a.message||"Failed to upload file"})))))}deleteFile(t,e,i){return this.api.post("/v2/clientzone/deleteCustomFieldFile",{file_id:t,field_id:e,client_id:i}).pipe(ke(()=>{}),He(o=>(console.error("File delete error:",o),Qe(()=>o))))}linkFile(t,e,i){return this.api.post("/v2/clientzone/linkCustomFieldFile",{existing_file_id:t,field_id:e,client_id:i}).pipe(ke(o=>({success:o.success,fileId:o.file_id,fileName:o.file_name,fileUrl:o.file_url})),He(o=>(console.error("File link error:",o),Qe(()=>o))))}validateFile(t,e=150,i=["application/pdf","image/jpeg","image/jpg","image/png","image/gif","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.oasis.opendocument.text","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.presentation","application/rtf","text/rtf","application/zip","application/x-zip-compressed","application/xml","text/xml","application/json","text/plain","text/csv","image/webp","image/svg+xml","
1image/tiff"]){let o=e*1024*1024;if(t.size>o)return`File size exceeds ${e}MB limit`;if(!i.includes(t.type))return`File type "${t.type}" is not allowed`}static \u0275fac=function(e){return new(e||n)};static \u0275prov=Zt({token:n,factory:n.\u0275fac,providedIn:"root"})};var Fo=(n,t)=>t.id;function wo(n,t){if(n&1&&c(0),n&2){let e=d(2);x(" Drop file",e.multipleFiles()?"s":""," here ")}}function To(n,t){n&1&&c(0," Click to upload or drag and drop ")}function Io(n,t){if(n&1){let e=y();l(0,"button",5),f("click",function(){u(e);let o=d();return _(o.triggerUpload())}),g(1,"fa-icon",6),l(2,"div",7)(3,"p",8),C(4,wo,1,1)(5,To,1,0),s(),l(6,"p",9),c(7),s()()()}if(n&2){let e=d();r(),p("icon",e.faCloudArrowUp),r(3),h(e.isDragging()?4:5),r(3),x(" Max ",e.maxSizeMB(),"MB \u2022 PDF, DOC, XLS, PPT, ODT, RTF, ZIP, XML, JSON, TXT, CSV, images ")}}function Do(n,t){if(n&1&&(l(0,"div",2),g(1,"fa-icon",10),l(2,"div",11)(3,"div",12),c(4," Uploading... "),s(),l(5,"div",13),g(6,"div",14),s()()()),n&2){let e=d();r(),p("icon",e.faCloudArrowUp),r(5),Je("width",e.uploadProgress()+"%")}}function Eo(n,t){if(n&1){let e=y();l(0,"div",15)(1,"div",18),f("click",function(o){u(e);let a=d(2);return o.preventDefault(),o.stopPropagation(),_(a.allSelected()?a.clearSelection():a.selectAll())}),g(2,"bc-checkbox-input",19),s(),l(3,"span",20),c(4),s(),l(5,"button",21),f("click",function(){u(e);let o=d(2);return _(o.bulkAttach("email"))}),g(6,"fa-icon",22),c(7," Email "),s(),l(8,"button",23),f("click",function(){u(e);let o=d(2);return _(o.bulkAttach("note"))}),g(9,"fa-icon",22),c(10," Note "),s(),l(11,"button",24),f("click",function(){u(e);let o=d(2);return _(o.bulkDelete())}),g(12,"fa-icon",22),c(13," Delete "),s()()}if(n&2){let e=d(2);r(),p("title",_i(e.allSelected()?"Deselect all":"Select all")),r(),p("id","dropzone-select-all")("value",e.allSelected())("indeterminate",e.someSelected()),r(2),x(" ",e.selectedCount()," selected "),r(2),p("icon",e.faEnvelope),r(3),p("icon",e.faNoteSticky),r(3),p("icon",e.faTrash)}}function ko(n,t){if(n&1){let e=y();l(0,"div",16)(1,"input",25),f("change",function(o){let a=u(e).$implicit,m=d(2);return _(m.toggleSelect(o,a))}),s(),l(2,"bc-file-chip",26),f("action",function(o){let a=u(e).$implicit,m=d(2);return _(m.handleFileMenuAction(o,a))})("remove",function(){let o=u(e).$implicit,a=d(2);return _(a.deleteFile(o.id,o.name))}),s()()}if(n&2){let e=t.$implicit,i=d(2);r(),p("checked",i.isSelected(e.id)),he("aria-label","Select "+e.name),r(),p("file",i.chipFile(e))("files",i.chipFiles())("fill",!0)("selected",i.isSelected(e.id))("menuItems",i.fileMenuItems(e))("removable",!0)}}function Mo(n,t){}function Vo(n,t){if(n&1){let e=y();l(0,"button",27),f("click",function(){u(e);let o=d(2);return _(o.toggleExpanded())}),g(1,"fa-icon",28),c(2),s()}if(n&2){let e=d(2);r(),p("icon",e.expanded()?e.faChevronUp:e.faChevronDown),r(),x(" ",e.expanded()?"Show less":"+"+e.hiddenCount()+" more"," ")}}function No(n,t){if(n&1&&(l(0,"div",3),C(1,Eo,14,9,"div",15),E(2,ko,3,8,"div",16,Fo,!1,Mo,0,0),C(5,Vo,3,2,"button",17),s()),n&2){let e=d();r(),h(e.hasSelection()?1:-1),r(),k(e.visibleFiles()),r(3),h(e.hasOverflow()?5:-1)}}function Lo(n,t){if(n&1&&(l(0,"div",4),c(1),s()),n&2){let e=d();r(),x(" ",e.error()," ")}}var Jt=3;function po(n){return{id:n.id,file_name:n.file_name,file_url:n.file_url,file_size:n.size,file_type:n.contentType}}function uo(n){return{id:Number(n.id),file_name:n.name,file_url:n.url,size:n.size||void 0,contentType:n.type||void 0}}var Dt=class n{fieldId=T.required();clientId=T.required();multipleFiles=T(!1);maxSizeMB=T(150);initialFileIds=T("");fileUploaded=M();attachToComposer=M();fileUploadService=F(It);clientService=F(Q);toastService=F(G);composerBridge=F(ut);constructor(){P(()=>{let t=this.initialFileIds();if(!ee(()=>this.isUploading())){if(!t||t.trim()===""){this.files.set([]);return}this.clientService.getCustomFieldFiles(t).subscribe({next:e=>{this.files.set(e.map(i=>({id:String(i.id),name:i.file_name,url:i.file_url,size:i.size??0,type:i.contentType??""})))},error:()=>{}})}})}faCloudArrowUp=cn;faChevronDown=De;faChevronUp=ln;faTrash=X;faEnvelope=we;faNoteSticky=Le;isDragging=S(!1);isUploading=S(!1);uploadProgress=S(0);files=S([]);error=S(null);expanded=S(!1);selectedIds=S(new Set);hasSelection=b(()=>this.selectedIds().size>0);selectedCount=b(()=>this.selectedIds().size);allSelected=b(()=>this.files().length>0&&this.selectedIds().size===this.files().length);someSelected=b(()=>this.selectedIds().size>0&&!this.allSelected());isSelected(t){return this.selectedIds().has(t)}toggleSelect(t,e){t.preventDefault(),t.stopPropagation();let i=new Set(this.selectedIds());i.has(e.id)?i.delete(e.id):i.add(e.id),this.selectedIds.set(i)}clearSelection(){this.selectedIds.set(new Set)}selectAll(){this.selectedIds.set(new Set(this.files().map(t=>
1t.id)))}getSelectedFiles(){return this.files().filter(t=>this.selectedIds().has(t.id))}bulkAttach(t){let e=this.getSelectedFiles().filter(i=>i.url);e.length&&(this.composerBridge.request(e.map(uo),t),this.attachToComposer.emit(t),this.clearSelection())}bulkDelete(){let t=this.getSelectedFiles();if(t.length){for(let e of t)this.deleteFile(e.id,e.name);this.clearSelection()}}hasOverflow=b(()=>this.files().length>Jt);visibleFiles=b(()=>this.expanded()?this.files():this.files().slice(0,Jt));hiddenCount=b(()=>Math.max(0,this.files().length-Jt));toggleExpanded(){this.expanded.update(t=>!t)}dropzoneClasses=b(()=>{let t="custom-field-dropzone";return this.error()?`${t} custom-field-dropzone-error`:this.isUploading()?`${t} custom-field-dropzone-uploading`:this.isDragging()?`${t} custom-field-dropzone-dragover`:`${t} custom-field-dropzone-idle`});onDragOver(t){t.preventDefault(),t.stopPropagation(),t.dataTransfer&&(t.dataTransfer.dropEffect="copy"),this.isDragging.set(!0)}onDragLeave(t){t.preventDefault(),t.stopPropagation(),this.isDragging.set(!1)}onDrop(t){t.preventDefault(),t.stopPropagation(),this.isDragging.set(!1);let e=t.dataTransfer;if(!e)return;let i=this.readCrmFiles(e);if(i){this.linkFiles(i);return}e.files.length>0&&this.handleFiles(e.files)}readCrmFiles(t){try{let e=t.getData("fileItemsData");if(e)return JSON.parse(e).map(po);let i=t.getData("fileItemData");if(i)return[po(JSON.parse(i))];let o=t.getData("attachmentData");if(o)return[JSON.parse(o)]}catch{}return null}async linkFiles(t){if(this.isUploading())return;let e=new Set(this.files().map(o=>o.url)),i=t.filter(o=>!!o.id&&!e.has(o.file_url)).slice(0,this.multipleFiles()?void 0:1);if(i.length!==0){this.isUploading.set(!0);try{for(let o of i){let a=await D(this.fileUploadService.linkFile(o.id,this.fieldId(),this.clientId()));if(!a.success||!a.fileId)throw new Error("link failed");let m={id:a.fileId,name:a.fileName||o.file_name,url:a.fileUrl,size:o.file_size??0,type:o.file_type??""};this.multipleFiles()?this.files.update(v=>[...v,m]):this.files.set([m]),this.fileUploaded.emit(a)}this.toastService.add(i.length===1?`"${i[0].file_name}" linked successfully`:`${i.length} files linked successfully`,2e3,"success")}catch{this.toastService.add("Failed to link file",3e3,"error")}finally{this.isUploading.set(!1)}}}triggerUpload(){let t=document.createElement("input");t.type="file",t.multiple=this.multipleFiles(),t.accept=".pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.odt,.ods,.odp,.rtf,.zip,.xml,.json,.txt,.csv,.jpg,.jpeg,.png,.gif,.webp,.svg,.tif,.tiff",t.onchange=e=>{let i=e.target;i.files&&i.files.length>0&&this.handleFiles(i.files)},t.click()}handleFiles(t){let e=this.multipleFiles()?Array.from(t):[t[0]];for(let i of e){let o=this.fileUploadService.validateFile(i,this.maxSizeMB());if(o){this.error.set(o),this.toastService.add(o,3e3,"error");return}}this.error.set(null),this.uploadFiles(e)}async uploadFiles(t){this.isUploading.set(!0),this.uploadProgress.set(0);for(let e=0;e<t.length;e++){let i=t[e];await new Promise(o=>{this.fileUploadService.uploadFile(i,this.fieldId(),this.clientId()).subscribe({next:a=>{if(a.success&&a.fileId){let m={id:a.fileId,name:a.fileName||i.name,url:a.fileUrl,size:i.size,type:i.type};this.multipleFiles()?this.files.update(v=>[...v,m]):this.files.set([m]),this.toastService.add(`File "${i.name}" uploaded successfully`,2e3,"success"),this.fileUploaded.emit(a)}else this.error.set(a.error||"Upload failed"),this.toastService.add(a.error||"Upload failed",3e3,"error");this.uploadProgress.set(Math.round((e+1)/t.length*100)),o()},error:a=>{console.error("Upload error:",a),this.error.set("Upload failed. Please try again."),this.toastService.add("Upload failed. Please try again.",3e3,"error"),o()}})})}this.isUploading.set(!1)}deleteFile(t,e){this.fileUploadService.deleteFile(t,this.fieldId(),this.clientId()).subscribe({next:()=>{this.files.update(i=>i.filter(o=>o.id!==t)),this.toastService.add(`File "${e}" deleted`,2e3,"success")},error:i=>{console.error("Delete error:",i),this.toastService.add("Failed to delete file",3e3,"error")}})}chipFile(t){return this.chipsById().get(t.id)}chipsById=b(()=>new Map(this.files().map(t=>[t.id,{id:Number(t.id),name:t.name,url:t.url??null,type:t.type,size:t.size}])));chipFiles=b(()=>[...this.chipsById().values()]);
1menuItemsById=b(()=>{let t=this.selectedIds(),e=a=>{let m=v=>a>1?`${v} (${a})`:v;return[{label:m("Attach to Email"),action:"attach-to-email",icon:we},{label:m("Attach to Workflow Note"),action:"attach-to-note",icon:Le}]},i=e(1),o=e(t.size);return new Map(this.files().map(a=>[a.id,t.has(a.id)&&t.size>1?o:i]))});fileMenuItems(t){return this.menuItemsById().get(t.id)??[]}handleFileMenuAction(t,e){let i=(this.selectedIds().has(e.id)?this.getSelectedFiles():[e]).filter(o=>o.url);if(i.length)switch(t){case"attach-to-email":case"attach-to-note":{let o=t==="attach-to-email"?"email":"note";this.composerBridge.request(i.map(uo),o),this.attachToComposer.emit(o);break}}}static \u0275fac=function(e){return new(e||n)};static \u0275cmp=V({type:n,selectors:[["app-file-dropzone"]],inputs:{fieldId:[1,"fieldId"],clientId:[1,"clientId"],multipleFiles:[1,"multipleFiles"],maxSizeMB:[1,"maxSizeMB"],initialFileIds:[1,"initialFileIds"]},outputs:{fileUploaded:"fileUploaded",attachToComposer:"attachToComposer"},decls:5,vars:6,consts:[[3,"dragover","dragleave","drop"],["type","button",1,"cursor-pointer","flex","flex-col","items-center","gap-2","w-full","bg-transparent","border-0","p-0"],[1,"flex","flex-col","items-center","gap-3","w-full"],[1,"flex","flex-col","gap-2","w-full"],[1,"text-danger-600","text-sm","text-center"],["type","button",1,"cursor-pointer","flex","flex-col","items-center","gap-2","w-full","bg-transparent","border-0","p-0",3,"click"],[1,"w-8","h-8","text-theme-secondary",3,"icon"],[1,"text-center"],[1,"text-theme-primary","text-sm","font-medium"],[1,"text-theme-secondary","text-xs","mt-1"],[1,"w-8","h-8","text-accent","animate-pulse",3,"icon"],[1,"w-full"],[1,"text-theme-primary","text-sm","text-center","mb-2"],[1,"w-full","bg-surface-subtle","rounded-full","h-2"],[1,"bg-accent-500","h-2","rounded-full","transition-all","duration-300"],[1,"flex","items-center","gap-2","px-2","py-1.5","rounded-lg","bg-accent-500/10","border","border-accent-500/30","text-xs"],[1,"flex","items-center","gap-2"],["type","button",1,"inline-flex","items-center","gap-1.5","px-2","py-1.5","rounded-lg","border","border-theme-subtle","bg-surface-component","hover:bg-surface-hover","text-xs","text-theme-secondary","hover:text-theme-primary","transition-colors"],[1,"flex","items-center","cursor-pointer",3,"click","title"],["size","sm",3,"id","value","indeterminate"],[1,"text-theme-primary","font-medium","flex-1"],["type","button","title","Attach to Email",1,"flex","items-center","gap-1","px-2","py-1","rounded","hover:bg-surface-hover","transition-colors","text-theme-secondary","hover:text-theme-primary",3,"click"],[1,"text-[11px]",3,"icon"],["type","button","title","Attach to Workflow N
1ote",1,"flex","items-center","gap-1","px-2","py-1","rounded","hover:bg-surface-hover","transition-colors","text-theme-secondary","hover:text-theme-primary",3,"click"],["type","button","title","Delete selected",1,"flex","items-center","gap-1","px-2","py-1","rounded","hover:bg-danger-500/10","transition-colors","text-danger-500",3,"click"],["type","checkbox",1,"shrink-0","w-3.5","h-3.5","rounded","border-theme-subtle","accent-accent-500","cursor-pointer",3,"change","checked"],["removeLabel","Delete",1,"flex-1","min-w-0",3,"action","remove","file","files","fill","selected","menuItems","removable"],["type","button",1,"inline-flex","items-center","gap-1.5","px-2","py-1.5","rounded-lg","border","border-theme-subtle","bg-surface-component","hover:bg-surface-hover","text-xs","text-theme-secondary","hover:text-theme-primary","transition-colors",3,"click"],[1,"text-[10px]",3,"icon"]],template:function(e,i){e&1&&(l(0,"div",0),f("dragover",function(a){return i.onDragOver(a)})("dragleave",function(a){return i.onDragLeave(a)})("drop",function(a){return i.onDrop(a)}),C(1,Io,8,3,"button",1),C(2,Do,7,3,"div",2),C(3,No,6,3,"div",3),C(4,Lo,2,1,"div",4),s()),e&2&&(ge(i.dropzoneClasses()),r(),h(!i.isUploading()&&(i.files().length===0||i.multipleFiles())?1:-1),r(),h(i.isUploading()?2:-1),r(),h(i.files().length>0&&!i.isUploading()?3:-1),r(),h(i.error()&&!i.isUploading()?4:-1))},dependencies:[Se,R,Re,Un],encapsulation:2,changeDetection:0})};var Po=n=>({client_id:n}),Ao=(n,t,e,i)=>({key:n,columnId:t,fieldId:e,label:i});function Ro(n,t){if(n&1&&(l(0,"div",1),g(1,"fa-icon",11),s()),n&2){let e=d();r(),p("icon",e.faGripVertical)}}function Uo(n,t){n&1&&(l(0,"div",3)(1,"div",12),g(2,"app-loader",13),s()()),n&2&&(r(2),p("loadingState",!0))}function $o(n,t){if(n&1&&(l(0,"span",4),c(1),s()),n&2){let e=d();r(),x("ID: ",e.field().id)}}function Oo(n,t){if(n&1&&(l(0,"a",18),c(1),s()),n&2){let e=t,i=d(3);p("bcFieldLink",e)("bcFieldLinkClientId",i.clientId()),r(),A(e.label)}}function Bo(n,t){if(n&1&&(l(0,"span",19),c(1),s()),n&2){let e=d(3);r(),A(e.field().value)}}function zo(n,t){if(n&1&&C(0,Oo,2,3,"a",18)(1,Bo,2,1,"span",19),n&2){let e,i=d(2);h((e=i.linkValue())?0:1,e)}}function Go(n,t){n&1&&(l(0,"span",17),c(1,"Not Set"),s())}function qo(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd",15)(4,"app-client-inline-edit",16),f("save",function(o){u(e);let a=d();return _(a.handleInlineEditSave(o))})("editingChange",function(o){u(e);let a=d();return _(a.handleEditingChange(o))}),C(5,zo,2,1)(6,Go,2,0,"span",17),s()()()}if(n&2){let e=d();r(2),x(" ",e.field().label," "),r(2),p("value",e.field().value)("clientId",e.clientId())("columnKey","custom_field_"+e.field().id)("fieldType",e.field().type)("fieldId",e.field().id)("accessLevel",e.field().access_level)("table","clients_additional_fields")("editAffordance",!!e.linkValue())("editAffordanceLabel","Edit "+e.field().label),r(),h(e.field().value?5:6)}}function jo(n,t){if(n&1&&c(0),n&2){let e=d(2);x(" ",e.field().value," ")}}function Ko(n,t){n&1&&(l(0,"span",17),c(1,"Not Set"),s())}function Qo(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd",15)(4,"app-client-inline-edit",20),f("save",function(o){u(e);let a=d();return _(a.handleInlineEditSave(o))})("editingChange",function(o){u(e);let a=d();return _(a.handleEditingChange(o))}),C(5,jo,1,1)(6,Ko,2,0,"span",17),s()()()}if(n&2){let e=d();r(2),x(" ",e.field().label," "),r(2),p("value",e.field().value)("clientId",e.clientId())("columnKey","custom_field_"+e.field().id)("fieldType",e.field().type)("fieldId",e.field().id)("accessLevel",e.field().access_level)("table","clients_additional_fields"),r(),h(e.field().value?5:6)}}function Ho(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd")(4,"bc-checkbox-input",21),f("valueChange",function(o){u(e);let a=d();return _(a.handleCheckboxChange(o))}),s()()()}if(n&2){let e=d();r(2),x(" ",e.field().label," "),r(2),p("value",e.checkboxValue())}}function Wo(n,t){if(n&1&&(l(0,"bc-badge",23),c(1),s()),n&2){let e=t;p("color",e.color),r(),A(e.label)}}function Jo(n,t){if(n&1&&c(0),n&2){let e=d(2);x(" ",e.dropdownDisplayValue()," ")}}
1function Xo(n,t){n&1&&(l(0,"span",17),c(1,"Not Set"),s())}function Yo(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd",15)(4,"app-client-inline-dropdown",22),f("save",function(o){u(e);let a=d();return _(a.handleInlineDropdownSave(o))})("editingChange",function(o){u(e);let a=d();return _(a.handleEditingChange(o))}),C(5,Wo,2,2,"bc-badge",23)(6,Jo,1,1)(7,Xo,2,0,"span",17),s()()()}if(n&2){let e,i=d();r(2),x(" ",i.field().label," "),r(2),p("displayValue",i.field().value)("currentValue",i.field().value)("clientId",i.clientId())("columnKey","custom_field_"+i.field().id)("fieldType",i.field().type)("fieldId",i.field().id)("accessLevel",i.field().access_level)("table","clients_additional_fields")("multiSelect",!1)("transformer",i.dropdownTransformer)("colorFunction",i.optionColorFunction)("options",i.dropdownOptions()),r(),h((e=i.coloredSelectedOptions()[0])?5:i.field().value?6:7,e)}}function Zo(n,t){if(n&1&&(l(0,"bc-badge",25),c(1),s()),n&2){let e=t.$implicit;p("color",e.color),r(),A(e.label)}}function ea(n,t){if(n&1&&(l(0,"div",24),E(1,Zo,2,2,"bc-badge",25,We),s()),n&2){let e=d(2);r(),k(e.coloredSelectedOptions())}}function ta(n,t){if(n&1&&c(0),n&2){let e=d(2);x(" ",e.dropdownDisplayValue()," ")}}function ia(n,t){n&1&&(l(0,"span",17),c(1,"Not Set"),s())}function na(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd",15)(4,"app-client-inline-dropdown",22),f("save",function(o){u(e);let a=d();return _(a.handleInlineDropdownSave(o))})("editingChange",function(o){u(e);let a=d();return _(a.handleEditingChange(o))}),C(5,ea,3,0,"div",24)(6,ta,1,1)(7,ia,2,0,"span",17),s()()()}if(n&2){let e=d();r(2),x(" ",e.field().label," "),r(2),p("displayValue",e.field().value)("currentValue",e.parsedMultiselectValue())("clientId",e.clientId())("columnKey","custom_field_"+e.field().id)("fieldType",e.field().type)("fieldId",e.field().id)("accessLevel",e.field().access_level)("table","clients_additional_fields")("multiSelect",!0)("transformer",e.dropdownTransformer)("colorFunction",e.optionColorFunction)("options",e.dropdownOptions()),r(),h(e.coloredSelectedOptions().length?5:e.field().value?6:7)}}function oa(n,t){if(n&1&&c(0),n&2){let e=d(2);x(" ",e.field().value," ")}}function aa(n,t){n&1&&(l(0,"span",17),c(1,"Not Set"),s())}function ra(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd",15)(4,"app-client-inline-edit",26),f("save",function(o){u(e);let a=d();return _(a.handleInlineEditSave(o))})("editingChange",function(o){u(e);let a=d();return _(a.handleEditingChange(o))}),C(5,oa,1,1)(6,aa,2,0,"span",17),s()()()}if(n&2){let e=d();r(2),x(" ",e.field().label," "),r(2),p("value",e.field().value)("clientId",e.clientId())("columnKey","custom_field_"+e.field().id)("fieldType",e.field().type)("fieldId",e.field().id)("accessLevel",e.field().access_level)("table","clients_additional_fields"),r(),h(e.field().value?5:6)}}function la(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd",15)(4,"app-file-dropzone",27),f("fileUploaded",function(o){u(e);let a=d();return _(a.handleFileUpload(o))})("attachToComposer",function(o){u(e);let a=d();return _(a.attachToComposer.emit(o))}),s()()()}if(n&2){let e=d();r(2),x(" ",e.field().label," "),r(2),p("fieldId",e.field().id)("clientId",e.clientId())("initialFileIds",e.field().value||"")("multipleFiles",!1)}}function sa(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd",15)(4,"app-file-dropzone",27),f("fileUploaded",function(o){u(e);let a=d();return _(a.handleFileUpload(o))})("attachToComposer",function(o){u(e);let a=d();return _(a.attachToComposer.emit(o))}),s()()()}if(n&2){let e=d();r(2),x(" ",e.field().label," "),r(2),p("fieldId",e.field().id)("clientId",e.clientId())("initialFileIds",e.field().value||"")("multipleFiles",!0)}}function da(n,t){if(n&1&&(l(0,"h4",6),c(1),s()),n&2){let e=d();r(),x(" ",e.field().label," ")}}function ca(n,t){n&1&&g(0,"div",7)}function ma(n,t){n&1&&g(0,"hr",8)}function pa(n,t){if(n&1&&(c(0),xe(1,"currencyFormat")),n&2){let e=d(2);x(" ",ye(1,1,+(e.field().value||0),e.field().currency_symbol||"$")," ")}}
1function ua(n,t){n&1&&(l(0,"span",17),c(1,"Not Set"),s())}function _a(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd",15)(4,"app-client-inline-edit",26),f("save",function(o){u(e);let a=d();return _(a.handleInlineEditSave(o))})("editingChange",function(o){u(e);let a=d();return _(a.handleEditingChange(o))}),C(5,pa,2,4)(6,ua,2,0,"span",17),s()()()}if(n&2){let e=d();r(2),x(" ",e.field().label," "),r(2),p("value",e.field().value)("clientId",e.clientId())("columnKey","custom_field_"+e.field().id)("fieldType",e.field().type)("fieldId",e.field().id)("accessLevel",e.field().access_level)("table","clients_additional_fields"),r(),h(e.field().value?5:6)}}function fa(n,t){if(n&1&&c(0),n&2){let e=d(2);x(" ",e.field().value," ")}}function Ca(n,t){n&1&&(l(0,"span",17),c(1,"Not Set"),s())}function ha(n,t){if(n&1&&g(0,"bc-location-map",31),n&2){let e=d(2);p("address",e.field().value)}}function ga(n,t){if(n&1&&g(0,"bc-location-map",32),n&2){let e=d(2);p("address",e.field().value)}}function ba(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd",28)(4,"div",29)(5,"app-client-inline-dropdown",30),f("save",function(o){u(e);let a=d();return _(a.handleInlineEditSave(o))})("editingChange",function(o){u(e);let a=d();return _(a.handleEditingChange(o))}),C(6,fa,1,1)(7,Ca,2,0,"span",17),s(),C(8,ha,1,1,"bc-location-map",31),s(),C(9,ga,1,1,"bc-location-map",32),s()()}if(n&2){let e=d();r(2),x(" ",e.field().label," "),r(3),p("displayValue",e.field().value)("currentValue",e.field().value)("clientId",e.clientId())("columnKey","custom_field_"+e.field().id)("fieldType",e.field().type)("fieldId",e.field().id)("accessLevel",e.field().access_level)("table","clients_additional_fields")("transformer",e.locationTransformer)("serverFetch",e.locationFetch()),r(),h(e.field().value?6:7),r(2),h(e.field().value&&!e.locationSettings().show_map?8:-1),r(),h(e.field().value&&e.locationSettings().show_map?9:-1)}}function va(n,t){if(n&1&&(l(0,"div"),g(1,"app-trigger-button-cell",33),s()),n&2){let e=d();r(),p("client",be(5,Po,e.clientId()))("column",fi(7,Ao,"custom_field_"+e.field().id,e.field().id,e.field().id,e.field().label))("buttonColor",e.field().color??null)("dependencyFieldIds",e.field().dependency_field_ids??null)("allFields",e.allFields())}}function xa(n,t){if(n&1&&(l(0,"a",18),c(1),s()),n&2){let e=t,i=d(3);p("bcFieldLink",e)("bcFieldLinkClientId",i.clientId()),r(),A(e.label)}}function ya(n,t){if(n&1&&(l(0,"span",35),c(1),s()),n&2){let e=d(3);r(),A(e.field().value)}}function Sa(n,t){if(n&1&&C(0,xa,2,3,"a",18)(1,ya,2,1,"span",35),n&2){let e,i=d(2);h((e=i.linkValue())?0:1,e)}}function Fa(n,t){n&1&&(l(0,"span",17),c(1,"Not Set"),s())}function wa(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd",15)(4,"app-client-inline-edit",34),f("save",function(o){u(e);let a=d();return _(a.handleInlineEditSave(o))})("editingChange",function(o){u(e);let a=d();return _(a.handleEditingChange(o))}),C(5,Sa,2,1)(6,Fa,2,0,"span",17),s()()()}if(n&2){let e=d();r(2),x(" ",e.field().label," "),r(2),p("value",e.field().value)("clientId",e.clientId())("columnKey","custom_field_"+e.field().id)("fieldType",e.field().type)("fieldId",e.field().id)("accessLevel",e.field().access_level)("table","clients_additional_fields")("editAffordance",!!e.linkValue())("editAffordanceLabel","Edit "+e.field().label),r(),h(e.field().value?5:6)}}function Ta(n,t){if(n&1&&c(0),n&2){let e=d(2);x(" ",e.userDisplayValue()," ")}}function Ia(n,t){n&1&&(l(0,"span",17),c(1,"Not Set"),s())}function Da(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd",15)(4,"app-client-inline-dropdown",36),f("save",function(o){u(e);let a=d();return _(a.handleInlineDropdownSave(o))})("loadOptions",function(o){u(e);let a=d();return _(a.handleLoadOptions(o))})("editingChange",function(o){u(e);let a=d();return _(a.handleEditingChange(o))}),C(5,Ta,1,1)(6,Ia,2,0,"span",17),s()()()}if(n&2){let e=d();r(2),x(" ",e.field().label," "),r(2),p("displayValue",e.field().value)("currentValue",e.field().value)("clientId",e.clientId())("columnKey","custom_field_"+e.field().id)("fieldType",e.field().type)("fieldId",e.field().id)("accessLevel",e.field().access_level)("table","clients_additional_fields")("multiSelect",!1)("transformer",e.userTransformer),r(),h(e.field().value?5:6)}}function Ea(n,t){if(n&1&&c(0),n&2){let e=d(2);x(" ",e.userDisplayValue()," ")}}
1function ka(n,t){n&1&&(l(0,"span",17),c(1,"Not Set"),s())}function Ma(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd",15)(4,"app-client-inline-dropdown",37),f("save",function(o){u(e);let a=d();return _(a.handleInlineDropdownSave(o))})("loadOptions",function(o){u(e);let a=d();return _(a.handleLoadOptions(o))})("editingChange",function(o){u(e);let a=d();return _(a.handleEditingChange(o))}),C(5,Ea,1,1)(6,ka,2,0,"span",17),s()()()}if(n&2){let e=d();r(2),x(" ",e.field().label," "),r(2),p("displayValue",e.field().value)("currentValue",e.parsedMultiselectValue())("clientId",e.clientId())("columnKey","custom_field_"+e.field().id)("fieldType",e.field().type)("fieldId",e.field().id)("accessLevel",e.field().access_level)("table","clients_additional_fields")("multiSelect",!0)("transformer",e.userTransformer)("options",e.userOptions()),r(),h(e.field().value?5:6)}}function Va(n,t){if(n&1&&c(0),n&2){let e=d(2);x(" ",e.clientSingleDisplayValue()," ")}}function Na(n,t){n&1&&(l(0,"span",17),c(1,"Not Set"),s())}function La(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd",15)(4,"app-client-inline-dropdown",38),f("save",function(o){u(e);let a=d();return _(a.handleInlineDropdownSave(o))})("editingChange",function(o){u(e);let a=d();return _(a.handleEditingChange(o))}),C(5,Va,1,1)(6,Na,2,0,"span",17),s()()()}if(n&2){let e=d();r(2),x(" ",e.field().label," "),r(2),p("displayValue",e.field().value)("currentValue",e.field().value)("clientId",e.clientId())("columnKey","custom_field_"+e.field().id)("fieldType",e.field().type)("fieldId",e.field().id)("accessLevel",e.field().access_level)("table","clients_additional_fields")("multiSelect",!1)("transformer",e.clientRefTransformer)("serverFetch",e.clientRefServerFetch),r(),h(e.clientSingleDisplayValue()?5:6)}}function Pa(n,t){if(n&1&&c(0),n&2){let e=d(2);x(" ",e.clientMultiDisplayValue()," ")}}function Aa(n,t){n&1&&(l(0,"span",17),c(1,"Not Set"),s())}function Ra(n,t){if(n&1){let e=y();l(0,"dl",5)(1,"dt",14),c(2),s(),l(3,"dd",15)(4,"app-client-inline-dropdown",38),f("save",function(o){u(e);let a=d();return _(a.handleInlineDropdownSave(o))})("editingChange",function(o){u(e);let a=d();return _(a.handleEditingChange(o))}),C(5,Pa,1,1)(6,Aa,2,0,"span",17),s()()()}if(n&2){let e=d();r(2),x(" ",e.field().label," "),r(2),p("displayValue",e.field().value)("currentValue",e.parsedMultiselectValue())("clientId",e.clientId())("columnKey","custom_field_"+e.field().id)("fieldType",e.field().type)("fieldId",e.field().id)("accessLevel",e.field().access_level)("table","clients_additional_fields")("multiSelect",!0)("transformer",e.clientRefTransformer)("serverFetch",e.clientRefServerFetch),r(),h(e.clientMultiDisplayValue()?5:6)}}function Ua(n,t){if(n&1&&(l(0,"div",9),c(1),s()),n&2){let e=d();r(),x(" Unsupported field type: ",e.field().type," ")}}function $a(n,t){if(n&1){let e=y();l(0,"button",41),f("click",function(o){return u(e),d(2).copyValue(),_(o.stopPropagation())}),g(1,"fa-icon",42),s()}if(n&2){let e=d(2);r(),p("icon",e.faCopy)}}function Oa(n,t){if(n&1){let e=y();l(0,"button",43),f("click",function(o){return u(e),d(2).copyValue(),_(o.stopPropagation())}),g(1,"fa-icon",42),s()}if(n&2){let e=d(2);r(),p("icon",e.faCopy)}}function Ba(n,t){if(n&1&&C(0,$a,2,1,"button",39)(1,Oa,2,1,"button",40),n&2){let e=d();h(e.isNonDesktop()?0:1)}}function za(n,t){if(n&1){let e=y();l(0,"button",44),f("click",function(o){return u(e),d().deleteField(),_(o.stopPropagation())}),g(1,"fa-icon",45),s()}if(n&2){let e=d();r(),p("icon",e.faTrash)}}var Et=class n{field=T.required();clientId=T.required();canEdit=T(!1);canReorder=T(!1);isEditMode=T(!1);allFields=T([]);usersList=T([]);fieldUpdated=M();fieldDeleted=M();fieldEditRequested=M();attachToComposer=M();isDeletingField=S(!1);clientService=F(Q);locationService=F(Hn);toastService=F(G);modalService=F(ie);breakpointService=F(bn);faCopy=Ai;faTrash=X;faGripVertical=Bi;isFieldEditing=S(!1);localCheckboxValue=S(!1);userOptions=b(()=>this.usersList().map(t=>({id:t.user_id,label:`${t.first_name} ${t.last_name}`})));checkboxValue=b(()=>this.field().type===4?this.localCheckboxValue():this.field().value==="1"||this.field().value==="true");constructor(){P(()=>{this.field().type===4&&this.localCheckboxValue.set(this.field().value==="1"||this.field().value==="true")})}isEditable=b(()=>{let t=[1,2,4,5,6,7,8,9,13,14,15,16,17,18,19,20];return this.canEdit()&&t.includes(this.field().type)});locationSettings=b(()=>$e(this.field().settings));locationFetch=b(()=>this.locationService.serverFetchFor(this.locationSettings(),()=>this.field().value));locationTransformer=t=>t;isStaticType=b(()=>[10,11,12].includes(this.field().type));isCopyableType=b(()=>[1,2,5,6,7,13,15,16,17,18,19,20].includes(this.field().type));showCopyButton=b(()=>!this.isEditMode()&&this.isCopyableType());showTrashIcon=b(()=>this.isEditMode());showDragHandle=b(()=>this.isEditMode()&&this.canReorder());isNonDesktop=b(()=>!this.breakpointService.isDesktop());linkValue=b(()=>{let t=this.field();return t.type!==1&&t.type!==15?null:Zn(t.value)});parsedMultiselectValue=b(()=>{let e=this.field().value;if(!e)return[];if(Array.isArray(e))return e;if(typeof e=="string")try{let i=JSON.parse(e);return Array.isArray(i)?i:[i]}catch{return e.split(",").map(i=>
1i.trim()).filter(Boolean)}return[]});dropdownOptions=b(()=>{let t=this.field();if(t.type===5||t.type===6){if(!t.dropdown_values)return[];try{let e=t.dropdown_values,i=typeof e=="string"?JSON.parse(e):e;return Array.isArray(i)?i:[]}catch(e){return console.error("Failed to parse dropdown values:",e),[]}}return[]});dropdownDisplayValue=b(()=>{let t=this.field(),e=t.value;if(t.type!==5&&t.type!==6)return e;if(!e||Array.isArray(e)&&e.length===0)return"";let i=this.dropdownOptions();return Kt(e,i,{fallback:"DELETED VALUE"})});coloredSelectedOptions=b(()=>{let t=this.field();if(t.type!==5&&t.type!==6)return[];let e=Sn(t.value,this.dropdownOptions(),{fallback:"DELETED VALUE"});return e.some(i=>i.color)?e:[]});userDisplayValue=b(()=>{let t=this.field(),e=t.value;if(t.type!==16&&t.type!==17)return e;if(!e||Array.isArray(e)&&e.length===0)return"";let i=this.userOptions();return Kt(e,i,{fallback:String(e)})||String(e)});dropdownTransformer=t=>({label:t.label,value:t.id,color:t.color??null});optionColorFunction=wn;userTransformer=t=>({label:t.label,value:t.id});clientRefTransformer=t=>({label:t.label,value:t.id});clientRefServerFetch=(t,e)=>this.clientService.searchClientsForPicker(t,e,50).pipe(ke(i=>({items:i.rows?.map(o=>({label:o.company_name||`Client #${o.client_id}`,value:String(o.client_id)}))??[],nextCursor:i.nextCursor??null,hasMore:!!i.hasMore})));handleEditingChange(t){this.isFieldEditing.set(t)}handleRowClick(){this.isEditMode()&&!this.isDeletingField()&&this.fieldEditRequested.emit(this.field())}async copyValue(){let t=this.field().value;if(!t){this.toastService.add("No value to copy",2e3,"info");return}try{await navigator.clipboard.writeText(t),this.toastService.add("Copied to clipboard",2e3,"success")}catch(e){console.error("Failed to copy:",e),this.toastService.add("Failed to copy to clipboard",2e3,"error")}}async deleteField(){await this.modalService.showModal(Y,{title:"Delete Custom Field",message:`Are you sure you want to delete the field "${this.field().label}"? This will delete the field and all its values across all clients.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",confirmPhrase:this.field().label})&&(this.isDeletingField.set(!0),this.clientService.deleteCustomField(this.field().id).subscribe({next:()=>{this.toastService.add("Field deleted successfully",2e3,"success"),this.isDeletingField.set(!1),this.fieldDeleted.emit(this.field().id)},error:e=>{console.error("Failed to delete field:",e),this.toastService.add("Failed to delete field",3e3,"error"),this.isDeletingField.set(!1)}}))}editField(){this.fieldEditRequested.emit(this.field())}async handleInlineEditSave(t){let e=this.field().value;this.fieldUpdated.emit({fieldId:this.field().id,value:t.value,success:!0});try{await D(this.clientService.updateClientField(t.params)),t.onSuccess(),this.toastService.add("Field updated",2e3,"success")}catch(i){this.fieldUpdated.emit({fieldId:this.field().id,value:e,success:!0}),t.onError(i),console.error("Field update error:",i),this.toastService.add("Failed to update",3e3,"error")}}async handleInlineDropdownSave(t){let e=this.field().type,i,o,a,m=t.value;if(typeof m=="string")try{let w=JSON.parse(m);Array.isArray(w)&&(m=w)}catch{m.includes(",")&&(m=m.split(","))}if(e===5||e===6)i=this.computeDropdownDisplayText(m);else if(e===16){let w=this.computeUserDisplay(m);i=w.text,o=w.photoUrl}else e===17?a=this.computeMultiUserJson(m):e===18?i=t.selectedOptions?.[0]?.label??"":e===19&&(i=t.selectedOptions?.map(w=>w.label).join(", ")??"");let v=this.field().value;this.fieldUpdated.emit({fieldId:this.field().id,value:t.params.value,success:!0,displayText:i,photoUrl:o,usersJson:a});try{await D(this.clientService.updateClientField(t.params)),t.onSuccess(),this.toastService.add("Field updated",2e3,"success")}catch(w){this.fieldUpdated.emit({fieldId:this.field().id,value:v,success:!0}),t.onError(w),console.error("Field update error:",w),this.toastService.add("Failed to update",3e3,"error")}}handleFileUpload(t){let e=this.field(),i=e.value??"",o=e.type===9&&i?`${i},${t.fileId}`:t.fileId;this.fieldUpdated.emit({fieldId:e.id,value:o,success:t.success})}handleCheckboxChange(t){let e=this.localCheckboxValue();this.localCheckboxValue.set(t);let i={table:"clients_additional_fields",column_name:`custom_field_${this.field().id}`,row_id:this.field().id,client_id:this.clientId(),value:t?"1":"0"};this.clientService.updateClientField(i).subscribe({next:o=>{this.fieldUpdated.emit({fieldId:this.field().id,value:t?"1":"0",success:!0}),this.toastService.add("Checkbox updated",2e3,"success")},error:o=>{this.localCheckboxValue.set(e),console.error("Checkbox update error:",o),this.toastService.add("Failed to update checkbox",3e3,"error")}})}async handleLoadOptions(t){try{let e=await D(this.clientService.getCustomFieldOptions(t.fieldId));t.onSuccess(e.options)}catch(e){console.error("[CustomFieldItem] Failed to load options:",e),this.toastService.add("Failed to load options",3e3,"error"),t.onError(e)}}computeDropdownDisplayText(t){let e=this.dropdownOptions();if(!t||!e.length)return"";if(Array.isArray(t))return t.map(a=>{let m=e.find(v=>v.id==a);return m?m.label:""}
1).filter(Boolean).join(", ");let i=e.find(o=>o.id==t);return i?i.label:""}computeUserDisplay(t){let e=this.usersList();if(!t||!e.length)return{text:""};let i=Array.isArray(t)?t[0]:t,o=e.find(a=>a.user_id==i);return o?{text:`${o.first_name} ${o.last_name||""}`.trim(),photoUrl:o.photo_url}:{text:""}}computeMultiUserJson(t){let e=this.usersList();if(!t||!e.length)return"[]";let o=(Array.isArray(t)?t:[t]).map(a=>{let m=e.find(v=>v.user_id==a);return m?{id:m.user_id,name:`${m.first_name} ${m.last_name||""}`.trim(),photo_url:m.photo_url||null}:null}).filter(Boolean);return JSON.stringify(o)}clientSingleDisplayValue=b(()=>this.field().client_ref_name??"");clientMultiDisplayValue=b(()=>this.field().client_ref_name??"");static \u0275fac=function(e){return new(e||n)};static \u0275cmp=V({type:n,selectors:[["app-custom-field-item"]],hostAttrs:[1,"custom-field-item"],inputs:{field:[1,"field"],clientId:[1,"clientId"],canEdit:[1,"canEdit"],canReorder:[1,"canReorder"],isEditMode:[1,"isEditMode"],allFields:[1,"allFields"],usersList:[1,"usersList"]},outputs:{fieldUpdated:"fieldUpdated",fieldDeleted:"fieldDeleted",fieldEditRequested:"fieldEditRequested",attachToComposer:"attachToComposer"},decls:27,vars:13,consts:[["cdkDrag","",1,"group","relative","py-2","px-1","hover:bg-surface-hover","transition-colors","rounded","border-b","border-theme-subtle","last:border-b-0","flex",3,"click","cdkDragDisabled"],["cdkDragHandle","",1,"flex","items-center","pr-2","cursor-move","text-theme-secondary","hover:text-theme-primary"],[1,"flex-1","min-w-0"],[1,"absolute","inset-0","z-50","flex","items-center","justify-center","bg-danger-500/20","rounded","backdrop-blur-[2px]"],[1,"hidden","group-hover:inline","absolute","bottom-1.5","right-3","text-theme-secondary","text-[10px]","select-none","pointer-events-none"],[1,"space-y-1"],[1,"text-theme-primary","text-base","font-headline","font-bold","mt-1","mb-0.5"],[1,"h-1"],[1,"border-theme-default","my-0.5"],[1,"text-theme-secondary","text-sm"],["type","button","title","Delete field",1,"absolute","top-1","right-2","p-1","rounded","hover:bg-surface-hover","transition-colors"],[1,"text-xs",3,"icon"],[1,"w-8","h-8"],[3,"loadingState"],[1,"text-theme-secondary","text-xs","font-normal"],[1,"text-theme-primary","text-sm"],["size","sm",3,"save","editingChange","value","clientId","columnKey","fieldType","fieldId","accessLevel","table","editAffordance","editAffordanceLabel"],[1,"text-theme-disabled"],[1,"text-accent","hover:underline","truncate","inline-block","max-w-full","align-middle",3,"bcFieldLink","bcFieldLinkClientId"],[1,"line-clamp-1"],["inputType","date","size","sm",3,"save","editingChange","value","clientId","columnKey","fieldType","fieldId","accessLevel","table"],["size","sm",3,"valueChange","value"],[3,"save","editingChange","displayValue","currentValue","clientId","columnKey","fieldType","fieldId","accessLevel","table","multiSelect","transformer","colorFunction","options"],[3,"color"],[1,"flex","flex-wrap","gap-1"],["variant","brand",3,"color"],["inputType","number","size","sm",3,"save","editingChange","value","clientId","columnKey","fieldType","fieldId","accessLevel","table"],[3,"fileUploaded","attachToComposer","fieldId","clientId","initialFileIds","multipleFiles"],[1,"text-theme-primary","text-sm","flex","flex-col","gap-2"],[1,"flex","items-center","gap-1","min-w-0"],[1,"flex-1","min-w-0",3,"save","editingChange","displayValue","currentValue","clientId","columnKey","fieldType","fieldId","accessLevel","table","transformer","serverFetch"],["variant","pin",3,"address"],[3,"address"],[3,"client","column","buttonColor","dependencyFieldIds","allFields"],["inputType","textarea","size","sm",3,"save","editingChange","value","clientId","columnKey","fieldType","fieldId","accessLevel","table","editAffordance","editAffordanceLabel"],[1,"line-clamp-4","whitespace-pre-wrap"],[3,"save","loadOptions","editingChange","displayValue","currentValue","clientId","columnKey","fieldType","fieldId","accessLevel","table","multiSelect","transformer"],[3,"save","loadOptions","editingChange","displayValue","currentValue","clientId","columnKey","fieldType","fieldId","accessLevel","table","multiSelect","transformer","options"],[3,"save","editingChange","displayValue","currentValue","clientId","columnKey","fieldType","fieldId","accessLevel","table","multiSelect","transformer","serverFetch"],["type","button","title","Copy value",1,"absolute","top-1","right-2","p-1","rounded","hover:bg-surface-hover","transition-colors"],["type","button","title","Copy value",1,"absolute","top-1","right-2","p-1","rounded","hover:bg-surface-hover","transition-opacity","has-hover:opacity-0","has-hover:group-hover:opacity-100"],["type","button","title","Copy value",1,"absolute","top-1","right-2","p-1","rounded","hover:bg-surface-hover","transition-colors",3,"click"],[1,"text-theme-secondary","text-xs",3,"icon"],["type","button","title","Copy value",1,"absolute","top-1","right-2","p-1","rounded","hover:bg-surface-hover","transition-opacity","has-hover:opacity-0","has-hover:group-hover:opacity-100",3,"click"],["type","button","title","Delete field",1,"absolute","top-1","right-2","p-1","rounded","hover:bg-surface-hover","transition-colors",3,"click"],[1,"text-danger-600","text-xs",3,"icon"]],template:function(e,i){if(e&1&&(l(0,"div",0),f("click",function(){return i.handleRowClick()}),C(1,Ro,2,1,"div",1),l(2,"div",2),C(3,Uo,3,1,"div",3),C(4,$o,2,1,"span",4),C(5,qo,7,11,"dl",5)(6,Qo,7,9,"dl",5)(7,Ho,5,2,"dl",5)(8,Yo,8,14,"dl",5)(9,na,8,14,"dl",5)(10,ra,7,9,"dl",5)(11,la,5,5,"dl",5)(12,sa,5,5,"dl",5)(13,da,2,1,"h4",6)(14,ca,1,0,"div",7)(1
15,ma,1,0,"hr",8)(16,_a,7,9,"dl",5)(17,ba,10,14,"dl",5)(18,va,2,12,"div")(19,wa,7,11,"dl",5)(20,Da,7,12,"dl",5)(21,Ma,7,13,"dl",5)(22,La,7,13,"dl",5)(23,Ra,7,13,"dl",5)(24,Ua,2,1,"div",9),s(),C(25,Ba,2,1),C(26,za,2,1,"button",10),s()),e&2){let o;N("cursor-pointer",i.isEditMode())("pointer-events-none",i.isDeletingField()),p("cdkDragDisabled",!i.canReorder()),r(),h(i.showDragHandle()?1:-1),r(),N("pointer-events-none",i.isEditMode()),r(),h(i.isDeletingField()?3:-1),r(),h(!i.isEditMode()&&!i.isFieldEditing()?4:-1),r(),h((o=i.field().type)===1?5:o===2?6:o===4?7:o===5?8:o===6?9:o===7?10:o===8?11:o===9?12:o===10?13:o===11?14:o===12?15:o===13?16:o===20?17:o===14?18:o===15?19:o===16?20:o===17?21:o===18?22:o===19?23:24),r(20),h(i.showCopyButton()?25:-1),r(),h(i.showTrashIcon()?26:-1)}},dependencies:[eo,H,Se,ne,R,qn,Gn,bt,vt,Re,Dt,to,Ie,Jn,xt],encapsulation:2,changeDetection:0})};var Xt=n=>[n],_o=()=>[],Ga=()=>[1],fo=(n,t)=>t.id;function qa(n,t){if(n&1){let e=y();l(0,"div",2)(1,"p",3),c(2),s(),l(3,"button",4),f("click",function(){u(e);let o=d();return _(o.retryLoadFieldTypes())}),c(4," Try Again "),s()()}if(n&2){let e=d();r(2),x(" ",e.fieldTypesErrorMessage()," ")}}function ja(n,t){n&1&&c(0," Refreshing... ")}function Ka(n,t){n&1&&c(0," Refresh to see latest changes ")}function Qa(n,t){if(n&1){let e=y();l(0,"button",17),f("click",function(){u(e);let o=d(3);return _(o.refreshField())}),C(1,ja,1,0)(2,Ka,1,0),s()}if(n&2){let e=d(3);p("disabled",e.isRefreshing()),r(),h(e.isRefreshing()?1:2)}}function Ha(n,t){if(n&1){let e=y();l(0,"div",6),g(1,"fa-icon",12),l(2,"div",13)(3,"p",14),c(4),s(),C(5,Qa,3,2,"button",15),s(),l(6,"button",16),f("click",function(){u(e);let o=d(2);return _(o.errorBanner.set(null))}),c(7," \xD7 "),s()()}if(n&2){let e=d(2);r(),p("icon",e.faCircleInfo),r(3),A(e.errorBanner()),r(),h(e.isConflictError()?5:-1)}}function Wa(n,t){if(n&1&&(l(0,"p",8),c(1),s()),n&2){let e=d(2);r(),x(" Field ID: ",e.data.id," ")}}function Ja(n,t){n&1&&(l(0,"label",18),c(1," Field Type "),s(),l(2,"div",19),g(3,"app-loader",20),l(4,"span",21),c(5,"Loading field types..."),s()()),n&2&&(r(3),p("loadingState",!0))}function Xa(n,t){n&1&&(l(0,"p",23),c(1," Note: Field type cannot be changed after creation "),s())}function Ya(n,t){if(n&1){let e=y();l(0,"app-searchable-select",22),f("selectionChange",function(o){u(e);let a=d(2);return _(a.onFieldTypeChange(o))}),s(),C(1,Xa,2,0,"p",23)}if(n&2){let e=d(2);p("dataSource",e.fieldTypes())("transformer",e.fieldTypeTransformer)("selectedValues",e.form.controls.fieldType.value!==null?be(7,Xt,e.form.controls.fieldType.value):j(9,_o))("label","Field Type")("placeholder","Select field type")("disabled",e.isEditMode()),r(),h(e.isEditMode()?1:-1)}}function Za(n,t){if(n&1){let e=y();l(0,"app-dropdown-options-editor",31),f("optionsChange",function(o){u(e);let a=d(3);return _(a.dropdownOptions.set(o))}),s()}if(n&2){let e=d(3);p("options",e.dropdownOptions())}}function er(n,t){if(n&1){let e=y();l(0,"bc-location-settings",32),ui("settingsChange",function(o){u(e);let a=d(3);return pi(a.locationSettings,o)||(a.locationSettings=o),_(o)}),s()}if(n&2){let e=d(3);mi("settings",e.locationSettings)}}function tr(n,t){if(n&1){let e=y();l(0,"div")(1,"app-searchable-select",33),f("selectionChange",function(o){u(e);let a=d(3);return _(a.onCurrencyChange(o))}),s()()}if(n&2){let e=d(3);r(),p("dataSource",e.currencies())("transformer",e.currencyTransformer)("selectedValues",e.form.controls.currency.value!==null?be(6,Xt,e.form.controls.currency.value):j(8,_o))("label","Currency")("placeholder","Select currency")("showRequiredStar",!0)}}function ir(n,t){if(n&1&&(l(0,"div")(1,"label",34),c(2," Button Color "),s(),l(3,"div",35),g(4,"input",36),l(5,"span",21),c(6),s()()()),n&2){let e=d(3);r(6),x(" ",e.form.controls.buttonColor.value," ")}}function nr(n,t){if(n&1&&(l(0,"span",39),c(1),s()),n&2){let e=d(4);r(),x(" (",e.selectedDependenciesCount()," selected) ")}}function or(n,t){n&1&&(l(0,"div",45),g(1,"app-loader",20),s()),n&2&&(r(),p("loadingState",!0))}function ar(n,t){if(n&1){let e=y();l(0,"label",49)(1,"bc-checkbox-input",51),f("valueChange",function(){let o=u(e).$implicit,a=d(5);return _(a.toggleDependencySelection(o.id))}),s(),g(2,"fa-icon",52),l(3,"span",53),c(4),s()()}if(n&2){let e=t.$implicit,i=d(5);p("for","dependency-"+e.id),r(),p("id","dependency-"+e.id)("value",i.selectedDependencyIds().has(e.id)),r(),p("icon",i.getIconForFieldType(e.type)),r(2),x(" ",e.label," ")}}
1function rr(n,t){n&1&&c(0," No matching fields found ")}function lr(n,t){n&1&&c(0," No fields available for dependencies ")}function sr(n,t){if(n&1&&(l(0,"p",50),C(1,rr,1,0)(2,lr,1,0),s()),n&2){let e=d(5);r(),h(e.dependencySearchQuery()?1:2)}}function dr(n,t){if(n&1&&(l(0,"div",46)(1,"div",47)(2,"div",48),E(3,ar,5,5,"label",49,fo,!1,sr,3,1,"p",50),s()()()),n&2){let e=d(4);r(3),k(e.filteredDependencyFields())}}function cr(n,t){if(n&1){let e=y();l(0,"div",26)(1,"div",37)(2,"label",38),c(3," Field Dependencies "),C(4,nr,2,1,"span",39),s(),l(5,"div",40)(6,"button",41),f("click",function(){u(e);let o=d(3);return _(o.selectAllDependencies())}),c(7," Select All "),s(),l(8,"button",42),f("click",function(){u(e);let o=d(3);return _(o.clearAllDependencies())}),c(9," Clear All "),s()()(),l(10,"div",43),g(11,"bc-text-input",44),s(),C(12,or,2,1,"div",45)(13,dr,6,1,"div",46),s()}if(n&2){let e=d(3);r(4),h(e.selectedDependenciesCount()>0?4:-1),r(4),p("disabled",e.selectedDependenciesCount()===0),r(4),h(e.clientService.customFieldsResource.isLoading()?12:13)}}function mr(n,t){if(n&1&&(l(0,"span",39),c(1),s()),n&2){let e=d(4);r(),x(" (",e.selectedUsersCount()," selected) ")}}function pr(n,t){n&1&&(l(0,"div",45),g(1,"app-loader",20),s()),n&2&&(r(),p("loadingState",!0))}function ur(n,t){if(n&1){let e=y();l(0,"div",56)(1,"bc-checkbox-input",57),f("valueChange",function(){let o=u(e).$implicit,a=d(5);return _(a.toggleUserSelection(o.id))}),s()()}if(n&2){let e=t.$implicit,i=d(5);r(),p("id","user-"+e.id)("value",i.selectedUserIds().has(e.id))("label",e.user_name+" "+e.user_surname)}}function _r(n,t){n&1&&c(0," No matching users found ")}function fr(n,t){n&1&&c(0," No users available ")}function Cr(n,t){if(n&1&&(l(0,"p",50),C(1,_r,1,0)(2,fr,1,0),s()),n&2){let e=d(5);r(),h(e.userSearchQuery()?1:2)}}function hr(n,t){if(n&1&&(l(0,"div",46)(1,"div",55)(2,"div",48),E(3,ur,2,3,"div",56,fo,!1,Cr,3,1,"p",50),s()()()),n&2){let e=d(4);r(3),k(e.filteredManagers())}}function gr(n,t){if(n&1){let e=y();l(0,"div",26)(1,"div",37)(2,"label",38),c(3," Available Users "),C(4,mr,2,1,"span",39),s(),l(5,"div",40)(6,"button",41),f("click",function(){u(e);let o=d(3);return _(o.selectAllUsers())}),c(7," Select All "),s(),l(8,"button",42),f("click",function(){u(e);let o=d(3);return _(o.clearAllUsers())}),c(9," Clear All "),s()()(),l(10,"div",43),g(11,"bc-text-input",54),s(),C(12,pr,2,1,"div",45)(13,hr,6,1,"div",46),s()}if(n&2){let e=d(3);r(4),h(e.selectedUsersCount()>0?4:-1),r(4),p("disabled",e.selectedUsersCount()===0),r(4),h(e.clientService.managersResource.isLoading()?12:13)}}function br(n,t){n&1&&(l(0,"div",30),g(1,"bc-checkbox-input",58),s())}function vr(n,t){if(n&1){let e=y();C(0,Za,1,1,"app-dropdown-options-editor",24),C(1,er,1,1,"bc-location-settings",25),C(2,tr,2,9,"div"),C(3,ir,7,1,"div"),C(4,cr,14,3,"div",26),C(5,gr,14,3,"div",26),l(6,"div")(7,"app-searchable-select",27),f("selectionChange",function(o){u(e);let a=d(2);return _(a.onAccessLevelChange(o))}),s(),l(8,"div",28)(9,"p",29),c(10," \u2139\uFE0F Access Level Information "),s(),l(11,"p",21),c(12," Higher levels have more access. Users need matching or higher access level to see or edit this field. Default is Level 1 (all users). "),s()()(),C(13,br,2,0,"div",30)}if(n&2){let e=d(2);h(e.shouldShowDropdownOptions()?0:-1),r(),h(e.shouldShowLocation()?1:-1),r(),h(e.shouldShowCurrency()?2:-1),r(),h(e.shouldShowColor()?3:-1),r(),h(e.shouldShowDependencies()?4:-1),r(),h(e.shouldShowUsers()?5:-1),r(2),p("dataSource",e.accessLevels())("transformer",e.accessLevelTransformer)("selectedValues",e.form.controls.accessLevel.value!==null?be(12,Xt,e.form.controls.accessLevel.value):j(14,Ga))("label","Access Level")("placeholder","Level 1 (Default)"),r(6),h(e.shouldShowRequired()?13:-1)}}function xr(n,t){if(n&1){let e=y();l(0,"div",5),C(1,Ha,8,3,"div",6),l(2,"div"),g(3,"bc-text-input",7),C(4,Wa,2,1,"p",8),s(),l(5,"div"),C(6,Ja,6,1)(7,Ya,2,10),s(),C(8,vr,14,15),s(),l(9,"div",9)(10,"button",10),f("click",function(){u(e);let o=d();return _(o.handleCancel())}),c(11," Cancel "),s(),l(12,"bc-loading-button",11),c(13),s()()}if(n&2){let e=d();r(),h(e.errorBanner()?1:-1),r(2),p("showErrorMessage",!1)("showRequiredStar",!0)("errorPropagateOnTouch",!0),r(),h(e.isEditMode()&&e.data?4:-1),r(2),h(e.isShowingLoader()?6:7),r(2),h(e.isShowingLoader()?-1:8),r(4),p("loading",e.isSubmitting())("disabled",e.isShowingLoader()||e.form.invali
1d),r(),x(" ",e.isEditMode()?"Save Changes":"Add Field"," ")}}var Ge=class n extends te{fb=F(xn);clientService=F(Q);toastService=F(G);faCircleInfo=Ti;isEditMode=b(()=>this.data!==null&&this.data!==void 0);modalTitle=b(()=>(this.isEditMode()?"Edit":"Add")+" Custom Field");form=this.fb.group({fieldName:["",[B.required,B.maxLength(255)]],fieldType:[null,B.required],accessLevel:[1],requiredForNewClients:[!1],currency:[null],buttonColor:["#3B82F6"],dependencySearch:[""],userSearch:[""]});accessLevels=b(()=>Array.from({length:10},(t,e)=>({id:e+1,label:`Level ${e+1}`})));dropdownOptions=S([]);originalDropdownOptions=S([]);selectedUserIds=S(new Set);selectedDependencyIds=S(new Set);locationSettings=S($e(null));isSubmitting=S(!1);isShowingLoader=S(!0);errorBanner=S(null);isConflictError=S(!1);isRefreshing=S(!1);fieldTypes=b(()=>this.clientService.fieldTypesResource.value()?.fieldTypes??[]);fieldType=ct(this.form.controls.fieldType.valueChanges,{initialValue:this.form.controls.fieldType.value});dependencySearchQuery=ct(this.form.controls.dependencySearch.valueChanges,{initialValue:this.form.controls.dependencySearch.value});userSearchQuery=ct(this.form.controls.userSearch.valueChanges,{initialValue:this.form.controls.userSearch.value});currencies=b(()=>this.clientService.fieldTypesResource.value()?.currencies??[]);currenciesFormatted=b(()=>this.currencies().map(t=>({id:t.id,name:`${t.name} (${t.symbol})`,symbol:t.symbol})));managers=b(()=>this.clientService.managersResource.value()??[]);allCustomFields=b(()=>this.clientService.customFieldsResource.value()??[]);availableDependencyFields=b(()=>{let t=[10,11,12,14];return this.allCustomFields().filter(e=>!t.includes(e.type))});filteredDependencyFields=b(()=>{let t=this.dependencySearchQuery()?.toLowerCase().trim()||"",e=this.availableDependencyFields();return t?e.filter(i=>i.label.toLowerCase().includes(t)):e});filteredManagers=b(()=>{let t=this.userSearchQuery()?.toLowerCase().trim()||"",e=this.managers();return t?e.filter(i=>`${i.user_name} ${i.user_surname}`.toLowerCase().includes(t)):e});selectedUsersCount=b(()=>this.selectedUserIds().size);fieldTypesHasError=b(()=>this.clientService.fieldTypesResource.error()!==void 0);fieldTypesErrorMessage=b(()=>this.clientService.fieldTypesResource.error()?.message??"Failed to load field types");fieldTypeTransformer=t=>({value:t.id,label:t.label});currencyTransformer=t=>({value:t.id,label:`${t.name} (${t.symbol})`});accessLevelTransformer=t=>({value:t.id,label:t.label});onFieldTypeChange(t){let e=t.length>0?t[0]:null;this.form.patchValue({fieldType:e})}onCurrencyChange(t){let e=t.length>0?t[0]:null;this.form.patchValue({currency:e})}onAccessLevelChange(t){let e=t.length>0?t[0]:1;this.form.patchValue({accessLevel:e})}shouldShowRequired=b(()=>{let t=this.fieldType();return t!==10&&t!==11&&t!==12&&t!==14});shouldShowDropdownOptions=b(()=>{let t=this.fieldType();return t===5||t===6});shouldShowCurrency=b(()=>this.fieldType()===13);shouldShowColor=b(()=>this.fieldType()===14);shouldShowUsers=b(()=>{let t=this.fieldType();return t===16||t===17});shouldShowLocation=b(()=>this.fieldType()===20);shouldShowDependencies=b(()=>this.fieldType()===14);selectedDependenciesCount=b(()=>this.selectedDependencyIds().size);constructor(){super(),P(()=>{let t=this.clientService.fieldTypesResource.isLoading(),e=this.clientService.fieldTypesResource.hasValue();t?this.isShowingLoader.set(!0):e&&this.isShowingLoader.set(!1)}),P(()=>{let t=this.fieldType(),e=this.form.controls.currency,i=this.form.controls.fieldType;t===13?e.setValidators([B.required]):e.clearValidators(),e.updateValueAndValidity();let a=this.dropdownOptions().some(v=>v.label.trim()!=="");if((t===5||t===6)&&!a)i.setErrors(L(I({},i.errors),{dropdownRequired:!0}));else if(i.errors?.dropdownRequired){let v=I({},i.errors);delete v.dropdownRequired,i.setErrors(Object.keys(v).length>0?v:null)}let m=this.selectedUserIds();if((t===16||t===17)&&m.size===0)i.setErrors(L(I({},i.errors),{userRequired:!0}));else if(i.errors?.userRequired){let v=I({},i.errors);delete v.userRequired,i.setErrors(Object.keys(v).length>0?v:null)}})}ngOnInit(){}ngAfterViewInit(){this.isEditMode()&&this.data?this.populateFormForEdit():this.form.patchValue({fieldType:1})}populateFormForEdit(){let t=this.data;if(this.form.patchValue({fieldName:t.label,fieldType:t.type,accessLevel:t.access_level,requiredForNewClients:t.required===1}),this.form.controls.fieldType.disable(),t.type===5||t.type===6){let e=t.dropdown_values,i=[];if(Array.isArray(e))i=e.map(a=>({id:Number(a.id),label:a.label,dropdown_order:Number(a.dropdown_order),color:a.color??null}));else if(typeof e=="string"&&e)try{i=JSON.parse(e).map(m=>({id:Number(m.id),label:m.label,dropdown_order:Number(m.dropdown_order),color:m.color??null}))}catch{i=[]}let o=i.map(a=>({id:a.id,label:a.label,color:a.color??null}));this.dropdownOptions.set(o),this.originalDropdownOptions.set(i)}if(t.type===13&&t.currency&&this.form.patchValue({currency:t.currency}),t.type===14&&t.color&&this.form.patchValue({buttonColor:t.color}),t.type===20&&this.locationSettings.set($e(t.settings)),(t.type===16||t.type===17)&&t.user_ids){let e=t.user_ids.split(",").map(i=>parseInt(i.trim())).filter(i=>!isNaN(i));this.selectedUserIds.set(new Set(e))}
1if(t.type===14&&t.dependency_field_ids){let e=t.dependency_field_ids.split(",").map(i=>parseInt(i.trim())).filter(i=>!isNaN(i));this.selectedDependencyIds.set(new Set(e))}}toggleUserSelection(t){this.selectedUserIds.update(e=>{let i=new Set(e);return i.has(t)?i.delete(t):i.add(t),i})}selectAllUsers(){let t=this.managers().map(e=>e.id);this.selectedUserIds.set(new Set(t))}clearAllUsers(){this.selectedUserIds.set(new Set)}toggleDependencySelection(t){this.selectedDependencyIds.update(e=>{let i=new Set(e);return i.has(t)?i.delete(t):i.add(t),i})}selectAllDependencies(){let t=this.availableDependencyFields().map(e=>e.id);this.selectedDependencyIds.set(new Set(t))}clearAllDependencies(){this.selectedDependencyIds.set(new Set)}getIconForFieldType(t){return{1:Qt,2:Dn,4:Mn,5:De,6:De,7:Ei,8:jt,9:jt,10:ki,11:Ui,12:mn,13:un,14:Di,15:Nn,16:nt,17:tn,20:Mi}[t]||Qt}async handleSubmit(){if(this.form.invalid){this.toastService.add("Please fill in all required fields",3e3,"error");return}if(this.shouldShowDropdownOptions()&&!this.optionsToSave().some(t=>t.label.trim()!=="")){this.toastService.add("Please add at least one dropdown option",3e3,"error");return}if(this.shouldShowUsers()&&this.selectedUserIds().size===0){this.toastService.add("Please select at least one user",3e3,"error");return}this.isSubmitting.set(!0),this.errorBanner.set(null),this.isConflictError.set(!1);try{this.isEditMode()?await this.updateField():await this.createField()}catch(t){console.error("Failed to save field:",t);let e=t?.error?.message||t?.message||"An unexpected error occurred. Please try again.";this.errorBanner.set(e),this.isConflictError.set(t?.status===409),this.isSubmitting.set(!1)}}async refreshField(){let t=this.data;if(t){this.isRefreshing.set(!0);try{let i=((await D(this.clientService.getCustomFieldOptions(t.id))).options??[]).map(o=>({id:o.id,label:o.label,dropdown_order:o.dropdown_order??0,color:o.color??null})).sort((o,a)=>o.dropdown_order-a.dropdown_order);this.dropdownOptions.set(i.map(o=>({id:o.id,label:o.label,color:o.color}))),this.originalDropdownOptions.set(i),this.errorBanner.set(null),this.isConflictError.set(!1)}catch(e){this.errorBanner.set(e?.error?.message||"Failed to refresh. Please close and reopen the modal."),this.isConflictError.set(!1)}finally{this.isRefreshing.set(!1)}}}async createField(){let t=this.buildAddParams(),e=await D(this.clientService.addClientField(t));if((e.type===5||e.type===6)&&!e.dropdown_values)try{let i=await D(this.clientService.getCustomFieldOptions(e.id));e.dropdown_values=i.options.map((o,a)=>({id:o.id,label:o.label,dropdown_order:a,color:o.color??null}))}catch(i){console.warn("Failed to fetch dropdown options for new field:",i)}this.close(e)}async updateField(){let t=this.data,e=this.form.getRawValue(),i={};e.fieldName!==t.label&&(i.label=e.fieldName),e.accessLevel!==t.access_level&&(i.access_level=e.accessLevel);let o=e.requiredForNewClients?1:0;o!==t.required&&(i.required=o);let a=this.form.controls.currency.value;t.type===13&&a!==t.currency&&(i.currency=a);let m=this.form.controls.buttonColor.value;t.type===14&&m!==t.color&&(i.color=m),(t.type===16||t.type===17)&&this.hasUserIdsChanged(t)&&(i.user_ids=Array.from(this.selectedUserIds()).join(",")),t.type===14&&this.hasDependencyIdsChanged(t)&&(i.dependency_field_ids=Array.from(this.selectedDependencyIds()).join(","));let v=this.locationSettings();t.type===20&&JSON.stringify(v)!==JSON.stringify($e(t.settings))&&(i.settings=v);let w=(t.type===5||t.type===6)&&this.hasDropdownOptionsChanged(t),U=Object.keys(i).length>0,O=null;if(U||w){let le=this.originalDropdownOptions(),Be=this.optionsToSave(),Ke=le.map(z=>z.id);O=(await D(this.clientService.syncCustomField(t.id,w?Be.map(z=>({id:z.id,label:z.label,color:z.color??null})):null,Ke,U?i:void 0))).options??null}let re=L(I({},t),{label:e.fieldName,access_level:e.accessLevel,required:o});t.type===13&&(re.currency=a),t.type===14&&(re.color=m,this.hasDependencyIdsChanged(t)&&(re.dependency_field_ids=Array.from(this.selectedDependencyIds()).join(","))),t.type===20&&(re.settings=v),(t.type===16||t.type===17)&&this.hasUserIdsChanged(t)&&(re.user_ids=Array.from(this.selectedUserIds()).join(",")),w&&O&&(re.dropdown_values=O.map(le=>({id:le.id,label:le.label,dropdown_order:le.dropdown_order,color:le.color??null}))),this.close(re)}buildAddParams(){let t=this.form.value,e={field_name:t.fieldName,field_type:t.fieldType,field_access_level:t.accessLevel,field_required:t.requiredForNewClients?1:0};if((t.fieldType===5||t.fieldType===6)&&(e.select_options=this.optionsToSave().map(i=>({label:i.label,color:i.color??null}))),t.fieldType===13&&(e.field_currency=t.currency??void 0),t.fieldType===14&&(e.field_color=t.buttonColor,this.selectedDependencyIds().size>0)){let i=Array.from(this.selectedDependencyIds()).join(",");e.field_dependency_ids=i}if(t.fieldType===16||t.fieldType===17){let i=Array.from(this.selectedUserIds()).join(",");e.field_user_ids=i}return t.fieldType===20&&(e.field_settings=this.locationSettings()),e}hasUserIdsChanged(t){let e=t.user_ids?t.user_ids.split(",").map(a=>parseInt(a.trim())).filter(a=>!isNaN(a)):[],i=Array.from(this.selectedUserIds());if(e.length!==i.length)return!0;let o=new Set(e);return!i.every(a=>o.has(a))}hasDependencyIdsChanged(t){let e=t.dependency_field_ids?t.dependency_field_ids.split(",").map(a=>parseInt(a.trim())).filter(a=>!isNaN(a)):[],i=Array.from(this.selectedDependencyIds());if(e.length!==i.length)return!0;let o=new Set(e);return!i.every(a=>o.has(a))}optionsToSave(){return this.dropdownOptions().filter(t=>t.id!==null||t.label.trim()!=="")}hasDropdownOptionsChanged(t){let e=this.originalDropdownOptions(),i=this.optionsToSave();if(e.length!==i.length)return!0;for(let m=0;m<i.length;m++){let v=i[m];if(v.id===null)return!0;let w=e.find(U=>U.id===v.id);if(!w||w.label!==v.label||(w.color??null)!==(v.color??null))return!0}let o=e.map(m=>m.id),a=i.map(m=>m.id);return!o.every((m,v)=>m===a[v])}retryLoadFieldTypes(){this.clientService.fieldTypesResource.reload()}handleCancel(){this.close(void 0)}static \u0275fac=function(e){return new(e||n)};static \u0275cmp=V({type:n,selectors:[["app-custom-field-modal"]],features:[Z],decls:4,vars:3,consts:[["size","xl",3,"closeModal","title"],[3,"ngSubmit","formGroup"],[1,"text-center","py-8"],[1,"text-danger-600","text-sm","mb-3"],["type","button",1,"btn","btn-outline","danger","btn-small",3,"click"],[1,"space-y-3"],[1,"flex","items-start","gap-2","bg-danger-50/10","border","border-danger-200","text-danger-500","rounded-lg","p-3"],["formControlName","fieldName","label","Field Name","placeholder","e.g. Project Status","rounded","lg",3,"showErrorMessage","showRequiredStar","errorPropagateOnTouch"],[1,"text-theme-disabled","text-xs","mt-1"],[1,"flex","justify-end","gap-2","mt-6","pt-4","border-t","border-theme-default"],["type","button",1,"btn","btn-ghost",3,"click"],["type","submit","loadingText","Saving...","buttonClass","btn btn-solid",3,"loading","disabled"],[1,"text-danger-500","mt-0.5","shrink-0",3,"icon"],[1,"flex-1"],[1,"text-sm"],["type","button",1,"mt-1","text-sm","font-medium","text-accent","underline","hover:no-underline",3,"disabled"],["type","button",1,"text-danger-500","hover:text-danger-600","
1shrink-0",3,"click"],["type","button",1,"mt-1","text-sm","font-medium","text-accent","underline","hover:no-underline",3,"click","disabled"],[1,"block","text-sm","font-medium","text-theme-primary","mb-1.5"],[1,"flex","items-center","gap-3","py-4"],[3,"loadingState"],[1,"text-theme-secondary","text-sm"],["size","md","mode","single",3,"selectionChange","dataSource","transformer","selectedValues","label","placeholder","disabled"],[1,"text-theme-secondary","text-xs","mt-1"],[3,"options"],[3,"settings"],[1,"border","border-theme-default","rounded-lg","p-3","bg-surface-subtle"],["size","md","mode","single",3,"selectionChange","dataSource","transformer","selectedValues","label","placeholder"],[1,"mt-3","p-3","bg-surface-elevated","border-l-4","border-accent-500","rounded"],[1,"text-theme-primary","text-sm","font-medium","mb-1"],[1,"flex","hover:bg-surface-hover","p-2","rounded","transition-colors","items-center"],[3,"optionsChange","options"],[3,"settingsChange","settings"],["size","md","mode","single",3,"selectionChange","dataSource","transformer","selectedValues","label","placeholder","showRequiredStar"],["for","color",1,"block","text-sm","font-medium","text-theme-primary","mb-1.5"],[1,"flex","items-center","gap-3"],["id","color","type","color","formControlName","buttonColor",1,"h-5","w-5","rounded-full","border","border-theme-default","cursor-pointer"],[1,"flex","items-center","justify-between","mb-2"],[1,"block","text-sm","font-medium","text-theme-primary"],[1,"ml-2","text-xs","text-accent","font-normal"],[1,"flex","gap-1"],["type","button",1,"text-xs","text-accent-600","hover:text-accent-700","px-2","py-1","hover:bg-surface-hover","rounded","transition-colors",3,"click"],["type","button",1,"text-xs","text-theme-secondary","hover:text-theme-primary","px-2","py-1","hover:bg-surface-hover","rounded","transition-colors",3,"click","disabled"],[1,"mb-2"],["formControlName","dependencySearch","inputType","search","placeholder","Search dependencies...","size","sm","rounded","lg"],[1,"flex","justify-center","py-4"],[1,"relative","border","border-theme-default","rounded-lg","overflow-hidden","bg-surface-component"],[1,"relative","max-h-52","overflow-y-auto","p-1"],[1,"space-y-1"],[1,"flex","items-center","gap-2","p-1.5","hover:bg-surface-hover","rounded","transition-colors","cursor-pointer",3,"for"],[1,"text-theme-secondary","text-xs","p-2","text-center"],["size","sm",3,"valueChange","id","value"],[1,"text-theme-secondary","text-xs",3,"icon"],[1,"text-sm","text-theme-primary"],["formControlName","userSearch","inputType","search","placeholder","Search users...","size","sm","rounded","lg"],[1,"relative","max-h-60","overflow-y-auto","p-1"],[1,"p-1.5","hover:bg-surface-hover","rounded","transition-colors"],["labelPosition","right","size","md",3,"valueChange","id","value","label"],["formControlName","requiredForNewClients","label","Required for new clients","id","required-checkbox","labelPosition","right","size","md"]],template:function(e,i){e&1&&(l(0,"bc-modal",0),f("closeModal",function(){return i.handleCancel()}),l(1,"form",1),f("ngSubmit",function(){return i.handleSubmit()}),C(2,qa,5,1,"div",2)(3,xr,14,10),s()()),e&2&&(p("title",i.modalTitle()),r(),p("formGroup",i.form),r(),h(i.fieldTypesHasError()?2:3))},dependencies:[Se,ne,ce,vn,K,de,ue,pe,me,R,oe,H,ae,q,Re,Ln,Qn,Wn],encapsulation:2,changeDetection:0})};var yr=(n,t)=>t.id;function Sr(n,t){if(n&1){let e=y();l(0,"button",14),f("click",function(){u(e);let o=d();return _(o.toggleEditMode())}),g(1,"fa-icon",6),s()}if(n&2){let e=d();N("text-accent",e.isEditMode())("text-theme-secondary",!e.isEditMode()),r(),p("icon",e.faPencil)}}function Fr(n,t){if(n&1&&c(0),n&2){let e=d(2);x(" (",e.totalFieldsCount(),") ")}}function wr(n,t){if(n&1&&c(0),n&2){let e=d(2);Xe(" (",e.visibleFieldsCount(),"/",e.totalFieldsCount(),") ")}}function Tr(n,t){if(n&1&&(l(0,"span",4),C(1,Fr,1,1)(2,wr,1,2),s()),n&2){let e=d();r(),h(e.showEmptyFields()?1:2)}}function Ir(n,t){if(n&1){let e=y();l(0,"button",15),f("click",function(){u(e);let o=d();return _(o.handleAddField())}),g(1,"fa-icon",16),l(2,"span"),c(3,"Add Field"),s()()}if(n&2){let e=d();r(),p("icon",e.faPlus)}}function Dr(n,t){n&1&&(l(0,"div",10),g(1,"app-loader"),s())}function Er(n,t){if(n&1){let e=y();l(0,"div",11)(1,"p",17),c(2),s(),l(3,"button",18),f("click",function(){u(e);let o=d();return _(o.fieldsResource.reload())}),c(4," Try Again "),s()()}if(n&2){let e=d();r(2),x(" ",e.fieldsResource.error()," ")}}function kr(n,t){if(n&1){let e=y();l(0,"app-custom-field-item",21),f("fieldUpdated",function(o){u(e);let a=d(2);return _(a.handleFieldUpdate(o))})("fieldDeleted",function(o){u(e);let a=d(2);return _(a.handleFieldDelete(o))})("fieldEditRequested",function(o){u(e);let a=d(2);return _(a.handleEditField(o))})("attachToComposer",function(o){u(e);let a=d(2);return _(a.attachToComposer.emit(o))}),s()}if(n&2){let e=t.$implicit,i=d(2);p("field",e)("clientId",i.clientId())("canEdit",i.canEditFields())("canReorder",i.canReorderFields())("isEditMode",i.isEditMode())("allFields",i.allFields())("usersList",i.usersList())}}function Mr(n,t){n&1&&(l(0,"div",13)(1,"p",22),c(2," No fields match your search "),s()())}function Vr(n,t){if(n&1){let e=y();l(0,"div",19),f("cdkDropListDropped",function(o){u(e);let a=d();return _(a.onFieldReorder(o))}),E(1,kr,1,7,"app-custom-field-item",20,yr,!1,Mr,3,0,"div",13),s()}if(n&2){let e=d();r(),k(e.visibleFields())}}function Nr(n,t){n&1&&(l(0,"div",13)(1,"p",22),c(2," No custom fields configured for this client "),s()())}var Oe=class n{clientId=T.required();attachToComposer=M();clientService=F(Q);authService=F(dt);toastService=F(G);modalService=F(ie);faSearch=st;faEye=sn;faEyeSlash=Pi;faPlus=Me;faPencil=Ne;isEditMode=S(!1);showEmptyFields=S(!0);searchQuery=S("");fieldsResource=this.clientService.getClientCustomFieldsValuesResource(()=>this.clientId());resourceFields=b(()=>this.fieldsResource.value()?.fields??[]);usersList=b(()=>(this.clientService.managersResource.value()??[]).map(e=>({user_id:e.id.toString(),first_name:e.user_name,last_name:e.user_surname,email:e.user_email,photo_url:e.photo_url??void 0,status:e.user_status===1?"active":"inactive"})));reorderedFields=S(null);allFields=b(()=>this.reorderedFields()??this.resourceFields());constructor(){P(()=>{this.clientId(),this.isEditMode.set(!1),this.reorderedFields.set(null)}),P(()=>{let t=this.clientService.selectedClient();if(!t)return;let e=this.allFields();if(e.length===0)return;let i=!1,o=e.map(a=>{let m=`custom_field_${a.id}`,v=t[m],w=t[`${m}_text`];if(v!==void 0&&String(v)!==String(a.value??"")){i=!0;let U=L(I({},a),{value:String(v)}
1);return(a.type===18||a.type===19)&&w!==void 0&&(U.client_ref_name=w??null),U}return a});i&&this.reorderedFields.set(o)})}userData=this.authService.userData;canManageFields=b(()=>this.authService.isSuperUser()||this.userData()?.can_manage_custom_fields===1);canToggleEditMode=this.canManageFields;canEditFields=b(()=>(this.userData()?.custom_field_access_level_edit??0)>=1);canReorderFields=b(()=>this.isEditMode()&&this.showEmptyFields()&&this.canManageFields());visibleFields=b(()=>{let t=this.allFields();this.showEmptyFields()||(t=t.filter(i=>[10,11,12,14].includes(i.type)?!0:i.value&&i.value.trim()!==""));let e=this.searchQuery().toLowerCase().trim();return e&&(t=t.filter(i=>{let o=i.label.toLowerCase().includes(e),a=i.value?.toLowerCase().includes(e);return o||a})),t});visibleFieldsCount=b(()=>this.visibleFields().length);totalFieldsCount=b(()=>this.allFields().length);onFieldReorder(t){if(t.previousIndex===t.currentIndex)return;let e=[...this.visibleFields()];zn(e,t.previousIndex,t.currentIndex);let i=e[t.currentIndex],o=t.currentIndex>0?e[t.currentIndex-1]:null,a=t.currentIndex<e.length-1?e[t.currentIndex+1]:null,m=[...this.allFields()],v=m.findIndex(O=>O.id===i.id);m.splice(v,1);let w=0;a?w=m.findIndex(O=>O.id===a.id):o?w=m.findIndex(O=>O.id===o.id)+1:w=0,m.splice(w,0,i),this.reorderedFields.set(m);let U=m.map((O,re)=>({fieldId:O.id,order:re+1}));this.clientService.updateCustomFieldOrder(U).subscribe({next:()=>{this.toastService.add("Custom field order updated successfully",2500,"success")},error:O=>{console.error("Failed to update field order:",O),this.reorderedFields.set(null),this.toastService.add("Failed to reorder custom fields. Please try again.",3500,"error")}})}handleFieldUpdate(t){if(t.success){let i=this.allFields().map(m=>{if(m.id===t.fieldId){let v=L(I({},m),{value:t.value});return(m.type===18||m.type===19)&&t.displayText!==void 0&&(v.client_ref_name=t.displayText),v}return m});this.reorderedFields.set(i);let o=`custom_field_${t.fieldId}`,a={[o]:t.value};t.usersJson!==void 0?a[`${o}_text`]=t.usersJson:t.displayText!==void 0&&(a[`${o}_text`]=t.displayText),t.photoUrl!==void 0&&(a[`${o}_photo_url`]=t.photoUrl),this.clientService.updateClientInList(this.clientId(),a)}}handleFieldDelete(t){let e=this.allFields(),i=e.find(a=>a.id===t),o=e.filter(a=>a.id!==t);this.reorderedFields.set(o),i?.type===14&&this.clientService.customFieldsResource.reload()}async handleAddField(){let t=await this.modalService.showModal(Ge,null);if(t){let e=this.allFields();this.reorderedFields.set([t,...e]),this.toastService.add("Custom field added successfully",2500,"success"),t.type===14&&this.clientService.customFieldsResource.reload(),(t.type===5||t.type===6)&&this.clientService.customFieldsWithDropValuesResource.reload()}}async handleEditField(t){let e=await this.modalService.showModal(Ge,t);if(e){let o=this.allFields().map(a=>a.id===e.id?e:a);this.reorderedFields.set(o),this.clientService.loadTableConfiguration(),(e.type===5||e.type===6)&&this.clientService.customFieldsWithDropValuesResource.reload(),this.toastService.add("Custom field updated successfully",2500,"success")}}toggleShowEmptyFields(){this.showEmptyFields.update(t=>!t)}toggleEditMode(){this.isEditMode.update(t=>!t)}updateSearchQuery(t){this.searchQuery.set(t)}static \u0275fac=function(e){return new(e||n)};static \u0275cmp=V({type:n,selectors:[["app-custom-fields-list"]],inputs:{clientId:[1,"clientId"]},outputs:{attachToComposer:"attachToComposer"},decls:17,vars:11,consts:[[1,"space-y-3"],[1,"flex","items-center","justify-between","gap-3"],[1,"font-headline","font-bold","text-lg","text-theme-primary","flex","items-center","gap-1.5"],["type","button",1,"p-1","rounded","hover:bg-surface-hover","transition-colors",3,"text-accent","text-theme-secondary"],[1,"text-theme-secondary","text-xs","font-normal"],["type","button",1,"btn","btn-ghost","btn-extra-small",3,"click"],[1,"text-xs",3,"icon"],[1,"relative","flex","gap-1"],["placeholder","Search fields...","inputType","search","size","sm","rounded","full",1,"flex-1",3,"ngModelChange","ngModel"],["type","button",1,"btn","btn-ghost","btn-extra-small","text-2xs","px-1","flex-shrink-0"],[1,"flex","items-center","justify-center","py-8"],[1,"text-center","py-6"],["cdkDropList","",1,"flex","flex-col"],[1,"text-center","py-8"],["type","button",1,"p-1","rounded","hover:bg-surface-hover","transition-colors",3,"click"],["type","button",1,"btn","btn-ghost","btn-extra-small","text-2xs","px-1","flex-shrink-0",3,"click"],[1,"text-2xs",3,"icon"],[1,"text-danger-600","text-sm","mb-3"],["type","button",1,"btn","btn-outline","danger","btn-small",3,"click"],["cdkDropList","",1,"flex","flex-col",3,"cdkDropListDropped"],[3,"field","clientId","canEdit","canReorder","isEditMode","allFields","usersList"],[3,"fieldUpdated","fieldDeleted","fieldEditRequested","attachToComposer","field","clientId","canEdit","canReorder","isEditMode","allFields","usersList"],[1,"text-theme-secondary","text-sm"]],template:function(e,i){e&1&&(l(0,"div",0)(1,"div",1)(2,"h3",2),c(3," Custom Fields "),C(4,Sr,2,5,"button",3),C(5,Tr,3,1,"span",4),s(),l(6,"button",5),f("click",function(){return i.toggleShowEmptyFields()}),g(7,"fa-icon",6),l(8,"span"),c(9),s()()(),l(10,"div",7)(11,"bc-text-input",8),f("ngModelChange",function(a){return i.updateSearchQuery(a)}),s(),C(12,Ir,4,1,"button",9),s(),C(13,Dr,2,0,"div",10)(14,Er,5,1,"div",11)(15,Vr,4,1,"div",12)(16,Nr,3,0,"div",13),s()),e&2&&(r(4),h(i.canToggleEditMode()?4:-1),r(),h(i.totalFieldsCount()>0?5:-1),r(),N("text-accent",i.showEmptyFields())("text-theme-secondary",!i.showEmptyFields()),r(),p("icon",i.showEmptyFields()?i.faEye:i.faEyeSlash),r(2),x("",i.showEmptyFields()?"Hide":"Show"," Empty"),r(2),p("ngModel",i.searchQuery()),r(),h(i.canManageFields()?12:-1),r(),h(i.fieldsResource.isLoading()?13:i.fieldsResource.error()?14:i.visibleFields().length>0?15:16))},dependencies:[Se,ne,K,Ae,R,jn,Et,q,H],encapsulation:2,changeDetection:0})};var Lr=(n,t)=>t.client_id,Pr=(n,t)=>t.id;function Ar(n,t){n&1&&(l(0,"div",12),g(1,"app-loader",19),s()),n&2&&(r(),p("loadingState",!0))}function Rr(n,t){n&1&&(l(0,"span",25),c(1," Selected "),s())}function Ur(n,t){if(n&1){let e=y();
1l(0,"li",21),f("click",function(){let o=u(e).$implicit,a=d(2);return _(a.selectClient(o.client_id))}),l(1,"div",22)(2,"div")(3,"p",23),c(4),s(),l(5,"p",24),c(6),s()(),C(7,Rr,2,0,"span",25),s()()}if(n&2){let e=t.$implicit,i=d(2);N("bg-surface-hover",i.isClientSelected(e.client_id))("border-l-2",i.isClientSelected(e.client_id))("border-accent-500",i.isClientSelected(e.client_id))("hover:bg-surface-hover",!i.isClientSelected(e.client_id)),r(4),x(" ",e.company_name," "),r(2),x(" ID: ",e.o_client_id," "),r(),h(i.isClientSelected(e.client_id)?7:-1)}}function $r(n,t){if(n&1&&(l(0,"ul",13),E(1,Ur,8,11,"li",20,Lr),s()),n&2){let e=d();r(),k(e.clients())}}function Or(n,t){if(n&1&&c(0),n&2){let e=d(2);x(' No clients found matching "',e.searchQuery(),'" ')}}function Br(n,t){n&1&&c(0," No additional clients available to link ")}function zr(n,t){if(n&1&&(l(0,"div",14)(1,"p",26),C(2,Or,1,1)(3,Br,1,0),s()()),n&2){let e=d();r(2),h(e.searchQuery()?2:3)}}function Gr(n,t){if(n&1&&(l(0,"span",29),c(1),s()),n&2){let e=t.$implicit;r(),x(" ",e.company_name," ")}}function qr(n,t){if(n&1&&(l(0,"div",15)(1,"p",27),c(2," Currently linked to: "),s(),l(3,"div",28),E(4,Gr,2,1,"span",29,Pr),s()()),n&2){let e=d();r(4),k(e.data==null||e.data.contact==null?null:e.data.contact.linked_clients)}}var kt=class n extends te{clientService=F(Q);toastService=F(G);faLink=Ve;faMagnifyingGlass=Pe;searchQuery=S("");clients=S([]);selectedClientId=S(null);isSearching=S(!1);isLinking=S(!1);hasSearched=S(!1);searchTimeout=null;selectedClient=b(()=>{let t=this.selectedClientId();return t===null?null:this.clients().find(e=>e.client_id===t)??null});contactDisplayName=b(()=>{let t=this.data?.contact;if(!t)return"Contact";let e=[t.user_name,t.user_surname].filter(Boolean);return e.length>0?e.join(" "):t.user_email?t.user_email:t.user_cell_number?t.user_cell_number:"Contact"});onDataSet(){this.data?.currentClientName&&this.searchQuery.set(this.data.currentClientName),this.search()}onSearchInput(t){let e=t.target.value;this.searchQuery.set(e),this.searchTimeout&&clearTimeout(this.searchTimeout),this.searchTimeout=setTimeout(()=>{this.search()},300)}async search(){if(this.data?.contact){this.isSearching.set(!0),this.hasSearched.set(!0);try{let t=await D(this.clientService.searchClientsForContact(this.data.contact.id,this.searchQuery()||void 0));this.clients.set(t.data??[])}catch(t){console.error("Error searching clients:",t),this.clients.set([])}finally{this.isSearching.set(!1)}}}selectClient(t){this.selectedClientId.set(t)}isClientSelected(t){return this.selectedClientId()===t}cancel(){this.close(void 0)}async confirm(){let t=this.selectedClient();if(!(!t||!this.data?.contact||this.isLinking())){this.isLinking.set(!0);try{(await D(this.clientService.linkContact(t.client_id,this.data.contact.id))).status?(this.toastService.add(`Contact linked to ${t.company_name}`,3e3,"success"),this.close({clientId:t.client_id,clientName:t.company_name})):this.toastService.add("Failed to link contact",3e3,"error")}catch(e){console.error("Error linking contact:",e),this.toastService.add("An error occurred while linking contact",3e3,"error")}finally{this.isLinking.set(!1)}}}static \u0275fac=(()=>{let t;return function(i){return(t||(t=se(n)))(i||n)}})();static \u0275cmp=V({type:n,selectors:[["app-link-contact-modal"]],features:[Z],decls:23,vars:8,consts:[["size","lg",3,"onBackdropClick"],[1,"flex","items-center","gap-4","mb-6"],[1,"w-10","h-10","p-2","rounded-lg","flex-shrink-0","flex","items-center","justify-center","bg-accent-50"],[1,"text-xl","text-accent",3,"icon"],[1,"flex-1","min-w-0"],[1,"text-2xl","font-headline","font-bold","text-theme-primary","leading-tight","tracking-normal"],[1,"text-sm","text-theme-secondary","mt-1"],[1,"relative","mb-4"],[1,"absolute","left-3","top-1/2","-translate-y-1/2","text-theme-secondary",3,"icon"],["type","text","placeholder","Search clients...",1,"w-full","pl-10","pr-4","py-2.5","bg-surface-component","border","border-theme-default","rounded-lg","text-theme-primary","placeholder:text-theme-disabled","focus:outline-none","focus:ring-1","ring-theme-default","ring-offset-1","ring-offset-theme",3,"input","value"],[1,"relative","border","border-theme-default","rounded-lg","overflow-hidden","bg-surface-component"],[1,"relative","max-h-[300px]","overflow-y-auto"],[1,"flex","items-center","justify-center","py-12"],[1,"divi
1de-y","divide-theme-subtle-50"],[1,"px-4","py-8","text-center"],[1,"mt-4","p-3","bg-surface-subtle","rounded-lg"],[1,"flex","justify-end","gap-3","border-t","border-theme-default","pt-4","mt-4"],["type","button",1,"btn","btn-ghost",3,"click"],["loadingText","Linking...","buttonClass","btn btn-solid",3,"buttonClick","loading","disabled"],[3,"loadingState"],[1,"px-4","py-3","cursor-pointer","transition-colors",3,"bg-surface-hover","border-l-2","border-accent-500","hover:bg-surface-hover"],[1,"px-4","py-3","cursor-pointer","transition-colors",3,"click"],[1,"flex","items-center","justify-between"],[1,"text-sm","font-medium","text-theme-primary"],[1,"text-xs","text-theme-secondary"],[1,"text-xs","font-medium","text-accent"],[1,"text-theme-secondary","text-sm"],[1,"text-xs","text-theme-secondary","mb-2"],[1,"flex","flex-wrap","gap-2"],[1,"inline-flex","items-center","px-2","py-1","rounded-full","bg-surface-component","text-theme-primary","text-xs","border","border-theme-subtle"]],template:function(e,i){e&1&&(l(0,"bc-modal",0),f("onBackdropClick",function(){return i.cancel()}),l(1,"div",1)(2,"div",2),g(3,"fa-icon",3),s(),l(4,"div",4)(5,"h2",5),c(6," Link Contact "),s(),l(7,"p",6),c(8),s()()(),l(9,"div",7),g(10,"fa-icon",8),l(11,"input",9),f("input",function(a){return i.onSearchInput(a)}),s()(),l(12,"div",10)(13,"div",11),C(14,Ar,2,1,"div",12)(15,$r,3,0,"ul",13)(16,zr,4,1,"div",14),s()(),C(17,qr,6,0,"div",15),l(18,"div",16)(19,"button",17),f("click",function(){return i.cancel()}),c(20," Cancel "),s(),l(21,"bc-loading-button",18),f("buttonClick",function(){return i.confirm()}),c(22," Link to Client "),s()()()),e&2&&(r(3),p("icon",i.faLink),r(5),x(' Link "',i.contactDisplayName(),'" to another client '),r(2),p("icon",i.faMagnifyingGlass),r(),p("value",i.searchQuery()),r(3),h(i.isSearching()?14:i.clients().length>0?15:i.hasSearched()?16:-1),r(3),h(!(i.data==null||i.data.contact==null||i.data.contact.linked_clients==null)&&i.data.contact.linked_clients.length?17:-1),r(4),p("loading",i.isLinking())("disabled",!i.selectedClient()))},dependencies:[ne,R,oe,H,ae],encapsulation:2,changeDetection:0})};function jr(n,t){if(n&1){let e=y();l(0,"button",8),f("click",function(){u(e);let o=d();return _(o.openSettings())}),g(1,"fa-icon",5),s()}if(n&2){let e=d();r(),p("icon",e.faGear)}}function Kr(n,t){if(n&1){let e=y();l(0,"button",10),f("click",function(){u(e);let o=d(2);return _(o.openSmsSettings())}),g(1,"fa-icon",5),s()}if(n&2){let e=d(2);r(),p("icon",e.faGear)}}function Qr(n,t){if(n&1){let e=y();l(0,"li",3)(1,"button",4),f("click",function(){u(e);let o=d();return _(o.sendText())}),g(2,"fa-icon",5),l(3,"span",6),c(4,"Text"),s()(),C(5,Kr,2,1,"button",9),s()}if(n&2){let e=d();r(),ge(e.canText()?"dropdown-menu-item":"dropdown-menu-item opacity-50 cursor-not-allowed"),p("disabled",!e.canText())("title",e.canText()?"":"Complete 10DLC registration to send texts"),r(),p("icon",e.faCommentDots),r(3),h(e.canText()?-1:5)}}function Hr(n,t){if(n&1){let e=y();l(0,"li")(1,"button",11),f("click",function(){u(e);let o=d();return _(o.sendWhatsApp())}),g(2,"fa-icon",5),l(3,"span",6),c(4,"WhatsApp"),s()()()}if(n&2){let e=d();r(2),p("icon",e.faWhatsapp)}}var Mt=class n{phoneNumber=T.required();clientId=T(null);clientName=T("");sipService=F(mo);settingsService=F(Ft);communicationService=F(Tt);extendedPanelService=F(_e);faPhone=qi;faGear=ot;faCommentDots=et;faWhatsapp=mt;hasDid=this.sipService.hasDid;registrationState=this.sipService.registrationState;canCall=b(()=>this.hasDid()&&this.registrationState()==="registered");whatsAppConnected=this.communicationService.whatsAppConnected;hasMessaging=b(()=>this.clientId()!==null);canText=this.communicationService.canSendSms;menuId="phone-chip-"+crypto.randomUUID();dropdown=null;ngAfterViewInit(){let t=document.getElementById(this.menuId+"-btn"),e=document.getElementById(this.menuId+"-menu");t&&e&&(this.dropdown=new gn(e,t,{placement:"bottom-start",triggerType:"click",offsetDistance:8})),this.communicationService.loadSmsStatus()}ngOnDestroy(){this.dropdown?.destroyAndRemoveInstance()}async call(){this.canCall()&&(this.dropdown?.hide(),await this.sipService.makeCall(this.phoneNumber()))}openSettings(){this.dropdown?.hide(),this.settingsService.open("calling",{tab:"phone-numbers"})}openSmsSettings(){this.dropdown?.hide(),this.settingsService.open("calling",{tab:"text-messages"})}sendText(){let t=this.clientId();t&&this.canText()&&(this.dropdown?.hide(),this.extendedPanelService.openWithComponent(fe,{clientId:t,clientName:this.clientName(),initialMode:"sms",initialPhoneTo:this.phoneNumber(),openTimestamp:Date.now()},"Communications"))}sendWhatsApp(){let t=this.clientId();t&&(this.dropdown?.hide(),this.extendedPanelService.openWithComponent(fe,{clientId:t,clientName:this.clientName(),initialMode:"whatsapp",initialPhoneTo:this.phoneNumber(),openTimestamp:Date.now()},"Communications"))}static \u0275fac=function(e){return new(e||n)};static \u0275cmp=V({type:n,selectors:[["bc-phone-chip"]],inputs:{phoneNumber:[1,"phoneNumber"],clientId:[1,"clientId"],clientName:[1,"clientName"]},decls:13,vars:12,consts:[["type","button",1,"inline-flex","items-center","gap-1","text-accent-600","hover:text-accent-700","hover:underline","text-sm","font-mono","focus:outline-none",3,"id"],[1,"text-xs",3,"icon"],[1,"hidden","fixed","dropdown-menu","w-52",3,"id"],[1,"relative"],["type","button",3,"click","disabled","title"],[3,"icon"],[1,"flex-1"],["type","button","title","Get a number",1,"absolute","right-2","top-1/2","-translate-y-1/2","p-1","text-accent-600","hover:text-accent-700","transition-colors"],["type","button","title","Get a number",1,"absolute","right-2","top-1/2","-translate-y-1/2","p-1","text-accent-600","hover:text-accent-700","transition-colors",3,"click"],["type","button","title","Set up text messaging",1,"absolute","right-2","top-1/2","-translate-y-1/2","p-1","text-accent-600","hover:text-accent-700","transition-colors"],["type","button","title","Set up text messaging",1,"absolute","right-2","top-1/2","-translate-y-1/2","p-1","text-accent-600","hover:text-accent-700","transition-colors",3,"click"],["type","button",1,"dropdown-menu-item",3,"click"]],template:function(e,i){e&1&&(l(0,"button",0),g(1,"fa-icon",1),c(2),s(),l(3,"div",2)(4,"ul")(5,"li",3)(6,"button",4),f("click",function(){return i.call()}),g(7,"fa-icon",5),l(8,"span",6),c(9,"Call"),s()(),C(10,jr,2,1,"button",7),s(),C(11,Qr,6,6,"li",3),C(12,Hr,5,1,"li"),s()()),e&2&&(p("id",i.menuId+"-btn"),r(),p("icon",i.faPhone),r(),x(" ",i.phoneNumber(),` 2`),r(),p("id",i.menuId+"-menu"),r(3),ge(i.canCall()?"dropdown-menu-item":"dropdown-menu-item opacity-50 cursor-not-allowed"),p("disabled",!i.canCall())("title",i.canCall()?"":"Phone offline"),r(),p("icon",i.faPhone),r(3),h(i.hasDid()?-1:10),r(),h(i.hasMessaging()?11:-1),r(),h(i.hasMessaging()&&i.whatsAppConnected()?12:-1))},dependencies:[R],encapsulation:2,changeDetection:0})};
2var Co=n=>({$implicit:n}),Nt=(n,t)=>t.id??n,Wr=(n,t)=>t.id;function Jr(n,t){n&1&&(l(0,"div",9),g(1,"app-loader",10),l(2,"p",11),c(3," Loading contacts... "),s()()),n&2&&(r(),p("loadingState",!0))}function Xr(n,t){if(n&1){let e=y();l(0,"div",9),g(1,"fa-icon",12),l(2,"p",13),c(3,"Failed to load contacts"),s(),l(4,"button",14),f("click",function(){u(e);let o=d();return _(o.contactsResource.reload())}),c(5," Retry "),s()()}if(n&2){let e=d();r(),p("icon",e.faAddressBook)}}function Yr(n,t){n&1&&(l(0,"p",26),c(1," No linked contacts "),s())}function Zr(n,t){if(n&1&&(l(0,"div",43)(1,"dt",44),c(2," Email "),s(),l(3,"dd",45)(4,"a",46),c(5),s()()()),n&2){let e=d(2).$implicit;r(4),p("href",qt("mailto:",e.user_email),Bt),r(),A(e.user_email)}}function el(n,t){if(n&1&&(l(0,"div",43)(1,"dt",44),c(2," Cell "),s(),l(3,"dd",47),g(4,"bc-phone-chip",48),s()()),n&2){let e=d(2).$implicit,i=d(4);r(4),p("phoneNumber",e.user_cell_number)("clientId",i.clientId())("clientName",i.clientName())}}function tl(n,t){if(n&1&&(l(0,"div",43)(1,"dt",44),c(2," Tel "),s(),l(3,"dd",47),g(4,"bc-phone-chip",49),s()()),n&2){let e=d(2).$implicit;r(4),p("phoneNumber",e.user_landline_number)}}function il(n,t){if(n&1&&(l(0,"dl",29),C(1,Zr,6,3,"div",43),C(2,el,5,3,"div",43),C(3,tl,5,1,"div",43),s()),n&2){let e=d().$implicit;r(),h(e.user_email?1:-1),r(),h(e.user_cell_number?2:-1),r(),h(e.user_landline_number?3:-1)}}function nl(n,t){if(n&1&&(l(0,"p",31),c(1),s()),n&2){let e=d().$implicit;r(),x(" ",e.notes," ")}}function ol(n,t){if(n&1&&(l(0,"bc-badge",51),c(1),s()),n&2){let e=d().$implicit;p("title",e.company_name),r(),x(" ",e.company_name||"Unnamed Client"," ")}}function al(n,t){if(n&1){let e=y();l(0,"bc-badge",53),f("badgeClick",function(){u(e);let o=d().$implicit,a=d(6);return _(a.openLinkedClient(o.client_id))}),c(1),s()}if(n&2){let e=d().$implicit;p("clickable",!0)("title","Open "+e.company_name),r(),x(" ",e.company_name||"Unnamed Client"," ")}}function rl(n,t){if(n&1&&C(0,ol,2,2,"bc-badge",51)(1,al,2,3,"bc-badge",52),n&2){let e=t.$implicit,i=d(6);h(e.client_id===i.clientId()?0:1)}}function ll(n,t){if(n&1&&(l(0,"div",32)(1,"span",50),c(2,"Clients:"),s(),E(3,rl,2,1,null,null,Nt),s()),n&2){let e=d().$implicit;r(3),k(e.linked_clients)}}function sl(n,t){n&1&&(l(0,"span",35),c(1,"Linked User"),s())}function dl(n,t){n&1&&(l(0,"span",36),c(1,"Invoices"),s())}function cl(n,t){n&1&&(l(0,"span",37),c(1,"No Email"),s())}function ml(n,t){n&1&&(l(0,"span",37),c(1,"No Text"),s())}function pl(n,t){n&1&&g(0,"app-loader",10),n&2&&p("loadingState",!0)}function ul(n,t){if(n&1&&g(0,"fa-icon",7),n&2){let e=d(5);p("icon",e.faLinkSlash)}}function _l(n,t){n&1&&g(0,"app-loader",10),n&2&&p("loadingState",!0)}function fl(n,t){if(n&1&&g(0,"fa-icon",7),n&2){let e=d(5);p("icon",e.faTrashCan)}}function Cl(n,t){n&1&&g(0,"div",42)}function hl(n,t){if(n&1){let e=y();l(0,"div",27)(1,"h5",28),c(2),s(),C(3,il,4,3,"dl",29),zt(4,30),C(5,nl,2,1,"p",31),C(6,ll,5,0,"div",32),l(7,"div",33)(8,"div",34),C(9,sl,2,0,"span",35),C(10,dl,2,0,"span",36),C(11,cl,2,0,"span",37),C(12,ml,2,0,"span",37),s(),l(13,"div",38)(14,"button",39),f("click",function(){let o=u(e).$implicit,a=d(4);return _(a.editContact(o))}),g(15,"fa-icon",7),s(),l(16,"button",40),f("click",function(){let o=u(e).$implicit,a=d(4);return _(a.unlinkContact(o))}),C(17,pl,1,1,"app-loader",10)(18,ul,1,1,"fa-icon",7),s(),l(19,"button",41),f("click",function(){let o=u(e).$implicit,a=d(4);return _(a.deleteContact(o))}),C(20,_l,1,1,"app-loader",10)(21,fl,1,1,"fa-icon",7),s()()(),C(22,Cl,1,0,"div",42),s()}if(n&2){let e=t.$implicit,i=t.$index,o=t.$count,a=d(4),m=Gt(17);r(2),x(" ",a.getContactDisplayName(e)," "),r(),h(a.hasContactInfo(e)?3:-1),r(),p("ngTemplateOutlet",m)("ngTemplateOutletContext",be(18,Co,e)),r(),h(e.notes&&e.notes!=="null"?5:-1),r(),h(e.linked_clients.length>0?6:-1),r(3),h(e.linked_user_id?9:-1),r(),h(e.receive_invoices===1?10:-1),r(),h(e.email_unsubscribe===1?11:-1),r(),h(e.sms_unsubscribe===1?12:-1),r(3),p("icon",a.faPenToSquare),r(),p("disabled",a.isUnlinking(e.id)||!!e.mirror_locked)("title",e.mirror_locked?"Linked user \u2014 remove the user first":"Unlink"),r(),h(a.isUnlinking(e.id)?17:18),r(2),p("disabled",a.isDeleting(e.id)||!!e.linked_user_id)("title",e.linked_user_id?"Linked user \u2014 remove the user first":"Delete"),r(),h(a.isDeleting(e.id)?20:21),r(2),h(i!==o-1?22:-1)}}function gl(n,t){if(n&1&&E(0,hl,23,20,"div",27,Nt),n&2){let e=d(3);k(e.linkedContacts())}}function bl(n,t){if(n&1&&(l(0,"div",24),C(1,Yr,2,0,"p",26)(2,gl,2,0),s()),n&2){let e=d(2);r(),h(e.linkedContacts().length===0?1:2)}}function vl(n,t){n&1&&(l(0,"p",26),c(1," No other contacts found "),s())}function xl(n,t){if(n&1&&(l(0,"div",43)(1,"dt",44),c(2," Email "),s(),l(3,"dd",45)(4,"a",46),c(5),s()()()),n&2){let e=d(2).$implicit;r(4),p("href",qt("mailto:",e.user_email),Bt),r(),A(e.user_email)}}function yl(n,t){if(n&1&&(l(0,"div",43)(1,"dt",44),c(2," Cell "),s(),l(3,"dd",47),g(4,"bc-phone-chip",48),s()()),n&2){let e=d(2).$implicit,i=d(4);r(4),p("phoneNumber",e.user_cell_number)("clientId",i.clientId())("clientName",i.clientName())}}function Sl(n,t){if(n&1&&(l(0,"div",43)(1,"dt",44),c(2," Tel "),s(),l(3,"dd",47),g(4,"bc-phone-chip",49),s()()),n&2){let e=d(2).$implicit;r(4),p("phoneNumber",e.user_landline_number)}}function Fl(n,t){if(n&1&&(l(0,"dl",29),C(1,xl,6,3,"div",43),C(2,yl,5,3,"div",43),C(3,Sl,5,1,"div",43),s()),n&2){let e=d().$implicit;r(),h(e.user_email?1:-1),r(),h(e.user_cell_number?2:-1),r(),h(e.user_landline_number?3:-1)}}function wl(n,t){if(n&1&&(l(0,"p",31),c(1),s()),n&2){let e=d().$implicit;r(),x(" ",e.notes," ")}}function Tl(n,t){if(n&1){let e=y();l(0,"bc-badge",53),f("badgeClick",function(){let o=u(e).$implicit,a=d(6);return _(a.openLinkedClient(o.client_id))}),c(1),s()}if(n&2){let e=t.$implicit;p("clickable",!0)("title","Open "+e.company_name),r(),x(" ",e.company_name||"Unnamed Client"," ")}}function Il(n,t){if(n&1&&(l(0,"div",32)(1,"span",50),c(2,"Linked to:"),s(),E(3,Tl,2,3,"bc-badge",52,Nt),s()),n&2){let e=d().$implicit;r(3),k(e.linked_clients)}}function Dl(n,t){n&1&&(l(0,"span",54),c(1,"Linked User"),s())}function El(n,t){n&1&&(l(0,"span",55),c(1,"Invoices"),s())}function kl(n,t){n&1&&(l(0,"span",56),c(1,"No Email"),s())}function Ml(n,t){n&1&&(l(0,"span",56),c(1,"No Text"),s())}function Vl(n,t){n&1&&g(0,"app-loader",10),n&2&&p("loadingState",!0)}
2function Nl(n,t){if(n&1&&g(0,"fa-icon",7),n&2){let e=d(5);p("icon",e.faTrashCan)}}function Ll(n,t){n&1&&g(0,"div",42)}function Pl(n,t){if(n&1){let e=y();l(0,"div",27)(1,"h5",28),c(2),s(),C(3,Fl,4,3,"dl",29),zt(4,30),C(5,wl,2,1,"p",31),C(6,Il,5,0,"div",32),l(7,"div",33)(8,"div",34),C(9,Dl,2,0,"span",54),C(10,El,2,0,"span",55),C(11,kl,2,0,"span",56),C(12,Ml,2,0,"span",56),s(),l(13,"div",38)(14,"button",39),f("click",function(){let o=u(e).$implicit,a=d(4);return _(a.editContact(o))}),g(15,"fa-icon",7),s(),l(16,"button",57),f("click",function(){let o=u(e).$implicit,a=d(4);return _(a.linkContact(o))}),g(17,"fa-icon",7),s(),l(18,"button",41),f("click",function(){let o=u(e).$implicit,a=d(4);return _(a.deleteContact(o))}),C(19,Vl,1,1,"app-loader",10)(20,Nl,1,1,"fa-icon",7),s()()(),C(21,Ll,1,0,"div",42),s()}if(n&2){let e=t.$implicit,i=t.$index,o=t.$count,a=d(4),m=Gt(17);r(2),x(" ",a.getContactDisplayName(e)," "),r(),h(a.hasContactInfo(e)?3:-1),r(),p("ngTemplateOutlet",m)("ngTemplateOutletContext",be(16,Co,e)),r(),h(e.notes&&e.notes!=="null"?5:-1),r(),h(e.linked_clients.length>0?6:-1),r(3),h(e.linked_user_id?9:-1),r(),h(e.receive_invoices===1?10:-1),r(),h(e.email_unsubscribe===1?11:-1),r(),h(e.sms_unsubscribe===1?12:-1),r(3),p("icon",a.faPenToSquare),r(2),p("icon",a.faLink),r(),p("disabled",a.isDeleting(e.id)||!!e.linked_user_id)("title",e.linked_user_id?"Linked user \u2014 remove the user first":"Delete"),r(),h(a.isDeleting(e.id)?19:20),r(2),h(i!==o-1?21:-1)}}function Al(n,t){if(n&1&&E(0,Pl,22,18,"div",27,Nt),n&2){let e=d(3);k(e.otherContacts())}}function Rl(n,t){if(n&1&&(l(0,"div",24),C(1,vl,2,0,"p",26)(2,Al,2,0),s()),n&2){let e=d(2);r(),h(e.otherContacts().length===0?1:2)}}function Ul(n,t){n&1&&(l(0,"div",25),g(1,"app-loader",10),s()),n&2&&(r(),p("loadingState",!0))}function $l(n,t){if(n&1){let e=y();l(0,"span",15),c(1,"Note: Only 50 contacts are displayed. Search to list more specific contacts."),s(),l(2,"div",16)(3,"div",17)(4,"div",18)(5,"button",19),f("click",function(){u(e);let o=d();return _(o.toggleLinkedSection())}),l(6,"div",20),g(7,"fa-icon",21),l(8,"span",22),c(9,"Linked Contacts"),s(),l(10,"span",23),c(11),s()()(),C(12,bl,3,1,"div",24),s(),l(13,"div",18)(14,"button",19),f("click",function(){u(e);let o=d();return _(o.toggleOtherSection())}),l(15,"div",20),g(16,"fa-icon",21),l(17,"span",22),c(18,"Other Contacts"),s(),l(19,"span",23),c(20),s()()(),C(21,Rl,3,1,"div",24),s()(),C(22,Ul,2,1,"div",25),s()}if(n&2){let e=d();r(3),N("blur-sm",e.refreshing())("opacity-50",e.refreshing())("pointer-events-none",e.refreshing()),r(4),p("icon",e.linkedSectionExpanded()?e.faChevronDown:e.faChevronRight),r(4),A(e.linkedContacts().length),r(),h(e.linkedSectionExpanded()?12:-1),r(4),p("icon",e.otherSectionExpanded()?e.faChevronDown:e.faChevronRight),r(4),A(e.otherContacts().length),r(),h(e.otherSectionExpanded()?21:-1),r(),h(e.refreshing()?22:-1)}}function Ol(n,t){n&1&&(l(0,"span",61),c(1,"Not Set"),s())}function Bl(n,t){if(n&1&&(l(0,"span",62),c(1),s()),n&2){let e=d().$implicit;p("title",e.text),r(),A(e.text)}}function zl(n,t){if(n&1&&(l(0,"bc-badge",64),c(1),s()),n&2){let e=t.$implicit;p("color",e.color),r(),A(e.label)}}function Gl(n,t){if(n&1&&(l(0,"div",63),E(1,zl,2,2,"bc-badge",64,We),s()),n&2){let e=d().$implicit;r(),k(e.pills)}}function ql(n,t){if(n&1&&(l(0,"div",43)(1,"dt",59),c(2),s(),l(3,"dd",60),C(4,Ol,2,0,"span",61)(5,Bl,2,2,"span",62)(6,Gl,3,0,"div",63),s()()),n&2){let e=t.$implicit;r(),p("title",e.label),r(),x(" ",e.label," "),r(2),h(e.empty?4:e.text!==null?5:6)}}function jl(n,t){if(n&1&&(l(0,"dl",58),E(1,ql,7,3,"div",43,Wr),s()),n&2){let e=d();r(),k(e)}}function Kl(n,t){n&1&&C(0,jl,3,0,"dl",58),n&2&&h(t.length>0?0:-1)}function Ql(n,t){if(n&1&&C(0,Kl,1,1),n&2){let e,i=t.$implicit,o=d();h((e=o.customFieldsFor(i))?0:-1,e)}}var Hl=new Set([10,11,12]),Vt=class n{clientService=F(Q);modalService=F(ie);toastService=F(G);contactCustomFieldService=F(Kn);socketService=F(Cn);currencyFormat=new xt;clientId=T.required();clientName=T("");initialSearch=T("");faAddressBook=it;faPlus=Me;faChevronDown=De;faChevronRight=Fe;faMagnifyingGlass=Pe;faPenToSquare=Vn;faTrashCan=En;faLink=kn;faLinkSlash=In;faRefresh=Tn;searchQuery=S("");debouncedQuery=S("");debounceTimeout=null;contactsResource=ze({params:()=>({clientId:this.clientId(),keyword:this.debouncedQuery()}),loader:async({params:t})=>t.clientId?(await D(this.clientService.searchContacts({client_id:t.clientId,keyword:t.keyword||void 0,include_custom_fields:!0}))).items??[]:[]});silentRefresh=S(!1);refetchAfterLoad=!1;refreshing=b(()=>this.contactsResource.isLoading()&&!this.silentRefresh());contacts=S([]);linkedSectionExpanded=S(!0);otherSectionExpanded=S(!1);isDeletingContactId=S(null);isUnlinkingContactId=S(null);linkedContacts=b(()=>{let t=this.clientId();return this.contacts().filter(e=>e.linked_clients?.some(i=>i.client_id===t))});otherContacts=b(()=>{let t=this.clientId();return this.contacts().filter(e=>!e.linked_clients?.some(i=>i.client_id===t))});fieldDefinitions=b(()=>this.contactCustomFieldService.fieldsResource.value()?.fields??[]);customFieldsByContact=b(()=>{let t=this.fieldDefinitions().filter(i=>!Hl.has(i.type)),e=new Map;for(let i of this.contacts()){let o=i.custom_field_values;!o||!this.isContactRecord(i)||e.set(i.id,t.map(a=>this.toCardField(a,o[a.id])))}return e});constructor(){P(()=>{let e=this.initialSearch();e&&(this.searchQuery.set(e),this.debouncedQuery.set(e))}),P(()=>{let e=this.searchQuery();this.debounceTimeout&&clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(()=>this.debouncedQuery.set(e),300)});let t=e=>{this.isShownHere(e.data)&&this.refetchQuietly()};this.socketService.on("contactsChanged",t),F(ei).onDestroy(()=>this.socketService.off("contactsChanged",t)),P(()=>{this.contactsResource.isLoading()||(this.silentRefresh.set(!1),this.refetchAfterLoad&&(this.refetchAfterLoad=!1,ee(()=>this.refetchQuietly())))}),P(()=>{if(this.contactsResource.hasValue()){let e=this.contactsResource.value()??[];this.contacts.set(e.map(i=>L(I({},i),{linked_clients:i.linked_clients??[]})))}})}isShownHere(t){let e=new Set((t.contact_ids??[]).map(Number)),i=new Set((t.client_ids??[]).map(Number));return i.has(this.clientId())||t.kind==="created"&&this.otherSectionExpanded()?!0:this.contacts().some(o=>this.isContactRecord(o)&&e.has(o.id)||o.linked_clients?.some(a=>i.has(a.client_id)))}refetchQuietly(){if(this.contactsResource.isLoading()){this.refetchAfterLoad=!0;return}this.silentRefresh.set(!0),this.contactsResource.reload()}customFieldsFor(t){return this.isContactRecord(t)?this.customFieldsByContact().get(t.id)??[]:[]}isContactRecord(t){return(t.source_type??"contact")==="contact"}toCardField(t,e){let i={id:t.id,label:t.label,empty:!1},o=L(I({},i),{text:null,pills:[],empty:!0});if(e==null||e==="")return t.type===4?L(I({},i),{text:"No",pills:[]}):o;switch(t.type){case 4:return L(I({},i),{text:e==="1"||e==="true"?"Yes":"No",pills:[]});
2case 5:case 6:{let a=Fn(e,t.dropdown_values);return a.length===0?o:a.some(m=>m.color)?L(I({},i),{text:null,pills:a}):L(I({},i),{text:a.map(m=>m.label).join(", "),pills:[]})}case 2:return L(I({},i),{text:Pn(e),pills:[]});case 13:return L(I({},i),{text:this.currencyFormat.transform(Number(e),t.currency_symbol||"$"),pills:[]});default:return L(I({},i),{text:e,pills:[]})}}refreshContactCustomFields(t){this.contactCustomFieldService.fieldsResource.reload(),D(this.contactCustomFieldService.getContactCustomFieldsValues(t)).then(e=>{let i={};for(let o of e.fields??[])o.value!=null&&o.value!==""&&(i[o.id]=o.value);this.contacts.update(o=>o.map(a=>a.id===t&&this.isContactRecord(a)?L(I({},a),{custom_field_values:i}):a))}).catch(e=>{console.error("Error refreshing contact custom fields:",e)})}hasContactInfo(t){return!!(t.user_email||t.user_cell_number||t.user_landline_number)}getContactDisplayName(t){let e=[t.user_name,t.user_surname].filter(Boolean);return e.length>0?e.join(" "):t.user_email?t.user_email:t.user_cell_number?t.user_cell_number:"Unnamed Contact"}onSearchInput(t){this.searchQuery.set(t)}toggleLinkedSection(){this.linkedSectionExpanded.update(t=>!t)}toggleOtherSection(){this.otherSectionExpanded.update(t=>!t)}async addContact(){let t={mode:"add",clientId:this.clientId()},e=await this.modalService.showModal(Ht,t);if(e){let i=L(I({},e.contact),{linked_clients:[...e.contact.linked_clients??[],{id:0,client_id:this.clientId(),o_client_id:0,company_name:""}]});this.contacts.update(o=>[i,...o]),this.linkedSectionExpanded.set(!0),this.refreshContactCustomFields(i.id)}}async editContact(t){let e={mode:"edit",contact:t,clientId:this.clientId()},i=await this.modalService.showModal(Ht,e);i&&this.contacts.update(o=>o.map(a=>a.id===t.id?I(I({},a),i.contact):a)),this.isContactRecord(t)&&this.refreshContactCustomFields(t.id)}async deleteContact(t){let e=this.getContactDisplayName(t);await this.modalService.showModal(Y,{title:"Delete Contact",message:`Are you sure you want to permanently delete "${e}"? This will remove the contact from all linked clients.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger"})&&(this.isDeletingContactId.set(t.id),D(this.clientService.deleteContact(t.id)).then(()=>{this.toastService.add("Contact deleted successfully",3e3,"success"),this.contacts.update(o=>o.filter(a=>a.id!==t.id))}).catch(o=>{console.error("Error deleting contact:",o),this.toastService.add("An error occurred while deleting contact",3e3,"error")}).finally(()=>{this.isDeletingContactId.set(null)}))}async linkContact(t){let e={contact:t,currentClientId:this.clientId(),currentClientName:this.clientName()||""};await this.modalService.showModal(kt,e)&&this.contactsResource.reload()}async unlinkContact(t){let e=this.clientId(),i=t.linked_clients?.find(m=>m.client_id===e);if(!i){this.toastService.add("Contact is not linked to this client",3e3,"error");return}let o=this.getContactDisplayName(t);await this.modalService.showModal(Y,{title:"Unlink Contact",message:`Remove "${o}" from this client? The contact will remain in the system and can be linked again later.`,confirmText:"Unlink",cancelText:"Cancel",variant:"warning"})&&(this.isUnlinkingContactId.set(t.id),D(this.clientService.unlinkContact(i.id)).then(()=>{this.toastService.add("Contact unlinked successfully",3e3,"success"),this.contacts.update(m=>m.map(v=>v.id===t.id?L(I({},v),{linked_clients:v.linked_clients?.filter(w=>w.id!==i.id)??[]}):v))}).catch(m=>{console.error("Error unlinking contact:",m),this.toastService.add("An error occurred while unlinking contact",3e3,"error")}).finally(()=>{this.isUnlinkingContactId.set(null)}))}isDeleting(t){return this.isDeletingContactId()===t}isUnlinking(t){return this.isUnlinkingContactId()===t}openLinkedClient(t){!t||t===this.clientId()||this.clientService.selectClient(t)}static \u0275fac=function(e){return new(e||n)};static \u0275cmp=V({type:n,selectors:[["app-client-contacts-tab"]],inputs:{clientId:[1,"clientId"],clientName:[1,"clientName"],initialSearch:[1,"initialSearch"]},decls:18,vars:5,consts:[["customFieldsTpl",""],[1,"p-3"],[1,"flex","items-center","gap-1","mb-3"],[1,"relative","flex-1"],[1,"absolute","left-2.5","top-1/2","-translate-y-1/2","text-theme-secondary","text-xs",3,"icon"],["placeholder","Search contacts...","inputType","search","size","sm","rounded","full",3,"ngModelChange","ngModel"],["title","Add Contact",1,"flex","items-center","text-2xs","p-1","rounded","hover:bg-surface-hover","text-accent","hover:text-theme-primary","transition-colors",3,"click"],[1,"text-2xs",3,"icon"],["title","Refresh Contacts",1,"gap-0.5","flex","items-center","text-2xs","p-1","rounded","hover:bg-surface-hover","text-theme-secondary","hover:text-theme-primary","transition-colors",3,"click"],[1,"text-center","py-8"],[3,"loadingState"],[1,"text-2xs","text-theme-secondary","mt-1.5"],[1,"text-3xl","text-danger-500","opacity-50","mb-1.5",3,"icon"],[1,"text-2xs","text-danger-600","mb-2"],[1,"btn","btn-outline","btn-extra-small","danger",3,"click"],[1,"text-center","text-theme-secondary","text-2xs","block","mb-2"],[1,"relative"],[1,"space-y-3","transition-all","duration-200"],[1,"border","border-theme-default","rounded-lg","overflow-hidden"],[1,"w-full","flex","items-center","justify-between","px-2","py-1.5","bg-surface-subtle","hover:bg-surface-hover","transition-colors",3,"click"],[1,"flex","items-center","gap-1.5"],[1,"text-2xs","text-theme-secondary",3,"icon"],[1,"text-xs","font-medium","text-theme-primary"],[1,"text-2xs","text-theme-secondary","bg-surface-component","px-1","py-0.5","rounded-full"],[1,"p-1.5","space-y-1.5","bg-surface-component"],[1,"absolute","
2inset-0","flex","items-center","justify-center"],[1,"text-2xs","text-theme-secondary","text-center","py-3"],[1,"px-2","py-1.5"],[1,"text-xs","font-semibold","text-theme-primary","truncate","mb-1"],[1,"space-y-0.5","text-2xs"],[3,"ngTemplateOutlet","ngTemplateOutletContext"],[1,"text-2xs","text-theme-secondary","italic","my-1","line-clamp-2"],[1,"flex","flex-wrap","items-center","gap-1","my-1"],[1,"flex","items-center","justify-between"],[1,"flex","flex-wrap","gap-1","text-[9px]"],[1,"px-1.5","rounded-full","bg-violet-100","text-violet-700"],[1,"px-1.5","rounded-full","bg-neutral-100","text-neutral-700"],[1,"px-1.5","rounded-full","bg-surface-subtle","text-theme-secondary"],[1,"flex","items-center","gap-0.5"],["title","Edit",1,"p-1","rounded","hover:bg-surface-hover","text-theme-secondary","hover:text-theme-primary","transition-colors",3,"click"],[1,"p-1","rounded","hover:bg-surface-hover","text-theme-secondary","hover:text-warning-600","transition-colors","disabled:opacity-50",3,"click","disabled","title"],[1,"p-1","rounded","hover:bg-surface-hover","text-theme-secondary","hover:text-danger-600","transition-colors","disabled:opacity-50",3,"click","disabled","title"],[1,"border-t","border-theme-default","mt-1.5"],[1,"flex","items-center","gap-1"],[1,"text-theme-secondary","w-10","shrink-0"],[1,"text-theme-primary","truncate","min-w-0"],[1,"text-accent-600","hover:text-accent-700",3,"href"],[1,"text-theme-primary"],[3,"phoneNumber","clientId","clientName"],[3,"phoneNumber"],[1,"text-2xs","text-theme-secondary","shrink-0"],["variant","accent","size","xs",3,"title"],["variant","info","size","xs",3,"clickable","title"],["variant","info","size","xs",3,"badgeClick","clickable","title"],[1,"px-1","rounded-full","bg-violet-100","text-violet-700"],[1,"px-1","rounded-full","bg-neutral-100","text-neutral-700"],[1,"px-1","rounded-full","bg-surface-component","text-theme-secondary"],["title","Link to this client",1,"p-1","rounded","hover:bg-surface-hover","text-theme-secondary","hover:text-accent-600","transition-colors",3,"click"],[1,"space-y-0.5","text-2xs","mt-0.5"],[1,"text-theme-secondary","shrink-0","max-w-[40%]","truncate",3,"title"],[1,"text-theme-primary","min-w-0"],[1,"text-theme-disabled"],[1,"block","truncate",3,"title"],[1,"flex","flex-wrap","gap-0.5"],["size","xs",3,"color"]],template:function(e,i){e&1&&(l(0,"div",1)(1,"div",2)(2,"div",3),g(3,"fa-icon",4),l(4,"bc-text-input",5),f("ngModelChange",function(a){return i.onSearchInput(a)}),s()(),l(5,"button",6),f("click",function(){return i.addContact()}),g(6,"fa-icon",7),l(7,"span"),c(8,"Add"),s()(),l(9,"button",8),f("click",function(){return i.contactsResource.reload()}),g(10,"fa-icon",7),l(11,"span"),c(12,"Refresh"),s()()(),C(13,Jr,4,1,"div",9)(14,Xr,6,1,"div",9)(15,$l,23,13),s(),ii(16,Ql,1,1,"ng-template",null,0,gi)),e&2&&(r(3),p("icon",i.faMagnifyingGlass),r(),p("ngModel",i.searchQuery()),r(2),p("icon",i.faPlus),r(4),p("icon",i.faRefresh),r(3),h(i.contacts().length===0&&i.refreshing()?13:i.contactsResource.error()&&i.contacts().length===0?14:15))},dependencies:[R,H,q,ne,K,Ae,Mt,Ie,xi],encapsulation:2,changeDetection:0})};var Wl=(n,t)=>t.id??"root";function Jl(n,t){if(n&1&&g(0,"fa-icon",1),n&2){let e=d(2);p("icon",e.faChevronRight)}}function Xl(n,t){if(n&1&&(l(0,"span",2),c(1),s()),n&2){let e=d().$implicit;p("title",e.label),r(),x(" ",e.label," ")}}function Yl(n,t){if(n&1&&g(0,"fa-icon",5),n&2){let e=d(3);p("icon",e.faHome)}}function Zl(n,t){if(n&1){let e=y();l(0,"button",4),f("click",function(){u(e);let o=d().$implicit,a=d();return _(a.onNavigate(o.id))})("dragover",function(o){u(e);let a=d().$implicit,m=d();return _(m.onBreadcrumbDragOver(a.id,o))})("dragleave",function(){u(e);let o=d().$implicit,a=d();return _(a.onBreadcrumbDragLeave(o.id))})("drop",function(o){u(e);let a=d().$implicit,m=d();return _(m.onBreadcrumbDrop(a.id,o))}),C(1,Yl,1,1,"fa-icon",5),c(2),s()}if(n&2){let e=d().$implicit,i=d();N("ring-2",i.dragOverBreadcrumbId()===e.id)("ring-accent-500",i.dragOverBreadcrumbId()===e.id),p("title",e.label),r(),h(e.id===null?1:-1),r(),x(" ",e.label," ")}}function es(n,t){if(n&1&&(C(0,Jl,1,1,"fa-icon",1),C(1,Xl,2,2,"span",2)(2,Zl,3,7,"button",3)),n&2){let e=t.$implicit,i=t.$index;h(i>0?0:-1),r(),h(e.isLast?1:2)}}var Lt=class n{faHome=Wi;faChevronRight=Fe;foldersTree=T(null);currentFolderId=T(null);navigate=M();breadcrumbDrop=M();attachmentDrop=M();dragOverBreadcrumbId=S(void 0);breadcrumbs=S([{id:null,label:"Home",isLast:!0}]);constructor(){P(()=>{let t=this.foldersTree();if(this.currentFolderId()===null){this.breadcrumbs.set([{id:null,label:"Home",isLast:!0}]);return}if(!t)return;let i=[{id:null,label:"Home",isLast:!1}],o=[],a=t.current;for(;a;)o.unshift(a),a=t.parent&&t.parent.id===a.parent_id?t.parent:null;o.forEach((m,v)=>{i.push({id:m.id,label:m.label,isLast:v===o.length-1})}),this.breadcrumbs.set(i)})}onNavigate(t){this.navigate.emit(t)}onBreadcrumbDragOver(t,e){e.preventDefault(),e.stopPropagation(),this.dragOverBreadcrumbId.set(t)}onBreadcrumbDragLeave(t){this.dragOverBreadcrumbId()===t&&this.dragOverBreadcrumbId.set(void 0)}onBreadcrumbDrop(t,e){e.preventDefault(),e.stopPropagation(),this.dragOverBreadcrumbId.set(void 0);let i=e.dataTransfer?.getData("attachmentData");if(i){this.attachmentDrop.emit({attachmentData:i,targetFolderId:t});return}this.breadcrumbDrop.emit({folderId:t,event:e})}static \u0275fac=function(e){return new(e||n)};static \u0275cmp=V({type:n,selectors:[["app-file-breadcrumb"]],inputs:{foldersTree:[1,"foldersTree"],currentFolderId:[1,"currentFolderId"]},outputs:{navigate:"navigate",breadcrumbDrop:"breadcrumbDrop",attachmentDrop:"attachmentDrop"},decls:3,vars:0,consts:[[1,"flex","items-center","gap-1","flex-nowrap","overflow-hidden","text-xs"],[1,"text-theme-disabled","text-[0.65rem]","flex-shrink-0",3,"icon"],[1,"text-theme-primary","font-medium","truncate",3,"title"],["type","button",1,"text-accent","hover:underline","font-medium","transition-colors","py-1","rounded","truncate","min-w-0","max-w-24",3,"title","ring-2","ring-accent-500"],["type","button",1,"text-accent","hover:underline","font-medium","transition-colors","py-1","rounded","truncate","min-w-0","max-w-24",3,"click","dragover","dragleave","drop","title"],[1,"mr-1",3,"icon"]],template:function(e,i){e&1&&(l(0,"nav",0),E(1,es,3,2,null,null,Wl),s()),e&2&&(r(),k(i.breadcrumbs()))},dependencies:[R],encapsulation:2,changeDetection:0})};var ts=()=>[import("./chunk-IXYFHADA.js").then(n=>n.FileSignaturesComponent)],ho=(n,t)=>t.id;function is(n,t){n&1&&(l(0,"div",2),g(1,"app-loader",3),s()),n&2&&(r(),p("loadingState",!0))}function ns(n,t){if(n&1&&g(0,"fa-icon",6),n&2){let e=d(2);p("icon",e.sortDirection()==="asc"?e.faSortUp:e.faSortDown)}}function os(n,t){if(n&1&&g(0,"fa-icon",6),n&2){let e=d(2);p("icon",e.sortDirection()==="asc"?e.faSortUp:e.faSortDown)}}function as(n,t){n&1&&(l(0,"div",14)(1,"div",26),g(2,"app-loader",3),s()()),n&2&&(r(2),p("loadingState",!0))}function rs(n,t){n&1&&(l(0,"div",15)(1,"div",26),g(2,"app-loader",3),s()()),n&2&&(r(2),p("loadingState",!0))}function ls(n,t){n&1&&(l(0,"div",16)(1,"div",26),g(2,"app-loader",3),s()()),n&2&&(r(2),p("loadingState",!0))}function ss(n,t){if(n&1){let e=y();l(0,"button",27),f("click",function(o){u(e);let a=d().$implicit,m=d(2);return _(m.onLocationClick(a.parent_id,o))}),c(1),s()}if(n&2){let e=d().$implicit;r(),x(" ",e.folder_path??"Home"," ")}}function ds(n,t){if(n&1){let e=y();l(0,"div",13),f("click",function(o){let a=u(e).$implicit,m=d(2);return _(m.onFolderClick(a,o))})("dragstart",function(o){let a=u(e).$implicit,m=d(2);return _(m.onFolderDragStart(a,o))})("dragend",function(o){u(e);let a=d(2);
2return _(a.onFolderDragEnd(o))})("dblclick",function(){let o=u(e).$implicit,a=d(2);return _(a.onFolderDoubleClick(o.id))})("contextmenu",function(o){let a=u(e).$implicit,m=d(2);return _(m.onFolderRightClick(a,o))})("longPress",function(o){let a=u(e).$implicit,m=d(2);return _(m.onFolderRightClick(a,o))})("dragover",function(o){let a=u(e).$implicit,m=d(2);return _(m.onFolderDragOver(a.id,o))})("dragleave",function(){let o=u(e).$implicit,a=d(2);return _(a.onFolderDragLeave(o.id))})("drop",function(o){let a=u(e).$implicit,m=d(2);return _(m.onFolderDrop(a,o))}),C(1,as,3,1,"div",14),C(2,rs,3,1,"div",15),C(3,ls,3,1,"div",16),l(4,"div",17),g(5,"fa-icon",18),l(6,"div",19)(7,"span",20),c(8),s(),C(9,ss,2,1,"button",21),s()(),l(10,"div",22),c(11),xe(12,"date"),s(),l(13,"div",23),c(14," \u2014 "),s(),l(15,"div",24),f("click",function(o){return o.stopPropagation()})("dblclick",function(o){return o.stopPropagation()}),l(16,"bc-context-menu",25),f("actionClick",function(o){let a=u(e).$implicit,m=d(2);return _(m.onFolderAction(o,a))}),s()()()}if(n&2){let e=t.$implicit,i=d(2);N("relative",i.isOperatingOnFolder(e.id))("pointer-events-none",i.isOperatingOnFolder(e.id))("bg-accent-100/10",i.isFolderSelected(e.id))("border-accent-500",i.isFolderSelected(e.id)||i.dragOverFolderId()===e.id)("border-l-4",i.isFolderSelected(e.id)||i.dragOverFolderId()===e.id),r(),h(i.deletingFolderIds().has(e.id)?1:-1),r(),h(i.renamingFolderIds().has(e.id)?2:-1),r(),h(i.movingFolderIds().has(e.id)?3:-1),r(2),p("icon",i.faFolder),r(3),A(e.label),r(),h(i.searchTerm()?9:-1),r(2),x(" ",ye(12,19,e.last_modified,"MMM d, y, h:mm a")," "),r(5),p("menuId","folder-menu-"+e.id)("items",i.getFolderMenuItems(e))}}function cs(n,t){n&1&&g(0,"div",29)}function ms(n,t){n&1&&(l(0,"div",14)(1,"div",26),g(2,"app-loader",3),s()()),n&2&&(r(2),p("loadingState",!0))}function ps(n,t){n&1&&(l(0,"div",15)(1,"div",26),g(2,"app-loader",3),s()()),n&2&&(r(2),p("loadingState",!0))}function us(n,t){n&1&&(l(0,"div",16)(1,"div",26),g(2,"app-loader",3),s()()),n&2&&(r(2),p("loadingState",!0))}function _s(n,t){if(n&1){let e=y();l(0,"button",35),f("click",function(o){u(e);let a=d().$implicit,m=d(2);return _(m.toggleSignatures(a.id,o))})("dblclick",function(o){return o.stopPropagation()}),l(1,"bc-badge",36),c(2),s()()}if(n&2){let e=t,i=d().$implicit,o=d(2);he("aria-expanded",o.expandedSignatureFileId()===i.id)("aria-label","Signature: "+e.label+". Show details"),r(),p("variant",e.variant)("icon",o.faFileSignature),r(),x(" ",e.label," ")}}function fs(n,t){if(n&1){let e=y();l(0,"button",37),f("click",function(o){u(e);let a=d().$implicit,m=d(2);return _(m.onLocationClick(a.parent_id,o))}),c(1),s()}if(n&2){let e=d().$implicit;r(),x(" ",e.folder_path??"Home"," ")}}function Cs(n,t){if(n&1){let e=y();l(0,"app-file-signatures",39),f("changed",function(){u(e);let o=d(5);return _(o.signaturesChanged.emit())}),s()}if(n&2){let e=d();p("requests",e)}}function hs(n,t){n&1&&(l(0,"div",40),g(1,"app-loader"),s())}function gs(n,t){n&1&&(l(0,"div",38),ni(1,Cs,1,1)(2,hs,2,0),ai(3,1,ts,2,null,null,0,null,oi),ri(),s())}function bs(n,t){if(n&1&&C(0,gs,5,0,"div",38),n&2){let e,i=d().$implicit,o=d(2);h((e=o.signaturesByFile().get(i.id))?0:-1,e)}}function vs(n,t){if(n&1){let e=y();l(0,"div",28),f("click",function(o){let a=u(e).$implicit,m=d(2);return _(m.onFileClick(a,o))})("dragstart",function(o){let a=u(e).$implicit,m=d(2);return _(m.onFileDragStart(a,o))})("dragend",function(o){u(e);let a=d(2);return _(a.onFileDragEnd(o))})("contextmenu",function(o){let a=u(e).$implicit,m=d(2);return _(m.onFileRightClick(a,o))})("longPress",function(o){let a=u(e).$implicit,m=d(2);return _(m.onFileRightClick(a,o))}),C(1,cs,1,0,"div",29),C(2,ms,3,1,"div",14),C(3,ps,3,1,"div",15),C(4,us,3,1,"div",16),l(5,"div",17),g(6,"fa-icon",30),l(7,"div",19)(8,"span",31),c(9),s(),C(10,_s,3,5,"button",32),C(11,fs,2,1,"button",33),s()(),l(12,"div",22),c(13),xe(14,"date"),s(),l(15,"div",23),c(16),s(),l(17,"div",34),f("click",function(o){return o.stopPropagation()}),l(18,"bc-context-menu",25),f("actionClick",function(o){let a=u(e).$implicit,m=d(2);return _(m.onFileAction(o,a))}),s()()(),C(19,bs,1,1)}if(n&2){let e,i=t.$implicit,o=d(2);N("relative",o.isOperatingOnFile(i.id)||o.newFileIds().has(i.id))("pointer-events-none",o.isOperatingOnFile(i.id))("bg-accent-100/10",o.isFileSelected(i.id))("border-accent-500",o.isFileSelected(i.id))("border-l-4",o.isFileSelected(i.id)),r(),h(o.newFileIds().has(i.id)?1:-1),r(),h(o.deletingFileIds().has(i.id)?2:-1),r(),h(o.renamingFileIds().has(i.id)?3:-1),r(),h(o.movingFileIds().has(i.id)?4:-1),r(2),ge(o.getFileIconColor(i.contentType,i.file_name)),p("icon",o.getFileIcon(i.contentType,i.file_name)),r(3),A(i.file_name),r(),h((e=o.signatureSummaryFor(i.id))?10:-1,e),r(),h(o.searchTerm()?11:-1),r(2),x(" ",ye(14,25,i.last_modified,"MMM d, y, h:mm a")," "),r(3),x(" ",o.formatFileSize(i.size)," "),r(2),p("menuId","file-menu-"+i.id)("items",o.getFileMenuItems(i)),r(),h(o.expandedSignatureFileId()===i.id?19:-1)}}function xs(n,t){if(n&1&&(l(0,"p",42),c(1),s(),l(2,"p",43),c(3," No file or folder for this client has that in its name. "),s()),n&2){let e=d(3);r(),x(' Nothing matches "',e.searchTerm(),'" ')}}function ys(n,t){if(n&1){let e=y();l(0,"p",42),c(1," This folder is empty "),s(),l(2,"p",43)(3,"button",44),f("click",function(){u(e);let o=d(3);return _(o.onUploadTrigger())}),c(4," Upload files "),s(),l(5,"span"),c(6," or "),s(),l(7,"button",44),f("click",function(){u(e);let o=d(3);return _(o.onCreateFolderTrigger())}),c(8," create subfolders "),s(),l(9,"span"),c(10," to get started"),s()()}}function Ss(n,t){if(n&1&&(l(0,"div",11),g(1,"fa-icon",41),C(2,xs,4,1)(3,ys,11,0),s()),n&2){let e=d(2);r(),p("icon",e.faFolderOpen),r(),h(e.searchTerm()?2:3)}}function Fs(n,t){if(n&1){let e=y();l(0,"div",12)(1,"p",43)(2,"button",44),f("click",function(){u(e);let o=d(2);return _(o.onUploadTrigger())}),c(3," Upload more files "),s(),l(4,"span"),c(5," or "),s(),l(6,"button",44),f("click",function(){u(e);let o=d(2);return _(o.onCreateFolderTrigger())}),c(7," create a new subfolder "),s()()()}}function ws(n,t){if(n&1){let e=y();l(0,"div",4)(1,"div",5),f("click",function(){u(e);let o=d();return _(o.toggleSort("name"))}),c(2," Name "),C(3,ns,1,1,"fa-icon",6),s(),l(4,"div",7),f("click",function(){u(e);let o=d();return _(o.toggleSort("last_modified"))}),c(5," Last Modified "),C(6,os,1,1,"fa-icon",6),s(),l(7,"div",8),c(8," File Size "),s(),g(9,"div",9),s(),E(10,ds,17,22,"div",10,ho),E(12,vs,20,28,null,null,ho),C(14,Ss,4,2,"div",11)(15,Fs,8,0,"div",12)}if(n&2){let e=d();r(3),h(e.sortField()==="name"?3:-1),r(3),h(e.sortField()==="last_modified"?6:-1),r(4),k(e.sortedFolders()),r(2),k(e.sortedFiles()),r(2),h(e.folders().length===0&&e.files().length===0?14:e.searchTerm()?-1:15)}}function go(n,t){let e=new Set([...n].filter(i=>t.has(i)));return e.size===n.size?n:e}var Pt=class n{faFolder=at;faFolderOpen=nn;faEdit=lt;faTrash=X;faSortUp=dn;faSortDown=Fi;faFileSignature=rt;sortField=S(null);sortDirection=S("asc");sortedFolders=b(()=>{let t=[...this.folders()],e=this.sortField();if(!e)return t;let i=this.sortDirection();return t.sort((o,a)=>{let m;return e==="name"?m=o.label.localeCompare(a.label):m=new Date(o.last_modified).getTime()-new Date(a.last_modified).getTime(),i==="asc"?m:-m})});sortedFiles=b(()=>{let t=[...this.files()],e=this.sortField();if(!e)return t;let i=this.sortDirection();return t.sort((o,a)=>{let m;return e==="name"?m=o.file_name.localeCompare(a.file_name):m=new Date(o.last_modified).getTime()-new Date(a.last_modified).getTime(),i==="asc"?m:-m})});toggleSort(t){if(this.sortField()===t){let i=t==="name"?"asc":"desc";this.sortDirection()===i?this.sortDirection.set(i==="asc"?"desc":"asc"):this.sortField.set(null)}else this.sortField.set(t),this.sortDirection.set(t==="name"?"asc":"desc")}folders=T.required();files=T.required();isLoading=T.required();searchTerm=T("");isDragging=T(!1);renamingFolderIds=T(new Set);renamingFileIds=T(new Set);deletingFolderIds=T(new Set);deletingFileIds=T(new Set);movingFolderIds=T(new Set);movingFileIds=T(new Set);newFileIds=T(new Set);
2signaturesByFile=T(new Map);protectedPdfIds=T(new Set);expandedSignatureFileId=S(null);signatureSummaryFor(t){let e=this.signaturesByFile().get(t)?.[0];return e?oo(e):null}toggleSignatures(t,e){e.stopPropagation(),this.expandedSignatureFileId.update(i=>i===t?null:t)}folderClick=M();locationClick=M();folderAction=M();fileAction=M();signaturesChanged=M();multiSelectAction=M();dropUpload=M();fileDragStart=M();folderDragStart=M();multiItemDragStart=M();folderDrop=M();attachmentDrop=M();dragEnter=M();dragLeave=M();uploadTrigger=M();createFolderTrigger=M();selectedFileIds=S(new Set);selectedFolderIds=S(new Set);dragOverFolderId=S(null);dragEnterCounter=0;contextMenuService=F(Ct);extendedPanelService=F(_e);getFileIcon=_t;getFileIconColor=ft;formatFileSize=Rn;ngAfterViewInit(){}isOperatingOnFolder(t){return this.renamingFolderIds().has(t)||this.deletingFolderIds().has(t)||this.movingFolderIds().has(t)}isOperatingOnFile(t){return this.renamingFileIds().has(t)||this.deletingFileIds().has(t)||this.movingFileIds().has(t)}isFileSelected(t){return this.selectedFileIds().has(t)}isFolderSelected(t){return this.selectedFolderIds().has(t)}constructor(){P(()=>{let t=new Set(this.folders().map(i=>i.id)),e=new Set(this.files().map(i=>i.id));ee(()=>{this.selectedFolderIds.update(i=>go(i,t)),this.selectedFileIds.update(i=>go(i,e))})})}hasMultipleSelections(){return this.selectedFileIds().size+this.selectedFolderIds().size>1}getSelectedFiles(){return this.sortedFiles().filter(t=>this.selectedFileIds().has(t.id))}getSelectedFolders(){return this.folders().filter(t=>this.selectedFolderIds().has(t.id))}clearSelection(){this.selectedFileIds.set(new Set),this.selectedFolderIds.set(new Set),this.lastClickedIndex=-1}lastClickedIndex=-1;getFolderIndex(t){return this.sortedFolders().findIndex(e=>e.id===t)}getFileIndex(t){let e=this.sortedFiles().findIndex(i=>i.id===t);return e===-1?-1:this.sortedFolders().length+e}applyRangeSelection(t,e){if(t===-1||e===-1)return;let i=this.sortedFolders(),o=this.sortedFiles(),a=Math.max(0,Math.min(t,e)),m=Math.max(t,e),v=new Set,w=new Set;for(let U=a;U<=m;U++)if(U<i.length)v.add(i[U].id);else{let O=U-i.length;O<o.length&&w.add(o[O].id)}this.selectedFolderIds.set(v),this.selectedFileIds.set(w)}onKeyDown(t){if((t.ctrlKey||t.metaKey)&&t.key==="a"){let e=document.activeElement;if(e&&(e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e.isContentEditable)||this.folders().length===0&&this.files().length===0||this.extendedPanelService.isOpen())return;t.preventDefault(),this.selectedFolderIds.set(new Set(this.folders().map(i=>i.id))),this.selectedFileIds.set(new Set(this.files().map(i=>i.id)))}}onFileClick(t,e){let i=this.getFileIndex(t.id);if(e.shiftKey&&this.lastClickedIndex!==-1)e.preventDefault(),e.stopPropagation(),this.applyRangeSelection(this.lastClickedIndex,i);else if(e.ctrlKey||e.metaKey){e.preventDefault(),e.stopPropagation();let o=new Set(this.selectedFileIds());o.has(t.id)?o.delete(t.id):o.add(t.id),this.selectedFileIds.set(o),this.lastClickedIndex=i}else e.stopPropagation(),this.selectedFileIds.set(new Set([t.id])),this.selectedFolderIds.set(new Set),this.lastClickedIndex=i,this.extendedPanelService.openWithComponent(no,{file:t},t.file_name,90)}onFolderClick(t,e){let i=this.getFolderIndex(t.id);if(e.shiftKey&&this.lastClickedIndex!==-1)e.preventDefault(),e.stopPropagation(),this.applyRangeSelection(this.lastClickedIndex,i);else if(e.ctrlKey||e.metaKey){e.preventDefault(),e.stopPropagation();let o=new Set(this.selectedFolderIds());o.has(t.id)?o.delete(t.id):o.add(t.id),this.selectedFolderIds.set(o),this.lastClickedIndex=i}else e.stopPropagation(),this.selectedFolderIds.set(new Set([t.id])),this.selectedFileIds.set(new Set),this.lastClickedIndex=i}getFolderMenuItems(t){let e=this.isOperatingOnFolder(t.id);return[{icon:on,label:"Upload File Here",action:"upload",disabled:e},{icon:lt,label:"Rename Folder",action:"rename",disabled:e},{icon:X,label:"Delete Folder",action:"delete",variant:"danger",disabled:e}]}isPdf(t){return t.contentType==="application/pdf"}isSignable(t){return this.isPdf(t)}getFileMenuItems(t){let e=this.isOperatingOnFile(t.id);return[{icon:Li,label:"Open in New Tab",action:"open",disabled:e},{icon:Ve,label:"Copy Link",action:"copy-link",disabled:e},{icon:we,label:"Attach to Email",action:"attach-email",disabled:e},{icon:rt,label:"Send for Signature",action:"send-for-signature",disabled:e||!this.isSignable(t),tooltip:this.isSignable(t)?void 0:"Only PDF documents can be sent for signature"},{icon:Ki,label:"Remove Password",action:"remove-password",hidden:!this.protectedPdfIds().has(t.id),disabled:e},{icon:Ze,label:"Add Password",action:"add-password",hidden:!this.isPdf(t)||this.protectedPdfIds().has(t.id),disabled:e},{icon:tt,label:"View Audit Trail",action:"view-audit-trail",hidden:!this.signaturesByFile().has(t.id),disabled:e}
2,{icon:Le,label:"Attach to Workflow Note",action:"attach-note",disabled:e},{icon:Ri,label:"Download",action:"download",disabled:e},{icon:lt,label:"Rename",action:"rename",disabled:e},{icon:X,label:"Delete",action:"delete",variant:"danger",disabled:e}]}getMultiSelectMenuItems(){let t=this.getSelectedFiles(),e=this.getSelectedFolders(),i=t.length+e.length,o=t.length,a=[{icon:X,label:`Delete All (${i})`,action:"delete-all",variant:"danger"}],m=t.filter(v=>this.isSignable(v)).length;return o>0&&e.length===0&&m===o&&a.push({icon:rt,label:`Send ${o} for Signature`,action:"send-all-for-signature"}),o>1&&e.length===0&&t.every(v=>this.isPdf(v))&&a.push({icon:wi,label:`Combine ${o} PDFs into One`,action:"merge-pdfs"}),o>0&&a.push({icon:we,label:`Attach to Email (${o})`,action:"attach-all-email"},{icon:Le,label:`Attach to WFN (${o})`,action:"attach-all-wfn"}),a}onLocationClick(t,e){e.preventDefault(),e.stopPropagation(),this.locationClick.emit(t)}onFolderDoubleClick(t){this.clearSelection(),this.folderClick.emit(t)}onFolderAction(t,e){this.folderAction.emit({action:t,folder:e})}onFileAction(t,e){this.fileAction.emit({action:t,file:e})}onMultiSelectAction(t){let e=this.getSelectedFiles(),i=this.getSelectedFolders();this.multiSelectAction.emit({action:t,folders:i,files:e}),this.clearSelection()}onDragEnter(t){t.preventDefault(),t.stopPropagation(),t.dataTransfer?.types.includes("Files")&&(this.dragEnterCounter++,this.dragEnterCounter===1&&this.dragEnter.emit())}onDragOver(t){t.preventDefault(),t.stopPropagation()}onDragLeave(t){t.preventDefault(),t.stopPropagation(),t.dataTransfer?.types.includes("Files")&&(this.dragEnterCounter--,this.dragEnterCounter===0&&this.dragLeave.emit())}onDrop(t){t.preventDefault(),t.stopPropagation(),this.dragEnterCounter=0,this.dragLeave.emit();let e=t.dataTransfer?.getData("attachmentData");if(e){this.attachmentDrop.emit({attachmentData:e,targetFolderId:null});return}this.dropUpload.emit({event:t})}onFileDragStart(t,e){if(this.isOperatingOnFile(t.id)){e.preventDefault();return}this.isFileSelected(t.id)?this.startMultiItemDrag(e):(e.target instanceof HTMLElement&&(e.target.style.opacity="0.4",e.dataTransfer&&this.createDragImage(e,t.file_name)),this.fileDragStart.emit({file:t,event:e}))}onFileDragEnd(t){t.target instanceof HTMLElement&&(t.target.style.opacity="1")}onFolderDragStart(t,e){if(this.isOperatingOnFolder(t.id)){e.preventDefault();return}this.isFolderSelected(t.id)?this.startMultiItemDrag(e):(e.target instanceof HTMLElement&&(e.target.style.opacity="0.4",e.dataTransfer&&this.createDragImage(e,t.label)),this.folderDragStart.emit({folder:t,event:e}))}onFolderDragEnd(t){t.target instanceof HTMLElement&&(t.target.style.opacity="1")}startMultiItemDrag(t){let e=this.getSelectedFiles(),i=this.getSelectedFolders(),o=e.length+i.length;if(t.target instanceof HTMLElement&&(t.target.style.opacity="0.4"),t.dataTransfer){t.dataTransfer.effectAllowed="copyMove",e.length>0&&(t.dataTransfer.setData("fileIds",e.map(v=>v.id).join(",")),t.dataTransfer.setData("fileItemsData",JSON.stringify(e)),ht(t.dataTransfer,e.map(v=>({url:v.file_url,name:v.file_name,type:v.contentType})))),i.length>0&&t.dataTransfer.setData("folderIds",i.map(v=>v.id).join(","));let a=document.createElement("div");a.textContent=`${o} item${o>1?"s":""}`,a.style.position="absolute",a.style.top="-9999px",a.style.padding="8px 12px";let m=getComputedStyle(document.documentElement).getPropertyValue("--color-accent").trim();a.style.backgroundColor=m?`rgb(${m})`:"#3b82f6",a.style.color="white",a.style.borderRadius="6px",a.style.fontSize="14px",a.style.fontWeight="500",document.body.appendChild(a),t.dataTransfer.setDragImage(a,0,0),setTimeout(()=>a.remove(),0)}this.multiItemDragStart.emit({files:e,folders:i,event:t})}createDragImage(t,e){if(!t.target||!t.dataTransfer)return;let i=document.createElement("div");i.style.cssText=` 3 position: absolute; 4 top: -9999px; 5 left: -9999px; 6 padding: 8px 12px; 7 background: rgb(var(--color-surface-elevated)); 8 border: 1px solid rgb(var(--color-border-theme-default)); 9 border-radius: 8px; 10 box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); 11 display: flex; 12 align-items: center; 13 gap: 8px; 14 max-width: 300px; 15 pointer-events: none; 16 opacity: 0.95; 17 `;let o=t.target.querySelector("fa-icon");if(o){let m=o.cloneNode(!0);m.style.fontSize="18px",i.appendChild(m)}let a=document.createElement("span");a.textContent=e,a.style.cssText=` 18 color: rgb(var(--color-text-theme-primary)); 19 font-weight: 500; 20 white-space: nowrap; 21 overflow: hidden; 22 text-overflow: ellipsis; 23 `,i.appendChild(a),document.body.appendChild(i),t.dataTransfer.setDragImage(i,0,0),setTimeout(()=>i.remove(),0)}onFolderDragOver(t,e){e.preventDefault(),e.stopPropagation(),this.dragOverFolderId.set(t)}onFolderDragLeave(t){this.dragOverFolderId()===t&&this.dragOverFolderId.set(null)}onFolderDrop(t,e){e.preventDefault(),e.stopPropagation(),this.dragOverFolderId.set(null),this.dragEnterCounter=0,this.dragLeave.emit();let i=e.dataTransfer?.getData("attachmentData");if(i){this.attachmentDrop.emit({attachmentData:i,targetFolderId:t.id});return}this.folderDrop.emit({folder:t,event:e})}onUploadTrigger(){this.uploadTrigger.emit()}onCreateFolderTrigger(){this.createFolderTrigger.emit()}onFolderRightClick(t,e){this.isOperatingOnFolder(t.id)||(this.isFolderSelected(t.id)||(this.selectedFolderIds.set(new Set([t.id])),this.selectedFileIds.set(new Set),this.lastClickedIndex=this.getFolderIndex(t.id)),this.hasMultipleSelections()?this.contextMenuService.show(e,this.getMultiSelectMenuItems(),i=>this.onMultiSelectAction(i)):this.contextMenuService.show(e,this.getFolderMenuItems(t),i=>this.onFolderAction(i,t)))}onFileRightClick(t,e){this.isOperatingOnFile(t.id)||(this.isFileSelected(t.id)||(this.selectedFileIds.set(new Set([t.id])),this.selectedFolderIds.set(new Set),this.lastClickedIndex=this.getFileIndex(t.id)),this.hasMultipleSelections()?this.contextMenuService.show(e,this.getMultiSelectMenuItems(),i=>this.onMultiSelectAction(i)):this.contextMenuService.show(e,this.getFileMenuItems(t),i=>this.onFileAction(i,t)))}static \u0275fac=function(e){return new(e||n)};static \u0275cmp=V({type:n,selectors:[["app-file-list"]],hostAttrs:[1,"flex","flex-1","flex-col"],hostBindings:function(e,i){e&1&&f("keydown",function(a){return i.onKeyDown(a)},ti)},inputs:{folders:[1,"folders"],files:[1,"files"],isLoading:[1,"isLoading"],searchTerm:[1,"searchTerm"],isDragging:[1,"isDragging"],renamingFolderIds:[1,"renamingFolderIds"],renamingFileIds:[1,"renamingFileIds"],deletingFolderIds:[1,"deletingFolderIds"],deletingFileIds:[1,"deletingFileIds"],mov
23ingFolderIds:[1,"movingFolderIds"],movingFileIds:[1,"movingFileIds"],newFileIds:[1,"newFileIds"],signaturesByFile:[1,"signaturesByFile"],protectedPdfIds:[1,"protectedPdfIds"]},outputs:{folderClick:"folderClick",locationClick:"locationClick",folderAction:"folderAction",fileAction:"fileAction",signaturesChanged:"signaturesChanged",multiSelectAction:"multiSelectAction",dropUpload:"dropUpload",fileDragStart:"fileDragStart",folderDragStart:"folderDragStart",multiItemDragStart:"multiItemDragStart",folderDrop:"folderDrop",attachmentDrop:"attachmentDrop",dragEnter:"dragEnter",dragLeave:"dragLeave",uploadTrigger:"uploadTrigger",createFolderTrigger:"createFolderTrigger"},decls:3,vars:7,consts:[[200,null],[1,"flex","flex-1","flex-col",3,"dragenter","dragover","dragleave","drop"],[1,"flex","items-center","justify-center","py-12"],[3,"loadingState"],[1,"grid","grid-cols-12","gap-3","px-4","py-2","bg-surface-subtle","border-b","border-theme-default","text-sm","font-medium","text-theme-secondary"],[1,"col-span-12","sm:col-span-9","md:col-span-6","flex","items-center","gap-1","cursor-pointer","select-none",3,"click"],[1,"text-xs","text-theme-secondary",3,"icon"],[1,"hidden","md:flex","md:col-span-3","items-center","gap-1","cursor-pointer","select-none",3,"click"],[1,"hidden","sm:block","sm:col-span-2","md:col-span-2"],[1,"hidden","sm:block","sm:col-span-1","md:col-span-1"],["draggable","true","appLongPress","",1,"grid","grid-cols-12","gap-3","px-4","py-2","hover:bg-surface-hover","transition-colors","cursor-pointer","items-center",3,"relative","pointer-events-none","bg-accent-100/10","border-accent-500","border-l-4"],[1,"flex","flex-col","items-center","justify-center","py-16","text-center","transition-colors"],[1,"px-4","py-6","text-center","border-t","border-theme-default"],["draggable","true","appLongPress","",1,"grid","grid-cols-12","gap-3","px-4","py-2","hover:bg-surface-hover","transition-colors","cursor-pointer","items-center",3,"click","dragstart","dragend","dblclick","contextmenu","longPress","dragover","dragleave","drop"],[1,"absolute","inset-0","z-50","flex","items-center","justify-center","bg-danger-500/20","rounded","backdrop-blur-[2px]"],[1,"absolute","inset-0","z-50","flex","items-center","justify-center","bg-accent-500/10","rounded","backdrop-blur-[2px]"],[1,"absolute","inset-0","z-50","flex","items-center","justify-center","bg-neutral-500/10","rounded","backdrop-blur-[2px]"],[1,"col-span-12","sm:col-span-9","md:col-span-6","flex","items-center","gap-2"],[1,"text-accent","text-lg","flex-shrink-0",3,"icon"],[1,"min-w-0"],[1,"block","text-theme-primary","font-medium","truncate","text-sm"],["type","button","title","Go to this folder",1,"block","max-w-full","truncate","text-xs","text-theme-secondary","hover:text-accent","hover:underline","text-left"],[1,"hidden","md:block","md:col-span-3","text-theme-secondary","text-xs"],[1,"hidden","sm:block","sm:col-span-2","md:col-span-2","text-theme-secondary","text-xs"],[1,"hidden","sm:flex","sm:col-span-1","md:col-span-1","justify-end",3,"click","dblclick"],[3,"actionClick","menuId","items"],[1,"w-8","h-8"],["type","button","title","Go to this folder",1,"block","max-w-full","truncate","text-xs","text-theme-secondary","hover:text-accent","hover:underline","text-left",3,"click"],["draggable","true","appLongPress","",1,"grid","grid-cols-12","gap-3","px-4","py-2","hover:bg-surface-hover","transition-colors","items-center","cursor-pointer",3,"click","dragstart","dragend","contextmenu","longPress"],[1,"animate-row-flash-success","pointer-events-none","absolute","inset-0","z-10","rounded"],[1,"text-lg","flex-shrink-0",3,"icon"],[1,"block","text-theme-primary","truncate","text-sm"],["type","button",1,"mt-0.5","flex","items-center","gap-1","rounded-full"],["type","button","title","Go to the folder holding this file",1,"block","max-w-full","truncate","text-xs","text-theme-secondary","hover:text-accent","hover:underline","text-left"],[1,"hidden","sm:flex","sm:col-span-1","md:col-span-1","justify-end",3,"click"],["type","button",1,"mt-0.5","flex","items-center","gap-1","rounded-full",3,"click","dblclick"],["size","xs",3,"variant","icon"],["type","button","title","Go to the folder holding this file",1,"block","max-w-full","truncate","text-xs","text-theme-secondary","hover:text-accent","hover:underline","text-left",3,"click"],[1,"px-4","pb-2","pt-1"],[3,"changed","requests"],[1,"flex","justify-center","py-2"],[1,"text-theme-disabled","text-6xl","mb-4",3,"icon"],[1,"text-theme-secondary","text-lg","mb-2"],[1,"text-theme-secondary","text-sm"],["type","button",1,"text-accent","hover:text-accent-dark","underline","cursor-pointer","bg-transparent","border-0","p-0","font-inherit","text-sm",3,"click"]],template:function(e,i){e&1&&(l(0,"div",1),f("dragenter",function(a){return i.onDragEnter(a)})("dragover",function(a){return i.onDragOver(a)})("dragleave",function(a){return i.onDragLeave(a)})("drop",function(a){return i.onDrop(a)}),C(1,is,2,1,"div",2)(2,ws,16,3),s()),e&2&&(N("border-2",i.isDragging())("border-dashed",i.isDragging())("border-accent-500",i.isDragging()),r(),h(i.isLoading()?1:2))},dependencies:[R,io,H,gt,Ie,Ye],encapsulation:2,changeDetection:0})};var At=class n extends te{isSubmitting=S(!1);folderForm=new Te({folderName:new ve("",[B.required,B.maxLength(255),B.pattern(/^[^/\\:*?"<>|]+$/)])});folderNameError=b(()=>{let t=this.folderNameControl;
23return!t.invalid||!t.touched?"":t.errors?.required?"Folder name is required":t.errors?.maxlength?"Folder name cannot exceed 255 characters":t.errors?.pattern?'Folder name cannot contain: / \\ : * ? " < > |':""});get folderNameControl(){return this.folderForm.get("folderName")}onSubmit(){if(this.folderForm.valid){let t=this.folderNameControl.value.trim();this.close({folderName:t})}else this.folderNameControl.markAsTouched()}onCancel(){this.close(null)}static \u0275fac=(()=>{let t;return function(i){return(t||(t=se(n)))(i||n)}})();static \u0275cmp=V({type:n,selectors:[["app-create-folder-modal"]],features:[Z],decls:10,vars:8,consts:[["modal-title","",1,"font-headline","font-bold","text-xl","text-theme-primary"],[1,"space-y-4",3,"ngSubmit","formGroup"],["formControlName","folderName","label","Folder Name","id","folderName","placeholder","Enter folder name",3,"errorText","showRequiredStar","errorPropagateOnTouch","autoFocus"],[1,"flex","gap-3","justify-end","mt-6"],["type","button",1,"btn","btn-ghost",3,"click","disabled"],["type","submit","buttonClass","btn btn-solid",3,"loading","disabled"]],template:function(e,i){e&1&&(l(0,"bc-modal")(1,"h2",0),c(2," Create New Folder "),s(),l(3,"form",1),f("ngSubmit",function(){return i.onSubmit()}),g(4,"bc-text-input",2),l(5,"div",3)(6,"button",4),f("click",function(){return i.onCancel()}),c(7," Cancel "),s(),l(8,"bc-loading-button",5),c(9," Create Folder "),s()()()()),e&2&&(r(3),p("formGroup",i.folderForm),r(),p("errorText",i.folderNameError())("showRequiredStar",!0)("errorPropagateOnTouch",!0)("autoFocus",!0),r(2),p("disabled",i.isSubmitting()),r(2),p("loading",i.isSubmitting())("disabled",i.folderForm.invali
23d))},dependencies:[ue,ce,K,de,pe,me,oe,ae,q],encapsulation:2,changeDetection:0})};function Ts(n,t){if(n&1&&(l(0,"span",5),c(1),s()),n&2){let e=d();r(),A(e.fileExtension())}}var qe=class n extends te{isSubmitting=S(!1);fileExtension=S("");renameForm=new Te({name:new ve("",[B.required,B.maxLength(255),B.pattern(/^[^/\\:*?"<>|]+$/)])});nameError=b(()=>{let t=this.nameControl;return!t.invalid||!t.touched?"":t.errors?.required?"Name is required":t.errors?.maxlength?"Name cannot exceed 255 characters":t.errors?.pattern?'Name cannot contain: / \\ : * ? " < > |':t.errors?.sameName?"Please enter a different name":""});get nameControl(){return this.renameForm.get("name")}ngAfterViewInit(){if(this.data?.currentName)if(this.data.type==="file"){let t=this.data.currentName.lastIndexOf(".");t>0?(this.fileExtension.set(this.data.currentName.slice(t)),this.nameControl.setValue(this.data.currentName.slice(0,t))):this.nameControl.setValue(this.data.currentName)}else this.nameControl.setValue(this.data.currentName)}onSubmit(){if(this.renameForm.valid){let t=this.nameControl.value.trim();if(this.data?.type==="file"&&this.fileExtension()&&(t=t+this.fileExtension()),t===this.data?.currentName){this.nameControl.setErrors({sameName:!0}),this.nameControl.markAsTouched();return}this.close({newName:t})}else this.nameControl.markAsTouched()}onCancel(){this.close(null)}static \u0275fac=(()=>{let t;return function(i){return(t||(t=se(n)))(i||n)}})();static \u0275cmp=V({type:n,selectors:[["app-rename-modal"]],features:[Z],decls:13,vars:11,consts:[["modal-title","",1,"font-headline","font-bold","text-xl","text-theme-primary"],[1,"space-y-4",3,"ngSubmit","formGroup"],[1,"flex","items-end","gap-1"],[1,"flex-1"],["formControlName","name","id","name","placeholder","Enter new name",3,"label","errorText","showRequiredStar","errorPropagateOnTouch","autoFocus"],[1,"text-theme-secondary","text-sm","pb-2"],[1,"flex","gap-3","justify-end","mt-6"],["type","button",1,"btn","btn-ghost",3,"click","disabled"],["type","submit","buttonClass","btn btn-solid",3,"loading","disabled"]],template:function(e,i){e&1&&(l(0,"bc-modal")(1,"h2",0),c(2),s(),l(3,"form",1),f("ngSubmit",function(){return i.onSubmit()}),l(4,"div",2)(5,"div",3),g(6,"bc-text-input",4),s(),C(7,Ts,2,1,"span",5),s(),l(8,"div",6)(9,"button",7),f("click",function(){return i.onCancel()}),c(10," Cancel "),s(),l(11,"bc-loading-button",8),c(12," Rename "),s()()()()),e&2&&(r(2),x(" Rename ",(i.data==null?null:i.data.type)==="folder"?"Folder":"File"," "),r(),p("formGroup",i.renameForm),r(3),p("label",(i.data==null?null:i.data.type)==="folder"?"Folder Name":"File Name")("errorText",i.nameError())("showRequiredStar",!0)("errorPropagateOnTouch",!0)("autoFocus",!0),r(),h(i.fileExtension()?7:-1),r(2),p("disabled",i.isSubmitting()),r(2),p("loading",i.isSubmitting())("disabled",i.renameForm.invalid))},dependencies:[ue,ce,K,de,pe,me,oe,ae,q],encapsulation:2,changeDetection:0})};function Is(n,t){if(n&1&&(l(0,"p",2),c(1),s()),n&2){let e=d();r(),x(' Anyone who opens "',e.fileName,'" will need this password, including in BaseCloud. BaseCloud does not keep a copy, so if the password is lost the file cannot be opened. ')}}function Ds(n,t){if(n&1&&(l(0,"p",2),c(1),s()),n&2){let e=d();r(),x(' "',e.fileName,'" needs a password to open. Enter it once and the file will be saved without one, so anyone with access can open it. ')}}function Es(n,t){if(n&1&&g(0,"bc-text-input",4),n&2){let e=d();p("notALogin",!0)("errorText",e.confirmErrorText())("errorPropagateOnTouch",!0)}}var bo=127,je=class n extends te{filesService=F(Ue);isSubmitting=S(!1);errorText=S("");confirmErrorText=S("");form=new Te({password:new ve("",{nonNullable:!0,validators:[B.required,B.maxLength(bo)]}),confirm:new ve("",{nonNullable:!0})});get isAdding(){return this.data?.mode==="add"}get fileName(){return this.data?.file.file_name??"This PDF"}onEnterKey(){this.onSubmit()}async onSubmit(){let{password:t,confirm:e}=this.form.controls;if(this.form.markAllAsTouched(),!(this.isSubmitting()||!this.data)){if(t.hasError("required")){this.errorText.set("Enter the password");return}if(t.hasError("maxlength")){this.errorText.set(`Use ${bo} characters or fewer`);return}if(this.isAdding&&e.value!==t.value){this.showError("The passwords do not match","confirm");return}this.isSubmitting.set(!0);try{this.isAdding?await this.add(t.value):await this.remove(t.value)}catch(i){this.showError(i?.message??(this.isAdding?"Could not add the password. Please try again.":"Could not remove the password. Please try again."))}finally{this.isSubmitting.set(!1)}}}async add(t){let e=await this.filesService.addPdfPassword(this.data.clientId,this.data.file.id,t);e.status==="protected"?this.close(e.file):this.showError("This PDF already has a password. Remove it first to set a new one.")}async remove(t){let e=await this.filesService.removePdfPassword(this.data.clientId,this.data.file.id,t);e.status==="unlocked"?this.close(e.file):e.status==="not_encrypted"?this.close(null):this.showError("That password is not correct")}showError(t,e="password"){let i=this.form.controls[e];(e==="password"?this.errorText:this.confirmErrorText).set(t),i.setErrors({server:!0}),i.markAsDirty()}onCancel(){this.close(null)}static \u0275fac=(()=>{let t;return function(i){return(t||(t=se(n)))(i||n)}})();static \u0275cmp=V({type:n,selectors:[["app-pdf-password-modal"]],features:[Z],decls:13,vars:12,consts:[["modal
23-title","",1,"font-headline","font-bold","text-xl","text-theme-primary"],[1,"space-y-4",3,"ngSubmit","formGroup"],[1,"text-sm","text-theme-secondary"],["formControlName","password","inputType","password","id","pdf-password","placeholder","Enter the password","rounded","lg",3,"label","notALogin","errorText","errorPropagateOnTouch","autoFocus"],["formControlName","confirm","label","Type it again","inputType","password","id","pdf-password-confirm","placeholder","Enter the same password","rounded","lg",3,"notALogin","errorText","errorPropagateOnTouch"],[1,"flex","gap-3","justify-end","mt-6"],["type","button",1,"btn","btn-ghost",3,"click","disabled"],["type","submit","buttonClass","btn btn-solid",3,"loading"]],template:function(e,i){e&1&&(l(0,"bc-modal")(1,"h2",0),c(2),s(),l(3,"form",1),f("ngSubmit",function(){return i.onSubmit()}),C(4,Is,2,1,"p",2)(5,Ds,2,1,"p",2),g(6,"bc-text-input",3),C(7,Es,1,3,"bc-text-input",4),l(8,"div",5)(9,"button",6),f("click",function(){return i.onCancel()}),c(10," Cancel "),s(),l(11,"bc-loading-button",7),c(12),s()()()()),e&2&&(r(2),x(" ",i.isAdding?"Add Password":"Remove Password"," "),r(),p("formGroup",i.form),r(),h(i.isAdding?4:5),r(2),p("label",i.isAdding?"New password":"PDF password")("notALogin",!0)("errorText",i.errorText())("errorPropagateOnTouch",!0)("autoFocus",!0),r(),h(i.isAdding?7:-1),r(2),p("disabled",i.isSubmitting()),r(2),p("loading",i.isSubmitting()),r(),x(" ",i.isAdding?"Add Password":"Remove Password"," "))},dependencies:[ue,ce,K,de,pe,me,oe,ae,q],encapsulation:2,changeDetection:0})};var ks=(n,t)=>t.id;function Ms(n,t){if(n&1){let e=y();l(0,"li",9)(1,"span",14),c(2),s(),g(3,"fa-icon",15),l(4,"span",16),c(5),s(),l(6,"div",17)(7,"button",18),f("click",function(){let o=u(e).$index,a=d();return _(a.moveFile(o,-1))}),g(8,"fa-icon",19),s(),l(9,"button",18),f("click",function(){let o=u(e).$index,a=d();return _(a.moveFile(o,1))}),g(10,"fa-icon",19),s()()()}if(n&2){let e=t.$implicit,i=t.$index,o=t.$index,a=t.$count,m=d();r(2),x("",i+1,"."),r(),ge(m.getFileIconColor(e.contentType,e.file_name)),p("icon",m.getFileIcon(e.contentType,e.file_name)),r(),p("title",e.file_name),r(),A(e.file_name),r(2),p("disabled",o===0||m.isSubmitting()),he("aria-label","Move "+e.file_name+" up"),r(),p("icon",m.faArrowUp),r(),p("disabled",o===a-1||m.isSubmitting()),he("aria-label","Move "+e.file_name+" down"),r(),p("icon",m.faArrowDown)}}function Vs(n,t){if(n&1&&(l(0,"p",10),c(1),s()),n&2){let e=d();r(),x(" ",e.mergeError()," ")}}var Rt=class n extends te{filesService=F(Ue);faArrowUp=Ji;faArrowDown=Vi;getFileIcon=_t;getFileIconColor=ft;files=S([]);isSubmitting=S(!1);nameError=S("");mergeError=S("");form=new Te({name:new ve("",{nonNullable:!0,validators:[B.required,B.maxLength(251),B.pattern(/^[^/\\:*?"<>|]+$/)]})});ngOnInit(){let t=this.data?.files??[];this.files.set(t);let e=t[0]?.file_name.replace(/\.pdf$/i,"")??"Document";this.form.controls.name.setValue(`${e} (combined)`)}onEnterKey(){this.onSubmit()}moveFile(t,e){this.files.update(i=>{let o=[...i];return[o[t],o[t+e]]=[o[t+e],o[t]],o})}async onSubmit(){let t=this.form.controls.name;if(this.form.markAllAsTouched(),!(this.isSubmitting()||!this.data)){if(t.invalid){this.nameError.set(t.errors?.pattern?'The name cannot contain: / \\ : * ? " < > |':t.errors?.maxlength?"The name is too long":"Give the new PDF a name");return}this.nameError.set(""),this.mergeError.set(""),this.isSubmitting.set(!0);try{let e=await this.filesService.mergePdfs(this.data.clientId,this.files().map(i=>i.id),`${t.value.trim()}.pdf`);this.close(e)}catch(e){this.mergeError.set(e?.message??"The PDFs could not be combined. Please try again.")}finally{this.isSubmitting.set(!1)}}}onCancel(){this.close(null)}static \u0275fac=(()=>{let t;return function(i){return(t||(t=se(n)))(i||n)}})();static \u0275cmp=V({type:n,selectors:[["app-merge-pdfs-modal"]],features:[Z],decls:23,vars:8,consts:[["modal-title","",1,"font-headline","font-bold","text-xl","text-theme-primary"],[1,"space-y-4",3,"ngSubmit","formGroup"],[1,"text-sm","text-theme-secondary"],[1,"flex","items-end","gap-1"],[1,"flex-1"],["formControlName","name","label","Name of the new PDF","id","merged-pdf-name","placeholder","Enter a name","rounded","lg",3,"errorText","errorPropagateOnTouch","showRequiredStar","autoF
23ocus"],[1,"text-theme-secondary","text-sm","pb-2"],[1,"mb-1","text-sm","font-medium","text-theme-primary"],[1,"max-h-72","overflow-y-auto","rounded-lg","border","border-theme-default","divide-y","divide-theme-default"],[1,"flex","items-center","gap-2","px-3","py-2"],["role","alert",1,"text-sm","text-danger-600"],[1,"flex","gap-3","justify-end","mt-6"],["type","button",1,"btn","btn-ghost",3,"click","disabled"],["type","submit","buttonClass","btn btn-solid",3,"loading"],[1,"w-5","flex-shrink-0","text-xs","text-theme-secondary"],[1,"flex-shrink-0",3,"icon"],[1,"flex-1","min-w-0","truncate","text-sm","text-theme-primary",3,"title"],[1,"flex","flex-shrink-0","items-center"],["type","button",1,"btn-icon-sm",3,"click","disabled"],[3,"icon"]],template:function(e,i){e&1&&(l(0,"bc-modal")(1,"h2",0),c(2," Combine PDFs "),s(),l(3,"form",1),f("ngSubmit",function(){return i.onSubmit()}),l(4,"p",2),c(5," The pages are put together into one new PDF, in the order below. The original files stay as they are. "),s(),l(6,"div",3)(7,"div",4),g(8,"bc-text-input",5),s(),l(9,"span",6),c(10,".pdf"),s()(),l(11,"div")(12,"p",7),c(13," Page order "),s(),l(14,"ol",8),E(15,Ms,11,12,"li",9,ks),s()(),C(17,Vs,2,1,"p",10),l(18,"div",11)(19,"button",12),f("click",function(){return i.onCancel()}),c(20," Cancel "),s(),l(21,"bc-loading-button",13),c(22," Combine "),s()()()()),e&2&&(r(3),p("formGroup",i.form),r(5),p("errorText",i.nameError())("errorPropagateOnTouch",!0)("showRequiredStar",!0)("autoFocus",!0),r(7),k(i.files()),r(2),h(i.mergeError()?17:-1),r(2),p("disabled",i.isSubmitting()),r(2),p("loading",i.isSubmitting()))},dependencies:[ue,ce,K,de,pe,me,R,oe,ae,q],encapsulation:2,changeDetection:0})};function Ns(n,t){if(n&1){let e=y();l(0,"div",6),f("focusout",function(){u(e);let o=d();return _(o.onSearchBlur())})("keydown.escape",function(){u(e);let o=d();return _(o.clearSearch())}),l(1,"bc-text-input",7),f("ngModelChange",function(o){u(e);let a=d();return _(a.onSearchInput(o))}),s()(),l(2,"div",8)(3,"button",9),f("click",function(){u(e);let o=d();return _(o.clearSearch())}),g(4,"fa-icon",10),s(),l(5,"button",11),f("click",function(){u(e);let o=d();return _(o.refreshCurrentFolder())}),g(6,"fa-icon",10),s()()}if(n&2){let e=d();r(),p("ngModel",e.searchQuery())("autoFocus",!0)("showErrorMessage",!1),r(3),p("icon",e.faXmark),r(),p("disabled",e.isRefreshing()||e.isUploading()),r(),N("animate-spin",e.isRefreshing()||e.isSearchPending()),p("icon",e.faRotate)}}function Ls(n,t){if(n&1){let e=y();l(0,"app-file-breadcrumb",12),f("navigate",function(o){u(e);let a=d();return _(a.navigateToFolder(o))})("breadcrumbDrop",function(o){u(e);let a=d();return _(a.handleBreadcrumbDrop(o))})("attachmentDrop",function(o){u(e);let a=d();return _(a.handleAttachmentDrop(o))}),s(),l(1,"div",8)(2,"button",13),f("click",function(){u(e);let o=d();return _(o.openSearch())}),g(3,"fa-icon",10),s(),l(4,"button",14),f("click",function(){u(e);let o=d();return _(o.refreshCurrentFolder())}),g(5,"fa-icon",10),s(),l(6,"button",15),f("click",function(){u(e);let o=d();return _(o.triggerUpload())}),g(7,"fa-icon",10),s(),l(8,"button",16),f("click",function(){u(e);let o=d();return _(o.openCreateFolderModal())}),g(9,"fa-icon",10),s()()}if(n&2){let e=d();p("foldersTree",e.foldersTree())("currentFolderId",e.currentFolderId()),r(3),p("icon",e.faMagnifyingGlass),r(),p("disabled",e.isRefreshing()||e.isUploading()),r(),N("animate-spin",e.isRefreshing()),p("icon",e.faRotate),r(),p("disabled",e.isLoading()||e.isUploading()),r(),p("icon",e.faArrowUpFromBracket),r(),p("disabled",e.isLoading()||e.isUploading()),r(),p("icon",e.faFolderPlus)}}function Ps(n,t){n&1&&(l(0,"span",18),c(1," (first matches only \u2014 narrow the search) "),s())}function As(n,t){if(n&1&&(l(0,"div",2)(1,"span",17),c(2),s(),C(3,Ps,2,0,"span",18),s()),n&2){let e=d();r(2),ci(" ",e.searchResultCount()," ",e.searchResultCount()===1?"result":"results",' for "',e.searchTerm(),'" '),r(),h(e.searchTruncated()?3:-1)}}function Rs(n,t){n&1&&(l(0,"div",3)(1,"div",19),g(2,"div",20),l(3,"span"),c(4,"Uploading files..."),s()()())}var vo=150,Us=vo*1024*1024,$s=3,Os=["fileid","folderid","fileids","folderids","fileitemdata","fileitemsdata","attachmentdata"],Ut=200,$t=class n{filesService=F(Ue);clientService=F(Q);modalService=F(ie);toastService=F(G);clipboard=F(pt);composerBridge=F(ut);signaturesService=F(ao);extendedPanelService=F(_e);attachToComposer=M();faArrowUpFromBracket=Yi;faFolderPlus=$i;faMagnifyingGlass=Pe;faRotate=pn;faXmark=Qi;clientId=T.required();currentFolderId=S(null);isUploading=S(!1);isDragging=S(!1);renamingFolderIds=S(new Set);renamingFileIds=S(new Set);deletingFolderIds=S(new Set);deletingFileIds=S(new Set);movingFolderIds=S(new Set);movingFileIds=S(new Set);newFileIds=S(new Set);searchQuery=S("");debouncedQuery=S("");searchExpanded=S(!1);searchOpen=b(()=>this.searchExpanded()||this.isSearching());searchTerm=b(()=>this.debouncedQuery().trim());isSearching=b(()=>this.searchTerm().length>0);filesResource=this.filesService.getFilesFolders(this.clientId,()=>this.currentFolderId());searchResource=this.filesService.searchFilesFolders(this.clientId,()=>this.debouncedQuery());constructor(){P(t=>{let e=this.searchQuery();if(!e.trim()){this.debouncedQuery.set("");return}let i=setTimeout(()=>this.debouncedQuery.set(e),300);t(()=>clearTimeout(i))}),P(()=>{this.clientId(),ee(()=>{this.currentFolderId.set(null),this.clearSearch()})}),P(()=>{let t=this.signatureLookup.error();t&&console.error("[esign] could not load signature status for these files",t)})}safeValue(t){return t.hasValue()?t.value():void 0}folders=b(()=>this.isSearching()?this.safeValue(this.searchResource)?.data?.folders??[]:this.safeValue(this.filesResource)?.data?.folders??[]);files=b(()=>
23this.isSearching()?this.safeValue(this.searchResource)?.data?.files??[]:this.safeValue(this.filesResource)?.data?.files??[]);visibleFileIds=b(()=>this.files().map(t=>t.id).sort((t,e)=>t-e),{equal:(t,e)=>t.length===e.length&&t.every((i,o)=>i===e[o])});signatureVersion=S(0);signatureLookup=ze({params:()=>({clientId:this.clientId(),fileIds:this.visibleFileIds(),version:this.signatureVersion()}),loader:async({params:t})=>{let e=[];for(let o=0;o<t.fileIds.length;o+=Ut)e.push(t.fileIds.slice(o,o+Ut));return(await Promise.all(e.map(o=>this.signaturesService.getRequestsForFiles(t.clientId,o)))).flat()}});lastSignatureRows={clientId:null,rows:[]};signatureRows=b(()=>{let t=this.clientId(),e=this.safeValue(this.signatureLookup);return e?(this.lastSignatureRows={clientId:t,rows:e},e):this.signatureLookup.isLoading()&&this.lastSignatureRows.clientId===t?this.lastSignatureRows.rows:[]});signaturesByFile=b(()=>{let t=new Map;for(let e of this.signatureRows()){let i=t.get(e.file_id);i?i.push(e):t.set(e.file_id,[e])}return t});refreshSignatures(){this.signatureVersion.update(t=>t+1)}visiblePdfIds=b(()=>this.files().filter(t=>t.contentType==="application/pdf").map(t=>t.id).sort((t,e)=>t-e),{equal:(t,e)=>t.length===e.length&&t.every((i,o)=>i===e[o])});pdfProtectionVersion=S(0);pdfProtectionLookup=ze({params:()=>({clientId:this.clientId(),fileIds:this.visiblePdfIds(),version:this.pdfProtectionVersion()}),loader:async({params:t})=>{let e=[];for(let o=0;o<t.fileIds.length;o+=Ut)e.push(t.fileIds.slice(o,o+Ut));let i=await Promise.all(e.map(o=>this.filesService.getPdfProtection(t.clientId,o)));return new Set(i.flat())}});protectedPdfIds=b(()=>this.safeValue(this.pdfProtectionLookup)??new Set);searchResultCount=b(()=>this.folders().length+this.files().length);searchTruncated=b(()=>this.safeValue(this.searchResource)?.data?.truncated??!1);isSearchPending=b(()=>this.searchQuery().trim()!==this.searchTerm()||this.isSearching()&&this.searchResource.isLoading());foldersTree=b(()=>this.safeValue(this.filesResource)?.data?.folders_tree??null);isLoading=b(()=>this.isSearching()?this.searchResource.isLoading()&&!this.searchResource.hasValue():this.filesResource.isLoading()&&!this.filesResource.hasValue());isRefreshing=b(()=>this.isSearching()?this.searchResource.isLoading():this.filesResource.isLoading());patchLoadedItems(t){this.patchResourceItems(this.filesResource,t),this.patchResourceItems(this.searchResource,t)}patchResourceItems(t,e){!t.hasValue()||t.isLoading()||t.update(i=>i?.data?L(I({},i),{data:I(I({},i.data),e(i.data))}):i)}refreshSearchIfActive(){this.isSearching()&&this.searchResource.reload()}removeLoadedItems(t,e){t.length===0&&e.length===0||this.patchLoadedItems(({folders:i,files:o})=>({folders:i.filter(a=>!t.includes(a.id)),files:o.filter(a=>!e.includes(a.id))}))}endpointSucceeded(t){return t!==0&&t!=="0"}touchLoadedFolder(t){if(t===null)return;let e=new Date().toISOString();this.patchLoadedItems(({folders:i,files:o})=>({folders:i.map(a=>a.id===t?L(I({},a),{last_modified:e}):a),files:o}))}navigateToFolder(t){this.clearSearch(),this.currentFolderId.set(t)}onSearchInput(t){this.searchQuery.set(t)}openSearch(){this.searchExpanded.set(!0)}onSearchBlur(){this.searchQuery().trim()||this.searchExpanded.set(!1)}clearSearch(){this.searchExpanded.set(!1),this.searchQuery.set(""),this.debouncedQuery.set("")}refreshCurrentFolder(){if(this.isSearching()){this.searchResource.reload(),this.toastService.add("Search refreshed",3e3,"success");return}this.filesResource.reload(),this.toastService.add("Files refreshed",3e3,"success")}async openCreateFolderModal(){let t=await this.modalService.showModal(At,{clientId:this.clientId(),parentId:this.currentFolderId()});t?.folderName&&this.createFolder(t.folderName)}createFolder(t){this.filesService.createFolder(this.clientId(),t,this.currentFolderId()).subscribe({next:e=>{e?.id?this.patchLoadedItems(({folders:i,files:o})=>({folders:[...i,e].sort((a,m)=>a.label.localeCompare(m.label)),files:o})):this.filesResource.reload(),this.toastService.add(`Folder "${e?.label??t}" created`,3e3,"success")},error:e=>{this.modalService.showModal(Wt,{title:"Create Folder Failed",body:e.error?.message||"Failed to create folder. Please try again."})}})}async handleFolderAction(t){let{action:e,folder:i}=t;switch(e){case"rename":await this.renameFolder(i);break;
23case"delete":await this.deleteFolder(i);break;case"upload":this.triggerFileUpload(i.id);break}}async renameFolder(t){let e=await this.modalService.showModal(qe,{currentName:t.label,type:"folder"});e?.newName&&(this.renamingFolderIds.update(i=>new Set([...i,t.id])),this.filesService.renameFolder(this.clientId(),t.id,e.newName).subscribe({next:i=>{if(this.renamingFolderIds.update(a=>{let m=new Set(a);return m.delete(t.id),m}),!this.endpointSucceeded(i)){this.toastService.add(`Failed to rename "${t.label}"`,5e3,"error");return}this.toastService.add(`Folder renamed to "${e.newName}"`,3e3,"success");let o=new Date().toISOString();this.patchLoadedItems(({folders:a,files:m})=>({folders:a.map(v=>v.id===t.id?L(I({},v),{label:e.newName,last_modified:o}):v),files:m}))},error:i=>{this.renamingFolderIds.update(o=>{let a=new Set(o);return a.delete(t.id),a}),this.toastService.add(i.error?.message||"Failed to rename folder",5e3,"error")}}))}async deleteFolder(t){await this.modalService.showModal(Y,{title:"Delete Folder",message:`Are you sure you want to delete "${t.label}"? This will delete all files and subfolders inside.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger"})&&(this.deletingFolderIds.update(i=>new Set([...i,t.id])),this.filesService.deleteFolder(this.clientId(),t.id).subscribe({next:i=>{if(this.deletingFolderIds.update(o=>{let a=new Set(o);return a.delete(t.id),a}),!this.endpointSucceeded(i)){this.toastService.add(`Failed to delete folder "${t.label}"`,5e3,"error");return}this.toastService.add(`Folder "${t.label}" deleted`,3e3,"success"),this.currentFolderId()===t.id?this.currentFolderId.set(t.parent_id):this.removeLoadedItems([t.id],[]),this.refreshSearchIfActive()},error:i=>{this.deletingFolderIds.update(o=>{let a=new Set(o);return a.delete(t.id),a}),this.toastService.add(i.error?.message||"Failed to delete folder",5e3,"error")}}))}async handleFileAction(t){let{action:e,file:i}=t;switch(e){case"open":window.open(i.file_url,"_blank","noopener,noreferrer");break;case"copy-link":{this.clipboard.copy(i.file_url)?this.toastService.add("Link copied to clipboard",3e3,"success"):this.toastService.add("Failed to copy link",3e3,"error");break}case"download":this.filesService.downloadFile(i.file_url,i.file_name);break;case"attach-email":this.composerBridge.request([{id:i.id,file_name:i.file_name,file_url:i.file_url,size:i.size,contentType:i.contentType}],"email"),this.attachToComposer.emit("email");break;case"attach-note":this.composerBridge.request([{id:i.id,file_name:i.file_name,file_url:i.file_url,size:i.size,contentType:i.contentType}],"note"),this.attachToComposer.emit("note");break;case"rename":await this.renameFile(i);break;case"delete":await this.deleteFile(i);break;case"send-for-signature":await this.sendForSignature([i]);break;case"view-audit-trail":await this.viewAuditTrail(i);break;case"remove-password":await this.removePdfPassword(i);break;case"add-password":await this.addPdfPassword(i);break}}async removePdfPassword(t){let e=this.clientId();this.renamingFileIds.update(a=>new Set([...a,t.id]));let i;try{i=await this.filesService.removePdfPassword(e,t.id)}catch(a){this.toastService.add(a?.message??"Could not remove the password. Please try again.",4e3,"error");return}finally{this.renamingFileIds.update(a=>{let m=new Set(a);return m.delete(t.id),m})}let o=null;i.status==="unlocked"?o=i.file:i.status==="password_required"?o=await this.modalService.showModal(je,{clientId:e,file:t,mode:"remove"})??null:i.status==="not_encrypted"&&this.toastService.add(`"${t.file_name}" does not have a password.`,3e3,"info"),this.pdfProtectionVersion.update(a=>a+1),o&&(this.applyReplacedPdf(t.id,o),this.toastService.add(`Password removed from "${t.file_name}"`,3e3,"success"))}async addPdfPassword(t){let e=await this.modalService.showModal(je,{clientId:this.clientId(),file:t,mode:"add"})??null;this.pdfProtectionVersion.update(i=>i+1),e&&(this.applyReplacedPdf(t.id,e),this.toastService.add(`Password added to "${t.file_name}"`,3e3,"success"))}applyReplacedPdf(t,e){let{file_url:i,size:o,last_modified:a}=e;this.patchLoadedItems(({folders:m,files:v})=>({folders:m,files:v.map(w=>w.id===t?L(I({},w),{file_url:i,size:o,last_modified:a}):w)}))}async viewAuditTrail(t){let e=this.signaturesByFile().get(t.id)?.[0]?.id;if(!e)return;let{SignatureAuditTrailModalComponent:i}=await import("./chunk-DRVCCAF7.js");await this.modalService.showModal(i,{requestId:e})}async sendForSignature(t){if(!t.length)return;document.getElementById("viewerContainer")&&this.extendedPanelService.close();
23let{SendForSignatureModalComponent:e}=await import("./chunk-LJ23N7DY.js"),i=await this.modalService.showModal(e,{clientId:this.clientId(),documents:t.map(o=>({fileId:o.id,fileName:o.file_name,fileUrl:o.file_url}))});if(i){if(this.refreshSignatures(),i.undelivered.length){this.toastService.add(`Sent for signature, but the email to ${i.undelivered.join(", ")} could not be sent. Check the address and use Resend.`,8e3,"error");return}this.toastService.add("Sent for signature. The first signer has been emailed.",4e3,"success")}}async handleMultiSelectAction(t){let{action:e,folders:i,files:o}=t,a=i.length+o.length;switch(e){case"delete-all":await this.deleteMultipleItems(i,o);break;case"send-all-for-signature":{await this.sendForSignature(o);break}case"merge-pdfs":await this.mergePdfs(o);break;case"attach-all-email":{if(o.length===0)break;this.composerBridge.request(o.map(m=>({id:m.id,file_name:m.file_name,file_url:m.file_url,size:m.size,contentType:m.contentType})),"email"),this.attachToComposer.emit("email");break}case"attach-all-wfn":{if(o.length===0)break;this.composerBridge.request(o.map(m=>({id:m.id,file_name:m.file_name,file_url:m.file_url,size:m.size,contentType:m.contentType})),"note"),this.attachToComposer.emit("note");break}}}async mergePdfs(t){if(t.length<2)return;let e=await this.modalService.showModal(Rt,{clientId:this.clientId(),files:t});e&&(this.addUploadedFile(e,e.parent_id??null),this.toastService.add(`Combined into "${e.file_name}"`,3e3,"success"))}async deleteMultipleItems(t,e){let i=t.length+e.length,o=t.length,a=e.length,m="";o>0&&a>0?m=`${o} folder${o>1?"s":""} and ${a} file${a>1?"s":""}`:o>0?m=`${o} folder${o>1?"s":""}`:m=`${a} file${a>1?"s":""}`;let v=e.filter($=>this.signedCopyOf($)).length,w=v===0?"":` ${v===1?"One of them is a signed document":`${v} of them are signed documents`}; the signature request${v===1?"":"s"} and audit trail${v===1?"":"s"} stay.`;if(!await this.modalService.showModal(Y,I({title:"Delete Items",message:`Are you sure you want to delete ${m}? This action cannot be undone.${w}`,confirmText:"Delete",cancelText:"Cancel",variant:"danger"},v>0?{confirmPhrase:"delete"}:{})))return;t.length>0&&this.deletingFolderIds.update($=>new Set([...$,...t.map(z=>z.id)])),e.length>0&&this.deletingFileIds.update($=>new Set([...$,...e.map(z=>z.id)]));let O=await Promise.allSettled(t.map($=>D(this.filesService.deleteFolder(this.clientId(),$.id)))),re=await Promise.allSettled(e.map($=>D(this.filesService.deleteFile($.id,!!this.signedCopyOf($))))),le=t.filter(($,z)=>{let Ce=O[z];return Ce.status==="fulfilled"&&this.endpointSucceeded(Ce.value)}).map($=>$.id),Be=e.filter(($,z)=>{let Ce=re[z];return Ce.status==="fulfilled"&&Ce.value?.status==="success"}).map($=>$.id);t.length>0&&this.deletingFolderIds.update($=>{let z=new Set($);return t.forEach(Ce=>z.delete(Ce.id)),z}),e.length>0&&this.deletingFileIds.update($=>{let z=new Set($);return e.forEach(Ce=>z.delete(Ce.id)),z}),this.removeLoadedItems(le,Be),(Be.length>0||le.length>0)&&this.clientService.clearAttachmentCache(),le.length>0&&this.refreshSearchIfActive();let Ke=i-le.length-Be.length;Ke===0?this.toastService.add(`Successfully deleted ${m}`,3e3,"success"):this.toastService.add(`Failed to delete ${Ke} of ${i} items`,5e3,"error")}async renameFile(t){let e=await this.modalService.showModal(qe,{currentName:t.file_name,type:"file"});e?.newName&&(this.renamingFileIds.update(i=>new Set([...i,t.id])),this.filesService.renameFile(t.id,e.newName).subscribe({next:()=>{this.toastService.add(`File renamed to "${e.newName}"`,3e3,"success");let i=new Date().toISOString();this.patchLoadedItems(({folders:o,files:a})=>({folders:o,files:a.map(m=>m.id===t.id?L(I({},m),{file_name:e.newName,last_modified:i}):m)})),this.renamingFileIds.update(o=>{let a=new Set(o);return a.delete(t.id),a})},error:i=>{this.renamingFileIds.update(o=>{let a=new Set(o);return a.delete(t.id),a}),this.modalService.showModal(Wt,{title:"Rename Failed",body:i.error?.error||"Failed to rename file. Please try again."})}}))}signedCopyOf(t){return this.signaturesByFile().get(t.id)?.find(e=>e.role==="signed_output")}async deleteFile(t){let e=this.signedCopyOf(t);await this.modalService.showModal(Y,e?{title:"Delete signed document?",message:`"${t.file_name}" is the signed copy of "${e.title}". Deleting it removes the file for good. The signature request and its audit trail stay.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",confirmPhrase:"delete"}:{title:"Delete File",message:`Are you sure you want to delete "${t.file_name}"? This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger"})&&(this.deletingFileIds.update(o=>new Set([...o,t.id])),this.filesService.deleteFile(t.id,!!e).subscribe({next:o=>{if(this.deletingFileIds.update(a=>
23{let m=new Set(a);return m.delete(t.id),m}),o?.status!=="success"){this.toastService.add(o?.error||`Failed to delete "${t.file_name}"`,5e3,"error");return}this.clientService.clearAttachmentCache(),this.toastService.add(`File "${t.file_name}" deleted`,3e3,"success"),this.removeLoadedItems([],[t.id])},error:o=>{this.deletingFileIds.update(a=>{let m=new Set(a);return m.delete(t.id),m}),this.toastService.add(o.error?.error||"Failed to delete file",5e3,"error")}}))}handleDragEnter(){this.isDragging.set(!0)}handleDragLeave(){this.isDragging.set(!1)}handleDropUpload(t){this.isDragging.set(!1);let e=t.event.dataTransfer?.files;if(e&&e.length>0){this.uploadFiles(Array.from(e),this.currentFolderId());return}this.reportFilelessDrop(t.event)}async handleAttachmentDrop(t){this.isDragging.set(!1);let e=JSON.parse(t.attachmentData);if(!e?.file_url||!e?.file_name)return;this.isUploading.set(!0);let i=t.targetFolderId??this.currentFolderId();this.filesService.saveAttachmentsToFolder([{file_url:e.file_url,file_name:e.file_name,size:e.file_size,file_type:e.file_type}],this.clientId(),i).subscribe({next:o=>{this.isUploading.set(!1),(o?.data??[]).forEach(m=>this.addUploadedFile(m,i)),this.toastService.add(`Saved "${e.file_name}" to files`,3e3,"success")},error:()=>{this.isUploading.set(!1),this.toastService.add("Failed to save attachment",3e3,"error")}})}handleFileDragStart(t){t.event.dataTransfer&&(t.event.dataTransfer.effectAllowed="copyMove",t.event.dataTransfer.setData("fileId",t.file.id.toString()),t.event.dataTransfer.setData("fileItemData",JSON.stringify(t.file)),ht(t.event.dataTransfer,[{url:t.file.file_url,name:t.file.file_name,type:t.file.contentType}]))}handleFolderDragStart(t){t.event.dataTransfer&&(t.event.dataTransfer.effectAllowed="move",t.event.dataTransfer.setData("folderId",t.folder.id.toString()))}handleMultiItemDragStart(t){}handleFolderDrop(t){let e=t.event.dataTransfer?.getData("fileId"),i=t.event.dataTransfer?.getData("folderId"),o=t.event.dataTransfer?.getData("fileIds"),a=t.event.dataTransfer?.getData("folderIds"),m=t.event.dataTransfer?.files;if(o||a){if(o&&o.split(",").map(w=>parseInt(w)).forEach(w=>this.moveFile(w,t.folder.id)),a){let v=a.split(",").map(w=>parseInt(w));for(let w of v)if(this.isCircularReference(w,t.folder.id)){this.toastService.add("Cannot move a folder into itself or its subfolders",3e3,"error");return}v.forEach(w=>this.moveFolder(w,t.folder.id))}}else if(e)this.moveFile(parseInt(e),t.folder.id);else if(i){let v=parseInt(i);if(this.isCircularReference(v,t.folder.id)){this.toastService.add("Cannot move a folder into itself or its subfolders",3e3,"error");return}this.moveFolder(v,t.folder.id)}else m&&m.length>0?this.uploadFiles(Array.from(m),t.folder.id):this.reportFilelessDrop(t.event)}handleBreadcrumbDrop(t){let e=t.event.dataTransfer?.getData("fileId"),i=t.event.dataTransfer?.getData("folderId"),o=t.event.dataTransfer?.getData("fileIds"),a=t.event.dataTransfer?.getData("folderIds"),m=t.event.dataTransfer?.files;if(o||a){if(o&&o.split(",").map(w=>parseInt(w)).forEach(w=>this.moveFile(w,t.folderId)),a){let v=a.split(",").map(w=>parseInt(w));for(let w of v)if(t.folderId!==null&&this.isCircularReference(w,t.folderId)){this.toastService.add("Cannot move a folder into itself or its subfolders",3e3,"error");return}v.forEach(w=>this.moveFolder(w,t.folderId))}}else if(e)this.moveFile(parseInt(e),t.folderId);else if(i){let v=parseInt(i);if(t.folderId!==null&&this.isCircularReference(v,t.folderId)){this.toastService.add("Cannot move a folder into itself or its subfolders",3e3,"error");return}this.moveFolder(v,t.folderId)}else m&&m.length>0&&this.uploadFiles(Array.from(m),t.folderId)}moveFile(t,e){this.movingFileIds.update(i=>new Set([...i,t])),this.filesService.moveFile(this.clientId(),t,e).subscribe({next:i=>{if(this.movingFileIds.update(o=>{let a=new Set(o);return a.delete(t),a}),!this.endpointSucceeded(i)){this.toastService.add("Failed to move file",5e3,"error");return}this.toastService.add("File moved successfully",3e3,"success"),e!==this.currentFolderId()&&(this.removeLoadedItems([],[t]),this.touchLoadedFolder(e)),this.refreshSearchIfActive()},error:i=>{this.movingFileIds.update(o=>{let a=new Set(o);return a.delete(t),a}
23),this.toastService.add(i.error?.message||"Failed to move file",5e3,"error")}})}moveFolder(t,e){this.movingFolderIds.update(i=>new Set([...i,t])),this.filesService.moveFolder(this.clientId(),t,e).subscribe({next:i=>{if(this.movingFolderIds.update(o=>{let a=new Set(o);return a.delete(t),a}),!this.endpointSucceeded(i)){this.toastService.add("Failed to move folder",5e3,"error");return}this.toastService.add("Folder moved successfully",3e3,"success"),e!==this.currentFolderId()&&this.removeLoadedItems([t],[]),this.refreshSearchIfActive()},error:i=>{this.movingFolderIds.update(o=>{let a=new Set(o);return a.delete(t),a}),this.toastService.add(i.error?.message||"Failed to move folder",5e3,"error")}})}isCircularReference(t,e){if(t===e)return!0;let i=this.folders(),o=(a,m)=>{let v=i.find(w=>w.id===a);return v?v.parent_id===m?!0:v.parent_id===null?!1:o(v.parent_id,m):!1};return o(e,t)}reportFilelessDrop(t){let e=Array.from(t.dataTransfer?.types??[]).map(o=>o.toLowerCase());Os.some(o=>e.includes(o))||this.toastService.add("That drop carried no file. New Outlook and Outlook on the web cannot hand one over \u2014 drag from classic Outlook, or save the email or attachment first and drag the saved file.",5e3,"error")}uploadFiles(t,e){let i=t.filter(U=>U.size>Us?(this.toastService.add(`${U.name} exceeds ${vo}MB limit`,3e3,"error"),!1):!0);if(i.length===0)return;this.isUploading.set(!0);let o=0,a=0,m=i.length,v=()=>{a--,m--,m===0?this.isUploading.set(!1):w()},w=()=>{for(;a<$s&&o<i.length;){let U=i[o++];a++,this.filesService.uploadFile(U,this.clientId(),e).subscribe({next:O=>{this.addUploadedFile(O,e),this.toastService.add(`"${U.name}" uploaded`,2e3,"success"),v()},error:()=>{this.toastService.add(`Failed to upload ${U.name}`,3e3,"error"),v()}})}};w()}addUploadedFile(t,e){if(e!==this.currentFolderId()){this.touchLoadedFolder(e);return}let i=L(I({},t),{last_modified:t.last_modified??new Date().toISOString()});this.patchResourceItems(this.filesResource,({folders:o,files:a})=>({folders:o,files:[...a,i].sort((m,v)=>m.file_name.localeCompare(v.file_name))})),this.flashNewFiles([i.id])}flashNewFiles(t){t.length&&(this.newFileIds.update(e=>new Set([...e,...t])),setTimeout(()=>{this.newFileIds.update(e=>{let i=new Set(e);return t.forEach(o=>i.delete(o)),i})},1500))}triggerFileUpload(t){let e=document.createElement("input");e.type="file",e.multiple=!0,e.style.display="none",document.body.appendChild(e);let i=()=>{document.body.contains(e)&&document.body.removeChild(e)};e.onchange=a=>{let m=a.target?.files;m&&m.length>0&&this.uploadFiles(Array.from(m),t),i()};let o=()=>{window.removeEventListener("focus",o),setTimeout(i,500)};window.addEventListener("focus",o),e.click()}triggerUpload(){this.triggerFileUpload(this.currentFolderId())}static \u0275fac=function(e){return new(e||n)};static \u0275cmp=V({type:n,selectors:[["app-client-files-tab"]],inputs:{clientId:[1,"clientId"]},outputs:{attachToComposer:"attachToComposer"},decls:8,vars:17,consts:[[1,"flex","flex-col","min-h-full"],[1,"flex","items-center","gap-2","px-3","py-2","bg-surface-component","border-b","border-theme-default"],[1,"flex","items-center","gap-2","px-3","py-1.5","text-xs","text-theme-secondary","bg-surface-subtle","border-b","border-theme-subtle"],[1,"px-3","py-1.5","bg-accent-500/10","border-b","border-accent-500/25"],[1,"flex","flex-1","flex-col","overflow-x-hidden"],[3,"locationClick","signaturesChanged","folderClick","folderAction","fileAction","multiSelectAction","dropUpload","fileDragStart","folderDragStart","multiItemDragStart","folderDrop","attachmentDrop","dragEnter","dragLeave","uploadTrigger","createFolderTrigger","folders","files","isLoading","searchTerm","isDragging","renamingFolderIds","renamingFileIds","deletingFolderIds","deletingFileIds","movingFolderIds","movingFileIds","newFileIds","signaturesByFile","protectedPdfIds"],[1,"flex-1","min-w-0",3,"focusout","keydown.escape"],["placeholder","Search all files...","inputType","search","size","sm","rounded","full",3,"ngModelChange","ngModel","autoFocus","showErrorMessage"],[1,"flex","items-center","gap-0.5","flex-shrink-0"],["type","button","title","Close search",1,"btn","btn-ghost","h-
237","w-7","p-0","flex","items-center","justify-center",3,"click"],[1,"text-xs",3,"icon"],["type","button","title","Refresh results",1,"btn","btn-ghost","h-7","w-7","p-0","flex","items-center","justify-center",3,"click","disabled"],[1,"flex-1","min-w-0",3,"navigate","breadcrumbDrop","attachmentDrop","foldersTree","currentFolderId"],["type","button","title","Search all files",1,"btn","btn-ghost","h-7","w-7","p-0","flex","items-center","justify-center",3,"click"],["type","button","title","Refresh folder",1,"btn","btn-ghost","h-7","w-7","p-0","flex","items-center","justify-center",3,"click","disabled"],["type","button","title","Upload files from your computer",1,"btn","btn-ghost","h-7","w-7","p-0","flex","items-center","justify-center",3,"click","disabled"],["type","button","title","Create new folder",1,"btn","btn-ghost","h-7","w-7","p-0","flex","items-center","justify-center",3,"click","disabled"],[1,"truncate"],[1,"text-theme-disabled","flex-shrink-0"],[1,"flex","items-center","gap-2","text-xs","text-accent"],[1,"inline-block","w-3","h-3","border-2","border-accent-500/30","border-t-accent-500","rounded-full","animate-spin"]],template:function(e,i){e&1&&(l(0,"div",0)(1,"div",1),C(2,Ns,7,8)(3,Ls,10,11),s(),C(4,As,4,4,"div",2),C(5,Rs,5,0,"div",3),l(6,"div",4)(7,"app-file-list",5),f("locationClick",function(a){return i.navigateToFolder(a)})("signaturesChanged",function(){return i.refreshSignatures()})("folderClick",function(a){return i.navigateToFolder(a)})("folderAction",function(a){return i.handleFolderAction(a)})("fileAction",function(a){return i.handleFileAction(a)})("multiSelectAction",function(a){return i.handleMultiSelectAction(a)})("dropUpload",function(a){return i.handleDropUpload(a)})("fileDragStart",function(a){return i.handleFileDragStart(a)})("folderDragStart",function(a){return i.handleFolderDragStart(a)})("multiItemDragStart",function(a){return i.handleMultiItemDragStart(a)})("folderDrop",function(a){return i.handleFolderDrop(a)})("attachmentDrop",function(a){return i.handleAttachmentDrop(a)})("dragEnter",function(){return i.handleDragEnter()})("dragLeave",function(){return i.handleDragLeave()})("uploadTrigger",function(){return i.triggerUpload()})("createFolderTrigger",function(){return i.openCreateFolderModal()}),s()()()),e&2&&(r(2),h(i.searchOpen()?2:3),r(2),h(i.isSearching()?4:-1),r(),h(i.isUploading()?5:-1),r(2),p("folders",i.folders())("files",i.files())("isLoading",i.isLoading())("searchTerm",i.searchTerm())("isDragging",i.isDragging())("renamingFolderIds",i.renamingFolderIds())("renamingFileIds",i.renamingFileIds())("deletingFolderIds",i.deletingFolderIds())("deletingFileIds",i.deletingFileIds())("movingFolderIds",i.movingFolderIds())("movingFileIds",i.movingFileIds())("newFileIds",i.newFileIds())("signaturesByFile",i.signaturesByFile())("protectedPdfIds",i.protectedPdfIds()))},dependencies:[R,Lt,Pt,q,ne,K,Ae],encapsulation:2,changeDetection:0})};var xo=(n,t)=>t.id;function Bs(n,t){if(n&1){let e=y();l(0,"button",8),f("click",function(){let o=u(e).$implicit,a=d();return _(a.activeGroupId.set(o.id))})("contextmenu",function(o){let a=u(e).$implicit,m=d();return _(m.openGroupMenu(o,a))})("longPress",function(o){let a=u(e).$implicit,m=d();return _(m.openGroupMenu(o,a))})("dragover",function(o){let a=u(e).$implicit,m=d();return _(m.onDragOverGroup(o,a.id))})("dragleave",function(){u(e);let o=d();return _(o.onDragLeaveGroup())})("drop",function(o){let a=u(e).$implicit,m=d();return _(m.onDropOnGroup(o,a.id))}),c(1),s()}if(n&2){let e=t.$implicit,i=d();N("text-accent",i.activeGroupId()===e.id)("border-accent-500",i.activeGroupId()===e.id)("text-theme-secondary",i.activeGroupId()!==e.id)("border-transparent",i.activeGroupId()!==e.id)("hover:text-theme-primary",i.activeGroupId()!==e.id)("!bg-accent-100",i.dragOverGroupId()===e.id),r(),x(" ",e.name," ")}}function zs(n,t){n&1&&g(0,"app-loader")}function Gs(n,t){if(n&1&&(l(0,"bc-badge",14),c(1),s()),n&2){let e=t.$implicit;r(),A(e)}}function qs(n,t){if(n&1&&(l(0,"span",16),c(1),s()),n&2){let e=d().$implicit;r(),x("(",e.row_count,")")}}function js(n,t){if(n&1){let e=y();l(0,"button",11),f("click",function(){let o=u(e).$implicit,a=d(2);return _(a.openTable(o))})("dragstart",function(o){let a=u(e).$implicit,m=d(2);return _(m.onDragStart(o,a))}),l(1,"div",12)(2,"span",13),c(3),s(),E(4,Gs,2,1,"bc-badge",14,li),s(),l(6,"div",15),C(
237,qs,2,1,"span",16),g(8,"fa-icon",17),s()()}if(n&2){let e=t.$implicit,i=t.$index,o=d(2);he("data-onboarding",i===0?"tables-first-table":null),r(3),A(e.label),r(),k(o.getGroupNames(e)),r(3),h(e.row_count>0?7:-1),r(),p("icon",o.faChevronRight)}}function Ks(n,t){if(n&1){let e=y();l(0,"div",10)(1,"p",18),c(2," No tables in this group "),s(),l(3,"button",19),f("click",function(){u(e);let o=d(2);return _(o.addTable())}),c(4," Add Table "),s()()}}function Qs(n,t){if(n&1&&(l(0,"div",7),E(1,js,9,4,"button",9,xo,!1,Ks,5,0,"div",10),s()),n&2){let e=d();r(),k(e.filteredTables())}}var Ot=class n{customTableService=F(On);extendedPanelService=F(_e);modalService=F(ie);toastService=F(G);contextMenuService=F(Ct);onboardingService=F(wt);clientId=T.required();clientName=T("");faChevronRight=Fe;faPencil=Ne;faTrash=X;activeGroupId=S("all");dragOverGroupId=S(null);tablesResource=this.customTableService.createTablesListResource(this.clientId);groupsResource=this.customTableService.getGroups();constructor(){this.customTableService.changes$.pipe(hn()).subscribe(()=>{this.tablesResource.reload(),this.groupsResource.reload()}),P(()=>{let t=this.onboardingService.tourStepId();(t==="tables-what"||t==="tables-open")&&this.activeGroupId()!=="all"&&ee(()=>this.activeGroupId.set("all"))})}groups=b(()=>this.groupsResource.value()?.groups??[]);tables=b(()=>this.tablesResource.value()?.tables??[]);filteredTables=b(()=>{let t=this.activeGroupId(),e=this.tables();return t==="all"?e:e.filter(i=>i.groups?.includes(t))});isLoading=b(()=>this.tablesResource.isLoading());groupNameMap=b(()=>{let t=new Map;for(let e of this.groups())t.set(e.id,e.name);return t});getGroupNames(t){let e=this.groupNameMap();return(t.groups??[]).map(i=>e.get(i)).filter(i=>!!i)}openTable(t){this.extendedPanelService.openWithComponent(lo,{clientId:this.clientId(),clientName:this.clientName(),initialTableId:t.id,expandNonce:Date.now()},"Custom Tables")}async addTable(){let t=await this.modalService.showModal(St,{title:"New Table",label:"Table Name",placeholder:"Enter table name",confirmText:"Create"});if(t)try{await D(this.customTableService.createTable({label:t})),this.tablesResource.reload(),this.customTableService.notifyChanges(),this.toastService.add("Table created",2e3,"success")}catch{this.toastService.add("Failed to create table",3e3,"error")}}async addGroup(){let t=await this.modalService.showModal(St,{title:"New Group",label:"Group Name",placeholder:"Enter group name",confirmText:"Create"});if(t)try{await D(this.customTableService.createGroup({name:t})),this.groupsResource.reload(),this.customTableService.notifyChanges(),this.toastService.add("Group created",2e3,"success")}catch{this.toastService.add("Failed to create group",3e3,"error")}}async deleteGroup(t){let e=t??this.lastContextMenuGroupId;if(!(!e||!await this.modalService.showModal(Y,{title:"Delete Group",message:'Are you sure you want to delete this group? Tables will be moved to "All".',confirmText:"Delete",cancelText:"Cancel",variant:"danger"})))try{await D(this.customTableService.deleteGroup({group_id:e})),this.groupsResource.reload(),this.tablesResource.reload(),this.customTableService.notifyChanges(),this.activeGroupId()===e&&this.activeGroupId.set("all"),this.toastService.add("Group deleted",2e3,"success")}catch{this.toastService.add("Failed to delete group",3e3,"error")}}lastContextMenuGroupId=null;openGroupMenu(t,e){t.preventDefault(),t.stopPropagation(),this.lastContextMenuGroupId=e.id,this.contextMenuService.show(t,[{label:"Rename",action:"rename",icon:this.faPencil},{type:"separator",label:"",action:""},{label:"Delete",action:"delete",variant:"danger",icon:this.faTrash}],i=>{i==="rename"?this.renameGroup(e):i==="delete"&&this.deleteGroup(e.id)},{compact:!0})}async renameGroup(t){let e=t??this.groups().find(o=>o.id===this.lastContextMenuGroupId);if(!e)return;let i=await this.modalService.showModal(St,{title:"Rename Group",label:"Group Name",placeholder:"Enter new name",confirmText:"Rename",initialValue:e.name});if(!(!i||i===e.name))try{await D(this.customTableService.updateGroup({group_id:e.id,name:i})),this.groupsResource.reload(),this.tablesResource.reload(),this.customTableService.n
23otifyChanges(),this.toastService.add("Group renamed",2e3,"success")}catch{this.toastService.add("Failed to rename group",3e3,"error")}}onDragStart(t,e){t.dataTransfer?.setData("text/plain",String(e.id)),t.dataTransfer.effectAllowed="move"}onDragOverGroup(t,e){t.preventDefault(),t.dataTransfer.dropEffect="move",this.dragOverGroupId.set(e)}onDragLeaveGroup(){this.dragOverGroupId.set(null)}async onDropOnGroup(t,e){t.preventDefault(),this.dragOverGroupId.set(null);let i=Number(t.dataTransfer?.getData("text/plain"));if(!i)return;let o=this.tables().find(a=>a.id===i);if(o&&!o.groups?.includes(e)){this.tablesResource.update(a=>a&&L(I({},a),{tables:a.tables.map(m=>m.id===i?L(I({},m),{groups:[...m.groups??[],e]}):m)}));try{await D(this.customTableService.addTableToGroup({group_id:e,table_id:i})),this.groupsResource.reload(),this.customTableService.notifyChanges()}catch{this.tablesResource.reload(),this.toastService.add("Failed to add to group",3e3,"error")}}}static \u0275fac=function(e){return new(e||n)};static \u0275cmp=V({type:n,selectors:[["app-client-tables-tab"]],inputs:{clientId:[1,"clientId"],clientName:[1,"clientName"]},decls:12,vars:12,consts:[[1,"flex","flex-col","h-full"],[1,"pt-1"],["dragScroll","","dragScrollAxis","x",1,"flex","items-center","overflow-x-auto","no-scrollbar","border-b","border-theme-subtle",3,"dragScrollFromButtons"],["type","button",1,"flex-shrink-0","px-3","py-2","text-xs","font-medium","border-b-2","transition-colors","whitespace-nowrap",3,"click"],["type","button","appLongPress","",1,"flex-shrink-0","px-3","py-2","text-xs","font-medium","border-b-2","transition-colors","whitespace-nowrap",3,"text-accent","border-accent-500","text-theme-secondary","border-transparent","hover:text-theme-primary","!bg-accent-100"],["type","button",1,"flex-shrink-0","px-2.5","py-2","text-xs","text-theme-secondary","hover:text-theme-primary","border-b-2","border-transparent","transition-colors",3,"click"],["data-onboarding","tables-list",1,"flex-1","overflow-y-auto","py-4","px-1"],[1,"space-y-1"],["type","button","appLongPress","",1,"flex-shrink-0","px-3","py-2","text-xs","font-medium","border-b-2","transition-colors","whitespace-nowrap",3,"click","contextmenu","longPress","dragover","dragleave","drop"],["type","button","draggable","true",1,"w-full","flex","items-center","justify-between","px-3","py-2.5","rounded-lg","hover:bg-surface-hover","transition-colors","group","text-left"],[1,"text-center","py-6"],["type","button","draggable","true",1,"w-full","flex","items-center","justify-between","px-3","py-2.5","rounded-lg","hover:bg-surface-hover","transition-colors","group","text-left",3,"click","dragstart"],[1,"flex","items-center","gap-1.5","min-w-0","flex-1"],[1,"text-sm","text-theme-primary","truncate"],["variant","info","size","xs"],[1,"flex","items-center","gap-2","flex-shrink-0"],[1,"text-xs","text-theme-secondary","flex-shrink-0"],[1,"text-xs","text-theme-secondary","has-hover:opacity-0","has-hover:group-hover:opacity-100","transition-opacity",3,"icon"],[1,"text-sm","text-theme-secondary"],["type","button",1,"btn","btn-outline","btn-small","mt-3",3,"click"]],template:function(e,i){e&1&&(l(0,"div",0)(1,"div",1)(2,"div",2)(3,"button",3),f("click",function(){return i.activeGroupId.set("all")}),c(4," All "),s(),E(5,Bs,2,13,"button",4,xo),l(7,"button",5),f("click",function(){return i.addGroup()}),c(8," + "),s()()(),l(9,"div",6),C(10,zs,1,0,"app-loader")(11,Qs,4,1,"div",7),s()()),e&2&&(r(2),p("dragScrollFromButtons",!0),r(),N("text-accent",i.activeGroupId()==="all")("border-accent-500",i.activeGroupId()==="all")("text-theme-secondary",i.activeGroupId()!=="all")("border-transparent",i.activeGroupId()!=="all")("hover:text-theme-primary",i.activeGroupId()!=="all"),r(2),k(i.groups()),r(5),h(i.isLoading()?10:11))},dependencies:[R,H,Ie,gt,yt],encapsulation:2,changeDetection:0})};var Hs=()=>({label:"Address 1",key:"adress_1"}),Ws=()=>({label:"Address 2",key:"adress_2"}),Js=()=>({label:"Address 3",key:"adress_3"}),Xs=()=>({label:"Address 4",key:"adress_4"}),Ys=()=>({label:"Address 5",key:"adress_5"}),Zs=(n,t,e,i,o)=>[n,t,e,i,o],ed=()=>({label:"Addressed To",key:"billing_adressed_to"}),td=()=>({label:"Billing Address 1",key:"billing_adress_1"}),id=()=>({label:"Billing Address 2",key:"billing_adress_2"}),nd=()=>({label:"Billing Address 3",key:"billing_adress_3"}),od=()=>({label:"Billing Address 4",key:"billing_adress_4"}),ad=()=>({label:"Billing Address 5",key:"billing_adress_5"}),rd=(n,t,e,i,o,a)=>[n,t,e,i,o,a],So=(n,t)=>t.key;function ld(n,t){if(n&1&&c(0),n&2){let e,i=d(2);x(" ",(e=i.client())==null?null:e.company_name," ")}}function sd(n,t){n&1&&(l(0,"span",14),c(1,"Unknown"),s())}function dd(n,t){if(n&1){let e=y();l(0,"div",4)(1,"div",11)(2,"app-client-inline-edit",12),f("save",function(o){u(e);let a=d();return _(a.handleInlineEditSave(o))})("valueChange",function(o){u(e);let a=d();return _(a.onCompanyNameChange(o))}),l(3,"h3",13),C(4,ld,1,1)(5,sd,2,0,"span",14),s()()(),l(6,"div",15)(7,"p",16),c(8),s(),l(9,"app-client-inline-dropdown",17),f("save",function(o){u(e);let a=d();return _(a.handleInlineDropdownSave(o))})("valueChange",function(o){u(e);let a=d();return _(a.onBuiltInFieldDropdownChange("status_label",o))}),l(10,"span",18),xe(11,"bcTextColor"),c(12),s()(),l(13,"button",19),f("click",function(){u(e);let o=d();return _(o.settingsService.open("client-statuses"))}),g(14,"fa-icon",20),s()()()}if(n&2){let e,i=d();r(2),p("value",i.client().company_name)("clientId",i.client().client_id)("columnKey","company_name")("table","clients"),r(2),h(!((e=i.client())==null||e.company_name==null)&&e.company_name.trim()?4:5),r(4),x(" ID: ",i.client().o_client_id," "),r(),p("displayValue",i.client().status_label)("currentValue",i.client().client_status)("clientId",i.client().client_id)("columnKey","status_label")("databaseKey","client_status")("options",i.statuses())("transformer",i.transformStatus)("colorFunction",i.statusColorFunction)("clearable",!1)("table","clients"),r(),Je("background-color",i.client().status_color)("color",ye(11,22,i.client().status_color,
23i.client().status_text_color)),r(2),x(" ",i.getStatusDisplayValue()," "),r(2),p("icon",i.faGear)}}function cd(n,t){n&1&&c(0," Error ")}function md(n,t){n&1&&c(0," Loading... ")}function pd(n,t){if(n&1&&(l(0,"div",4)(1,"h3",21),C(2,cd,1,0)(3,md,1,0),s()()),n&2){let e=d();r(2),h(e.resource.error()?2:e.resource.isLoading()?3:-1)}}function ud(n,t){if(n&1){let e=y();l(0,"li")(1,"button",24),f("click",function(){u(e);let o=d(2);return _(o.handleAssumeRole())}),g(2,"fa-icon",25),c(3," Assume role "),s()()}if(n&2){let e=d(2);r(2),p("icon",e.faArrowRightToBracket)}}function _d(n,t){if(n&1){let e=y();l(0,"li")(1,"button",24),f("click",function(){u(e);let o=d(2);return _(o.handleMergeClient())}),g(2,"fa-icon",25),c(3," Merge client "),s()(),l(4,"li",26)(5,"button",27),f("click",function(){u(e);let o=d(2);return _(o.handleDeleteClient())}),g(6,"fa-icon",25),c(7," Delete client "),s()()}if(n&2){let e=d(2);r(2),p("icon",e.faCodeMerge),r(4),p("icon",e.faTrash)}}function fd(n,t){if(n&1){let e=y();l(0,"div",6)(1,"button",22),g(2,"fa-icon",8),s(),l(3,"div",23)(4,"ul")(5,"li")(6,"button",24),f("click",function(){u(e);let o=d();return _(o.showActivity())}),g(7,"fa-icon",25),c(8," Show activity "),s()(),l(9,"li")(10,"button",24),f("click",function(){u(e);let o=d();return _(o.copyClientLink())}),g(11,"fa-icon",25),c(12," Copy link "),s()(),l(13,"li")(14,"button",24),f("click",function(){u(e);let o=d();return _(o.handleCreateCalendarEvent())}),g(15,"fa-icon",25),c(16," New Meeting "),s()(),C(17,ud,4,1,"li"),C(18,_d,8,2),s()()()}if(n&2){let e=d();r(2),p("icon",e.faEllipsisVertical),r(5),p("icon",e.faChartLine),r(4),p("icon",e.faLink),r(4),p("icon",e.faCalendarPlus),r(2),h(e.canAssumeRole()?17:-1),r(),h(e.canDeleteClients()?18:-1)}}function Cd(n,t){if(n&1){let e=y();l(0,"button",34),f("click",function(){u(e);let o=d(2);return _(o.handleSendWhatsapp())}),g(1,"fa-icon",25),c(2," WhatsApp "),s()}if(n&2){let e=d(2);r(),p("icon",e.faWhatsapp)}}function hd(n,t){if(n&1){let e=y();l(0,"button",46),f("click",function(){u(e);let o=d(2);return _(o.switchTab("files"))}),g(1,"fa-icon",39),l(2,"span"),c(3,"Files"),s()()}if(n&2){let e=d(2);N("text-theme-secondary",e.activeTab()!=="files")("border-transparent",e.activeTab()!=="files")("hover:text-theme-primary",e.activeTab()!=="files")("text-accent",e.activeTab()==="files")("border-accent-500",e.activeTab()==="files"),r(),p("icon",e.faFolder)}}function gd(n,t){if(n&1){let e=y();l(0,"button",47),f("click",function(){u(e);let o=d(2);return _(o.switchTab("accounting"))}),g(1,"fa-icon",39),l(2,"span"),c(3,"Accounting"),s()()}if(n&2){let e=d(2);N("text-theme-secondary",e.activeTab()!=="accounting")("border-transparent",e.activeTab()!=="accounting")("hover:text-theme-primary",e.activeTab()!=="accounting")("text-accent",e.activeTab()==="accounting")("border-accent-500",e.activeTab()==="accounting"),r(),p("icon",e.faFileInvoiceDollar)}}function bd(n,t){if(n&1){let e=y();l(0,"div",45)(1,"span",48),g(2,"fa-icon",25),c(3," Edit Mode \u2014 Tap a field to edit "),s(),l(4,"button",49),f("click",function(){u(e);let o=d(2);return _(o.customFieldsList().isEditMode.set(!1))}),g(5,"fa-icon",25),s()()}if(n&2){let e=d(2);r(2),p("icon",e.faPencil),r(3),p("icon",e.faTimes)}}function vd(n,t){if(n&1){let e=y();l(0,"div",28)(1,"div",29)(2,"button",30),f("click",function(){u(e);let o=d();return _(o.handleCreateNote())}),g(3,"fa-icon",25),c(4," Note "),s(),l(5,"button",31),f("click",function(){u(e);let o=d();return _(o.handleSendEmail())}),g(6,"fa-icon",25),c(7," Email "),s(),l(8,"button",32),f("click",function(){u(e);let o=d();return _(o.handleSendSms())}),g(9,"fa-icon",25),c(10," Text "),s(),C(11,Cd,3,1,"button",33),l(12,"button",34),f("click",function(){u(e);let o=d();return _(o.handleViewCommunications())}),g(13,"fa-icon",25),c(14," Comms "),s()()(),l(15,"div",35),g(16,"bc-text-input",36),s(),l(17,"div",37)(18,"button",38),f("click",function(){u(e);let o=d();return _(o.switchTab("details"))}),g(19,"fa-icon",39),l(20,"span"),c(21,"Details"),s()(),l(22,"button",40),f("click",function(){u(e);let o=d();return _(o.switchTab("contacts"))}),g(23,"fa-icon",39),l(24,"span"),c(25,"Contacts"),s()(),C(26,hd,4,11,"button",41),l(27,"button",42),f("click",function(){u(e);let o=d();return _(o.switchTab("tables"))}),g(28,"fa-icon",39),l(29,"span"),c(30,"Tables"),s()(),C(31,gd,4,11,"button",43),l(32,"button",44),f("click",function(){u(e);let o=d();return _(o.switchTab("activity"))}),g(33,"fa-icon",39),l(34,"span"),c(35,"Activity"),s()()(),C(36,bd,6,2,"div",45)}if(n&2){let e,i=d();r(3),p("icon",i.faStickyNote),r(3),p("icon",i.faEnvelope),r(3),p("icon",i.faCommentDots),r(2),h(i.whatsAppConnected()?11:-1),r(2),p("icon",i.faComments),r(3),N("opacity-50",i.resource.isLoading())("pointer-events-none",i.resource.isLoading()),p("initialValue",i.notesValue())("onBlurSave",i.saveNotes),r(),p("dragScrollFromButtons",!0),r(),N("text-theme-secondary",i.activeTab()!=="details")("border-transparent",i.activeTab()!=="details")("hover:text-theme-primary",i.activeTab()!=="details")("text-accent",i.activeTab()==="details")("border-accent-500",i.activeTab()==="details"),r(),p("icon",i.faUser),r(3),N("text-theme-secondary",i.activeTab()!=="contacts")("border-transparent",i.activeTab()!=="contacts")("hover:text-theme-primary",i.activeTab()!=="contacts")("text-accent",i.activeTab()==="contacts")("border-accent-500",i.activeTab()==="contacts"),r(),p("icon",i.faAddressBook),r(3),h(i.hasFilesAccess()?26:-1),r(),N("text-theme-secondary",i.activeTab()!=="tables")("border-transparent",i.activeTab()!=="tables")("hover:text-theme-primary",i.activeTab()!=="tables")("text-accent",i.activeTab()==="tables")("border-accent-500",i.activeTab()==="tables"),r(),p("icon",i.faTableCellsLarge),r(3),h(i.hasAccountingAccess()?31:-1),r(),N("text-theme-secondary",i.activeTab()!=="activity")("border-transparent",i.activeTab()!=="activity")("hover:text-theme-primary",i.activeTab()!=="activity")("text-accent",i.activeTab()==="activity")("border-accent-500",i.activeTab()==="activity"),r(),p("icon",i.faClockRotateLeft),r(3),h((e=i.customFieldsList())!=null&&e.isEditMode()?36:-1)}}function xd(n,t){if(n&1){let e=y();l(0,"div",58)(1,"dt",16),c(2),s(),l(3,"dd",61)(4,"app-client-inline-edit",67),f("save",function(o){u(e);let a=d(4);return _(a.handleInlineEditSave(o))}
23),c(5),s()()()}if(n&2){let e=t.$implicit,i=d(4);r(2),x(" ",e.label," "),r(2),p("value",i.client()[e.key])("clientId",i.client().client_id)("columnKey",e.key)("databaseKey",e.key)("table","clients"),r(),A(i.client()[e.key]||"\u2014")}}function yd(n,t){n&1&&(l(0,"dl",65),E(1,xd,6,7,"div",58,So),s()),n&2&&(r(),k(Ci(5,Zs,j(0,Hs),j(1,Ws),j(2,Js),j(3,Xs),j(4,Ys))))}function Sd(n,t){if(n&1){let e=y();l(0,"div",58)(1,"dt",16),c(2),s(),l(3,"dd",61)(4,"app-client-inline-edit",67),f("save",function(o){u(e);let a=d(4);return _(a.handleInlineEditSave(o))}),c(5),s()()()}if(n&2){let e=t.$implicit,i=d(4);r(2),x(" ",e.label," "),r(2),p("value",i.client()[e.key])("clientId",i.client().client_id)("columnKey",e.key)("databaseKey",e.key)("table","clients"),r(),A(i.client()[e.key]||"\u2014")}}function Fd(n,t){n&1&&(l(0,"dl",65),E(1,Sd,6,7,"div",58,So),s()),n&2&&(r(),k(hi(6,rd,j(0,ed),j(1,td),j(2,id),j(3,nd),j(4,od),j(5,ad))))}function wd(n,t){if(n&1){let e=y();l(0,"div",50)(1,"div",55)(2,"h4",56),c(3," Client Information "),s(),l(4,"dl",57)(5,"div",58)(6,"dt",16),c(7," Manager "),s(),l(8,"app-client-inline-dropdown",59),f("save",function(o){u(e);let a=d(2);return _(a.handleInlineDropdownSave(o))})("valueChange",function(o){u(e);let a=d(2);return _(a.onBuiltInFieldDropdownChange("admin_responsible_name",o))}),l(9,"dd",60),c(10),s()()(),l(11,"div",58)(12,"dt",16),c(13," Registered "),s(),l(14,"dd",61),c(15),xe(16,"date"),s()(),l(17,"div",58)(18,"dt",16),c(19," First Contact "),s(),l(20,"dd",61),c(21),s()()()(),l(22,"div")(23,"div",62),f("click",function(){u(e);let o=d(2);return _(o.showCompanyAddress.set(!o.showCompanyAddress()))}),l(24,"dt",63),g(25,"fa-icon",64),c(26," Company Address "),s()(),C(27,yd,3,11,"dl",65),s(),l(28,"div")(29,"div",62),f("click",function(){u(e);let o=d(2);return _(o.showBillingAddress.set(!o.showBillingAddress()))}),l(30,"dt",63),g(31,"fa-icon",64),c(32," Billing Address "),s()(),C(33,Fd,3,13,"dl",65),s(),l(34,"app-custom-fields-list",66),f("attachToComposer",function(o){u(e);let a=d(2);return _(a.handleAttachFilesToComposer(o))}),s()()}if(n&2){let e=d(2);r(8),p("displayValue",e.getManagerDisplayValue())("currentValue",e.client().admin_responsible)("clientId",e.client().client_id)("columnKey","admin_responsible_name")("databaseKey","admin_responsible")("options",e.managers())("transformer",e.transformManager)("clearable",!1)("table","clients"),r(2),x(" ",e.getManagerDisplayValue()," "),r(5),x(" ",ye(16,21,e.client().date_registered,"dd MMM yyyy @ HH:mm:ss")," "),r(6),x(" ",e.client().first_contact," "),r(4),N("rotate-90",e.showCompanyAddress()),p("icon",e.faChevronRight),r(2),h(e.showCompanyAddress()?27:-1),r(4),N("rotate-90",e.showBillingAddress()),p("icon",e.faChevronRight),r(2),h(e.showBillingAddress()?33:-1),r(),p("clientId",e.clientId())}}function Td(n,t){if(n&1&&g(0,"app-client-contacts-tab",51),n&2){let e,i=d(2);p("clientId",i.clientId())("clientName",((e=i.client())==null?null:e.company_name)??"")("initialSearch",i.defaultContactSearch())}}function Id(n,t){if(n&1){let e=y();l(0,"app-client-files-tab",68),f("attachToComposer",function(o){u(e);let a=d(2);return _(a.handleAttachFilesToComposer(o))}),s()}if(n&2){let e=d(2);p("clientId",e.clientId())}}function Dd(n,t){if(n&1){let e=y();l(0,"app-client-accounting-tab",68),f("attachToComposer",function(o){u(e);let a=d(2);return _(a.handleAttachFilesToComposer(o))}),s()}if(n&2){let e=d(2);p("clientId",e.clientId())}}function Ed(n,t){if(n&1&&g(0,"app-client-tables-tab",53),n&2){let e,i=d(2);p("clientId",i.clientId())("clientName",((e=i.client())==null?null:e.company_name)??"")}}function kd(n,t){if(n&1&&g(0,"app-activity-log-panel",54),n&2){let e=d(2);p("clientId",e.clientId())}}function Md(n,t){if(n&1&&(l(0,"div",9),C(1,wd,35,24,"div",50)(2,Td,1,3,"app-client-contacts-tab",51)(3,Id,1,1,"app-client-files-tab",52)(4,Dd,1,1,"app-client-accounting-tab",52)(5,Ed,1,2,"app-client-tables-tab",53)(6,kd,1,1,"app-activity-log-panel",54),s()),n&2){let e,i=d();r(),h((e=i.activeTab())==="details"?1:e==="contacts"?2:e==="files"?3:e==="accounting"?4:e==="tables"?5:e==="activity"?6:-1)}}function Vd(n,t){if(n&1){let e=y();l(0,"div",69),g(1,"fa-icon",70),l(2,"div",71)(3,"h3",72),c(4," Client Deleted "),s(),l(5,"p",73),c(6," This client has been deleted and is no longer available. "),s()(),l(7,"button",74),f("click",function(){u(e);let o=d(2);return _(o.close())}),c(8," Close "),s()()}if(n&2){let e=d(2);r(),p("icon",e.faTrash)}}function Nd(n,t){if(n&1&&(l(0,"div",75),g(1,"fa-icon",76),l(2,"div",71)(3,"h3",72),c(4),s(),l(5,"p",73),c(6," You do not have access to this client "),s()(),l(7,"div",77)(8,"p",78),c(9," Responsible Manager "),s(),l(10,"p",79),c(11),s()(),l(12,"p",80),c(13," Please contact the responsible manager to request access to this client. "),s()()),n&2){let e=t,i=d(3);r(),p("icon",i.faLock),r(3),x(" ",e.client_name," "),r(7),Xe(" ",e.admin_responsible_name," ",e.admin_responsible_surname," ")}}function Ld(n,t){if(n&1&&(l(0,"div",82)(1,"p",85),c(2),s()()),n&2){let e=d(4);r(2),x(" ",e.errorMessage()," ")}}function Pd(n,t){if(n&1){let e=y();l(0,"div",69),g(1,"fa-icon",81),l(2,"div",71)(3,"h3",72),c(4," Failed to Load Client "),s(),l(5,"p",73),c(6," The requested client could not be found or loaded. "),s()(),C(7,Ld,3,1,"div",82),l(8,"button",83),f("click",function(){u(e);let o=d(3);return _(o.retryLoad())}),g(9,"fa-icon",84),c(10," Try Again "),s()()}if(n&2){let e=d(3);r(),p("icon",e.faExclamationTriangle),r(6),h(e.errorMessage()?7:-1),r(2),p("icon",e.faRotateRight)}}function Ad(n,t){if(n&1&&C(0,Nd,14,4,"div",75)(1,Pd,11,3,"div",69),n&2){let e,i=d(2);h((e=i.accessRestrictedData())?0:1,e)}}function Rd(n,t){n&1&&(g(0,"app-loader",86),l(1,"p",87),c(2," Loading client... "),s()),n&2&&p("loadingState",!0)}function Ud(n,t){if(n&1&&(l(0,"div",10),C(1,Vd,9,1,"div",69)(2,Ad,2,1)(3,Rd,3,1),s()),n&2){let e=d();r(),h(e.isDeleted()?1:e.resource.error()?2:e.resource.isLoading()?3:-1)}}var yo=class n{clientService=F(Q);toastService=F(G);accountService=F(fn);clipboard=F(pt);panelService=F(An);extendedPanelService=F(_e);contactLinkService=F(Xn);communicationService=F(Tt);whatsAppConnected=this.communicationService.whatsAppConnected;authService=F(dt);modalService=F(ie);settingsService=F(Ft);bottomPanelService=F(Yn);router=F(Si);activatedRoute=F(yi);onboardingService=F(wt);faUser=nt;faChartLine=Xi;faLink=Ve;faFolder=at;faFileInvoiceDollar=zi;faTimes=Hi;faSearch=st;faAddressBook=it;faCodeMerge=Ni;faTrash=X;faExclamationTriangle=Oi;faRotateRight=Gi;faLock=Ze;faEnvelope=we;faCommentDots=et;faWhatsapp=mt;faComments=ji;faStickyNote=rn;faEllipsisVertical=an;faPlus=Me;faClockRotateLeft=tt;faTableCellsLarge=Ii;faGear=ot;faChevronRight=Fe;faPencil=Ne;faCalendarPlus=Zi;faArrowRightToBracket=en;canAssumeRole=b(()=>this.authService.userData()?.admin_status===2&&!this.authService.isAssumingRole());hasFilesAccess=b(()=>this.authService.isSuperUser()||this.authService.userData()?.files_access===1);hasAccountingAccess=b(()=>this.authService.isSuperUser()||this.authService.userData()?.view_invoices===1);showCompanyAddress=S(!1);showBillingAddress=S(!1);customFieldsList=bi(Oe);previewClient=T(null);onClose=T();
23focusNoteId=T(null);defaultTab=T(null);defaultContactSearch=T("");activeTab=S("details");resource=this.clientService.selectedClientResource;managers=b(()=>this.clientService.managersResource.value()??[]);statuses=b(()=>this.clientService.statusesResource.value()??[]);errorMessage=b(()=>{let t=this.resource.error();if(!t)return"";if(t&&typeof t=="object"&&"error"in t){let e=t;return e.error?.error||e.message||"An unknown error occurred"}return String(t)});accessRestrictedData=b(()=>{let t=this.resource.error();if(!t)return null;let e=t?.error?.data??t?.data;return e?.client_name?e:null});client=b(()=>this.clientService.selectedClient()??this.previewClient());isDeleted=b(()=>this.clientService.selectedClient()?.deleted===1);hasClient=b(()=>this.client()!==null&&!this.isDeleted());canDeleteClients=b(()=>this.authService.isSuperUser()||this.authService.userData()?.can_delete_clients===1);clientId=b(()=>this.client()?.client_id??0);notesValue=b(()=>this.client()?.notes||"");transformManager=t=>({label:`${t.user_name} ${t.user_surname}`,value:t.id,disabled:t.user_status!==1,photoUrl:t.photo_url||null});transformStatus=t=>({label:t.label,value:t.client_status_id,disabled:t.active!==1});statusColorFunction=t=>{let e=this.statuses().find(i=>i.client_status_id===t.value);return e?{backgroundColor:e.color,textColor:yn(e.color,e.text_color)??""}:null};getManagerDisplayValue(){let t=this.client();return t?t.admin_responsible_name&&t.admin_responsible_surname?`${t.admin_responsible_name} ${t.admin_responsible_surname}`:t.admin_responsible_name||"Select manager":"Select manager"}getStatusDisplayValue(){return this.client()?.status_label||"Select status"}focusNoteConsumed=!1;constructor(){this.communicationService.loadWhatsAppStatus(),vi(()=>{this.hasClient()&&$n([{triggerId:"moreActionsButton",menuId:"moreActionsMenu"}])}),P(()=>{let e=this.focusNoteId(),i=this.client();e&&i&&!this.focusNoteConsumed&&(this.focusNoteConsumed=!0,setTimeout(()=>this.handleViewCommunications(e),100))}),P(()=>{this.client()&&ee(()=>this.onboardingService.resolveInteractiveStep("client-opened"))});let t=this.defaultTab();t&&this.activeTab.set(t),P(()=>{let e=this.defaultTab();e&&this.activeTab.set(e)})}switchTab(t){this.activeTab.set(t)}showActivity(){this.activeTab.set("activity")}copyClientLink(){let t=this.clientId();if(!t)return;let e=this.accountService.buildDashboardUrl("clients",{selected_client:String(t)});this.clipboard.copy(e),this.toastService.add("Link copied to clipboard",3e3,"success")}async handleCreateCalendarEvent(){let{EventCreateEditPanelComponent:t}=await import("./chunk-RG7NVFED.js"),e=this.clientId();this.bottomPanelService.open(t,I({},e?{clientId:e}:{}))}close(){this.panelService.close()}saveNotes=async t=>{await D(this.clientService.updateClientField({table:"clients",client_id:this.clientId(),column_name:"notes",value:t})),this.clientService.updateClientInList(this.clientId(),{notes:t})};interceptMailtoClick(t){let e=this.client();this.contactLinkService.handleClick(t,{clientId:e?.client_id??null,clientName:e?.company_name??""})}handleSendEmail(){let t=this.client();t&&this.extendedPanelService.openWithComponent(fe,{clientId:t.client_id,clientName:t.company_name,initialMode:"email",openTimestamp:Date.now()},"Communications")}handleSendSms(){let t=this.client();t&&this.extendedPanelService.openWithComponent(fe,{clientId:t.client_id,clientName:t.company_name,initialMode:"sms",o
23penTimestamp:Date.now()},"Communications")}handleSendWhatsapp(){let t=this.client();t&&this.extendedPanelService.openWithComponent(fe,{clientId:t.client_id,clientName:t.company_name,initialMode:"whatsapp",openTimestamp:Date.now()},"Communications")}handleCreateNote(){let t=this.client();t&&this.extendedPanelService.openWithComponent(fe,{clientId:t.client_id,clientName:t.company_name,initialMode:"note",openTimestamp:Date.now()},"Communications")}handleAttachFilesToComposer(t){let e=this.client();e&&this.extendedPanelService.openWithComponent(fe,{clientId:e.client_id,clientName:e.company_name,initialMode:t,openTimestamp:Date.now()},"Communications")}handleViewCommunications(t){let e=this.client();e&&this.extendedPanelService.openWithComponent(fe,I({clientId:e.client_id,clientName:e.company_name,initialMode:"note",startMinimized:!0},t?{focusNoteId:t}:{}),"Communications")}async handleMergeClient(){let t=this.client();if(!t)return;let{MergeClientModalComponent:e}=await import("./chunk-CDS5R77Z.js"),i=await this.modalService.showModal(e,{currentClientId:t.client_id,currentClientName:t.company_name||`Client ${t.client_id}`});i&&(this.clientService.flashClientRows([t.client_id],"danger"),setTimeout(()=>{this.clientService.removeClientsFromList([t.client_id]),this.clientService.selectedClientId.set(i.primaryClientId),this.router.navigate([],{relativeTo:this.activatedRoute,queryParams:{selected_client:i.primaryClientId},queryParamsHandling:"merge"})},600),this.toastService.add(`Client merged into "${i.primaryClientName}"`,3e3,"success"))}handleAssumeRole(){let t=this.client();if(!t)return;let e=`${window.location.origin}/dashboard/${t.client_id}/clients`;window.open(e,"_blank","noopener")}async handleDeleteClient(){let t=this.client();if(!t)return;let e=t.client_id,i=t.company_name||`Client ${e}`;await this.modalService.showModal(Y,{title:"Delete Client",message:`Are you sure you want to delete "${i}"? This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",confirmPhrase:i,onConfirm:()=>this.clientService.bulkDeleteClients({selectAllMode:!1,selectedItems:[e],excludeItems:[]}).pipe(Yt(()=>{this.clientService.removeClientsFromList([e]),this.clientService.clearSelection(),this.panelService.close(),this.router.navigate([],{relativeTo:this.activatedRoute,queryParams:{selected_client:null},queryParamsHandling:"merge"}),this.toastService.add(`"${i}" has been deleted`,3e3,"success")}))})}retryLoad(){this.resource.reload()}onBuiltInFieldDropdownChange(t,e){let i=this.client();if(!i)return;let o=e.value;switch(t){case"status_label":{let a=this.statuses().find(m=>m.client_status_id===o);if(!a)return;this.clientService.updateClientInList(i.client_id,{client_status:o,status_label:a.label,status_color:a.color,status_text_color:a.text_color});break}case"admin_responsible_name":{let a=this.managers().find(m=>m.id===o);if(!a)return;this.clientService.updateClientInList(i.client_id,{admin_responsible:o,admin_responsible_name:a.user_name,admin_responsible_surname:a.user_surname});break}}}async handleInlineSave(t){let e=this.client();if(!e){t.onError("No client selected");return}let i={};t.columnKey==="status_label"?i={client_status:e.client_status,status_label:e.status_label,status_color:e.status_color,status_text_color:e.status_text_color}:t.columnKey==="admin_responsible_name"?i={admin_responsible:e.admin_responsible,admin_responsible_name:e.admin_responsible_name,admin_responsible_surname:e.admin_responsible_surname}:t.columnKey==="company_name"&&(i={company_name:e.company_name});try{await D(this.clientService.updateClientField({table:t.table,client_id:t.clientId,column_name:t.databaseKey,value:t.value})),t.onSuccess(),this.toastService.add("Field updated",2e3,"success")}catch(o){this.clientService.updateClientInList(t.clientId,i),t.onError(o),this.toastService.add("Failed to update field",3e3,"error")}}onCompanyNameChange(t){let e=this.client();e&&this.clientService.updateClientInList(e.client_id,{company_name:t})}async handleInlineEditSave(t){let e=this.clientService.getClientFieldValue(t.params.client_id,t.columnKey);this.clientService.updateClientInList(t.params.client_id,{[t.columnKey]:t.value});try{await D(this.clientService.updateClientField(t.params)),t.onSuccess(),this.toastService.add("Updated",2e3,"success")}catch(i){this.clientService.updateClientInList(t.params.client_id,{[t.columnKey]:e}),t.onError(i),this.toastService.add("Failed to update",3e3,"error")}}async handleInlineDropdownSave(t){let e=this.clientService.getClientFieldValue(t.params.client_id,t.databaseKey);this.clientService.updateClientInList(t.params.client_id,{[t.databaseKey]:t.value});try{await D(this.clientService.updateClientField(t.params)),t.onSuccess(),this.toastService.add("Updated",2e3,"success")}catch(i){this.clientService.updateClientInList(t.params.client_id,{[t.databaseKey]:e}),t.onError(i),this.toastService.add("Failed to update",3e3,"error")}}static \u0275fac=function(e){return new(e||n)};static \u0275cmp=V({type:n,selectors:[["app-client-sidebar"]],viewQuery:function(e,i){e&1&&si(i.customFieldsList,Oe,5),e&2&&di()},hostAttrs:[1,"flex","flex-col","h-full","min-h-0"],inputs:{previewClient:[1,"previewClient"],onClose:[1,"onClose"],focusNoteId:[1,"focusNoteId"],defaultTab:[1,"defaultTab"],defaultContactSearch:[1,"defaultContactSearch"]},decls:13,vars:5,consts:[[1,"flex","flex-col","flex-1","min-h-0","w-full",3,"click"],[1,"flex-shrink-0","bg-surface-component"],[1,"pt-4","px-5","pb-2"],[1,"flex","items-start","gap-3"],[1,"flex-1","min-w-0"],[1,"flex-shrink-0","flex","items-start","gap-0.5"],[1,"relative"],["title","Close","type","button",1,"flex","items-center","justify-center","p-1.5","rounded-lg","hover:bg-surface-hover","transition-colors",3,"click"],[1,"text-theme-secondary","text-sm",3,"icon"],["cdkScrollable","",1,"flex-1","min-h-0","overflow-y-auto","no-scrollbar"],[1,"flex-1","min-h-0","flex","flex-col","items-center","justify-center","p-8","overflow-y-auto","overflow-x-hidden"],[1,"flex","items-start","gap-1.5"],[1,"min-w-0","flex-1",3,"save","valueChange","value","clientId","columnKey","table"],[1,"font-headline","font-bold","leading-snug","text-lg","text-theme-primary","cursor-pointer","hover:bg-surface-hover","rounded","px-1","-mx-1","line-clamp-2"],[1,"text-theme-secondary","italic"],[1,"group","flex","items-center","gap-2","mt-2"],[1,"text-xs","text-theme-secondary"],[3,"save","valueChange","displayValue","currentValue","clientId","columnKey","databaseKey","options","transformer","colorFunction","clearable","table"],[1,"inline-flex","items-center","px-2","py-0.5","rounded-md","text-xs","font-medium","cursor-pointer"],["type","button","title","Manage statuses",1,"has-hover:opacity-0","has-hover:group-hover:opacity-100","transition-opacity","text-theme-secondary","hover:text-accent","p-0.5",3,"click"],[1,"text-2xs",3,"icon"],[1,"font-headline","font-bold","text-base","text-theme-primary"],["title","More actions","type","button","id","moreActionsButton","data-dropdown-toggle","moreActionsMenu","data-dropdown-placement","bottom-end",1,"flex","items-center","justify-center","p-1.5","rounded-lg","hover:bg-surface-hover","transition-colors"],["id","moreActionsMenu",1,"hidden","absolute","mt-1","dropdown-menu-sm"],["type","button",1,"dropdown-menu-item-sm",3,"click"],[3,"icon"],[1,"dropdown-divider"],["type","button",1,"dropdown-menu-item-danger-sm",3,"click"],[1,"px-4"],[1,"flex","flex-wrap","gap-1.5"],["type","button","data-onboarding","client-note-btn",1,"btn","btn-ghost","btn-extra-small",3,"click"],["type","button","data-onboarding","email-compose-btn",1,"btn","btn-ghost","btn-extra-small",3,"click"],["type","button","data-onboarding","messaging-text-btn",1,"btn","btn-ghost","btn-extra-small",3,"click"],["type","button",1,"btn","btn-ghost","btn-extra-small"],["type","button",1,"btn","btn-ghost","btn-extra-small",3,"click"],[1,"px-3","py-2","border-b","border-theme-default"],["inputType","textarea","placeholder","Add general notes about this client...","size","sm","rounded","lg",3,"initialValue","onBlurSave"],["dragScroll","","dragScrollAxis","x",1,"flex","border-b","border-theme-subtle","overflow-x-auto","no-scrollbar",3,"dragScrollFromButtons"],["type","button","data-onboarding","client-tab-details",1,"flex-1","flex","items-center","justify-center","gap-1.5","px-3","py-2.5","text-xs","font-medium","border-b-2","transition-colors","whitespace-nowrap",3,"click"],[1,"text-xs",3,"icon"],["type","button","data-onboarding","client-tab-contacts",1,"flex-1","flex","items-center","justify-center","gap-1.5","px-3","py-2.5","text-xs","font-medium","border-b-2","transition-colors","whitespace-nowrap",3,"click"],["type","button","data-onboarding","client-tab-files",1,"flex-1","flex","items-center","justify-center","gap-1.5","px-3","py-2.5","text-xs","font-medium","border-b-2","transition-colors","whitespace-nowrap",3,"text-theme-secondary","border-transparent","hover:text-theme-primary","text-accent","border-accent-500"],["type","button","data-onboarding","client-tab-tables",1,"flex-1","flex","items-center","justify-center","gap-1.5","px-3","py-2.5","text-xs","font-medium","border-b-2","transition-colors","whitespace-nowrap",3,"click"],["type","button","data-onboarding","client-tab-accounting",1,"flex-1","flex","items-center","justify-center","gap-1.5","px-3","py-2.5","text-xs","font-medium","border-b-2","transition-colors","whitespace-nowrap",3,"text-theme-secondary","border-transparent","hover:text-theme-primary","text-accent","border-accent-500"],["type","button","data-onboarding","client-tab-activity",1,"flex-1","flex","items-center","justify-center","gap-1.5","px-3","py-2.5","text-xs","font-medium","border-b-2","transition-colors","whitespace-nowrap",3,"click"],[1,"flex","items-center","justify-between","px-3","py-1","bg-accent-500","text-on-accent","text-xs"],["type","button","data-onboarding","client-tab-files",1,"flex-1","flex","items-center","justify-center","gap-1.5","px-3","py-2.5","text-xs","font-medium","border-b-2","transition-colors","whitespace-nowrap",3,"click"],["type","button","data-onboarding","client-tab-accounting",1,"flex-1","flex","items-center","justify-center","gap-1.5","px-3","py-2.5","text-xs","font-medium","border-b-2","transition-colors","whitespace-nowrap",3,"click"],[1,"flex","items-center","gap-1.5"],["type","button",1,"p-1","rounded","hover:bg-white/20","transition-colors",3,"click"],[1,"p-2","space-y-1"],[3,"clientId","clientName","
23initialSearch"],[3,"clientId"],[3,"clientId","clientName"],[1,"flex","flex-col","h-full","min-h-0",3,"clientId"],[1,"@container"],[1,"text-lg","font-headline","font-bold","text-theme-primary","mb-4"],[1,"grid","grid-cols-1","@lg:grid-cols-2","gap-x-6","gap-y-1"],[1,"flex","justify-between","items-start","py-1.5","px-2","-mx-2","hover:bg-surface-hover","transition-colors","rounded"],[3,"save","valueChange","displayValue","currentValue","clientId","columnKey","databaseKey","options","transformer","clearable","table"],[1,"text-xs","text-theme-primary","text-right","font-semibold","cursor-pointer","hover:bg-surface-subtle","rounded","px-1"],[1,"text-xs","text-theme-primary","text-right","font-semibold"],[1,"flex","justify-between","items-start","py-1.5","px-2","-mx-2","hover:bg-surface-hover","transition-colors","rounded","cursor-pointer",3,"click"],[1,"text-xs","text-theme-secondary","flex","items-center","gap-1.5"],[1,"transition-transform","duration-200","text-[0.6em]",3,"icon"],[1,"grid","grid-cols-1","gap-y-1","pl-4"],[1,"mt-3","block",3,"attachToComposer","clientId"],[3,"save","value","clientId","columnKey","databaseKey","table"],[3,"attachToComposer","clientId"],[1,"max-w-md","w-full","text-center","space-y-4"],[1,"text-5xl","text-theme-secondary",3,"icon"],[1,"space-y-2"],[1,"text-lg","font-headline","font-bold","text-theme-primary"],[1,"text-theme-secondary","text-sm"],["type","button",1,"btn","btn-ghost",3,"click"],[1,"max-w-sm","w-full","text-center","space-y-5"],[1,"text-5xl","text-danger-400",3,"icon"],[1,"bg-surface-subtle","border","border-theme-subtle","rounded-lg","p-4","text-left","space-y-2"],[1,"text-xs","text-theme-secondary","uppercase","tracking-wide","font-medium"],[1,"text-sm","text-theme-primary","font-medium"],[1,"text-xs","text-theme-secondary","px-4"],[1,"text-5xl","text-danger-500",3,"icon"],[1,"bg-surface-subtle","border","border-theme-subtle","rounded-lg","p-3","text-left","overflow-hidden"],["type","button",1,"btn","btn-solid",3,"click"],[1,"mr-2",3,"icon"],[1,"text-xs","font-mono","text-theme-secondary","break-all","overflow-wrap-anywhere"],[3,"loadingState"],[1,"mt-4","text-theme-secondary","text-sm"]],template:function(e,i){e&1&&(l(0,"div",0),f("click",function(a){return i.interceptMailtoClick(a)}),l(1,"div",1)(2,"div",2)(3,"div",3),C(4,dd,15,25,"div",4)(5,pd,4,1,"div",4),l(6,"div",5),C(7,fd,19,6,"div",6),l(8,"button",7),f("click",function(){return i.close()}),g(9,"fa-icon",8),s()()()(),C(10,vd,37,59),s(),C(11,Md,7,1,"div",9)(12,Ud,4,1,"div",10),s()),e&2&&(r(4),h(i.hasClient()?4:5),r(3),h(i.hasClient()?7:-1),r(2),p("icon",i.faTimes),r(),h(i.hasClient()?10:-1),r(),h(i.hasClient()?11:12))},dependencies:[R,q,Vt,$t,ro,Ot,Oe,H,bt,vt,so,yt,Bn,co,Ye],encapsulation:2,changeDetection:0})};export{Mt as a,yo as b};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.