'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 TablePropTypes = require('../TablePropTypes.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,
  /** Empty state to render, either a custom element or an object */
  emptyState: TablePropTypes.EmptyStatePropTypes.isRequired,
  totalColumns: PropTypes__default.default.number.isRequired,
  isFiltered: PropTypes__default.default.bool.isRequired,
  onEmptyStateAction: PropTypes__default.default.func,
  // 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,
  /** icon to display while no data in table */
  emptyStateIcon: PropTypes__default.default.oneOfType([PropTypes__default.default.func, PropTypes__default.default.oneOf(['error', 'error404', 'empty', 'not-authorized', 'no-result', 'success', ''])])
};
var defaultProps = {
  id: 'EmptyTable',
  onEmptyStateAction: null,
  testId: '',
  emptyStateIcon: ''
};
var EmptyTable = function EmptyTable(_ref) {
  var id = _ref.id,
    totalColumns = _ref.totalColumns,
    isFiltered = _ref.isFiltered,
    emptyState = _ref.emptyState,
    onEmptyStateAction = _ref.onEmptyStateAction,
    _ref$emptyState = _ref.emptyState,
    messageWithFilters = _ref$emptyState.messageWithFilters,
    message = _ref$emptyState.message,
    buttonLabel = _ref$emptyState.buttonLabel,
    buttonLabelWithFilters = _ref$emptyState.buttonLabelWithFilters,
    messageBody = _ref$emptyState.messageBody,
    messageWithFiltersBody = _ref$emptyState.messageWithFiltersBody,
    testID = _ref.testID,
    testId = _ref.testId,
    emptyStateIcon = _ref.emptyStateIcon;
  return /*#__PURE__*/React__default.default.createElement(react.TableBody, {
    id: "".concat(id, "-empty-table")
    // TODO: remove deprecated 'testID' in v3
    ,
    "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.isValidElement(emptyState) ? emptyState : /*#__PURE__*/React__default.default.createElement("div", {
    className: "empty-table-cell--default"
  }, isFiltered ? /*#__PURE__*/React__default.default.createElement(EmptyState, {
    icon: "no-result",
    title: messageWithFilters,
    body: messageWithFiltersBody || '',
    action: onEmptyStateAction ? {
      label: buttonLabelWithFilters,
      onClick: onEmptyStateAction,
      kind: 'secondary'
    } : null
  }) : /*#__PURE__*/React__default.default.createElement(EmptyState, {
    icon: emptyStateIcon !== '' ? emptyStateIcon : 'empty',
    title: message,
    body: messageBody || '',
    action: onEmptyStateAction ? {
      label: buttonLabel,
      onClick: onEmptyStateAction
    } : null
  })))));
};
EmptyTable.propTypes = propTypes;
EmptyTable.defaultProps = defaultProps;
EmptyTable.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "EmptyTable",
  "props": {
    "id": {
      "defaultValue": {
        "value": "'EmptyTable'",
        "computed": false
      },
      "description": "The unique id of the table",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "onEmptyStateAction": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "emptyStateIcon": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "icon to display while no data in table",
      "type": {
        "name": "union",
        "value": [{
          "name": "func"
        }, {
          "name": "enum",
          "value": [{
            "value": "'error'",
            "computed": false
          }, {
            "value": "'error404'",
            "computed": false
          }, {
            "value": "'empty'",
            "computed": false
          }, {
            "value": "'not-authorized'",
            "computed": false
          }, {
            "value": "'no-result'",
            "computed": false
          }, {
            "value": "'success'",
            "computed": false
          }, {
            "value": "''",
            "computed": false
          }]
        }]
      },
      "required": false
    },
    "emptyState": {
      "description": "Empty state to render, either a custom element or an object",
      "type": {
        "name": "custom",
        "raw": "EmptyStatePropTypes.isRequired"
      },
      "required": false
    },
    "totalColumns": {
      "description": "",
      "type": {
        "name": "number"
      },
      "required": true
    },
    "isFiltered": {
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": true
    },
    "testID": {
      "description": "",
      "type": {
        "name": "custom",
        "raw": "deprecate(\n  PropTypes.string,\n  `The 'testID' prop has been deprecated. Please use 'testId' instead.`\n)"
      },
      "required": false
    }
  }
};
var EmptyTable$1 = EmptyTable;

module.exports = EmptyTable$1;
