{"version":3,"file":"chunk-hb2dzar6.js","sources":["packages/vanilla/lib/features/header/src/navigation-pill/navigation-pill.service.ts"],"sourcesContent":["import { Injectable, signal } from '@angular/core';\n\nimport { MenuAction, MenuContentItem, MenuItemsService, MenuSection } from '@frontend/vanilla/core';\nimport { Observable, Subject } from 'rxjs';\n\n/**\n * @whatItDoes\n *\n * Provides access to the currently active navigation and filter pill.\n * Provides possibility to adjust the counter for items with `badgeType: counter`.\n *\n * @howToUse\n *\n * ```\n * navigationPillService.activeNavigationPill.subscribe((navPill: MenuContentItem | null) => { ... });\n * navigationPillService.setBadgeCounter(itemName, count, cssClass?);\n * ```\n *\n * @stable\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class NavigationPillService {\n readonly currentNavigationPill = signal(null);\n readonly currentFilterPill = signal(null);\n\n get activeNavigationPill(): Observable {\n return this.activeNavigationPillSubject;\n }\n\n get activeFilterPill(): Observable {\n return this.activeFilterSubject;\n }\n\n private activeNavigationPillSubject = new Subject();\n private activeFilterSubject = new Subject();\n private currentActiveNavPill: MenuContentItem | null;\n\n constructor(private menuItemsService: MenuItemsService) {}\n\n /**\n * @description Sets the counter value for items with type: `badgeType: counter`.\n */\n setBadgeCounter(itemName: string, count: any, cssClass?: string) {\n this.menuItemsService.setCounter(MenuSection.HeaderPills, itemName, count, cssClass);\n }\n\n /**\n * @description Resets the state of navigation pills menu.\n */\n resetActiveItem() {\n this.menuItemsService.setActive(MenuSection.HeaderPills, null);\n\n this.activeNavigationPillSubject.next(null);\n this.activeFilterSubject.next(null);\n\n this.currentNavigationPill.set(null);\n this.currentFilterPill.set(null);\n }\n\n /**\n * @description Toggle navigation pill active state in a breadcrumb-like fashion.\n */\n setActiveItem(item: MenuContentItem) {\n const isNavigationPill = item.clickAction === MenuAction.SELECT_NAVIGATION_PILL;\n const isActive = this.menuItemsService.isActive(MenuSection.HeaderPills, item.name);\n\n this.menuItemsService.setActive(MenuSection.HeaderPills, isActive ? null : item.name);\n\n if (isNavigationPill) {\n if (isActive) {\n this.resetActiveItem();\n this.currentActiveNavPill = null;\n } else {\n this.currentActiveNavPill = item;\n this.activeNavigationPillSubject.next(item);\n this.currentNavigationPill.set(item);\n }\n } else {\n if (isActive) {\n this.activeFilterSubject.next(null);\n this.activeNavigationPillSubject.next(this.currentActiveNavPill);\n\n this.currentFilterPill.set(null);\n this.currentNavigationPill.set(this.currentActiveNavPill);\n\n this.menuItemsService.setActive(MenuSection.HeaderPills, this.currentActiveNavPill?.name || null);\n } else {\n this.activeFilterSubject.next(item);\n this.currentFilterPill.set(item);\n }\n }\n }\n}\n"],"names":["NavigationPillService","activeNavigationPill","activeNavigationPillSubject","activeFilterPill","activeFilterSubject","constructor","menuItemsService","currentNavigationPill","signal","currentFilterPill","Subject","setBadgeCounter","itemName","count","cssClass","setCounter","MenuSection","HeaderPills","resetActiveItem","setActive","next","set","setActiveItem","item","_a","isNavigationPill","clickAction","MenuAction","SELECT_NAVIGATION_PILL","isActive","name","currentActiveNavPill","ɵɵinject","MenuItemsService","u","factory","ɵfac","providedIn","_NavigationPillService"],"mappings":"wFAuBaA,IAAAA,CAAAA,CAAAA,CAAqB,IAAA,CAA5B,IAAOA,EAAP,MAAOA,CAAqB,CAI9B,IAAIC,oBAAoB,EAAA,CACpB,OAAO,IAAKC,CAAAA,2BAChB,CAEA,IAAIC,gBAAAA,EAAgB,CAChB,OAAO,IAAA,CAAKC,mBAChB,CAMAC,WAAoBC,CAAAA,CAAAA,CAAkC,CAAlC,IAAAA,CAAAA,gBAAAA,CAAAA,EAfX,IAAAC,CAAAA,qBAAAA,CAAwBC,GAA+B,IAAI,CAAA,CAC3D,IAAAC,CAAAA,iBAAAA,CAAoBD,EAA+B,CAAA,IAAI,EAUxD,IAAAN,CAAAA,2BAAAA,CAA8B,IAAIQ,CAAAA,CAClC,IAAAN,CAAAA,mBAAAA,CAAsB,IAAIM,EAGuB,CAKzDC,eAAgBC,CAAAA,CAAAA,CAAkBC,CAAYC,CAAAA,CAAAA,CAAiB,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