import React from 'react'
import { Form, Row, Col, Input, Select, DatePicker, Card, Button, InputNumber, Switch  ,AutoComplete, Pagination, Spin } from 'antd'
import moment from 'moment'
import PropTypes from 'prop-types'
import {
  empty,
  extendFilterGroup,
  extendGroupRule,
  extendInclude, extendOrder,
  extendRule,
  getDataFieldValue,
  initFilter,
  initFilterGroup,
} from '../../utils/common'
import {connect} from "dva/index";

import DropDownPagination from './DropDownPagination';

import FromModal from '../FormModal';

const Option = Select.Option
const RangePicker = DatePicker.RangePicker
const AutoOption = AutoComplete.Option;
const OptGroup = AutoComplete.OptGroup;



class DropDownPaginationEx extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      data: {
        Data:[]
      },
      value:'',
      oldValue:'',
    }
  };

  selectAutoItem = ({record,complete,data,isClear}) => {
    const {onSelect} = this.props;
    if (typeof onSelect === 'function') {
      onSelect({
        data: data,
        record: record,
        isClear:isClear,
      });
    };
    if(typeof complete === 'function'){
      complete();
    }
  };




  render () {
    const { inputShowField,inpuNavField,inputLabelField,fieldName,onChangeHandle,inputDataApi,
         disabled,data,width,inputFilterField, showFormCode,showIDField,value,inputSortField,inputSortOrder } = this.props;
    const showFormId=data&&showIDField?getDataFieldValue(data,showIDField):null;
    const tmpData={
      showField: inputShowField,
      navField: inpuNavField,
      labelField: inputLabelField,
      filterField: inputFilterField,
      sortField: inputSortField,
      sortOrder: inputSortOrder,
      onChangeHandle,
      width,
      onFilter:({params})=> {
        const onFilter = this.props.onFilter;
        if (typeof onFilter === 'function') {
          onFilter({
            params: params,
          });
        };
      }
    }
    let controlValue=value?value:getDataFieldValue(data,fieldName);
    return (
      <div >
        <DropDownPagination  api={inputDataApi} value={controlValue} disable={disabled} showFormCode={showFormCode} showFormId={showFormId} onSelect={this.selectAutoItem} data={tmpData} onChange={({value})=>{
          const onChange=this.props.onChange;
          if ( typeof onChange === 'function') {
            onChange({
              value,
            });
          };
        }}/>
      </div>
    )
  }
}

export default connect(({ app, loading, listPage, login }) => ({ app, loading, listPage, login }))(Form.create()(DropDownPaginationEx));
