import{a as g}from"./chunk-THKS2M3R.js";import{h as m}from"./chunk-NMMBNW5X.js";import{m as s,n as D}from"./chunk-GJIGZB63.js";import{b as u}from"./chunk-5VDVFGVW.js";import{a as r,b as h,ga as a,ka as l,m as d,pa as S,r as i,w as p}from"./chunk-J476KISY.js";var x=(()=>{class c extends g{get model$(){return this._model$}get attachments$(){return this._attachments$}get connections$(){return this._connections$}get chatLog$(){return this._chatLog$}get isEditMode(){return u.isSet(this.model?.id)}constructor(t){super(),this.apiService=t,this.model=null,this.modelS=new i(1),this._model$=this.modelS.asObservable(),this.attachmentsS=new i(1),this._attachments$=this.attachmentsS.asObservable(),this.connectionsS=new i(1),this._connections$=this.connectionsS.asObservable(),this.chatLogS=new i(1),this._chatLog$=this.chatLogS.asObservable(),this.selectedDocuments=[]}unset(){this.formGroup=void 0}unsetModel(){this.model=null,this.modelS.next(null),this.attachmentsS.next(null),this.connectionsS.next(null),this.chatLogS.next(null)}fetch(t){this.apiService.get(s.documents.fetch(t)).subscribe(e=>{this.unsetModel(),this.formGroup=new m([]),this.model=e,this.modelS.next(e)})}fetchList(t){return this.apiService.post(s.documents.fetchList,{Keywords:t&&t.search?t.search:"",SubjectId:t&&t.subjectId?t.subjectId:"",Doctypes:t.docTypes,Statuses:t.statuses,Classifications:t.classifications,Users:t.users,Departments:t.departments,CostDrvs:t.costDrvs,DateFrom:t.dateFrom?t.dateFrom:null,DateTo:t.dateTo?t.dateTo:null,TakeAll:!1,Start:t.start,Length:t.length,SortColumn:t.sortColumn,SortOrder:t.sortOrder,ShowDeleted:!!(t&&t.showDeleted==!0),Id:t.id?t.id:null,Note:t.note?t.note:null,RefNo:t.refNo?t.refNo:null,MailBoxId:t.mailBoxId?t.mailBoxId:null,StorageId:t.storageId?t.storageId:null,GUID:t.guid?t.guid:null})}deleteDocuments(t){let e=this.selectedDocuments.map(n=>n.anDocumentQId);return this.apiService.post(s.documents.deleteDocuments,{Ids:e,IsDeleted:t})}permanentDeleteDocuments(){let t=this.selectedDocuments.map(e=>e.anDocumentQId);return this.apiService.post(s.documents.permanentDeleteDocuments,{Ids:t})}deleteDocument(t){return this.apiService.post(s.documents.deleteDocuments,{Ids:[t],IsDeleted:!0})}fetchNeighour(t,e,n=!0){return this.apiService.get(s.documents.fetchNeighour+`${u.qparams({acKey:t,docType:e,isPrevious:n})}`).pipe(a(o=>{this.formGroup=new m([]),this.model=o,this.modelS.next(o)}))}fetchChatLogList(t){return this.apiService.post(s.tasks.fetchChatLogList,{DocumentQid:this.model?.id,TaskQid:this.model?.id,TakeAll:!0}).pipe(a(e=>{this.chatLogS.next(e)}))}fetchConnectionsList(){return this.model?.acKey?this.apiService.get(s.documents.fetchConnectionsList(this.model.acKey)).pipe(a(t=>{this.connectionsS.next(t)})):(this.connectionsS.next(null),p())}fetchAttachmentsList(t){this.apiService.get(s.attachments.fetchAttachmentsList(t)).subscribe(e=>{this.attachmentsS.next(e)})}getFileByteArray(t){return new d(e=>{let n=new FileReader;n.readAsArrayBuffer(t),n.onload=()=>{let o=n.result;e.next(new Uint8Array(o)),e.complete()},n.onerror=()=>{console.log("Error reading file")}})}runDocumentWorkflow(t,e){return console.log(this.selectedDocuments),this.apiService.post(s.documents.runDocumentWorkflow,{DocumentId:e,WorkflowId:t,Items:e?null:this.selectedDocuments})}fetchDocumentWorkflows(t){return this.apiService.post(s.documents.fetchDocumentWorkflows,{FormName:"MNDocuments%",FormName2:"PAW",WizardType:t})}fetchAvailableDocumentLinks(t){return this.apiService.get(s.documents.fetchAvailableDocumentLinks(t))}addNewDocumentConnection(t,e){return this.apiService.post(s.documents.addNewDocumentConnection,{DocumentQid:t,AcKey:e.acKey,FormName:"PAW_Documentation"})}saveForm(t){return this.apiService.put(s.documents.saveForm,r({},t))}create(t,e){let n=e??this.model;var o=h(r({},n),{Files:t});return this.apiService.post(s.documents.create,r({},o))}static{this.\u0275fac=function(e){return new(e||c)(S(D))}}static{this.\u0275prov=l({token:c,factory:c.\u0275fac,providedIn:"root"})}}return c})();export{x as a};
