import SmartBarChart from '../../charts/SmartBarChart';
import SmartLineChart from '../../charts/SmartLineChart';

const BASE_DATA = [
  { name: '04-19', series_0: 16, series_1: 12 },
  { name: '04-20', series_0: 24, series_1: 18 },
  { name: '04-21', series_0: 28, series_1: 22 },
  { name: '04-22', series_0: 22, series_1: 30 },
  { name: '04-23', series_0: 18, series_1: 26 },
  { name: '04-24', series_0: 26, series_1: 24 },
  { name: '04-25', series_0: 30, series_1: 21 },
  { name: '04-26', series_0: 24, series_1: 17 },
  { name: '04-27', series_0: 20, series_1: 15 },
];

const BASE_SERIES = [
  { dataKey: 'series_0', name: 'Series 1', colorToken: 'data-0' },
  { dataKey: 'series_1', name: 'Series 2', colorToken: 'data-4' },
];

/**
 * 图表基础：可视化验证图表共性外壳（网格、坐标轴、图例、Hover 游标）。
 */
export default function ChartFoundationPreview({
  showGrid = true,
  showXAxis = true,
  showYAxis = true,
  showLegend = true,
  legendPosition = 'bottom',
  legendShape = 'line',
  cursorMode = 'line',
  showLabel = false,
}) {
  const commonConfig = {
    showLegend,
    showXAxis,
    showYAxis,
    legendPosition,
    height: 340,
    yAxisTickCount: 7,
  };

  if (cursorMode === 'fill') {
    return (
      <SmartBarChart
        spec={{
          data: BASE_DATA,
          series: BASE_SERIES,
          config: {
            ...commonConfig,
            grid: showGrid,
            showLabel: false,
            cornerMode: 'rounded',
          },
        }}
      />
    );
  }

  return (
    <SmartLineChart
      spec={{
        data: BASE_DATA,
        series: BASE_SERIES,
        config: {
          ...commonConfig,
          grid: showGrid,
          showDots: false,
          curveType: 'linear',
          legendShape: legendShape === 'dot' ? 'dot' : 'line',
          showLabel: !!showLabel,
        },
      }}
    />
  );
}
