import{a as F}from"./chunk-VESPME54.js";import{a as p}from"./chunk-WQP4LGDK.js";import{a as H}from"./chunk-54NLPTVP.js";import{c as T}from"./chunk-C2WGQZZS.js";import{j as I}from"./chunk-57DG2VC5.js";import{m,n as b}from"./chunk-GJIGZB63.js";import{h as A,i as _,j as y,k as O}from"./chunk-NLMVBXFK.js";import{Eb as S,Ib as g,N as v,P as w,Vb as L,a as h,b as f,cc as d,dc as P,fa as D,lc as l,p as u,sb as n,x as C}from"./chunk-J476KISY.js";var K=(()=>{class a extends H{constructor(t,e,o,s){super(),this.router=t,this.route=e,this.postalCodesService=o,this.apiService=s,this.destroy$=new u,this.allPostalCodes=[],this.mainHeaderDef={},this.mainListDef={listTitle:"PostalCodes",gridSettings:{id:"postal-codes-main-list",selectableRows:!1,loadData:(i,r,c)=>{let x=f(h({},this.mainListDef.filtersDef.model),{SortColumn:c?.column,SortOrder:c?.order,start:i,length:r-i});return this.loadPostalCodesForList(x)}},columnsDef:[{id:"post",colId:"AcPost",label:"Code",width:100,pinned:"left",render:{component:p,params:{getParams:i=>({label:i.post,link:["/postal-codes/postal-codes-main/edit",i.post],onSelected:()=>{this.mainListPopupRef?.close()}})}}},{id:"name",colId:"AcName",label:"Name",flex:1,render:{component:p,params:{getParams:i=>{let r=i.name&&i.name.trim()!=="";return{label:r?i.name:"",link:r?["/postal-codes/postal-codes-main/edit",i.post]:null,onSelected:()=>{this.mainListPopupRef?.close()}}}}}}],filtersDef:{fields:[{id:"keywords",label:"SearchFilter",component:I,icon:"far fa-search"}],model:{keywords:""}}},this.mainOptionsDef={navigation:[]}}ngOnInit(){this.loadAllPostalCodes(),this.router.events.pipe(v(t=>t instanceof A),D(this.destroy$)).subscribe(()=>{this.updateTitle()}),this.updateTitle()}ngOnDestroy(){this.destroy$.next(),this.destroy$.complete()}loadAllPostalCodes(){let t={Start:0,Length:1e3};this.apiService.post(m.postalCodes.list,t).pipe(w(e=>(this.postalCodesService.showErrorDialog(),C(()=>e)))).subscribe({next:e=>{this.allPostalCodes=e.items||[]}})}loadPostalCodesForList(t){let e={Start:t?.start||0,Length:t?.length||1e3};t?.SortColumn&&(e.SortColumn=t.SortColumn),t?.SortOrder&&(e.SortOrder=t.SortOrder),t?.keywords&&(e.Keywords=t.keywords);let o=new URLSearchParams;return Object.keys(e).forEach(s=>{e[s]!==null&&e[s]!==void 0&&o.append(s,e[s].toString())}),this.apiService.post(m.postalCodes.list,e)}navigateToNeighbour(t){let e=this.route.firstChild?.snapshot.params.id;if(!e||this.allPostalCodes.length===0)return;let o=this.allPostalCodes.findIndex(i=>i.post===e);if(o===-1)return;let s=t?o-1:o+1;if(s>=0&&s<this.allPostalCodes.length){let i=this.allPostalCodes[s];this.router.navigate(["./edit",i.post],{relativeTo:this.route})}}updateTitle(){}onMainListOpened(t){this.mainListPopupRef=t}onActivate(t){if(t&&typeof t.getViewActions=="function"){let e=t.getViewActions();if(e&&Array.isArray(e)){this.mainHeaderDef.viewActions=e,setTimeout(()=>{let o=window.__codeListsComponent;o&&o.loadActionsFromChildComponent(this)},150);return}}t&&"mainHeaderDef"in t?(this.mainHeaderDef=t.mainHeaderDef,setTimeout(()=>{let e=window.__codeListsComponent;e&&e.loadActionsFromChildComponent(this)},0)):(this.mainHeaderDef.viewActions=[],setTimeout(()=>{let e=window.__codeListsComponent;e&&e.loadActionsFromChildComponent(this)},0))}getViewActions(){return this.mainHeaderDef.viewActions||[]}updateHeaderFromChild(t){this.mainHeaderDef=t}static{this.\u0275fac=function(e){return new(e||a)(n(O),n(_),n(F),n(b))}}static{this.\u0275cmp=S({type:a,selectors:[["paw-postal-codes-main"]],standalone:!1,features:[g],decls:2,vars:3,consts:[[3,"mainListOpened","headerDef","optionsDef","viewList"],[3,"activate"]],template:function(e,o){e&1&&(d(0,"paw-main-view",0),l("mainListOpened",function(i){return o.onMainListOpened(i)}),d(1,"router-outlet",1),l("activate",function(i){return o.onActivate(i)}),P()()),e&2&&L("headerDef",o.mainHeaderDef)("optionsDef",o.mainOptionsDef)("viewList",o.mainListDef)},dependencies:[T,y],styles:[".paw-list-actions{border-top:none!important}"]})}}return a})();export{K as a};
