/**
 * WordPress dependencies
 */
/**
 * External dependencies
 */
import type { EntityId, Maybe } from '@nab/types';

/**
 * Internal dependencies
 */
import { SingularPostSearcher } from './singular';
import { MultiplePostSearcher } from './multiple';
import type { PostSearcherProps as P } from './types';

export type SingularPostSearcherProps = P< EntityId, Maybe< EntityId > >;
export type MultiplePostSearcherProps = P< ReadonlyArray< EntityId > >;
export type PostSearcherProps =
	| ( {
			readonly isMultiple: true;
	  } & MultiplePostSearcherProps )
	| ( { readonly isMultiple?: false } & SingularPostSearcherProps );

export const PostSearcher = ( {
	isMultiple,
	...props
}: PostSearcherProps ): JSX.Element =>
	isMultiple ? (
		<MultiplePostSearcher
			{ ...( props as unknown as MultiplePostSearcherProps ) }
		/>
	) : (
		<SingularPostSearcher
			{ ...( props as unknown as SingularPostSearcherProps ) }
		/>
	);
