import { IGenericSwitch } from '../../../../generic/types';
import { IRWCOption, IRWCMessage, IRWCAnswerComponent } from '../../../types';
import { getAnswerComponent } from '../../../helpers/answer-types';

export const transformSwitch = ({ props }: IGenericSwitch): IRWCMessage => {
  const options: Array<IRWCOption> = [
    { label: 'True', value: true },
    { label: 'False', value: false }
  ];

  const selected = options.filter(op => op.value === props.value);
  const defaultValue = selected?.map(o => o.label);

  const answerComponent: IRWCAnswerComponent = getAnswerComponent('rwc-radio-group');

  answerComponent.vBind = {
    options,
    defaultValue
  };

  const result: IRWCMessage = {
    message: props.label,
    answerComponent
  };

  return result;
};