"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _react = require("react");
var _styles = require("./styles");
var _enums = require("../../enums");
var _hooks = require("../../hooks");
var _AllCategoriesTitle = _interopRequireDefault(require("../../elements/AllCategoriesTitle/AllCategoriesTitle"));
var _BackButtonIconElement = _interopRequireDefault(require("../../elements/BackButtonIconElement/BackButtonIconElement"));
var _CategoryRowItem = _interopRequireDefault(require("./CategoryRowItem/CategoryRowItem"));
var _native = require("@react-navigation/native");
var _CategoryListSkeleton = _interopRequireDefault(require("./CategoryListSkeleton/CategoryListSkeleton"));
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const AmityAllCategoriesPage = () => {
  const pageId = _enums.PageID.all_categories_page;
  const {
    accessibilityId,
    themeStyles
  } = (0, _hooks.useAmityPage)({
    pageId
  });
  const {
    categories,
    loading,
    onNextCategoryPage
  } = (0, _hooks.useCategories)({
    limit: 20
  });
  const styles = (0, _styles.useStyles)(themeStyles);
  const navigation = (0, _native.useNavigation)();
  const onPressCategory = (0, _react.useCallback)(category => {
    navigation.navigate('CommunitiesByCategoryPage', {
      category
    });
  }, [navigation]);
  return /*#__PURE__*/React.createElement(_reactNativeSafeAreaContext.SafeAreaView, {
    testID: accessibilityId,
    style: styles.container
  }, /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.header
  }, /*#__PURE__*/React.createElement(_reactNative.Pressable, {
    onPress: () => navigation.goBack()
  }, /*#__PURE__*/React.createElement(_BackButtonIconElement.default, {
    pageID: pageId,
    style: styles.headerIcon
  })), /*#__PURE__*/React.createElement(_AllCategoriesTitle.default, {
    title: 'All Categories',
    pageId: pageId
  }), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.empty
  })), /*#__PURE__*/React.createElement(_reactNative.FlatList, {
    data: categories,
    renderItem: ({
      item
    }) => /*#__PURE__*/React.createElement(_reactNative.Pressable, {
      onPress: () => onPressCategory(item)
    }, /*#__PURE__*/React.createElement(_CategoryRowItem.default, {
      category: item,
      pageId: pageId
    })),
    keyExtractor: item => item.categoryId,
    contentContainerStyle: styles.listContent,
    style: styles.list,
    onEndReached: () => {
      onNextCategoryPage === null || onNextCategoryPage === void 0 || onNextCategoryPage();
    },
    onEndReachedThreshold: 0.5,
    ListFooterComponent: loading ? /*#__PURE__*/React.createElement(_CategoryListSkeleton.default, {
      themeStyle: themeStyles,
      amount: !categories ? 20 : 4
    }) : null
  }));
};
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(AmityAllCategoriesPage);
//# sourceMappingURL=index.js.map