'use strict';

var React = require('react');
var PropTypes = require('prop-types');
var react = require('@carbon/react');
var EmptyState = require('../../EmptyState/EmptyState.js');
var Settings = require('../../../constants/Settings.js');
var deprecate = require('../../../internal/deprecate.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);

var iotPrefix = Settings.settings.iotPrefix;
var propTypes = {
  /** The unique id of the table */
  id: PropTypes__default.default.string,
  // TODO: remove deprecated 'testID' in v3
  // eslint-disable-next-line react/require-default-props
  testID: deprecate(PropTypes__default.default.string, "The 'testID' prop has been deprecated. Please use 'testId' instead."),
  testId: PropTypes__default.default.string,
  /** set of internationalized labels */
  i18n: PropTypes__default.default.objectOf(PropTypes__default.default.oneOfType([PropTypes__default.default.string, PropTypes__default.default.func, PropTypes__default.default.element])).isRequired,
  totalColumns: PropTypes__default.default.number.isRequired,
  /** Empty error state to render */
  errorState: PropTypes__default.default.element,
  error: PropTypes__default.default.string,
  onErrorStateAction: PropTypes__default.default.func
};
var defaultProps = {
  id: 'ErrorTable',
  testId: 'ErrorTable',
  error: null,
  errorState: null,
  onErrorStateAction: null
};
var ErrorTable = function ErrorTable(_ref) {
  var id = _ref.id,
    testID = _ref.testID,
    testId = _ref.testId,
    i18n = _ref.i18n,
    totalColumns = _ref.totalColumns,
    error = _ref.error,
    errorState = _ref.errorState,
    onErrorStateAction = _ref.onErrorStateAction;
  return /*#__PURE__*/React__default.default.createElement(react.TableBody, {
    id: id,
    "data-testid": testID || testId
  }, /*#__PURE__*/React__default.default.createElement(react.TableRow, {
    className: "".concat(iotPrefix, "--empty-table--table-row")
  }, /*#__PURE__*/React__default.default.createElement(react.TableCell, {
    colSpan: totalColumns
  }, /*#__PURE__*/React__default.default.createElement("div", {
    className: "empty-table-cell--default"
  }, /*#__PURE__*/React__default.default.isValidElement(errorState) ? errorState : /*#__PURE__*/React__default.default.createElement(EmptyState, {
    icon: "error",
    title: i18n.tableErrorStateTitle,
    body: error || '',
    action: onErrorStateAction ? {
      label: i18n.buttonLabelOnTableError,
      onClick: onErrorStateAction,
      kind: 'secondary'
    } : null
  })))));
};
ErrorTable.propTypes = propTypes;
ErrorTable.defaultProps = defaultProps;
ErrorTable.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "ErrorTable",
  "props": {
    "id": {
      "defaultValue": {
        "value": "'ErrorTable'",
        "computed": false
      },
      "description": "The unique id of the table",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'ErrorTable'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "error": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "errorState": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Empty error state to render",
      "type": {
        "name": "element"
      },
      "required": false
    },
    "onErrorStateAction": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "testID": {
      "description": "",
      "type": {
        "name": "custom",
        "raw": "deprecate(\n  PropTypes.string,\n  `The 'testID' prop has been deprecated. Please use 'testId' instead.`\n)"
      },
      "required": false
    },
    "i18n": {
      "description": "set of internationalized labels",
      "type": {
        "name": "objectOf",
        "value": {
          "name": "union",
          "value": [{
            "name": "string"
          }, {
            "name": "func"
          }, {
            "name": "element"
          }]
        }
      },
      "required": true
    },
    "totalColumns": {
      "description": "",
      "type": {
        "name": "number"
      },
      "required": true
    }
  }
};
var ErrorTable$1 = ErrorTable;

module.exports = ErrorTable$1;
