"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _switch = _interopRequireDefault(require("@alifd/next/lib/switch"));
var _rating = _interopRequireDefault(require("@alifd/next/lib/rating"));
var _timePicker = _interopRequireDefault(require("@alifd/next/lib/time-picker2"));
var _numberPicker = _interopRequireDefault(require("@alifd/next/lib/number-picker"));
var _datePicker = _interopRequireDefault(require("@alifd/next/lib/date-picker2"));
var _input = _interopRequireDefault(require("@alifd/next/lib/input"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _react = _interopRequireDefault(require("react"));
var _typeData = require("../../../type/type-data");
var RenderCell = /*#__PURE__*/function (_React$Component) {
  (0, _inheritsLoose2["default"])(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 = _typeData.componentTypeList.filter(function (item) {
          return item.tplType.includes(bizType);
        });
        componentType = list.length ? list[0].value : 'Input';
      }
      if (componentType === 'Input') {
        return /*#__PURE__*/_react["default"].createElement(_input["default"], {
          value: _this.state.editValue,
          onChange: onChange,
          placeholder: placeholder
        });
      }
      if (componentType === 'DatePicker') {
        return /*#__PURE__*/_react["default"].createElement(_datePicker["default"], {
          onChange: onChange,
          value: _this.state.editValue,
          outputFormat: "YYYY-MM-DD",
          placeholder: placeholder
        });
      }
      if (componentType === 'TextArea') {
        return /*#__PURE__*/_react["default"].createElement(_input["default"].TextArea, {
          onChange: onChange,
          value: _this.state.editValue,
          placeholder: placeholder
        });
      }
      if (componentType === 'NumberPicker') {
        return /*#__PURE__*/_react["default"].createElement(_numberPicker["default"], {
          onChange: onChange,
          value: _this.state.editValue
        });
      }
      if (componentType === 'TimePicker') {
        return /*#__PURE__*/_react["default"].createElement(_timePicker["default"], {
          onChange: onChange,
          value: _this.state.editValue,
          placeholder: placeholder
        });
      }
      if (componentType === 'Rating') {
        return /*#__PURE__*/_react["default"].createElement(_rating["default"], {
          onChange: onChange,
          value: _this.state.editValue
        });
      }
      if (componentType === 'Switch') {
        return /*#__PURE__*/_react["default"].createElement(_switch["default"], {
          onChange: onChange,
          checked: _this.state.editValue
        });
      }
      return /*#__PURE__*/_react["default"].createElement(_input["default"], {
        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["default"].Component);
RenderCell.displayName = 'RenderCell';
var _default = RenderCell;
exports["default"] = _default;