import React from 'react';
import { Bar } from '@ant-design/charts';
import { BarConfig } from '@ant-design/charts/es/bar';
import isEmpty from '../_utils/isEmpty';
import { Empty } from 'antd';

export interface IBarProps extends BarConfig {}

const barDefaultConfig = {
  height: 400,
  // 统一图例的显示位置
  legend: { position: 'bottom' } as any,
  autoFit: true
}

export default ({...rest}: IBarProps) => {
  const {loading, data} = rest;
  if (loading === false && isEmpty(data)) {
    return <Empty />
  }
  if (isEmpty(data)) {
    rest.data = [];
  }
  return <Bar {...barDefaultConfig} {...rest} />;
};
