//公用饼图
import EmptySpace from '@/components/EmptySpace';
import { Flex } from 'antd';
import classNames from 'classnames';
import { CSSProperties } from 'react';
import Chart from './Chart';
import styles from './index.less';
interface PieChartDto {
  data?: any; //数据源
  labelGap?: number; //label间距
  style?: CSSProperties; //样式
  chartStyle?: CSSProperties; //chartStyle样式
  labelClassName?: string; //label样式
  color?: string[]; //颜色
}
const PieChart: React.FC<PieChartDto> = ({
  style,
  labelGap = 8,
  chartStyle = { width: '260px', height: '300px' },
  data = [],
  labelClassName,
  color = ['#FF9B5D', '#FFE335', '#29B5FF'],
}) => {
  return (
    <Flex style={{ ...style }} align="center" gap={20}>
      {data.length > 0 ? (
        <>
          <Chart data={data} color={color} style={{ ...chartStyle }} />
          <div className={styles.label} style={{ gap: labelGap }}>
            {data.map((it:any, index: number) => (
              <Flex
                align="center"
                justify="space-between"
                key={it.ssqy}
                className={classNames(styles.labelItem, labelClassName)}
              >
                <div className={styles.dot} style={{ backgroundColor: color[index] }}></div>
                <div>{it.ssqy}</div>
                <p className={styles.valueWrap}>
                  <b>{it.num}</b>
                  <span>件</span>
                </p>
                {/* <p>
                  <b>{parseFloat(Number(it.percent).toFixed(1))}</b>%
                </p> */}
              </Flex>
            ))}
          </div>
        </>
      ) : (
        <EmptySpace describe="暂无数据" style={{ height: '160px' }} />
      )}
    </Flex>
  );
};
export default PieChart;
