import { BaseFacet } from '../BaseFacet' ; import QueryManager , { ValueFilter } from '../../core/QueryManager' ; export class VisibleWhenRuleSet { constructor ( private facets , private rules ) { } getActiveFacets ( queryManager , ctx ) { const rulesSatisfied = this . rules . filter ( ( rule ) => rule ( queryManager , ctx ) ) ; return rulesSatisfied . length === this . rules . length ? this . facets : [ ] ; } } export function VisibleWhen ( facets , rules ) { return new VisibleWhenRuleSet ( facets , rules ) ; } export function FacetSelectedRule ( identifier , value ? ) { return ( queryManager ) => { const identifierFilters = queryManager . getFiltersById ( identifier ) as Array < ValueFilter > ; if ( ! identifierFilters ) return false ; if ( ! value ) return true ; if ( value ) { return ! ! identifierFilters . find ( ( filter ) => filter . value === value ) ; } } ; }