import{f as l}from"./chunk-BF2DTN46.js";import{a as k}from"./chunk-3CPHBZBV.js";import{I as b,J as R,g as S,s as T}from"./chunk-52M7WMZM.js";import{c as M}from"./chunk-ZEBPBUY2.js";import{s as I,t as Q,w as P,x as K}from"./chunk-Q7WVU44Z.js";import{$b as a,Ac as d,Bc as h,Cc as u,Cd as D,F as A,Kb as C,Qb as x,Td as O,a as w,ad as _,b as v,ic as r,jc as m,k as g,kc as c,la as E,od as L,tc as p,xb as o,yb as y,yc as F}from"./chunk-HEIW4SFT.js";Q();E();L();K();O();R();var V=["titleTpl"];function q(i,f){i&1&&(r(0,"div",3),c(1,"paw-spinner",4),m()),i&2&&(o(),a("showBackdrop",!0))}function B(i,f){if(i&1&&c(0,"paw-preview-file",5),i&2){let e=p();a("file",e.selectedAttachmentFilePreviewData)}}function j(i,f){if(i&1&&(r(0,"div",6)(1,"div",7)(2,"div"),c(3,"paw-input-field",8),m()(),r(4,"div",9),c(5,"paw-tag",10),r(6,"div",11),c(7,"paw-action",12),m()()()),i&2){let e=p();o(3),a("field",e.inputFields.attachment)("model",e.dataModel),o(2),F("label","",(e.selectedDocumentAttachmentIndex+1).toString(),"/",e.documentAttachments.length.toString(),""),o(2),a("action",e.openAttachmentExternalAction)}}var te=(()=>{class i{constructor(e){this.apiService=e,this.isLoading=!0,this.documentAttachments=[],this.selectedDocumentAttachmentIndex=-1,this.inputFields={attachment:{id:"attachment",component:T,options:[],type:"material",valueMapper:t=>t.id,labelMapper:t=>`${t.name}`,valueSetter:t=>t.value,onChange:t=>{this.onAttachmentChange(t)}}},this.dataModel={attachment:null},this.openAttachmentExternalAction={id:"open-attachment-external",icon:"far fa-external-link",onSelected:()=>{this.previewFileComponent?.openFileInFullscreen()},type:"mat-button",styleClass:"paw-drawer-header-action"}}ngAfterViewInit(){setTimeout(()=>{this.drawerApi?.setTitleTemplate(this.titleTpl)})}ngOnInit(){this.fetchFiles()}ngOnDestroy(){this.documentAttachments=[],this.dataModel.attachment=null,this.selectedDocumentAttachmentIndex=-1}onAttachmentChange(e){if(e){let t=this.documentAttachments.find(n=>n.id===e);if(!t)return;this.dataModel.attachments=t.id,this.selectedDocumentAttachmentIndex=this.documentAttachments.indexOf(t),this.selectedAttachmentFilePreviewData={id:t.id,name:t.name,documentKey:t.documentKey}}}fetchFiles(){return g(this,null,function*(){if(!this.id){this.selectedAttachmentFilePreviewData=void 0;return}this.isLoading=!0;let e=yield A(this.apiService.get(I.attachments.fetchAttachmentsList(this.id)));e&&e.length>0?(this.documentAttachments=e,this.dataModel.attachment=e[0].id,this.inputFields.attachment=v(w({},this.inputFields.attachment),{options:[...e]}),this.selectedAttachmentFilePreviewData={id:e[0].id,name:e[0].name,documentKey:e[0].documentKey}):(this.documentAttachments=[],this.dataModel.attachment=null,this.selectedDocumentAttachmentIndex=-1),this.isLoading=!1})}static{this.\u0275fac=function(t){return new(t||i)(y(P))}}static{this.\u0275cmp=C({type:i,selectors:[["paw-side-preview"]],viewQuery:function(t,n){if(t&1&&(d(l,5),d(V,5)),t&2){let s;h(s=u())&&(n.previewFileComponent=s.first),h(s=u())&&(n.titleTpl=s.first)}},inputs:{id:"id",drawerApi:"drawerApi"},standalone:!1,decls:4,vars:2,consts:[["titleTpl",""],["class","loading-container",4,"ngIf"],[3,"file",4,"ngIf"],[1,"loading-container"],["size","m",3,"showBackdrop"],[3,"file"],[1,"paw-area-h"],[1,"paw-col-d"],[1,"paw-label-width",3,"field","model"],[1,"paw-col","flex","content-center","items-center","paw-gap-xs"],["type","neutral",3,"label"],[1,"side-preview-actions"],[3,"action"]],template:function(t,n){t&1&&x(0,q,2,1,"div",1)(1,B,1,1,"paw-preview-file",2)(2,j,8,6,"ng-template",null,0,_),t&2&&(a("ngIf",n.isLoading),o(),a("ngIf",n.selectedAttachmentFilePreviewData))},dependencies:[D,S,l,M,k,b],styles:["[_nghost-%COMP%]{height:100%;width:100%;background-color:var(--paw-color-page-bg);display:block}[_nghost-%COMP%]   .loading-container[_ngcontent-%COMP%]{width:100%;height:100%;position:absolute}  .attachment-select-option{cursor:pointer;-webkit-user-select:none;user-select:none}  .attachment-select-option>div{width:100%}"]})}}return i})();export{te as a};
