import { IGenericCreditCard } from "../../../../generic/types";
import { IRWCAnswerComponent } from '../../../types';
import { RWCAnswerComponent } from '../../../classes/v5';

export const transformCreditCard = ({props, children}: IGenericCreditCard): IRWCAnswerComponent => {
    const initResult = {
        ...props.rwc
    };

    const result = children.reduce((acc, child) => {
        const { type, props } = child;

        if (!acc[type]) acc[type] = [];
            acc[type].push(props?.rwc);

        return acc;

    }, initResult);

    return new RWCAnswerComponent(result, 'rwc-credit');
};
