const handleMarkLineOrMarkPoint = (options, arr) => {
  return options
    .filter((item) => arr?.includes(item.value))
    ?.map((v) => ({
      type: v.value,
      name: v.label,
    }));
};
const handleSeries = (form, seriesData, option) => {
  let series = form?.seriesArray?.map((item, index) => {
    let _temp = {
      type: item.chartType,
      // name: item?.chartName ?? '',
      colorBy: 'series',
      data:
        form.xDataType === 'selectedData'
          ? `$[${form.seriesData}]`
          : '${' + seriesData[index] + '}',
      custom_config: {
        unit: item?.unit ?? '',
      },
    };
    _temp.markPoint = {
      data: handleMarkLineOrMarkPoint(option, item.markPoint),
    };
    _temp.markLine = {
      data: handleMarkLineOrMarkPoint(option, item.markLine),
    };
    return _temp;
  });
  return {
    series,
  };
};
const handleOthers = (form) => {
  let legend = {
    left: form.legendPosition ?? '',
  };
  let grid = {
    left: form.left,
    right: form.right,
    top: form.top,
    bottom: form.bottom,
  };
  let dataZoom = {
    show: form?.showDataZoom ?? false,
  };
  return { legend, grid, dataZoom };
};
const handleCustomConfig = (form) => {
  return {
    custom_style: {
      width: form.width + '%',
      height: form.height + '%',
    },
    custom_config: {
      renderBy: form.xDataType,
    },
  };
};
const handleTitle = (form) => {
  return {
    title: {
      show: form?.showTitle ?? false,
      text: form?.text ?? '',
      textStyle: {
        color: form?.fontColor ?? '',
        fontSize: form.fontSize,
      },
    },
  };
};
const defaultChartOptions = {
  'custom_style': {
    'width': '',
    'height': '',
  },
  'custom_config': {
    'renderBy': 'allData',
  },
  'title': {
    'show': false,
    'text': '',
    'textStyle': {
      'color': '#000000',
      'fontSize': 14,
    },
  },
  'series': [],
  'legend': {
    'left': 'right',
  },
  'grid': {
    'left': 20,
    'right': 20,
    'top': 20,
    'bottom': 20,
  },
  'dataZoom': {
    'show': false,
  },
  'xAxis': {
    'name': '',
    'type': 'category',
    'data': '',
  },
  'yAxis': [
    {
      'name': '',
      'gridIndex': 0,
    },
  ],
};
const defaultLayoutOptions = {
  'layout': '上表下图',
  'chartCount': 1,
  'tableConfigs': [
    {
      'title': '',
      'width': '100%',
      'height': '70%',
    },
  ],
};
const defaultConfig = {
  'layoutOptions': {
    'layout': '上表下图',
    'chartCount': 1,
    'tableConfigs': [
      {
        'title': '',
        'width': '100%',
        'height': '60%',
      },
    ],
  },
  'chartOptions': [
    {
      'custom_style': {
        'width': '100%',
        'height': '100%',
      },
      'custom_config': {
        'renderBy': 'allData',
      },
      'title': {
        'text': '',
        'textStyle': {
          'color': '#000000',
          'fontSize': 14,
        },
      },
      'xAxis': {
        'name': '',
        'type': 'category',
        'data': '',
      },
      'yAxis': [
        {
          'name': '',
          'gridIndex': 0,
        },
      ],
      'series': [],
      'legend': {
        'left': 'right',
      },
      'grid': {
        'left': 20,
        'right': 20,
        'top': 20,
        'bottom': 20,
      },
      'dataZoom': {
        show: false,
      },
    },
  ],
};
const calculateWidth = () => {

};
export {
  handleSeries, handleOthers, handleCustomConfig, handleTitle, defaultChartOptions, defaultLayoutOptions,defaultConfig
};
