import type { GenericContentSlot } from '../../schemas/generic-slot-schema';
import type { AmplienceContentItem, BaseContentItem } from '../../types';
import { AmplienceComponent } from '../AmplienceComponent';

export const GenericSlot = ({ item: { content }, locale }: AmplienceContentItem<GenericContentSlot>) => {
  // Amplience Generic Slot is a localized component, unlike Amplience Core components.
  // Because of this, it receives two different types of responses that we need to handle below.
  const item = (content?.values?.find((item) => item.locale === locale)?.value ?? content) as
    | BaseContentItem
    | undefined;

  if (!item) return null;

  return <AmplienceComponent item={item} locale={locale} />;
};
