import React from 'react'
import { Form, Button, Row } from 'antd'
import Styles from './style.less'

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

  const handleReset = e => {
    props.form.resetFields()
    if (props.onReset) {
      props.onReset(props.form.getFieldsValue())
    }
  }

  return (
    <Form layout="inline" onSubmit={handleSubmit} className={Styles['x-search-form']}>
      <div style={{ display: 'flex', width: '100%' }}>
        <div style={{ flex: 'none', maxWidth: 'calc(100% - 180px)' }}>
          {props.render(props.form)}
        </div>
        <div style={{ flex: 'none', width: '180px' }}>
          <Form.Item>
            <Button type="primary" htmlType="submit">搜索</Button>
          </Form.Item>
          <Form.Item>
            <Button onClick={handleReset}>重置</Button>
          </Form.Item>
        </div>
      </div>
    </Form>
  )
})
