"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

var _react = _interopRequireWildcard(require("react"));

var _mobxReactLite = require("mobx-react-lite");

var _mobx = require("mobx");

var _raf = _interopRequireDefault(require("raf"));

var _classnames = _interopRequireDefault(require("classnames"));

var _isNil = _interopRequireDefault(require("lodash/isNil"));

var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));

var _isString = _interopRequireDefault(require("lodash/isString"));

var _isObject = _interopRequireDefault(require("lodash/isObject"));

var _UnitConvertor = require("../../../lib/_util/UnitConvertor");

var _KeyCode = _interopRequireDefault(require("../../../lib/_util/KeyCode"));

var _measureScrollbar = _interopRequireDefault(require("../../../lib/_util/measureScrollbar"));

var _ConfigContext = _interopRequireDefault(require("../../../lib/config-provider/ConfigContext"));

var _TableContext = _interopRequireDefault(require("./TableContext"));

var _utils = require("./utils");

var _enum = require("../data-set/enum");

var _TableStore = require("./TableStore");

var _enum2 = require("./enum");

var _CheckBox = _interopRequireDefault(require("../check-box/CheckBox"));

var _localeContext = require("../locale-context");

var _Button = _interopRequireDefault(require("../button/Button"));

var _enum3 = require("../button/enum");

var _enum4 = require("../form/enum");

var _focusable = require("../_util/focusable");

var _SelectionTreeBox = _interopRequireDefault(require("./SelectionTreeBox"));

var _utils2 = require("../field/utils");

var _LocaleContext = _interopRequireDefault(require("../locale-context/LocaleContext"));

var _isEmpty = _interopRequireDefault(require("../_util/isEmpty"));

var _enum5 = require("../core/enum");

var _util = _interopRequireDefault(require("../overflow-tip/util"));

var _singleton = require("../tooltip/singleton");

var _useComputed = _interopRequireDefault(require("../use-computed"));

var _enum6 = require("../field/enum");

var _utils3 = require("../output/utils");

var _iteratorUtils = require("../_util/iteratorUtils");

var _Tooltip = _interopRequireDefault(require("../tooltip/Tooltip"));

var _excluded = ["afterClick"];
var inTab = false;

