import { IGenericCarousel } from "../../../../generic/types";
import { IRWCAnswerComponent } from "../../../types";
import { transformCard } from '../index';

export const transformCarousel = (msg: IRWCAnswerComponent): IGenericCarousel => {
  const carousel: IGenericCarousel = {
    type: 'carousel',
    props: {
      rwc: {
        scrollDirection: msg.vBind?.scrollDirection || "",
        hasOtherOption: msg.vBind?.hasOtherOption || false,
        multiple: msg.vBind?.multiple || false,
        pagination: msg.vBind?.pagination || false
      }
    },
    children: [],
  };

  if (carousel.props.rwc.hasOtherOption) {
    carousel.props.rwc.otherOptionData = msg.vBind?.otherOptionData;
  }

  if (carousel.props.rwc.multiple) {
    carousel.props.rwc.submitBtnLabel = msg.vBind?.submitBtnLabel || "";
    carousel.props.rwc.cancelBtnLabel = msg.vBind?.cancelBtnLabel || "",
    carousel.props.rwc.preselectedCards = msg.vBind?.preselectedCards || [];
  }

  if (msg.vBind?.options && msg?.vBind.options.length) {
    const cards = msg.vBind.options.map(transformCard);
    carousel.children.push(...cards);
  }


  return carousel;
};