/** * WordPress dependencies */ import { useSelect } from '@safe-wordpress/data'; import { useMemo } from '@safe-wordpress/element'; /** * Internal dependencies */ import { store as NAB_SEGMENTS } from '@nab/segmentation-rules'; import type { SegmentationRuleTypeName } from '@nab/types'; import { EMPTY_OBJECT } from '@nab/utils'; export type SegmentationRuleOption = { readonly value: string; readonly label: string; }; export function useSegmentationRuleTypeOptions( name: SegmentationRuleTypeName ): ReadonlyArray< SegmentationRuleOption > { const options: Record< string, string > = useSelect( ( select ) => select( NAB_SEGMENTS ).getSegmentationRuleType( name )?.options ?? EMPTY_OBJECT, [ name ] ); return useMemo( () => Object.entries( options ).map( ( [ value, label ] ) => ( { value, label, } ) ), [ options ] ); }