"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _color = _interopRequireDefault(require("color"));
var _IconButton = _interopRequireDefault(require("../IconButton/IconButton"));
var _Text = _interopRequireDefault(require("../Typography/Text"));
var _theming = require("../../core/theming");
var _MaterialCommunityIcons = _interopRequireDefault(require("react-native-vector-icons/MaterialCommunityIcons"));
var _tokens = require("../../styles/tokens");
var _utils = require("./utils");
var _TouchableRipple = _interopRequireDefault(require("../TouchableRipple/TouchableRipple.native"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
const PaginationControls = _ref => {
  let {
    page,
    numberOfPages,
    onPageChange,
    showFastPaginationControls,
    pageNeighbours = 1
  } = _ref;
  pageNeighbours = Math.max(0, Math.min(pageNeighbours, 2));
  const theme = (0, _theming.useTheme)();
  const textColor = _tokens.colors.black;
  numberOfPages = Math.max(1, numberOfPages);
  // if (!numberOfPages || numberOfPages === 1) return null;
  const pages = (0, _utils.fetchPageNumbers)(page, pageNeighbours, numberOfPages);
  return /*#__PURE__*/React.createElement(_reactNative.View, {
    style: {
      flexDirection: 'row',
      alignItems: 'center'
    }
  }, showFastPaginationControls ? /*#__PURE__*/React.createElement(_IconButton.default, {
    icon: _ref2 => {
      let {
        size,
        color
      } = _ref2;
      return /*#__PURE__*/React.createElement(_MaterialCommunityIcons.default, {
        name: "chevron-double-left",
        color: color,
        size: size,
        style: [{
          transform: [{
            scaleX: _reactNative.I18nManager.isRTL ? -1 : 1
          }],
          lineHeight: size,
          backgroundColor: 'transparent'
        }]
      });
    },
    iconColor: textColor,
    disabled: page === 0,
    onPress: () => onPageChange(0),
    accessibilityLabel: "page-first"
  }) : null, /*#__PURE__*/React.createElement(_IconButton.default, {
    icon: _ref3 => {
      let {
        size,
        color
      } = _ref3;
      return /*#__PURE__*/React.createElement(_MaterialCommunityIcons.default, {
        name: "chevron-left",
        color: color,
        size: size,
        style: [{
          transform: [{
            scaleX: _reactNative.I18nManager.isRTL ? -1 : 1
          }],
          lineHeight: size,
          backgroundColor: 'transparent'
        }]
      });
    },
    iconColor: textColor,
    disabled: page === 0,
    onPress: () => onPageChange(page - 1),
    accessibilityLabel: "chevron-left"
  }), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: {
      flexDirection: 'row'
    }
  }, pages.map((p, i) => {
    return /*#__PURE__*/React.createElement(_TouchableRipple.default, {
      style: [styles.basePageButton, page + 1 === p && {
        backgroundColor: theme.colors.primary.default
      }],
      onPress: () => {
        onPageChange(p - 1);
      },
      key: i,
      rippleColor: theme.colors.primary.default
    }, /*#__PURE__*/React.createElement(_Text.default, {
      style: [page + 1 === p && {
        color: _tokens.colors.white
      }]
    }, p));
  })), /*#__PURE__*/React.createElement(_IconButton.default, {
    icon: _ref4 => {
      let {
        size,
        color
      } = _ref4;
      return /*#__PURE__*/React.createElement(_MaterialCommunityIcons.default, {
        name: "chevron-right",
        color: color,
        size: size,
        style: [{
          transform: [{
            scaleX: _reactNative.I18nManager.isRTL ? -1 : 1
          }],
          lineHeight: size,
          backgroundColor: 'transparent'
        }]
      });
    },
    iconColor: textColor,
    disabled: numberOfPages === 0 || page === numberOfPages - 1,
    onPress: () => onPageChange(page + 1),
    accessibilityLabel: "chevron-right"
  }), showFastPaginationControls ? /*#__PURE__*/React.createElement(_IconButton.default, {
    icon: _ref5 => {
      let {
        size,
        color
      } = _ref5;
      return /*#__PURE__*/React.createElement(_MaterialCommunityIcons.default, {
        name: "chevron-double-right",
        color: color,
        size: size,
        style: [{
          transform: [{
            scaleX: _reactNative.I18nManager.isRTL ? -1 : 1
          }],
          lineHeight: size,
          backgroundColor: 'transparent'
        }]
      });
    },
    iconColor: textColor,
    disabled: numberOfPages === 0 || page === numberOfPages - 1,
    onPress: () => onPageChange(numberOfPages - 1),
    accessibilityLabel: "page-last"
  }) : null);
};
const Pagination = _ref6 => {
  let {
    label,
    accessibilityLabel,
    page,
    numberOfPages,
    onPageChange,
    style,
    theme,
    showFastPaginationControls = false,
    numberOfItemsPerPageList,
    numberOfItemsPerPage,
    onItemsPerPageChange,
    selectPageDropdownLabel,
    selectPageDropdownAccessibilityLabel,
    ...rest
  } = _ref6;
  const labelColor = (0, _color.default)(_tokens.colors.black).alpha(0.6).rgb().string();
  return /*#__PURE__*/React.createElement(_reactNative.View, _extends({}, rest, {
    style: [styles.container, style, {
      flex: 1
    }],
    accessibilityLabel: "pagination-container"
  }), /*#__PURE__*/React.createElement(PaginationControls, {
    showFastPaginationControls: showFastPaginationControls,
    onPageChange: onPageChange,
    page: page,
    numberOfPages: numberOfPages
  }));
};
const styles = _reactNative.StyleSheet.create({
  container: {
    justifyContent: 'center',
    flexDirection: 'column',
    alignItems: 'center',
    flex: 1
  },
  optionsContainer: {
    flexDirection: 'row',
    alignItems: 'center',
    marginVertical: 6
  },
  label: {
    fontSize: 12,
    marginRight: 16
  },
  button: {
    textAlign: 'center',
    marginRight: 16
  },
  iconsContainer: {
    flexDirection: 'row'
  },
  contentStyle: {
    flexDirection: 'row-reverse'
  },
  basePageButton: {
    height: 48,
    width: 48,
    alignItems: 'center',
    justifyContent: 'center',
    borderRadius: 16
  }
});
var _default = (0, _theming.withTheme)(Pagination);
exports.default = _default;
//# sourceMappingURL=Pagination.js.map