/**
 * @deprecated Replace with `BarChart` from `@material-hu/components/design-system/Charts/BarChart`.
 * Note: this wrapper applies fixed CSAT severity colors — consumers must pass equivalent `colors` prop.
 */
import { BarChart, BarChartData, BarChartProps } from './BarChart';

const COLORS = ['#B42318', '#F04438', '#F79009', '#16B364', '#087443'];

const getColors = (data: BarChartData[]) => {
  if (data.length === COLORS.length) return COLORS;

  if (data.length < COLORS.length) {
    return data.map((item, index) => {
      if (item?.color) return item?.color;
      if (index === 0 || index === data.length - 1) return COLORS[index];
      return COLORS[index + 1];
    });
  }

  return data.map((item, index) => item?.color || COLORS[index]);
};

export type NumberRatingChartProps = BarChartProps;

export const NumberRatingChart = ({ data }: NumberRatingChartProps) => {
  const colors = getColors(data);

  const formattedData = data.map((item, index) => ({
    ...item,
    color: colors[index],
  }));

  return <BarChart data={formattedData} />;
};

export default NumberRatingChart;
