import{a as N}from"./chunk-E5KY24MI.js";import{b as B}from"./chunk-BPPM5RYG.js";import{a as _}from"./chunk-2E6SHZTR.js";import{a as K}from"./chunk-5DV4GAJI.js";import{a as Q}from"./chunk-UCQASQVE.js";import{a as k}from"./chunk-HFTVCBYM.js";import{e as L}from"./chunk-HF45QMXH.js";import{n as l}from"./chunk-UG3JEY24.js";import{M as j,O as x,Y as P,g as T}from"./chunk-43DYGKIM.js";import{c as R,d as z}from"./chunk-XX55TKIW.js";import{c as U}from"./chunk-LHFHLR5H.js";import{a as A}from"./chunk-LYZVOFWI.js";import{e as F,f as G,s,t as H,w as b,x as q}from"./chunk-SBDFU3ZH.js";import{$b as c,A as g,Ea as D,F as a,G as h,Kb as C,Lb as w,Nd as S,Td as E,ic as p,jc as u,k as r,kc as y,la as V,od as M,ra as v,rc as I,xb as m,yb as d}from"./chunk-HEIW4SFT.js";E();V();z();H();x();M();q();var me=(()=>{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:Q,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,O)=>r(this,null,function*(){return yield this.deleteDocumentConnection(O.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(_.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=K.errorHandler(t);i&&(this.errorDialogRef=this.dialogService.openTyped({id:k.DialogInvoiceDocumentsError,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:B,bindings:{id:e}})}static{this.\u0275fac=function(o){return new(o||n)(d(b),d(N),d(L))}}static{this.\u0275cmp=C({type:n,selectors:[["paw-invoice-documents"]],inputs:{id:"id",gridConfigId:"gridConfigId",dataModel:"dataModel"},standalone:!1,features:[D],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})();G();M();var we=(()=>{class n{static{this.\u0275fac=function(o){return new(o||n)}}static{this.\u0275mod=w({type:n})}static{this.\u0275inj=v({imports:[S,U,P,F,l]})}}return n})();export{me as a,we as b};
