import React from 'react';
import './index.less'
import GRefTable from "../GRefTable";
import {Checkbox, DatePicker} from 'antd'
import GTableList from "../GTableList";
import GInput from "../GInput";
import GSearch from "../GSearch";


export interface GComponentsProps {
  onChange: (val: any) => void
  onReferChange: (val: any) => void

  [propName: string]: any
}

const GComponents: React.FC<GComponentsProps> = (props) => {
  const {DISPLAYTYPE, onChange, onReferChange} = props
  let ResultComponents = null
  switch (DISPLAYTYPE.toUpperCase()) {
    case 'REFTEXT':
    case 'TEXT':
    case 'PASSWORD':
    case 'TEXTAREA':
      ResultComponents = <GInput {...props} onChange={onChange}/>
      break
    case 'CALENDAR':
      ResultComponents = <DatePicker onChange={onChange} format="YYYY-MM-DD"/>
      break
    case 'DATETIME':
      ResultComponents = <DatePicker onChange={onChange} showTime format="YYYY-MM-DD HH:mm:ss"/>
      break
    case 'SEARCH':
      ResultComponents = <GSearch {...props}/>
      break
    case 'BOOLEAN':
      ResultComponents = <Checkbox checked={props.value}
                                   onChange={(val) => {
                                     onChange(val.target.checked)
                                   }}/>
      break
    case 'TABLELIST':
      ResultComponents = <GTableList {...props} onChange={onChange}/>
      break
    case 'TABLESELECT':
      ResultComponents = <GTableList {...props} onChange={onChange}/>
      break
    case 'REFTABLE':
    case 'SYSREFLIST':
    case 'USERREFLIST':
    case 'REFTABLECOMBO':
    case 'SYSREFCOMBO':
    case 'USERREFCOMBO':
      ResultComponents = <GRefTable {...props}
                                    onReferChange={(val: any) => {
                                      onReferChange(val)
                                    }}
                                    onChange={onChange}/>
      break
    case 'HIDDEN':
      ResultComponents = <div>{DISPLAYTYPE}</div>
      break
    default:
      ResultComponents = <div>{DISPLAYTYPE}</div>
  }

  return ResultComponents
};

export default GComponents;
