import type { FC } from 'react';
import type { AmplienceContentItem, BaseContentItem } from '../../types';
import { GenericSlot } from '../GenericSlot';
import { PromoCarouselAdapter } from '../PromoCarouselAdapter';

export const getAmplienceLocale = (appLocale: string) => {
  switch (appLocale) {
    case 'de':
      return 'de-DE';
    case 'en':
    default:
      return 'en';
  }
};

const getComponentForSchema = (schemaName: string) => {
  switch (schemaName) {
    case 'https://content.hasbro.com/slots/generic-slot':
      return GenericSlot;
    case 'https://content.hasbro.com/models/promotion-message':
      return PromoCarouselAdapter;
    default:
      return () => null;
  }
};

export const AmplienceComponent = ({ item, locale }: AmplienceContentItem<BaseContentItem>) => {
  const Component = getComponentForSchema(item._meta?.schema) as FC<AmplienceContentItem<BaseContentItem>>;
  return <Component item={item} locale={getAmplienceLocale(locale)} />;
};
