import { memo, useState } from 'react';
import { useStyles } from './styles';
import AmityTopSearchBarComponent from '../../features/search/components/TopSearchBar';
import { SafeAreaView } from 'react-native-safe-area-context';
import { useAmityGlobalSearchViewModel } from '../../hooks';
import { TabName } from '../../enums/enumTabName';
import CustomTab from '../../components/CustomTab';
import AmityCommunitySearchResultComponent from '../../features/search/components/CommunitySearchResult';
import { PageID } from '../../enums';
import { useAmityPage } from '../../hooks';
import AmityUserSearchResultComponent from '../../features/search/components/UserSearchResult';
import CommunityListSkeleton from '../../components/CommunityListSkeleton/CommunityListSkeleton';
import { View } from 'react-native';
const AmitySocialGlobalSearchPage = () => {
  const pageId = PageID.social_global_search_page;
  const {
    isExcluded,
    themeStyles
  } = useAmityPage({
    pageId
  });
  const styles = useStyles(themeStyles);
  const [searchValue, setSearchValue] = useState('');
  const [searchType, setSearchType] = useState(TabName.Communities);
  const {
    searchResult,
    onNextCommunityPage,
    onNextUserPage,
    isLoading
  } = useAmityGlobalSearchViewModel(searchValue, searchType);
  const renderCommunitySkeleton = (length = 12) => /*#__PURE__*/React.createElement(View, {
    style: styles.communityListSkeleton
  }, /*#__PURE__*/React.createElement(CommunityListSkeleton, {
    themeStyle: themeStyles,
    amount: length,
    hasTitle: false
  }));
  const isCommunity = searchType === TabName.Communities;
  if (isExcluded) return null;
  return /*#__PURE__*/React.createElement(SafeAreaView, {
    style: styles.container
  }, /*#__PURE__*/React.createElement(AmityTopSearchBarComponent, {
    searchType: searchType,
    setSearchValue: setSearchValue
  }), /*#__PURE__*/React.createElement(CustomTab, {
    onTabChange: setSearchType,
    tabName: [TabName.Communities, TabName.Users]
  }), isCommunity ? /*#__PURE__*/React.createElement(React.Fragment, null, isLoading && !searchResult && renderCommunitySkeleton(), /*#__PURE__*/React.createElement(AmityCommunitySearchResultComponent, {
    pageId: pageId,
    searchType: searchType,
    searchResult: searchResult,
    onNextPage: onNextCommunityPage
  }), isLoading && renderCommunitySkeleton(4)) : /*#__PURE__*/React.createElement(AmityUserSearchResultComponent, {
    pageId: pageId,
    searchResult: searchResult,
    onNextPage: onNextUserPage
  }));
};
export default /*#__PURE__*/memo(AmitySocialGlobalSearchPage);
//# sourceMappingURL=index.js.map