import{a as B}from"./chunk-XOPZBU7S.js";import{b as _}from"./chunk-V5WXIQRU.js";import{a as K}from"./chunk-TO5YSVKW.js";import{a as Q}from"./chunk-5DV4GAJI.js";import{a as P}from"./chunk-NGAY5NCM.js";import{e as L}from"./chunk-ALSZTHVZ.js";import{n as l}from"./chunk-DQXFRGXZ.js";import{K as j,M as z,W as k,g as T}from"./chunk-HQWCEBNO.js";import{c as R,d as q}from"./chunk-42X3ZN6C.js";import{c as U}from"./chunk-TI456YDF.js";import{a as A}from"./chunk-CYCG24O3.js";import{e as F,f as E,s,t as G,w as b,x as H}from"./chunk-CPKBOKTQ.js";import{$b as c,A as g,Ea as C,F as a,G as h,Kb as D,Lb as w,Md as S,Sd as V,hc as p,ic as u,jc as y,k as r,la as O,nd as M,qc as I,ra as v,xb as m,yb as d}from"./chunk-PGS4AHIT.js";V();O();q();G();z();M();H();var se=(()=>{class n{get datagridId(){return this.id?this.id+"-document-links":void 0}get datagridConfigId(){return this.gridConfigId?this.gridConfigId+"-document-links":void 0}constructor(e,o,t){this.apiService=e,this.drawerService=o,this.dialogService=t,this.isUploading=!1,this.fileUploadModel={file:null},this.inputFields={file:{id:"file",component:j,onChange:i=>{this.uploadFiles(i)}}},this.invoiceDocumentsColumns=[{id:"preview-col",label:"",width:"50",pinned:"left",render:{component:A,params:i=>({action:{id:"preview-document-action-"+i?.moveQid,icon:"far fa-eye",type:"paw-action-icon",isDisabled:!1,onSelected:()=>{this.openPreview(i?.documentQid.toString())}}})}},{id:"acKey",colId:"AcKey",label:"Number",pinned:"left",render:{component:P,params:{getParams:i=>({link:"/documentation/documents/documents-form/document-data",label:i.acKeyView,queryParams:{id:i.documentQid}})}}},{id:"user",label:"User",flex:1},{id:"date",label:"TaskDateCreated",flex:1,format:i=>R.dateFromIso(i)}],this.invoiceDocumentsSettings={loadData:()=>this.dataModel?this.apiService.get(s.move.getInvoiceDocuments(this.dataModel.moveQid)).pipe(h(i=>({items:i,totalItems:i?.length||0}))):g(),rowActions:[{id:"invoice-document-delete",label:"Delete",icon:"far fa-trash-alt",onSelected:(i,f,N)=>r(this,null,function*(){return yield this.deleteDocumentConnection(N.documentQid)})}]}}ngOnChanges(e){this.onDataModelChanges(e.dataModel)}ngOnDestroy(){this.drawerRef?.dispose(),this.errorDialogRef?.close()}onDataModelChanges(e){e&&!e.isFirstChange()&&e.currentValue!==e.previousValue&&this.gridApi?.reloadData()}onGridReady(e){this.gridApi=e}uploadFiles(e){return r(this,null,function*(){if(this.isUploading=!0,this.dataModel&&e){let o=yield a(K.getBase64Files(e));try{yield a(this.apiService.post(s.move.createDocumentAndAddConnection,{AcKey:this.dataModel.acKey,DocType:this.dataModel.docType,Subject:this.dataModel.subject,Files:o}))}catch(t){let i=Q.errorHandler(t);i&&(this.errorDialogRef=this.dialogService.openTyped({type:"error",text:i,confirmButtonLabel:"Ok",denyButtonLabel:null}))}this.gridApi?.reloadData()}this.isUploading=!1})}deleteDocumentConnection(e){return r(this,null,function*(){if(!this.dataModel)return;let o=yield a(this.apiService.get(s.move.deleteInvoiceDocumentConnection(this.dataModel.moveQid,e)));this.gridApi?.reloadData()})}openPreview(e){this.drawerRef=this.drawerService.open({drawerContext:"documents-preview",size:"m",title:"DocumentPreview",headerStyleClass:"no-gap",component:_,bindings:{id:e}})}static{this.\u0275fac=function(o){return new(o||n)(d(b),d(B),d(L))}}static{this.\u0275cmp=D({type:n,selectors:[["paw-invoice-documents"]],inputs:{id:"id",gridConfigId:"gridConfigId",dataModel:"dataModel"},standalone:!1,features:[C],decls:5,vars:7,consts:[[1,"paw-area-v","paw-holder"],[1,"paw-col"],[3,"field","model","isLoading"],[1,"paw-col-d","grid-container"],[3,"ready","id","configId","cols","settings"]],template:function(o,t){o&1&&(p(0,"div",0)(1,"div",1),y(2,"paw-input-field",2),u(),p(3,"div",3)(4,"paw-datagrid",4),I("ready",function(f){return t.onGridReady(f)}),u()()()),o&2&&(m(2),c("field",t.inputFields.file)("model",t.fileUploadModel)("isLoading",t.isUploading),m(2),c("id",t.datagridId)("configId",t.datagridConfigId)("cols",t.invoiceDocumentsColumns)("settings",t.invoiceDocumentsSettings))},dependencies:[T,l],encapsulation:2})}}return n})();E();M();var Ce=(()=>{class n{static{this.\u0275fac=function(o){return new(o||n)}}static{this.\u0275mod=w({type:n})}static{this.\u0275inj=v({imports:[S,U,k,F,l]})}}return n})();export{se as a,Ce as b};
