import _extends from "@babel/runtime/helpers/esm/extends";
import React from 'react';
import Tooltip from '../tooltip';
import Skeleton from '../skeleton';
var TableCell = function TableCell(_ref) {
  var columns = _ref.columns,
    row = _ref.row,
    _ref$errors = _ref.errors,
    errors = _ref$errors === void 0 ? {} : _ref$errors,
    rowIndex = _ref.rowIndex,
    emptyText = _ref.emptyText,
    onCellClick = _ref.onCellClick,
    isLoading = _ref.isLoading;
  /* eslint-disable react/jsx-no-useless-fragment */
  return /*#__PURE__*/React.createElement(React.Fragment, null, columns.map(function (column, index) {
    var _ref2, _currentRowValue$valu, _row$_id;
    var currentRowValue = row[column.prop];
    var cellValue = (_ref2 = (_currentRowValue$valu = currentRowValue === null || currentRowValue === void 0 ? void 0 : currentRowValue.value) !== null && _currentRowValue$valu !== void 0 ? _currentRowValue$valu : currentRowValue) !== null && _ref2 !== void 0 ? _ref2 : emptyText;
    var shouldBeRenderElement = column.renderHandler(currentRowValue, row, rowIndex);
    var hasError = errors[column.prop];
    return /*#__PURE__*/React.createElement("td", {
      style: _extends({
        fontSize: "".concat(column === null || column === void 0 ? void 0 : column.fontSize),
        textAlign: column !== null && column !== void 0 && column.align ? "".concat(column === null || column === void 0 ? void 0 : column.align, " !important") : 'left',
        paddingLeft: '0.3rem',
        paddingRight: '0.3rem',
        color: "".concat(column === null || column === void 0 ? void 0 : column.color),
        boxSizing: 'border-box',
        border: "".concat(hasError ? '2px dashed red' : 'none'),
        whiteSpace: column !== null && column !== void 0 && column.noWrap ? 'nowrap' : 'normal'
      }, currentRowValue === null || currentRowValue === void 0 ? void 0 : currentRowValue.style),
      "data-column": column.prop,
      key: "row-td-".concat((_row$_id = row === null || row === void 0 ? void 0 : row._id) !== null && _row$_id !== void 0 ? _row$_id : 'col', "-").concat(column.prop.toString()),
      onClick: function onClick() {
        return onCellClick && onCellClick(currentRowValue, rowIndex, index);
      },
      className: column.className
    }, isLoading ? /*#__PURE__*/React.createElement(Skeleton, {
      borderRadius: "10px",
      style: {
        margin: '5px 0px 5px 5px'
      },
      width: "95%",
      height: 20
    }) : /*#__PURE__*/React.createElement(Tooltip.Small, {
      className: "cell",
      text: hasError,
      disabled: hasError ? false : true
    }, shouldBeRenderElement ? shouldBeRenderElement : cellValue));
  }));
  /* eslint-enable */
};
export default TableCell;