import{g as d}from"./chunk-YNMJUTTB.js";import{a as k}from"./chunk-QUNTXJDW.js";import{I as L,J as V,g as T,s as b}from"./chunk-2UFYIZBQ.js";import{c as S}from"./chunk-4ZOOZI6F.js";import{s as P,t as K,w as M,x as R}from"./chunk-BRJ3RGGT.js";import{$b as a,$c as I,Ac as f,Bc as w,Bd as _,F as y,Kb as x,Qb as D,Sd as Q,a as v,b as A,hc as c,ic as l,jc as s,k as g,la as E,nd as O,sc as h,xb as r,xc as F,yb as C,zc as u}from"./chunk-PGS4AHIT.js";var p=class{static orderAttachments(m){return m.slice().sort((e,t)=>{let n=e.name?.toLowerCase().endsWith(".pdf")?-1:1,o=t.name?.toLowerCase().endsWith(".pdf")?-1:1;return n-o})}};K();E();O();R();Q();V();var q=["titleTpl"];function B(i,m){i&1&&(c(0,"div",3),s(1,"paw-spinner",4),l()),i&2&&(r(),a("showBackdrop",!0))}function W(i,m){if(i&1&&s(0,"paw-preview-file",5),i&2){let e=h();a("file",e.selectedAttachmentFilePreviewData)}}function j(i,m){if(i&1&&(c(0,"div",6)(1,"div",7)(2,"div"),s(3,"paw-input-field",8),l()(),c(4,"div",9),s(5,"paw-tag",10),c(6,"div",11),s(7,"paw-action",12),l()()()),i&2){let e=h();r(3),a("field",e.inputFields.attachment)("model",e.dataModel),r(2),F("label","",(e.selectedDocumentAttachmentIndex+1).toString(),"/",e.documentAttachments.length.toString(),""),r(2),a("action",e.openAttachmentExternalAction)}}var ae=(()=>{class i{constructor(e){this.apiService=e,this.isLoading=!0,this.documentAttachments=[],this.selectedDocumentAttachmentIndex=-1,this.inputFields={attachment:{id:"attachment",component:b,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 y(this.apiService.get(P.attachments.fetchAttachmentsList(this.id)));e&&e.length>0?(e=p.orderAttachments(e),this.documentAttachments=e,this.dataModel.attachment=e[0].id,this.inputFields.attachment=A(v({},this.inputFields.attachment),{options:[...e]}),this.selectedAttachmentFilePreviewData={id:e[0].id,name:e[0].name,documentKey:e[0].documentKey},this.selectedDocumentAttachmentIndex=0):(this.documentAttachments=[],this.dataModel.attachment=null,this.selectedDocumentAttachmentIndex=-1),this.isLoading=!1})}static{this.\u0275fac=function(t){return new(t||i)(C(M))}}static{this.\u0275cmp=x({type:i,selectors:[["paw-side-preview"]],viewQuery:function(t,n){if(t&1&&(u(d,5),u(q,5)),t&2){let o;f(o=w())&&(n.previewFileComponent=o.first),f(o=w())&&(n.titleTpl=o.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&&D(0,B,2,1,"div",1)(1,W,1,1,"paw-preview-file",2)(2,j,8,6,"ng-template",null,0,I),t&2&&(a("ngIf",n.isLoading),r(),a("ngIf",n.selectedAttachmentFilePreviewData))},dependencies:[_,T,d,S,k,L],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{p as a,ae as b};
