/**
 * Created by baoyinghai on 11/17/16.
 */
import React from 'react';
import { Checkbox } from '../../../../../components/mxa';
import staticDisplay from './StaticDisplay';
import { VIEW, EDIT } from '../../constant';

class CheckboxWrapper extends React.Component {

  _change = e => {
    const { onChange } = this.props;
    onChange(e || null);
  };

  render() {
    return (
      <Checkbox {...this.props} onChange={this._change} checked={this.props.value} />
    );
  }
}

const compRender = config => {
  const { record, props } = config;
  return (
    <CheckboxWrapper disabled={record.isReadonly || (props.isModalInputMappingItem && props.isLeadInto && props.modalInputIsReadonly)} />
  );
};

export default {
  [VIEW]: staticDisplay,
  [EDIT]: compRender
};
