"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _styles = require("./styles");
var _TopSearchBar = _interopRequireDefault(require("../../features/search/components/TopSearchBar"));
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
var _hooks = require("../../hooks");
var _enumTabName = require("../../enums/enumTabName");
var _CustomTab = _interopRequireDefault(require("../../components/CustomTab"));
var _CommunitySearchResult = _interopRequireDefault(require("../../features/search/components/CommunitySearchResult"));
var _enums = require("../../enums");
var _UserSearchResult = _interopRequireDefault(require("../../features/search/components/UserSearchResult"));
var _CommunityListSkeleton = _interopRequireDefault(require("../../components/CommunityListSkeleton/CommunityListSkeleton"));
var _reactNative = require("react-native");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const AmitySocialGlobalSearchPage = () => {
  const pageId = _enums.PageID.social_global_search_page;
  const {
    isExcluded,
    themeStyles
  } = (0, _hooks.useAmityPage)({
    pageId
  });
  const styles = (0, _styles.useStyles)(themeStyles);
  const [searchValue, setSearchValue] = (0, _react.useState)('');
  const [searchType, setSearchType] = (0, _react.useState)(_enumTabName.TabName.Communities);
  const {
    searchResult,
    onNextCommunityPage,
    onNextUserPage,
    isLoading
  } = (0, _hooks.useAmityGlobalSearchViewModel)(searchValue, searchType);
  const renderCommunitySkeleton = (length = 12) => /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.communityListSkeleton
  }, /*#__PURE__*/React.createElement(_CommunityListSkeleton.default, {
    themeStyle: themeStyles,
    amount: length,
    hasTitle: false
  }));
  const isCommunity = searchType === _enumTabName.TabName.Communities;
  if (isExcluded) return null;
  return /*#__PURE__*/React.createElement(_reactNativeSafeAreaContext.SafeAreaView, {
    style: styles.container
  }, /*#__PURE__*/React.createElement(_TopSearchBar.default, {
    searchType: searchType,
    setSearchValue: setSearchValue
  }), /*#__PURE__*/React.createElement(_CustomTab.default, {
    onTabChange: setSearchType,
    tabName: [_enumTabName.TabName.Communities, _enumTabName.TabName.Users]
  }), isCommunity ? /*#__PURE__*/React.createElement(React.Fragment, null, isLoading && !searchResult && renderCommunitySkeleton(), /*#__PURE__*/React.createElement(_CommunitySearchResult.default, {
    pageId: pageId,
    searchType: searchType,
    searchResult: searchResult,
    onNextPage: onNextCommunityPage
  }), isLoading && renderCommunitySkeleton(4)) : /*#__PURE__*/React.createElement(_UserSearchResult.default, {
    pageId: pageId,
    searchResult: searchResult,
    onNextPage: onNextUserPage
  }));
};
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(AmitySocialGlobalSearchPage);
//# sourceMappingURL=index.js.map