'use client';

import type { Title as PromotionMessage } from '../../schemas/promotion-message-schema';
import type { AmplienceContentItem } from '../../types';
import { PromoCarousel } from '../TopNavigation/PromoCarousel';

export const PromoCarouselAdapter = ({ item: { promoMessages } }: AmplienceContentItem<PromotionMessage>) => {
  if (!promoMessages || !promoMessages.length) return;

  const adaptedData = promoMessages
    .filter((promoMessage) => promoMessage?.content?.richTextField)
    .map((promoMessage) => ({
      text: promoMessage.content?.richTextField ?? '',
      color: promoMessage.color,
    }));

  return <PromoCarousel promotions={adaptedData} />;
};
