import { EditableNumberRangeFilter , Facet , Filter , isEditableNumberRangeFilter } from '@empathyco/x-types' ; import { Store } from 'vuex' ; import { RootXStoreState } from '../../../store/store.types' ; import { addFacetIfNotPresent } from './add-facet-if-not-present' ; import { FilterEntity } from './types' ; /**
 * Allows selecting and deselecting a filter of  {@link @empathyco/x-types#EditableNumberRangeFilter
 * | EditableNumberRangeFilter}.
 *
 *  internal export class EditableNumberRangeFilterEntity implements FilterEntity { public constructor ( protected store ) { } static accepts ( filter ) { return isEditableNumberRangeFilter ( filter ) ; } /**
     * It sets  {@link @empathyco/x-types#EditableNumberRangeFilter | EditableNumberRangeFilter} to
     * false and reset the  {@link @empathyco/x-types#EditableNumberRangeFilter
 * | EditableNumberRangeFilter} values to null.
     *
     *  param filter deselect ( filter ) { const newFilter = { ... filter , selected : false , range : { min : null , max : null } } ; newFilter . id = this . getNewFilterId ( newFilter ) ; this . removePreviousFilter ( filter . facetId ) ; this . store . commit ( 'x/facets/setFilter' , newFilter ) ; addFacetIfNotPresent ( this . store , filter . facetId , 'EditableNumberRangeFacet' ) ; } /**
     * It selects the  {@link @empathyco/x-types#EditableNumberRangeFilter
 * | EditableNumberRangeFilter}.
     *
     *  param filter remarks select ( filter ) { const newFilterId = this . getNewFilterId ( filter ) ; this . removePreviousFilter ( filter . facetId ) ; this . store . commit ( 'x/facets/setFilter' , { ... filter , id : newFilterId , selected : this . isSelected ( filter ) } ) ; addFacetIfNotPresent ( this . store , filter . facetId , 'EditableNumberRangeFacet' ) ; } param filter returns internal protected getNewFilterId ( filter ) { return `${ filter . facetId }:${ String ( filter . range . min ) }_${ String ( filter . range . max ) }` ; } param filter returns internal protected isSelected ( filter ) { return filter . range . min !== null || filter . range . max !== null ; } param facetId internal protected removePreviousFilter ( facetId ) { const previousFilter = this . getFilterByFacet ( facetId ) ; if ( previousFilter ) { this . store . commit ( 'x/facets/removeFilter' , previousFilter ) ; } } param facetId returns internal protected getFilterByFacet ( facetId ) { return this . store . getters [ 'x/facets/facets' ] [ facetId ] ?. filters ?. [ 0 ] ; } }