'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
require('core-js/modules/es.array.concat.js');
require('core-js/modules/es.array.map.js');
var React = require('react');
var PropTypes = require('prop-types');
var react = require('@carbon/react');
var classnames = require('classnames');
var Settings = require('../../../constants/Settings.js');
var deprecate = require('../../../internal/deprecate.js');

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

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _toConsumableArray__default = /*#__PURE__*/_interopDefault(_toConsumableArray);
var React__default = /*#__PURE__*/_interopDefault(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);

var iotPrefix = Settings.settings.iotPrefix;
var propTypes = {
  hasRowSelection: PropTypes__default.default.oneOf(['multi', 'single', false]),
  hasRowExpansion: PropTypes__default.default.bool,
  hasRowNesting: PropTypes__default.default.bool,
  hasRowActions: PropTypes__default.default.bool,
  rowCount: PropTypes__default.default.number,
  /* used to show X number of loading skeletons when columns are unknown */
  columnCount: PropTypes__default.default.number,
  columns: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
    id: PropTypes__default.default.string.isRequired
  })),
  // 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,
  /** shows an additional column that can expand/shrink as the table is resized  */
  showExpanderColumn: PropTypes__default.default.bool
};
var defaultProps = {
  hasRowSelection: false,
  hasRowExpansion: false,
  hasRowActions: false,
  hasRowNesting: false,
  rowCount: 10,
  columnCount: 5,
  columns: [],
  testId: '',
  showExpanderColumn: false
};

/** This component is exactly like the DataTableSkeleton component from carbon, but it shows your headers while it loads */
var TableSkeletonWithHeaders = function TableSkeletonWithHeaders(_ref) {
  var hasRowSelection = _ref.hasRowSelection,
    hasRowExpansion = _ref.hasRowExpansion,
    hasRowActions = _ref.hasRowActions,
    hasRowNesting = _ref.hasRowNesting,
    columns = _ref.columns,
    rowCount = _ref.rowCount,
    columnCount = _ref.columnCount,
    testID = _ref.testID,
    testId = _ref.testId,
    showExpanderColumn = _ref.showExpanderColumn;
  var rows = _toConsumableArray__default.default(Array(rowCount > 0 ? rowCount - 1 : 0));
  var loadingColumns = columns.length ? columns : _toConsumableArray__default.default(Array(columnCount > 0 ? columnCount : 1)).map(function (c, i) {
    return {
      id: i
    };
  });
  return /*#__PURE__*/React__default.default.createElement(react.TableBody, {
    "data-testid": testID || testId
  }, /*#__PURE__*/React__default.default.createElement(react.TableRow, {
    className: classnames__default.default("".concat(iotPrefix, "--table-skeleton-with-headers--table-row"), _defineProperty__default.default({}, "".concat(iotPrefix, "--table-skeleton-with-headers--table-row--head"), !columns.length))
  }, hasRowSelection === 'multi' ? /*#__PURE__*/React__default.default.createElement(react.TableCell, null) : null, hasRowExpansion || hasRowNesting ? /*#__PURE__*/React__default.default.createElement(react.TableCell, null) : null, loadingColumns.map(function (column) {
    return /*#__PURE__*/React__default.default.createElement(react.TableCell, {
      key: "skeletonCol-".concat(column.id)
    }, /*#__PURE__*/React__default.default.createElement(react.SkeletonText, null));
  }), showExpanderColumn ? /*#__PURE__*/React__default.default.createElement(react.TableCell, {
    "data-testid": "".concat(testID || testId, "-expander-column")
  }) : null, hasRowActions ? /*#__PURE__*/React__default.default.createElement(react.TableCell, null) : null), rows.map(function (row, rowIndex) {
    return /*#__PURE__*/React__default.default.createElement(react.TableRow, {
      key: "skeletonRow-".concat(rowIndex),
      className: "".concat(iotPrefix, "--table-skeleton-with-headers--table-row")
    }, hasRowSelection === 'multi' ? /*#__PURE__*/React__default.default.createElement(react.TableCell, null) : null, hasRowExpansion || hasRowNesting ? /*#__PURE__*/React__default.default.createElement(react.TableCell, null) : null, loadingColumns.map(function (v, colIndex) {
      return /*#__PURE__*/React__default.default.createElement(react.TableCell, {
        key: "emptycell-".concat(colIndex)
      }, rowIndex === 0 && !columns.length ? /*#__PURE__*/React__default.default.createElement(react.SkeletonText, null) : null);
    }), showExpanderColumn ? /*#__PURE__*/React__default.default.createElement(react.TableCell, {
      "data-testid": "".concat(testID || testId, "-skeletonRow-").concat(rowIndex, "-expander-column")
    }) : null, hasRowActions ? /*#__PURE__*/React__default.default.createElement(react.TableCell, null) : null);
  }));
};
TableSkeletonWithHeaders.propTypes = propTypes;
TableSkeletonWithHeaders.defaultProps = defaultProps;
TableSkeletonWithHeaders.__docgenInfo = {
  "description": "This component is exactly like the DataTableSkeleton component from carbon, but it shows your headers while it loads",
  "methods": [],
  "displayName": "TableSkeletonWithHeaders",
  "props": {
    "hasRowSelection": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'multi'",
          "computed": false
        }, {
          "value": "'single'",
          "computed": false
        }, {
          "value": "false",
          "computed": false
        }]
      },
      "required": false
    },
    "hasRowExpansion": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "hasRowActions": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "hasRowNesting": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "rowCount": {
      "defaultValue": {
        "value": "10",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "number"
      },
      "required": false
    },
    "columnCount": {
      "defaultValue": {
        "value": "5",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "number"
      },
      "required": false
    },
    "columns": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": {
            "id": {
              "name": "string",
              "required": true
            }
          }
        }
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "showExpanderColumn": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "shows an additional column that can expand/shrink as the table is resized",
      "type": {
        "name": "bool"
      },
      "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
    }
  }
};
var TableSkeletonWithHeaders$1 = TableSkeletonWithHeaders;

module.exports = TableSkeletonWithHeaders$1;
