import { ChartSeriesItem } from "@progress/kendo-react-charts";

const generateChartSeriesItem = (
  data: any,
  isApplyToolTip: boolean = true,
  type: any,
  chartSeriesItem: object,
  isChartLabelContentVisible: any,
  chartLabelContent: (props: any, labelContentField: any) => any,
  labelContentField: any
) => {
  if (!data) return null;

  if (["pie", "donut", "radarLine"].includes(type)) {
    return (
      <ChartSeriesItem
        tooltip={{ visible: isApplyToolTip }}
        data={data}
        type={type}
        {...chartSeriesItem}
        labels={{
          visible: isChartLabelContentVisible,
          content: (props) => chartLabelContent(props, labelContentField),
        }}
      />
    );
  }

  return data.map((item: any, index: number) => (
    <ChartSeriesItem
      key={index}
      tooltip={{ visible: isApplyToolTip }}
      data={item.data}
      name={item.name}
      type={type}
      labels={{
        visible: isChartLabelContentVisible,
        content: (props) => chartLabelContent(props, labelContentField),
      }}
      markers={{ visible: false }}
    />
  ));
};

export default generateChartSeriesItem;
