import { FeatureCardProps } from '../FeatureCard';

const addColorFromIndex = (obj: FeatureCardProps, index: number): FeatureCardProps => {
  const colors = ['aqua', 'purple', 'orange', 'green'] as const;
  const colorIndex = index % colors.length;
  const color = colors[colorIndex];
  return { ...obj, color };
};

export const splitAndColorArray = (arr: FeatureCardProps[]): FeatureCardProps[][] => {
  const result: FeatureCardProps[][] = [[], []];
  const half = arr.length / 2;
  const splitIndex = Math.floor(half);

  arr.forEach((obj: FeatureCardProps, index: number) => {
    const newObj = addColorFromIndex(obj, index);

    if (index < splitIndex) {
      result[0].push(newObj);
    } else {
      result[1].push(newObj);
    }
  });

  return result;
};
