import React from 'react';
import './index.less';
import echarts from 'echarts/lib/echarts';
import ReactEchartsCore from 'echarts-for-react/lib/core';
import 'echarts/lib/chart/pie';
import 'echarts/lib/component/tooltip';
import 'echarts/lib/component/title';
import 'echarts/lib/component/legend';

function BarChart(props) {
  const { className = '', theme = 'shine', option = {}, data = [] } = props;
  let defaultOption = {
    series: [
      {
        data: [],
        type: 'bar',
      },
    ],
    xAxis: {
      type: 'key',
    },
    yAxis: {
      type: 'value',
    },
  };
  if (data.length > 0) {
    defaultOption.series.data = data;
  } else {
    defaultOption = option;
  }
  return (
    <div className={`bar-chart ${className}`}>
      <ReactEchartsCore echarts={echarts} option={defaultOption} notMerge lazyUpdate theme={theme} />
    </div>
  );
}
export default BarChart;
