{"version":3,"file":"chunk-b4khfjsi.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","isNavigationPill","clickAction","MenuAction","SELECT_NAVIGATION_PILL","isActive","name","currentActiveNavPill","ɵɵinject","MenuItemsService","factory","ɵfac","providedIn","_NavigationPillService"],"mappings":"kFAuBaA,IAAAA,CAAAA,CAAAA,CAAqB,IAAA,CAA5B,IAAOA,EAAP,MAAOA,CAAqB,CAI9B,IAAIC,oBAAAA,EAAoB,CACpB,OAAO,IAAA,CAAKC,2BAChB,CAEA,IAAIC,kBAAgB,CAChB,OAAO,IAAKC,CAAAA,mBAChB,CAMAC,WAAAA,CAAoBC,EAAkC,CAAlC,IAAA,CAAAA,iBAAAA,CAfX,CAAA,IAAA,CAAAC,sBAAwBC,EAA+B,CAAA,IAAI,CAC3D,CAAA,IAAA,CAAAC,iBAAoBD,CAAAA,EAAAA,CAA+B,IAAI,CAUxD,CAAA,IAAA,CAAAN,4BAA8B,IAAIQ,CAAAA,CAClC,KAAAN,mBAAsB,CAAA,IAAIM,EAGuB,CAKzDC,eAAgBC,CAAAA,CAAAA,CAAkBC,EAAYC,CAAiB,CAAA,CAC3D,KAAKR,gBAAiBS,CAAAA,UAAAA,CAAW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