import _defineProperty from '@babel/runtime/helpers/defineProperty';
import 'core-js/modules/es.array.concat.js';
import React__default from 'react';
import PropTypes from 'prop-types';
import { TableRow, TableCell } from '@carbon/react';
import classnames from 'classnames';
import { settings } from '../../../../constants/Settings.js';
import Button from '../../../Button/Button.js';
import SkeletonRow from '../SkeletonRow.js';
import { TableColumnsPropTypes } from '../../TablePropTypes.js';
import { HtmlElementRefProp } from '../../../../constants/SharedPropTypes.js';

var iotPrefix = settings.iotPrefix,
  prefix = settings.prefix;
var propTypes = {
  /** The unique row id */
  id: PropTypes.string.isRequired,
  /** The unique id for the table */
  tableId: PropTypes.string.isRequired,
  /** The unique id for the table test */
  testId: PropTypes.string.isRequired,
  /**  total columns has the overall total */
  totalColumns: PropTypes.number.isRequired,
  columns: TableColumnsPropTypes,
  /** call back function for when load more row is clicked */
  onRowLoadMore: PropTypes.func.isRequired,
  /** I18N label for load more */
  loadMoreText: PropTypes.string.isRequired,
  /** boolean to decide if is in loading state or not */
  isLoadingMore: PropTypes.bool.isRequired,
  hasRowSelection: PropTypes.oneOf(['multi', 'single', false]),
  hasRowExpansion: PropTypes.bool,
  hasRowNesting: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({
    /** If the hierarchy only has 1 nested level of children */
    hasSingleNestedHierarchy: PropTypes.bool
  })]),
  hasRowActions: PropTypes.bool,
  /** shows an additional column that can expand/shrink as the table is resized  */
  showExpanderColumn: PropTypes.bool,
  /** offset level if row is nested */
  nestingLevel: PropTypes.number,
  rowVisibilityRef: HtmlElementRefProp
};
var defaultProps = {
  columns: [],
  hasRowActions: false,
  hasRowExpansion: false,
  hasRowNesting: false,
  hasRowSelection: false,
  showExpanderColumn: false,
  nestingLevel: 0,
  rowVisibilityRef: undefined
};
var TableBodyLoadMoreRow = function TableBodyLoadMoreRow(_ref) {
  var id = _ref.id,
    tableId = _ref.tableId,
    testId = _ref.testId,
    rowVisibilityRef = _ref.rowVisibilityRef,
    onRowLoadMore = _ref.onRowLoadMore,
    loadMoreText = _ref.loadMoreText,
    hasRowActions = _ref.hasRowActions,
    hasRowExpansion = _ref.hasRowExpansion,
    hasRowNesting = _ref.hasRowNesting,
    hasRowSelection = _ref.hasRowSelection,
    showExpanderColumn = _ref.showExpanderColumn,
    nestingLevel = _ref.nestingLevel,
    columns = _ref.columns,
    totalColumns = _ref.totalColumns,
    isLoadingMore = _ref.isLoadingMore;
  var singleSelectionIndicatorWidth = hasRowSelection === 'single' ? 0 : 5;
  var nestingLevelPixels = nestingLevel * 32;

  // if this a single hierarchy (i.e. only 1 level of nested children), do NOT show the gray offset
  var nestingOffset = hasRowNesting !== null && hasRowNesting !== void 0 && hasRowNesting.hasSingleNestedHierarchy ? 0 : hasRowSelection === 'single' ? nestingLevelPixels - singleSelectionIndicatorWidth : nestingLevelPixels;
  return isLoadingMore ? /*#__PURE__*/React__default.createElement(SkeletonRow, {
    id: id,
    columns: columns,
    rowVisibilityRef: rowVisibilityRef,
    tableId: tableId,
    testId: testId,
    hasRowActions: hasRowActions,
    hasRowExpansion: hasRowExpansion,
    hasRowNesting: hasRowNesting,
    hasRowSelection: hasRowSelection,
    showExpanderColumn: showExpanderColumn
  }) : /*#__PURE__*/React__default.createElement(TableRow, {
    isSelected: false,
    className: classnames("".concat(iotPrefix, "--expandable-tablerow--expanded"), _defineProperty(_defineProperty({}, "".concat(iotPrefix, "--expandable-tablerow--indented"), parseInt(nestingOffset, 10) > 0), "".concat(iotPrefix, "--expandable-tablerow--childless"), hasRowNesting)),
    "data-nesting-offset": nestingOffset,
    style: {
      '--row-nesting-offset': "".concat(nestingOffset, "px")
    }
  }, (hasRowExpansion || hasRowNesting) && /*#__PURE__*/React__default.createElement(TableCell, {
    className: "".concat(prefix, "--table-expand")
  }), /*#__PURE__*/React__default.createElement(TableCell, {
    key: "".concat(tableId, "-").concat(id, "-row-load-more-cell"),
    colSpan: totalColumns,
    className: "".concat(iotPrefix, "--load-more-cell"),
    "data-testid": "".concat(testId, "-").concat(id, "-load-more")
  }, /*#__PURE__*/React__default.createElement(Button, {
    className: "".concat(iotPrefix, "--load-more-cell--content ").concat(iotPrefix, "--table__cell__offset"),
    onClick: function onClick() {
      return onRowLoadMore(id);
    },
    kind: "ghost",
    loading: isLoadingMore
  }, loadMoreText)));
};
TableBodyLoadMoreRow.defaultProps = defaultProps;
TableBodyLoadMoreRow.propTypes = propTypes;
TableBodyLoadMoreRow.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "TableBodyLoadMoreRow",
  "props": {
    "columns": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "custom",
        "raw": "TableColumnsPropTypes"
      },
      "required": false
    },
    "hasRowActions": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "hasRowExpansion": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "hasRowNesting": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "union",
        "value": [{
          "name": "bool"
        }, {
          "name": "shape",
          "value": {
            "hasSingleNestedHierarchy": {
              "name": "bool",
              "description": "If the hierarchy only has 1 nested level of children",
              "required": false
            }
          }
        }]
      },
      "required": false
    },
    "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
    },
    "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
    },
    "nestingLevel": {
      "defaultValue": {
        "value": "0",
        "computed": false
      },
      "description": "offset level if row is nested",
      "type": {
        "name": "number"
      },
      "required": false
    },
    "rowVisibilityRef": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "",
      "type": {
        "name": "custom",
        "raw": "HtmlElementRefProp"
      },
      "required": false
    },
    "id": {
      "description": "The unique row id",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "tableId": {
      "description": "The unique id for the table",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "testId": {
      "description": "The unique id for the table test",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "totalColumns": {
      "description": "total columns has the overall total",
      "type": {
        "name": "number"
      },
      "required": true
    },
    "onRowLoadMore": {
      "description": "call back function for when load more row is clicked",
      "type": {
        "name": "func"
      },
      "required": true
    },
    "loadMoreText": {
      "description": "I18N label for load more",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "isLoadingMore": {
      "description": "boolean to decide if is in loading state or not",
      "type": {
        "name": "bool"
      },
      "required": true
    }
  }
};
var TableBodyLoadMoreRow$1 = TableBodyLoadMoreRow;

export { TableBodyLoadMoreRow$1 as default };