var TableCellInner = function TableCellInner(props) {
  var column = props.column,
      record = props.record,
      children = props.children,
      style = props.style,
      disabled = props.disabled,
      inAggregation = props.inAggregation,
      prefixCls = props.prefixCls,
      colSpan = props.colSpan,
      headerGroup = props.headerGroup,
      rowGroup = props.rowGroup;
  var multipleValidateMessageLengthRef = (0, _react.useRef)(0);
  var tooltipShownRef = (0, _react.useRef)();

  var _useContext = (0, _react.useContext)(_ConfigContext["default"]),
      getTooltip = _useContext.getTooltip,
      getTooltipTheme = _useContext.getTooltipTheme,
      getTooltipPlacement = _useContext.getTooltipPlacement;

  var _useContext2 = (0, _react.useContext)(_TableContext["default"]),
      pristine = _useContext2.pristine,
      aggregation = _useContext2.aggregation,
      inlineEdit = _useContext2.inlineEdit,
      rowHeight = _useContext2.rowHeight,
      tableStore = _useContext2.tableStore,
      dataSet = _useContext2.dataSet,
      columnEditorBorder = _useContext2.columnEditorBorder,
      indentSize = _useContext2.indentSize,
      checkField = _useContext2.checkField,
      selectionMode = _useContext2.selectionMode;

  var innerPrefixCls = "".concat(prefixCls, "-inner");
  var tooltip = tableStore.getColumnTooltip(column);
  var name = column.name,
      key = column.key,
      lock = column.lock,
      renderer = column.renderer,
      command = column.command,
      align = column.align,
      tooltipProps = column.tooltipProps;
  var columnKey = (0, _utils.getColumnKey)(column);
  var height = record.getState("__column_resize_height_".concat(name));
  var currentEditRecord = tableStore.currentEditRecord;
  var field = dataSet.getField(name);
  var fieldDisabled = disabled || field && field.get('disabled', record);
  var innerRef = (0, _react.useRef)(null);
  var prefixRef = (0, _react.useRef)(null);

  var _useState = (0, _react.useState)(children ? indentSize * record.level : 0),
      _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
      paddingLeft = _useState2[0],
      setPaddingLeft = _useState2[1];

  var columnCommand = (0, _useComputed["default"])(function () {
    if (typeof command === 'function') {
      return command({
        dataSet: dataSet,
        record: record,
        aggregation: aggregation
      });
    }

    return command;
  }, [record, command, dataSet, aggregation]);
  var canFocus = (0, _react.useMemo)(function () {
    return !fieldDisabled && (!inlineEdit || record === currentEditRecord);
  }, [fieldDisabled, record, currentEditRecord, inlineEdit]);
  var cellEditor = (0, _utils.getEditorByColumnAndRecord)(column, record);
  var cellEditorInCell = (0, _utils.isInCellEditor)(cellEditor);
  var hasEditor = !pristine && cellEditor && !cellEditorInCell;
  var showEditor = (0, _react.useCallback)(function (cell) {
    if (name) {
      if (!lock && tableStore.overflowX) {
        var tableBodyWrap = tableStore.virtual ? cell.offsetParent.parentNode.parentNode : cell.offsetParent;

        if (tableBodyWrap) {
          var _tableStore$columnGro = tableStore.columnGroups,
              leftLeafColumnsWidth = _tableStore$columnGro.leftLeafColumnsWidth,
              rightLeafColumnsWidth = _tableStore$columnGro.rightLeafColumnsWidth;
          var offsetLeft = cell.offsetLeft,
              offsetWidth = cell.offsetWidth;
          var scrollLeft = tableBodyWrap.scrollLeft;
          var width = Math.round(tableBodyWrap.getBoundingClientRect().width);
          var leftSide = offsetLeft - leftLeafColumnsWidth;
          var rightSide = offsetLeft + offsetWidth - width + rightLeafColumnsWidth + (0, _measureScrollbar["default"])();
          var sl = scrollLeft;

          if (sl < rightSide) {
            sl = rightSide;
          }

          if (sl > leftSide) {
            sl = leftSide;
          }

          if (sl !== scrollLeft) {
            tableBodyWrap.scrollLeft = sl;
          }
        }
      }

      tableStore.showEditor(name);
      var editor = tableStore.editors.get(name);

      if (editor) {
        if (editor.cellNode) {
          if (tableStore.inlineEdit) {
            if (editor.inTab) {
              editor.inTab = false;
            } else {
              editor.focus();
            }
          } else {
            editor.hideEditor();
          }
        } else if (tableStore.inlineEdit) {
          editor.focus();
        } else {
          (0, _raf["default"])(function () {
            editor.alignEditor(!(0, _utils.isStickySupport)() && lock ? (0, _utils.findCell)(tableStore, columnKey, lock, undefined, true) : cell);
            editor.focus();
          });
        }
      }
    }
  }, [column, name, columnKey, tableStore]);
  var handleEditorKeyDown = (0, _react.useCallback)(function (e) {
    switch (e.keyCode) {
      case _KeyCode["default"].TAB:
        {
          var cell = (0, _utils.findCell)(tableStore, columnKey);

          if (cell) {
            if (cell.contains(document.activeElement)) {
              inTab = true;
            } else {
              var node = (0, _focusable.findFirstFocusableElement)(cell);

              if (node) {
                inTab = true;
                node.focus();
              }
            }
          }

          break;
        }

      default:
    }
  }, [tableStore, columnKey]);
  var handleCommandSave = (0, _react.useCallback)(function () {
    return dataSet.submit().then(function (result) {
      if (result !== false) {
        tableStore.currentEditRecord = undefined;
      }
    });
  }, [tableStore, dataSet]);
  var handleCommandCancel = (0, _react.useCallback)(function () {
    if (record.status === _enum.RecordStatus.add) {
      dataSet.remove(record);
    } else {
      record.reset();
      tableStore.currentEditRecord = undefined;
    }
  }, [tableStore, record, dataSet]);
  var handleCommandEdit = (0, _react.useCallback)(function () {
    if (tableStore.inlineEdit) {
      tableStore.currentEditRecord = record;
    }
  }, [tableStore, record]);
  var handleCommandDelete = (0, _react.useCallback)(function () {
    dataSet["delete"](record);
  }, [dataSet, record]);
  var multiLine = field && field.get('multiLine', record);
  var fieldType = !aggregation && rowHeight !== 'auto' && field && field.get('type', record);
  var rows = multiLine ? (0, _iteratorUtils.iteratorReduce)(dataSet.fields.values(), function (count, dsField) {
    var bind = dsField.get('bind', record);

    if (bind && bind.startsWith("".concat(name, "."))) {
      return count + 1;
    }

    return count;
  }, 0) : 0;

  var checkBox = function () {
    if (children) {
      if (selectionMode === _enum2.SelectionMode.treebox) {
        return /*#__PURE__*/_react["default"].createElement(_SelectionTreeBox["default"], {
          record: record
        });
      }

      if (checkField && !tableStore.hasCheckFieldColumn) {
        return /*#__PURE__*/_react["default"].createElement(_CheckBox["default"], {
          name: checkField,
          record: record,
          disabled: disabled,
          indeterminate: record.isIndeterminate
        });
      }
    }
  }();

  var renderCommand = (0, _react.useCallback)(function () {
    var tableCommandProps = tableStore.getConfig('tableCommandProps');
    var classString = (0, _classnames["default"])("".concat(prefixCls, "-command"), tableCommandProps && tableCommandProps.className);

    if (record.editing) {
      return [/*#__PURE__*/_react["default"].createElement(_Button["default"], (0, _extends2["default"])({}, tableCommandProps, {
        key: "save",
        className: classString,
        onClick: handleCommandSave,
        funcType: _enum3.FuncType.link
      }), (0, _localeContext.$l)('Table', 'save_button')), /*#__PURE__*/_react["default"].createElement(_Button["default"], (0, _extends2["default"])({}, tableCommandProps, {
        key: "cancel",
        className: classString,
        onClick: handleCommandCancel,
        funcType: _enum3.FuncType.link
      }), (0, _localeContext.$l)('Table', 'cancel_button'))];
    }

    if (columnCommand) {
      var commands = [];
      columnCommand.forEach(function (button) {
        var tableButtonProps = {};

        if ((0, _mobx.isArrayLike)(button)) {
          tableButtonProps = button[1] || {};
          button = button[0];
        }

        if ((0, _isString["default"])(button) && button in _enum2.TableCommandType) {
          var getButtonProps = function getButtonProps(type) {
            switch (type) {
              case _enum2.TableCommandType.edit:
                return {
                  funcType: _enum3.FuncType.link,
                  onClick: handleCommandEdit,
                  disabled: disabled,
                  children: (0, _localeContext.$l)('Table', 'edit_button'),
                  key: 'edit'
                };

              case _enum2.TableCommandType["delete"]:
                return {
                  funcType: _enum3.FuncType.link,
                  onClick: handleCommandDelete,
                  disabled: disabled,
                  children: (0, _localeContext.$l)('Table', 'delete_button'),
                  key: 'delete'
                };

              default:
            }
          };

          var defaultButtonProps = getButtonProps(button);

          if (defaultButtonProps) {
            var _tableButtonProps = tableButtonProps,
                afterClick = _tableButtonProps.afterClick,
                buttonProps = (0, _objectWithoutProperties2["default"])(_tableButtonProps, _excluded);

            if (afterClick) {
              var onClick = defaultButtonProps.onClick;

              defaultButtonProps.onClick = /*#__PURE__*/function () {
                var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(e) {
                  return _regenerator["default"].wrap(function _callee$(_context) {
                    while (1) {
                      switch (_context.prev = _context.next) {
                        case 0:
                          e.persist();
                          _context.prev = 1;
                          _context.next = 4;
                          return onClick(e);

                        case 4:
                          _context.prev = 4;
                          afterClick(e);
                          return _context.finish(4);

                        case 7:
                        case "end":
                          return _context.stop();
                      }
                    }
                  }, _callee, null, [[1,, 4, 7]]);
                }));

                return function (_x) {
                  return _ref.apply(this, arguments);
                };
              }();
            }

            var otherProps = (0, _extends2["default"])({}, defaultButtonProps);
            commands.push( /*#__PURE__*/_react["default"].createElement(_Button["default"], (0, _extends2["default"])({}, tableCommandProps, otherProps, buttonProps, {
              className: (0, _classnames["default"])(classString, otherProps.className, buttonProps.className)
            })));
          }
        } else if ( /*#__PURE__*/(0, _react.isValidElement)(button)) {
          commands.push( /*#__PURE__*/(0, _react.cloneElement)(button, (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, tableCommandProps), button.props), {}, {
            className: (0, _classnames["default"])(classString, button.props.className)
          })));
        } else if ((0, _isObject["default"])(button)) {
          commands.push( /*#__PURE__*/_react["default"].createElement(_Button["default"], (0, _extends2["default"])({}, tableCommandProps, button, {
            className: (0, _classnames["default"])(classString, button.className)
          })));
        }
      });
      return commands;
    }
  }, [tableStore, prefixCls, record, columnCommand, aggregation, disabled, handleCommandEdit, handleCommandDelete, handleCommandSave, handleCommandCancel]);
  var renderEditor = (0, _react.useCallback)(function () {
    if ( /*#__PURE__*/(0, _react.isValidElement)(cellEditor)) {
      /**
       * 渲染多行编辑器
       */
      if (multiLine) {
        return cellEditor;
      }

      var newEditorProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, cellEditor.props), {}, {
        record: record,
        name: name,
        pristine: pristine,
        disabled: disabled || inlineEdit && !record.editing,
        indeterminate: checkField && checkField === name && record.isIndeterminate,
        labelLayout: _enum4.LabelLayout.none,
        showHelp: _enum6.ShowHelp.none
      });
      return /*#__PURE__*/(0, _react.cloneElement)(cellEditor, newEditorProps);
    }
  }, [disabled, cellEditor, checkField, multiLine, record, name, pristine, inlineEdit]);
  var cellRenderer = (0, _react.useMemo)(function () {
    if (columnCommand) {
      return renderCommand;
    }

    if (cellEditorInCell) {
      return renderEditor;
    }

    if (aggregation && renderer) {
      return function (rendererProps) {
        return renderer((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, rendererProps), {}, {
          aggregation: aggregation
        }));
      };
    }

    return renderer;
  }, [columnCommand, cellEditorInCell, renderEditor, renderCommand, renderer, field, aggregation]);
  var prefixStyle = (0, _react.useMemo)(function () {
    if (!aggregation || !tableStore.hasAggregationColumn) {
      if (height !== undefined && rows === 0) {
        return (0, _objectSpread2["default"])({
          height: (0, _UnitConvertor.pxToRem)(height),
          lineHeight: 1.5
        }, style);
      }

      if (rowHeight !== 'auto') {
        var isComboQueryColumn = key === _TableStore.COMBOBAR_KEY;
        var isCheckBox = fieldType === _enum.FieldType["boolean"] || key === _TableStore.SELECTION_KEY;
        var multiple = field && field.get('multiple', record);
        var borderPadding = isCheckBox || multiple || isComboQueryColumn ? 4 : 2;
        var heightPx = rows > 0 ? (rowHeight + 2) * rows + 1 : rowHeight;
        var lineHeightPx = hasEditor || isCheckBox || multiple || isComboQueryColumn ? rowHeight - borderPadding : rowHeight;
        return (0, _objectSpread2["default"])({
          height: (0, _UnitConvertor.pxToRem)(heightPx),
          lineHeight: rows > 0 ? 'inherit' : (0, _UnitConvertor.pxToRem)(lineHeightPx)
        }, style);
      }
    }

    return style;
  }, [fieldType, key, rows, rowHeight, height, style, aggregation, hasEditor]);
  var textAlign = (0, _react.useMemo)(function () {
    return align || (columnCommand ? _enum2.ColumnAlign.center : tableStore.getConfig('tableColumnAlign')(column, field, record));
  }, [columnCommand, align, column, field, record]);
  var colSpanStyle = (0, _react.useMemo)(function () {
    return colSpan && colSpan > 1 && (textAlign === _enum2.ColumnAlign.right || textAlign === _enum2.ColumnAlign.center) ? {
      width: "calc(100% - ".concat((0, _UnitConvertor.pxToRem)(30), ")")
    } : {};
  }, [colSpan, textAlign]);
  var innerStyle = (0, _react.useMemo)(function () {
    if (inAggregation) {
      return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, prefixStyle), colSpanStyle);
    }

    return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
      textAlign: textAlign
    }, prefixStyle), colSpanStyle);
  }, [inAggregation, textAlign, prefixStyle, colSpanStyle]);
  var value = name ? pristine ? record.getPristineValue(name) : record.get(name) : undefined;
  var renderValidationResult = (0, _react.useCallback)(function (validationResult) {
    if (validationResult && validationResult.validationMessage) {
      var validationMessage = validationResult.validationMessage;

      if (name) {
        var editor = tableStore.editors.get(name);

        if (editor && editor.editorProps && typeof editor.editorProps.validationRenderer === 'function') {
          var validationRenderer = editor.editorProps.validationRenderer;
          validationMessage = validationRenderer(validationResult, validationResult.validationProps);

          if ((0, _isNil["default"])(validationMessage)) {
            return;
          }
        }
      }

      return (0, _utils2.renderValidationMessage)(validationMessage, true, tableStore.getProPrefixCls);
    }
  }, [name, tableStore.editors]);
  var isValidationMessageHidden = (0, _react.useCallback)(function (message) {
    return !message || pristine;
  }, [pristine]);
  var editorBorder = !inlineEdit && hasEditor;

  var getRenderedValue = function getRenderedValue() {
    var processValue = function processValue(v) {
      if (!(0, _isNil["default"])(v)) {
        var _text = (0, _isPlainObject["default"])(v) ? v : (0, _utils2.processValue)(v, {
          dateFormat: (0, _utils2.getDateFormatByField)(field, undefined, record),
          showInvalidDate: tableStore.getConfig('showInvalidDate'),
          isNumber: [_enum.FieldType.number, _enum.FieldType.currency, _enum.FieldType.bigNumber].includes(fieldType),
          precision: field && field.get('precision', record),
          useZeroFilledDecimal: tableStore.getConfig('useZeroFilledDecimal')
        });

        return (0, _utils2.processFieldValue)(_text, field, {
          getProp: function getProp(propName) {
            return field && field.get(propName, record);
          },
          lang: dataSet && dataSet.lang || _LocaleContext["default"].locale.lang
        }, true, record, tableStore.getConfig);
      }

      return '';
    };

    var processRenderer = function processRenderer(value, repeat) {
      var processedValue;

      if (field && (field.getLookup(record) || field.get('options', record) || field.get('lovCode', record))) {
        if ((0, _mobx.isArrayLike)(value)) {
          var isCascader = !field.get('multiple', record) || value.some(function (v) {
            return (0, _mobx.isArrayLike)(v);
          });
          processedValue = value.map(function (v) {
            return field.getText(v, undefined, record);
          }).join(isCascader ? '/' : '、');
        } else {
          processedValue = field.getText(value, undefined, record);
        }
      } // 值集中不存在 再去取直接返回的值


      var text = (0, _isNil["default"])(processedValue) ? processValue(value) : processedValue;
      return (cellRenderer || _utils3.defaultOutputRenderer)({
        value: value,
        text: text,
        record: record,
        dataSet: dataSet,
        name: name,
        repeat: repeat,
        headerGroup: headerGroup,
        rowGroup: rowGroup
      });
    };

    if (field) {
      if (!cellEditorInCell) {
        var multiple = field.get('multiple', record);
        var range = field.get('range', record);
        var tagRenderer = tableStore.getColumnTagRenderer(column);

        if (multiple) {
          var _renderMultipleValues = (0, _utils2.renderMultipleValues)(value, {
            disabled: disabled,
            readOnly: true,
            range: range,
            prefixCls: prefixCls,
            tagRenderer: tagRenderer,
            processRenderer: processRenderer,
            renderValidationResult: renderValidationResult,
            isValidationMessageHidden: isValidationMessageHidden,
            showValidationMessage: function showValidationMessage(e, message) {
              return (0, _utils2.showValidationMessage)(e, message, getTooltipTheme('validation'), getTooltipPlacement('validation'), tableStore.getConfig);
            },
            validationResults: field.getValidationErrorValues(record)
          }),
              tags = _renderMultipleValues.tags,
              multipleValidateMessageLength = _renderMultipleValues.multipleValidateMessageLength,
              isOverflowMaxTagCount = _renderMultipleValues.isOverflowMaxTagCount;

          multipleValidateMessageLengthRef.current = multipleValidateMessageLength;

          if (isOverflowMaxTagCount) {
            return /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], {
              title: processRenderer(value)
            }, tags);
          }

          return tags;
        }

        if (range) {
          return (0, _utils2.renderRangeValue)((0, _utils2.toRangeValue)(value, range), {
            processRenderer: processRenderer
          });
        }
      }

      if (field.get('multiLine', record)) {
        var _renderMultiLine = (0, _utils2.renderMultiLine)({
          name: name,
          field: field,
          record: record,
          dataSet: dataSet,
          prefixCls: innerPrefixCls,
          renderer: cellRenderer,
          renderValidationResult: renderValidationResult,
          isValidationMessageHidden: isValidationMessageHidden,
          processValue: processValue,
          tooltip: tooltip,
          labelTooltip: getTooltip('label')
        }),
            lines = _renderMultiLine.lines,
            _multipleValidateMessageLength = _renderMultiLine.multipleValidateMessageLength;

        multipleValidateMessageLengthRef.current = _multipleValidateMessageLength;
        return lines;
      }
    }

    var textNode = processRenderer(value);
    return textNode === '' ? tableStore.getConfig('tableDefaultRenderer') : textNode;
  };

  var result = getRenderedValue();
  var text = (0, _isEmpty["default"])(result) || (0, _mobx.isArrayLike)(result) && !result.length ? editorBorder ? undefined : tableStore.getConfig('renderEmpty')('Output') : result;
  var handleFocus = (0, _react.useCallback)(function (e) {
    if (canFocus) {
      handleMouseEnter(e);

      if (key !== _TableStore.SELECTION_KEY) {
        dataSet.current = record;
      }

      if (hasEditor) {
        showEditor(e.currentTarget);
      }

      if (!(0, _utils.isStickySupport)() && (key === _TableStore.SELECTION_KEY || !hasEditor)) {
        var cell = (0, _utils.findCell)(tableStore, columnKey, lock);

        if (cell && !cell.contains(document.activeElement)) {
          var node = (0, _focusable.findFirstFocusableElement)(cell);

          if (node && !inTab) {
            node.focus();
          }
        }
      }
    }

    inTab = false;
  }, [tableStore, dataSet, record, lock, columnKey, canFocus, hasEditor, showEditor, text]);
  var showTooltip = (0, _react.useCallback)(function (e) {
    if (field && !(multipleValidateMessageLengthRef.current > 0 || !field.get('validator', record) && field.get('multiple', record) && (0, _utils2.toMultipleValue)(value, field.get('range', record)).length)) {
      var validationResults = field.getValidationErrorValues(record);
      var message = validationResults && !!validationResults.length && renderValidationResult(validationResults[0]);

      if (!isValidationMessageHidden(message)) {
        (0, _utils2.showValidationMessage)(e, message, getTooltipTheme('validation'), getTooltipPlacement('validation'), tableStore.getConfig);
        return true;
      }
    }

    var element = e.currentTarget;

    if (element && !multiLine && (tooltip === _enum5.Tooltip.always || tooltip === _enum5.Tooltip.overflow && (0, _util["default"])(element))) {
      var current = innerRef.current;

      if (text && current && current.contains(element)) {
        var tooltipConfig = (0, _isObject["default"])(tooltipProps) ? tooltipProps : {};
        var duration = (tooltipConfig.mouseEnterDelay || 0.1) * 1000;
        (0, _singleton.show)(element, (0, _objectSpread2["default"])({
          title: text,
          placement: getTooltipPlacement('table-cell') || 'right',
          theme: getTooltipTheme('table-cell')
        }, tooltipConfig), duration);
        return true;
      }
    }

    return false;
  }, [getTooltipTheme, getTooltipPlacement, renderValidationResult, isValidationMessageHidden, field, record, tooltip, multiLine, text, innerRef]);
  var handleMouseEnter = (0, _react.useCallback)(function (e) {
    if (!tableStore.columnResizing && !tooltipShownRef.current && showTooltip(e)) {
      tooltipShownRef.current = true;
    }
  }, [tooltipShownRef, tableStore, showTooltip]);
  var handleMouseLeave = (0, _react.useCallback)(function () {
    if (!tableStore.columnResizing && tooltipShownRef.current) {
      var tooltipConfig = (0, _isObject["default"])(tooltipProps) ? tooltipProps : {};
      var duration = (tooltipConfig.mouseLeaveDelay || 0.1) * 1000;
      (0, _singleton.hide)(duration);
      tooltipShownRef.current = false;
    }
  }, [tooltipShownRef, tableStore]);
  (0, _react.useEffect)(function () {
    if (name && inlineEdit && record === currentEditRecord) {
      var currentEditor = tableStore.editors.get(name);

      if (currentEditor) {
        currentEditor.alignEditor();
      }

      return function () {
        if (currentEditor) {
          currentEditor.hideEditor();
        }
      };
    }
  }, []);
  (0, _react.useEffect)(function () {
    return function () {
      if (tooltipShownRef.current) {
        (0, _singleton.hide)();
        tooltipShownRef.current = false;
      }
    };
  }, [tooltipShownRef]);
  (0, _react.useLayoutEffect)(function () {
    var current = innerRef.current;
    var activeEmptyCell = tableStore.activeEmptyCell;

    if (current && activeEmptyCell && activeEmptyCell.dataset.index === name && tableStore.dataSet.current === record) {
      delete tableStore.activeEmptyCell;

      if (current.tabIndex === -1) {
        var firstFocusableElement = (0, _focusable.findFirstFocusableElement)(current);

        if (firstFocusableElement) {
          firstFocusableElement.focus();
        }
      } else {
        current.focus();
      }
    }
  }, [record]);
  var innerProps = {
    tabIndex: hasEditor && canFocus ? 0 : -1,
    onFocus: handleFocus,
    children: text,
    ref: innerRef
  };
  var empty = field ? (0, _utils2.isFieldValueEmpty)(value, field.get('range', record), field.get('multiple', record), field.get('type', record) === _enum.FieldType.object ? field.get('valueField', record) : undefined, field.get('type', record) === _enum.FieldType.object ? field.get('textField', record) : undefined) : false;
  var innerClassName = [innerPrefixCls];

  if (columnEditorBorder) {
    innerClassName.push("".concat(prefixCls, "-inner-bordered"));
  }

  if (editorBorder) {
    innerClassName.push("".concat(prefixCls, "-inner-editable"));
  }

  var highlight;
  var inValid;

  if (field) {
    if (!pristine && field.isDirty(record)) {
      innerClassName.push("".concat(prefixCls, "-inner-dirty"));
    }

    if (!inlineEdit && !cellEditorInCell) {
      inValid = !field.isValid(record);
      field.get('required', record);

      if (inValid) {
        innerClassName.push("".concat(prefixCls, "-inner-invalid"));
      }
    }

    if (editorBorder) {
      if (field.get('required', record) && (empty || !tableStore.getConfig('showRequiredColorsOnlyEmpty'))) {
        innerClassName.push("".concat(prefixCls, "-inner-required"));
      }

      highlight = field.get('highlight', record);

      if (highlight) {
        innerClassName.push("".concat(prefixCls, "-inner-highlight"));
      }
    }
  }

  if (fieldDisabled) {
    innerClassName.push("".concat(prefixCls, "-inner-disabled"));
  }

  if (multiLine) {
    innerClassName.push("".concat(prefixCls, "-inner-multiLine"));
  }

  if (!(0, _utils.isStickySupport)() && !hasEditor) {
    innerProps.onKeyDown = handleEditorKeyDown;
  }

  if (inValid || tooltip) {
    innerProps.onMouseEnter = handleMouseEnter;
    innerProps.onMouseLeave = handleMouseLeave;
  }

  if (rowHeight === 'auto') {
    innerClassName.push("".concat(prefixCls, "-inner-auto-height"));
  } else {
    innerClassName.push("".concat(prefixCls, "-inner-row-height-fixed"));
  }

  if (height !== undefined && rows === 0) {
    innerClassName.push("".concat(prefixCls, "-inner-fixed-height"));
  }

  if ((0, _isString["default"])(innerProps.children) && innerProps.children.includes('\n') && (rowHeight === 'auto' || height !== undefined && rows === 0)) {
    innerClassName.push("".concat(prefixCls, "-inner-pre"));
  }

  (0, _react.useEffect)(function () {
    // 兼容Table Tree模式嵌套过深样式
    var current = prefixRef.current;

    if (current && paddingLeft !== 0) {
      var parentElement = current.parentElement,
          prefixWidth = current.offsetWidth;

      if (parentElement) {
        var parentWidth = parentElement.clientWidth;

        if (prefixWidth > parentWidth) {
          setPaddingLeft(Math.max(paddingLeft - (prefixWidth - parentWidth), 0));
        }
      }
    }
  }, [prefixRef, paddingLeft, setPaddingLeft]);

  var indentText = children && /*#__PURE__*/_react["default"].createElement("span", {
    style: {
      paddingLeft: (0, _UnitConvertor.pxToRem)(paddingLeft)
    }
  });

  var prefix = children && /*#__PURE__*/_react["default"].createElement("span", {
    key: "prefix",
    className: "".concat(prefixCls, "-prefix"),
    style: prefixStyle,
    ref: prefixRef
  }, indentText, children, checkBox);

  var output = /*#__PURE__*/_react["default"].createElement("span", (0, _extends2["default"])({
    key: "output"
  }, innerProps, {
    style: innerStyle,
    className: innerClassName.join(' ')
  }));

  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, prefix, highlight ? (column.highlightRenderer || tableStore.cellHighlightRenderer)((0, _utils2.transformHighlightProps)(highlight, {
    dataSet: dataSet,
    record: record,
    name: name
  }), output) : output);
};

TableCellInner.displayName = 'TableCellInner';

var _default = (0, _mobxReactLite.observer)(TableCellInner);

exports["default"] = _default;
//# sourceMappingURL=TableCellInner.js.map
