export function sanitizeKey( value ) {
	return String( value || '' )
		.toLowerCase()
		.replace( /[^a-z0-9_-]/g, '' );
}

const VALID_CROSS_ENTITY_SIGNATURES = new Set( [
	'customers|orders',
	'orders|products',
	'customers|orders|products',
] );

export function isValidCrossEntitySelection( primary, related = [] ) {
	const entities = Array.isArray( primary )
		? primary
		: [ primary ].concat( Array.isArray( related ) ? related : [] );

	const signature = [ ...new Set( entities.map( sanitizeKey ).filter( Boolean ) ) ]
		.sort()
		.join( '|' );

	return VALID_CROSS_ENTITY_SIGNATURES.has( signature );
}
