"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _FormLabel = _interopRequireDefault(require("../../../../../elements/FormLabel"));
var _styles = require("./styles");
var _enums = require("../../../../../enums");
var _Typography = require("../../../../../../core/components/Typography/Typography");
var _reactNativeSvg = require("react-native-svg");
var _icons = require("../../../../../../core/assets/icons");
var _BehaviourProvider = require("../../../../../providers/BehaviourProvider");
var _native = require("@react-navigation/native");
var _CategoryChip = _interopRequireDefault(require("../../../../../components/CategoryChip/CategoryChip"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function Categories({
  onChange,
  categories,
  goBack
}) {
  const {
    styles,
    theme
  } = (0, _styles.useStyles)();
  const {
    AmityCommunitySetupPageBehavior
  } = (0, _BehaviourProvider.useBehaviour)();
  const navigation = (0, _native.useNavigation)();
  const onAddedAction = addedCategories => {
    goBack();
    onChange(addedCategories);
  };
  return /*#__PURE__*/React.createElement(_reactNative.View, null, /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.labelContainer
  }, /*#__PURE__*/React.createElement(_FormLabel.default, {
    optional: true,
    pageId: _enums.PageID.community_setup_page,
    elementId: _enums.ElementID.community_category_title
  })), categories.length > 0 ? /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.categoryContainer
  }, /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.selectedCategoriesContainer
  }, categories.map(category => /*#__PURE__*/React.createElement(_CategoryChip.default, {
    category: category,
    key: category.categoryId,
    onPress: () => onChange(categories.filter(cat => cat.categoryId !== category.categoryId))
  }))), /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    onPress: () => {
      if (AmityCommunitySetupPageBehavior.goToAddCategoryPage) {
        return AmityCommunitySetupPageBehavior.goToAddCategoryPage({
          categories,
          onAddedAction
        });
      }
      navigation.navigate('CommunityAddCategory', {
        categories,
        onAddedAction
      });
    }
  }, /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    width: 20,
    height: 20,
    xml: (0, _icons.arrowRight)(),
    color: theme.colors.baseShade2
  }))) : /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    style: styles.categoryContainer,
    onPress: () => {
      if (AmityCommunitySetupPageBehavior.goToAddCategoryPage) {
        return AmityCommunitySetupPageBehavior.goToAddCategoryPage({
          categories,
          onAddedAction
        });
      }
      navigation.navigate('CommunityAddCategory', {
        categories,
        onAddedAction
      });
    }
  }, /*#__PURE__*/React.createElement(_Typography.Typography.Body, {
    style: styles.categoryText
  }, "Select category"), /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    width: 20,
    height: 20,
    xml: (0, _icons.arrowRight)(),
    color: theme.colors.baseShade2
  })));
}
var _default = exports.default = Categories;
//# sourceMappingURL=index.js.map