import React from 'react'
import { Form } from 'antd'

export default Form.create({})((props) => {
  const handleSubmit = (e) => {
    e.preventDefault();
    props.form.validateFields((err, values) => {
      if (!err) {
        props.onSearch(values)
      }
    });
  }

  const handleReset = () => {
    props.form.resetFields();
    props.onSearch(undefined)
  }

  const { getFieldDecorator } = props.form

  const childProps = {
    form: props.form
  }

  return (
    <Form layout="inline" onSubmit={e => handleSubmit(e)}>
      {
        props.render(childProps)
      }
      <Form.Item>
        <Button type="primary" htmlType="submit">
          搜索
        </Button>
        <Button style={{ marginLeft: 8 }} onClick={handleReset}>
          重置
          </Button>
      </Form.Item>
    </Form>
  )
})
