import React from 'react';
import { Button, Col, Form, Row, DatePicker, Space } from 'antd';
import { ClearOutlined, SearchOutlined } from '@ant-design/icons';
import styles from "../DeptMaintain.less";

const FormItem = Form.Item; 
const DeptMaintainRenderSimpleForm = (props) => {
    const [form] = Form.useForm();
    const { submitButtons, handleSearch, handleFormReset, params } = props;
    
    React.useEffect(() => {
        form.setFieldsValue({
            year: params?.year,
        });
    }, [params]);

    const onFinish = values => {
        const searchParams = {
            ...values,
            year: values.year ? values.year.format('YYYY') : undefined,
        };
        handleSearch && handleSearch(searchParams);
    };

    const myhandleFormReset = () => {
        form.resetFields();
        handleFormReset && handleFormReset();
    };

    return (
        <div className={styles.searchFormContainer}>
            <Form
                form={form}
                onFinish={onFinish}
                layout="vertical"
                className={styles.searchForm}
            >
                <Row gutter={16}>
                    <Col span={6}>
                        <Form.Item
                            name="year"
                            label="年份"
                        >
                            <DatePicker 
                                picker="year" 
                                placeholder="请选择年份"
                                style={{ width: '100%' }}
                                allowClear
                            />
                        </Form.Item>
                    </Col>
                    <Col span={18}>
                        <Form.Item label=" " colon={false}>
                            <Space size="middle">
                                <Button
                                    type="primary"
                                    htmlType="submit"
                                    icon={<SearchOutlined />}
                                    className={styles.searchButton}
                                >
                                    查询
                                </Button>
                                <Button
                                    onClick={myhandleFormReset}
                                    icon={<ClearOutlined />}
                                    className={styles.resetButton}
                                >
                                    重置
                                </Button>
                            </Space>
                        </Form.Item>
                    </Col>
                </Row>
            </Form>
        </div>
    );

};

export default DeptMaintainRenderSimpleForm;
