import {Space, Button} from 'antd';
import {FC} from 'react';
import {Search, Refresh, FileExcel, Filter, Clear} from '@icon-park/react';

type Props = {
  /** @deprecated */
  offset?: number;
  onSearch: () => void;
  onExport?: () => void;
  isSearching?: boolean;
  isExporting?: boolean;
  onRefresh?: () => void;
  onFilter?: () => void;
  onReset?: () => void;
};

const FiterButtonGroup: FC<Props> = function ({
  onSearch,
  onExport,
  onRefresh,
  onFilter,
  onReset,
  isSearching,
  isExporting,
}) {
  return (
    <>
      <Space className='width-full'>
        <Button
          loading={isSearching}
          type='primary'
          onClick={onSearch}
          data-testid={'search_btn'}
          icon={<Search theme='outline' className='anticon' />}
          htmlType='submit'
        >
          查询
        </Button>
        {onRefresh && (
          <Button
            loading={isSearching}
            onClick={onRefresh}
            data-testid='refresh_btn'
            className='ant-btn-color-green'
            icon={<Refresh theme='outline' className='anticon' />}
            htmlType='button'
          >
            刷新
          </Button>
        )}
        {onExport && (
          <Button
            data-testid='export_btn'
            loading={isExporting}
            type='default'
            onClick={onExport}
            icon={<FileExcel theme='outline' className='anticon' />}
            htmlType='button'
          >
            导出
          </Button>
        )}
        {onReset && (
          <Button
            type='primary'
            danger
            onClick={onReset}
            icon={<Clear theme='outline' className='anticon' />}
            htmlType='button'
            data-testid='reset_btn'
          >
            重置
          </Button>
        )}
        {onFilter && (
          <Button
            type='default'
            onClick={onFilter}
            icon={<Filter theme='outline' className='anticon' />}
            htmlType='button'
            data-testid='filter_btn'
          >
            筛选
          </Button>
        )}
      </Space>
    </>
  );
};

export default FiterButtonGroup;
