import _Switch from "@alifd/next/es/switch";
import _Rating from "@alifd/next/es/rating";
import _TimePicker from "@alifd/next/es/time-picker2";
import _NumberPicker from "@alifd/next/es/number-picker";
import _DatePicker from "@alifd/next/es/date-picker2";
import _Input from "@alifd/next/es/input";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import React from 'react';
import { componentTypeList } from "../../../type/type-data";
var RenderCell = /*#__PURE__*/function (_React$Component) {
  _inheritsLoose(RenderCell, _React$Component);
  function RenderCell(props) {
    var _this;
    _this = _React$Component.call(this, props) || this;
    _this._renderComponent = function (componentType, bizType) {
      // let showComponentType = componentType;
      var onChange = function onChange(value) {
        _this.setState({
          editValue: value
        });
        _this.props.onChange && _this.props.onChange(value);
      };
      var placeholder = '';
      if (!componentType) {
        var list = componentTypeList.filter(function (item) {
          return item.tplType.includes(bizType);
        });
        componentType = list.length ? list[0].value : 'Input';
      }
      if (componentType === 'Input') {
        return /*#__PURE__*/React.createElement(_Input, {
          value: _this.state.editValue,
          onChange: onChange,
          placeholder: placeholder
        });
      }
      if (componentType === 'DatePicker') {
        return /*#__PURE__*/React.createElement(_DatePicker, {
          onChange: onChange,
          value: _this.state.editValue,
          outputFormat: "YYYY-MM-DD",
          placeholder: placeholder
        });
      }
      if (componentType === 'TextArea') {
        return /*#__PURE__*/React.createElement(_Input.TextArea, {
          onChange: onChange,
          value: _this.state.editValue,
          placeholder: placeholder
        });
      }
      if (componentType === 'NumberPicker') {
        return /*#__PURE__*/React.createElement(_NumberPicker, {
          onChange: onChange,
          value: _this.state.editValue
        });
      }
      if (componentType === 'TimePicker') {
        return /*#__PURE__*/React.createElement(_TimePicker, {
          onChange: onChange,
          value: _this.state.editValue,
          placeholder: placeholder
        });
      }
      if (componentType === 'Rating') {
        return /*#__PURE__*/React.createElement(_Rating, {
          onChange: onChange,
          value: _this.state.editValue
        });
      }
      if (componentType === 'Switch') {
        return /*#__PURE__*/React.createElement(_Switch, {
          onChange: onChange,
          checked: _this.state.editValue
        });
      }
      return /*#__PURE__*/React.createElement(_Input, {
        onChange: onChange,
        placeholder: placeholder
      });
    };
    _this.state = {
      editValue: _this.props.value
    };
    return _this;
  }
  var _proto = RenderCell.prototype;
  _proto.render = function render() {
    var _this$props = this.props,
      mode = _this$props.mode,
      pageInfo = _this$props.pageInfo,
      editRowIndex = _this$props.editRowIndex,
      child = _this$props.child,
      value = _this$props.value,
      index = _this$props.index;
    var props = child.props,
      key = child.key;
    var isEdit = props.isEdit;
    if (value === undefined) return null;
    if (!isEdit) return value;
    if (editRowIndex == index) {
      var componentType = props.componentType,
        bizType = props.bizType;
      return this._renderComponent(componentType, bizType);
    }
    return value;
  };
  return RenderCell;
}(React.Component);
RenderCell.displayName = 'RenderCell';
export default RenderCell;