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); }
import * as React from 'react';
import { StyleSheet, View, I18nManager } from 'react-native';
import color from 'color';
import IconButton from '../IconButton/IconButton';
import Text from '../Typography/Text';
import { withTheme, useTheme } from '../../core/theming';
import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons';
import { colors } from '../../styles/tokens';
import { fetchPageNumbers } from './utils';
import TouchableRipple from '../TouchableRipple/TouchableRipple.native';
const PaginationControls = _ref => {
  let {
    page,
    numberOfPages,
    onPageChange,
    showFastPaginationControls,
    pageNeighbours = 1
  } = _ref;
  pageNeighbours = Math.max(0, Math.min(pageNeighbours, 2));
  const theme = useTheme();
  const textColor = colors.black;
  numberOfPages = Math.max(1, numberOfPages);
  // if (!numberOfPages || numberOfPages === 1) return null;
  const pages = fetchPageNumbers(page, pageNeighbours, numberOfPages);
  return /*#__PURE__*/React.createElement(View, {
    style: {
      flexDirection: 'row',
      alignItems: 'center'
    }
  }, showFastPaginationControls ? /*#__PURE__*/React.createElement(IconButton, {
    icon: _ref2 => {
      let {
        size,
        color
      } = _ref2;
      return /*#__PURE__*/React.createElement(MaterialCommunityIcon, {
        name: "chevron-double-left",
        color: color,
        size: size,
        style: [{
          transform: [{
            scaleX: I18nManager.isRTL ? -1 : 1
          }],
          lineHeight: size,
          backgroundColor: 'transparent'
        }]
      });
    },
    iconColor: textColor,
    disabled: page === 0,
    onPress: () => onPageChange(0),
    accessibilityLabel: "page-first"
  }) : null, /*#__PURE__*/React.createElement(IconButton, {
    icon: _ref3 => {
      let {
        size,
        color
      } = _ref3;
      return /*#__PURE__*/React.createElement(MaterialCommunityIcon, {
        name: "chevron-left",
        color: color,
        size: size,
        style: [{
          transform: [{
            scaleX: I18nManager.isRTL ? -1 : 1
          }],
          lineHeight: size,
          backgroundColor: 'transparent'
        }]
      });
    },
    iconColor: textColor,
    disabled: page === 0,
    onPress: () => onPageChange(page - 1),
    accessibilityLabel: "chevron-left"
  }), /*#__PURE__*/React.createElement(View, {
    style: {
      flexDirection: 'row'
    }
  }, pages.map((p, i) => {
    return /*#__PURE__*/React.createElement(TouchableRipple, {
      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, {
      style: [page + 1 === p && {
        color: colors.white
      }]
    }, p));
  })), /*#__PURE__*/React.createElement(IconButton, {
    icon: _ref4 => {
      let {
        size,
        color
      } = _ref4;
      return /*#__PURE__*/React.createElement(MaterialCommunityIcon, {
        name: "chevron-right",
        color: color,
        size: size,
        style: [{
          transform: [{
            scaleX: 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, {
    icon: _ref5 => {
      let {
        size,
        color
      } = _ref5;
      return /*#__PURE__*/React.createElement(MaterialCommunityIcon, {
        name: "chevron-double-right",
        color: color,
        size: size,
        style: [{
          transform: [{
            scaleX: 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 = color(colors.black).alpha(0.6).rgb().string();
  return /*#__PURE__*/React.createElement(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 = 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
  }
});
export default withTheme(Pagination);
//# sourceMappingURL=Pagination.js.map