import React, { useState } from 'react';
import PieChart, { IPieChart } from '../pie-chart';
import Filter, { IChartData } from '../filter/pie';
import useFilter from '../filter/useFilterPie';

interface IProps extends IPieChart{
  data: IChartData[]
}

export default ({...rest}: IProps) => {
  // 选中的筛选值
  const [value, setValue] = useState<(string | number)[]>([]);
  const {multiple, data} = useFilter(value, rest as any);

  return (
    <>
      <Filter multiple={multiple} value={value} data={rest.data} onChangeValue={(newValue) => {
        setValue(newValue);
      }} />
      <PieChart {...rest} data={data as any} />
    </>
  );
};
