import{S as a,ta as s}from"./chunk-56X5LYJH.js";import{a as o}from"./chunk-TSRGIXR5.js";var d={periodSwitcher:"financial-periods",facilitySwitcher:"facilities-switcher",facilityQueryParams:"facility_id",periodQueryParams:"financial_period_id"};var n=class{_storageKey="";_componentId;currentItem=s(null);items=s([]);isListLoading=s(!1);isSwitchLoading=s(!1);constructor(t){this._componentId=t}addItem(t){if(this.items().some(e=>e.id===t.id)){console.warn(`[${this._componentId}] Item with id ${t.id} already exists`);return}this.items.update(e=>[...e,t]),this.items().length===1&&this.setCurrentItem(t)}updateItem(t){this.items.update(e=>e.map(i=>i.id===t.id?o(o({},i),t):i)),this.currentItem()?.id===t.id&&this.setCurrentItem(t)}removeItem(t){if(this.items.update(e=>e.filter(i=>i.id!==t)),this.currentItem()?.id===t){if(this.items().length)this.setCurrentItem(this.items()[0]);else if(this.currentItem.set(null),this._storageKey)try{localStorage.removeItem(this._storageKey)}catch(e){console.warn(`[${this._componentId}] Failed to remove item from storage:`,e)}}}initialize(t,e=[]){this._storageKey=t,this.items.set(e),this.loadCurrentItem()}loadCurrentItem(){if(!(!this._storageKey||this.items().length===0))try{let t=localStorage.getItem(this._storageKey);if(!t)return;let e=JSON.parse(t),i=this.items().find(h=>h.id===e.id);i&&this.currentItem.set(i)}catch(t){console.warn(`[${this._componentId}] Failed to load stored item:`,t)}}setCurrentItem(t){if(this.currentItem.set(t),this._storageKey)try{localStorage.setItem(this._storageKey,JSON.stringify(t))}catch(e){console.warn(`[${this._componentId}] Failed to save item to storage:`,e)}}reset(){this.items.set([]),this.currentItem.set(null),this.isListLoading.set(!1),this.isSwitchLoading.set(!1)}getCurrentItem(){return this.currentItem()}getItems(){return[...this.items()]}isCurrentlyLoading(){return this.isListLoading()||this.isSwitchLoading()}};var c=class r{instances=new Map;create(t){if(!this.instances.has(t)){let e=new n(t);this.instances.set(t,e)}return this.instances.get(t)}destroy(t){this.instances.delete(t)}get(t){return this.instances.get(t)}static \u0275fac=function(e){return new(e||r)};static \u0275prov=a({token:r,factory:r.\u0275fac,providedIn:"root"})};export{d as a,c as b};
