import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { Icon, Button } from '@alifd/next';
import CustomForm from '../custom-form';
import styles from './index.module.scss';

export default function SearchFilter(props) {
  const { formConfig, value, onChange, onReset } = props;

  /**
   * 提交回调函数
   */
  const handleSubmit = (errors, formValue) => {
    if (errors) {
      console.log({ errors });
      return;
    }

    props.onSubmit(formValue);
  };

  const config = formConfig;

  return (
    <CustomForm
      config={config}
      value={value}
      formChange={onChange}
      handleSubmit={handleSubmit}
      handleReset={onReset}
    />
  );
}

SearchFilter.propTypes = {
  formConfig: PropTypes.array.isRequired,
  value: PropTypes.object.isRequired,
  onChange: PropTypes.func,
  onSubmit: PropTypes.func,
  onReset: PropTypes.func
};

SearchFilter.defaultProps = {
  onChange: () => {},
  onSubmit: () => {},
  onReset: () => {}
};
