import 'core-js/modules/es.array.concat.js';
import React__default from 'react';
import PropTypes from 'prop-types';
import { settings } from '../../constants/Settings.js';
import { handleEnterKeyDown } from '../../utils/componentUtilityFunctions.js';
import deprecate from '../../internal/deprecate.js';
import { CaretLeft, CaretRight } from '@carbon/icons-react';

var iotPrefix = settings.iotPrefix,
  prefix = settings.prefix;
var SimplePaginationPropTypes = {
  /** current page number */
  page: PropTypes.number.isRequired,
  /** The maximum page number that can be navigated to */
  maxPage: PropTypes.number.isRequired,
  /** Gets called back with arguments (page, maxPage) */
  pageOfPagesText: PropTypes.func,
  /** Internationalized label for the word 'Page' */
  pageText: PropTypes.string,
  /** Internationalized label for the word 'Next page' */
  nextPageText: PropTypes.string,
  /** Internationalized label for the word 'Previous page' */
  prevPageText: PropTypes.string,
  /** Callback when the page is changed */
  onPage: PropTypes.func.isRequired,
  /** total number of items */
  totalItems: PropTypes.number,
  /** Internationalized label for the word 'Items' or function receiving
   * a param for the total: (total) => `${total} items`} */
  totalItemsText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
  // eslint-disable-next-line react/require-default-props
  testID: deprecate(PropTypes.string, "The 'testID' prop has been deprecated. Please use 'testId' instead."),
  /** Id that can be used for testing */
  testId: PropTypes.string,
  /** the size of the buttons in pagination */
  size: PropTypes.oneOf(['sm', 'md', 'lg'])
};
var SimplePaginationDefaultProps = {
  pageOfPagesText: function pageOfPagesText(page, maxPage) {
    return "Page ".concat(page, " of ").concat(maxPage);
  },
  pageText: null,
  nextPageText: 'Next page',
  prevPageText: 'Prev page',
  totalItemsText: 'Items',
  totalItems: undefined,
  testId: "".concat(iotPrefix, "-simple-pagination"),
  size: 'lg'
};

/** This is a lighter weight pagination component than the default Carbon one */
var SimplePagination = function SimplePagination(_ref) {
  var pageText = _ref.pageText,
    prevPageText = _ref.prevPageText,
    nextPageText = _ref.nextPageText,
    pageOfPagesText = _ref.pageOfPagesText,
    totalItemsText = _ref.totalItemsText,
    totalItems = _ref.totalItems,
    page = _ref.page,
    maxPage = _ref.maxPage,
    onPage = _ref.onPage,
    testID = _ref.testID,
    testId = _ref.testId,
    size = _ref.size;
  var hasPrev = page > 1;
  var hasNext = page <= maxPage - 1;
  var handleNext = function handleNext() {
    return onPage(page + 1);
  };
  var handlePrev = function handlePrev() {
    return onPage(page - 1);
  };
  return /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(iotPrefix, "-simple-pagination-container ").concat(prefix, "--pagination--").concat(size),
    "data-testid": testID || testId
  }, totalItems ? /*#__PURE__*/React__default.createElement("span", {
    className: "".concat(iotPrefix, "-simple-pagination-page-label"),
    maxpage: maxPage
  }, typeof totalItemsText === 'function' ? totalItemsText(totalItems) : "".concat(totalItems, " ").concat(totalItemsText)) : null, /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(iotPrefix, "-simple-pagination-page-bar")
  }, /*#__PURE__*/React__default.createElement("span", {
    className: "".concat(iotPrefix, "-simple-pagination-page-label"),
    maxpage: maxPage
  }, pageText ? "".concat(pageText, " ").concat(page) : pageOfPagesText(page, maxPage)), maxPage > 1 ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
    className: hasPrev ? "".concat(prefix, "--pagination__button ").concat(prefix, "--pagination__button--backward ").concat(iotPrefix, "-addons-simple-pagination-button") : "".concat(prefix, "--pagination__button ").concat(prefix, "--pagination__button--backward ").concat(iotPrefix, "-addons-simple-pagination-button-disabled"),
    role: "button",
    tabIndex: hasPrev ? 0 : -1,
    onClick: hasPrev ? handlePrev : undefined,
    onKeyDown: hasPrev ? function (evt) {
      return handleEnterKeyDown(evt, handlePrev);
    } : undefined,
    "data-testid": "".concat(testID || testId, "-backward-button")
  }, /*#__PURE__*/React__default.createElement(CaretLeft, {
    dir: "ltr",
    "aria-label": prevPageText,
    className: hasPrev ? "".concat(iotPrefix, "-simple-pagination-caret") : "".concat(iotPrefix, "-simple-pagination-caret-disabled")
  })), /*#__PURE__*/React__default.createElement("div", {
    className: hasNext ? "".concat(prefix, "--pagination__button ").concat(prefix, "--pagination__button--forward ").concat(iotPrefix, "-addons-simple-pagination-button") : "".concat(prefix, "--pagination__button ").concat(prefix, "--pagination__button--forward ").concat(iotPrefix, "-addons-simple-pagination-button-disabled"),
    role: "button",
    tabIndex: hasNext ? 0 : -1,
    onClick: hasNext ? handleNext : undefined,
    onKeyDown: hasNext ? function (evt) {
      return handleEnterKeyDown(evt, handleNext);
    } : undefined,
    "data-testid": "".concat(testID || testId, "-forward-button")
  }, /*#__PURE__*/React__default.createElement(CaretRight, {
    dir: "ltr",
    "aria-label": nextPageText,
    className: hasNext ? "".concat(iotPrefix, "-simple-pagination-caret") : "".concat(iotPrefix, "-simple-pagination-caret-disabled")
  }))) : null));
};
SimplePagination.propTypes = SimplePaginationPropTypes;
SimplePagination.defaultProps = SimplePaginationDefaultProps;
SimplePagination.__docgenInfo = {
  "description": "This is a lighter weight pagination component than the default Carbon one",
  "methods": [],
  "displayName": "SimplePagination",
  "props": {
    "pageOfPagesText": {
      "defaultValue": {
        "value": "(page, maxPage) => `Page ${page} of ${maxPage}`",
        "computed": false
      },
      "description": "Gets called back with arguments (page, maxPage)",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "pageText": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Internationalized label for the word 'Page'",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "nextPageText": {
      "defaultValue": {
        "value": "'Next page'",
        "computed": false
      },
      "description": "Internationalized label for the word 'Next page'",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "prevPageText": {
      "defaultValue": {
        "value": "'Prev page'",
        "computed": false
      },
      "description": "Internationalized label for the word 'Previous page'",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "totalItemsText": {
      "defaultValue": {
        "value": "'Items'",
        "computed": false
      },
      "description": "Internationalized label for the word 'Items' or function receiving\na param for the total: (total) => `${total} items`}",
      "type": {
        "name": "union",
        "value": [{
          "name": "string"
        }, {
          "name": "func"
        }]
      },
      "required": false
    },
    "totalItems": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "total number of items",
      "type": {
        "name": "number"
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "`${iotPrefix}-simple-pagination`",
        "computed": false
      },
      "description": "Id that can be used for testing",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "size": {
      "defaultValue": {
        "value": "'lg'",
        "computed": false
      },
      "description": "the size of the buttons in pagination",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'sm'",
          "computed": false
        }, {
          "value": "'md'",
          "computed": false
        }, {
          "value": "'lg'",
          "computed": false
        }]
      },
      "required": false
    },
    "page": {
      "description": "current page number",
      "type": {
        "name": "number"
      },
      "required": true
    },
    "maxPage": {
      "description": "The maximum page number that can be navigated to",
      "type": {
        "name": "number"
      },
      "required": true
    },
    "onPage": {
      "description": "Callback when the page is changed",
      "type": {
        "name": "func"
      },
      "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 SimplePagination$1 = SimplePagination;

export { SimplePaginationPropTypes, SimplePagination$1 as default };
