import * as React from 'react';
import { useCallback, useRef, useState } from 'react';
import { StyleSheet, View } from 'react-native';
import CustomSocialTab from '../../components/CustomSocialTab/CustomSocialTab';
import { useUiKitConfig } from '../../hooks';
import { ComponentID, ElementID, PageID } from '../../enums/enumUIKitID';
import { useTheme } from 'react-native-paper';
import { useBehaviour } from '../../providers/BehaviourProvider';
import AmitySocialHomeTopNavigationComponent from '../../features/feed/components/TopNavigation';
import AmityMyCommunitiesComponent from '../../features/feed/components/MyCommunities';
import AmityNewsFeedComponent from '../../features/feed/components/NewsFeed';
import AmityExploreComponent from '../../features/feed/components/Explore';
import { SafeAreaView } from 'react-native-safe-area-context';
import UserProfile from '../../features/user/Profile';
import useAuth from '../../../core/hooks/useAuth';
import Divider from '../../components/Divider';
const PROFILE_TAB = 'Profile';
const AmitySocialHomePage = () => {
  const theme = useTheme();
  const {
    client
  } = useAuth();
  const styles = StyleSheet.create({
    container: {
      flex: 1,
      backgroundColor: theme.colors.background
    }
  });
  const {
    AmitySocialHomePageBehaviour
  } = useBehaviour();
  const [newsFeedTab] = useUiKitConfig({
    page: PageID.social_home_page,
    component: ComponentID.WildCardComponent,
    element: ElementID.newsfeed_button,
    keys: ['text']
  });
  const [exploreTab] = useUiKitConfig({
    page: PageID.social_home_page,
    component: ComponentID.WildCardComponent,
    element: ElementID.explore_button,
    keys: ['text']
  });
  const [myCommunitiesTab] = useUiKitConfig({
    page: PageID.social_home_page,
    component: ComponentID.WildCardComponent,
    element: ElementID.my_communities_button,
    keys: ['text']
  });
  const [activeTab, setActiveTab] = useState(newsFeedTab);
  const visitedTabs = useRef(new Set([newsFeedTab]));
  const onTabChange = useCallback(tabName => {
    if (AmitySocialHomePageBehaviour !== null && AmitySocialHomePageBehaviour !== void 0 && AmitySocialHomePageBehaviour.onChooseTab) return AmitySocialHomePageBehaviour === null || AmitySocialHomePageBehaviour === void 0 ? void 0 : AmitySocialHomePageBehaviour.onChooseTab(tabName);
    visitedTabs.current.add(tabName);
    setActiveTab(tabName);
  }, [AmitySocialHomePageBehaviour]);
  const onPressExploreCommunity = useCallback(() => {
    onTabChange(exploreTab);
  }, [exploreTab, onTabChange]);
  const tabStyle = tab => ({
    flex: 1,
    display: activeTab === tab ? 'flex' : 'none'
  });
  return /*#__PURE__*/React.createElement(SafeAreaView, {
    testID: "social_home_page",
    accessibilityLabel: "social_home_page",
    id: "social_home_page",
    style: styles.container
  }, /*#__PURE__*/React.createElement(AmitySocialHomeTopNavigationComponent, {
    activeTab: activeTab
  }), /*#__PURE__*/React.createElement(CustomSocialTab, {
    activeTab: activeTab,
    onTabChange: onTabChange,
    tabNames: [newsFeedTab, exploreTab, myCommunitiesTab, PROFILE_TAB]
  }), /*#__PURE__*/React.createElement(Divider, null), /*#__PURE__*/React.createElement(View, {
    style: tabStyle(newsFeedTab)
  }, /*#__PURE__*/React.createElement(AmityNewsFeedComponent, {
    pageId: PageID.social_home_page,
    onPressExploreCommunity: onPressExploreCommunity
  })), visitedTabs.current.has(exploreTab) && /*#__PURE__*/React.createElement(View, {
    style: tabStyle(exploreTab)
  }, /*#__PURE__*/React.createElement(AmityExploreComponent, {
    pageId: PageID.social_home_page
  })), visitedTabs.current.has(myCommunitiesTab) && /*#__PURE__*/React.createElement(View, {
    style: tabStyle(myCommunitiesTab)
  }, /*#__PURE__*/React.createElement(AmityMyCommunitiesComponent, {
    pageId: PageID.social_home_page,
    componentId: ComponentID.my_communities
  })), visitedTabs.current.has(PROFILE_TAB) && /*#__PURE__*/React.createElement(View, {
    style: tabStyle(PROFILE_TAB)
  }, /*#__PURE__*/React.createElement(UserProfile, {
    inline: true,
    stickyTab: false,
    userId: (client === null || client === void 0 ? void 0 : client.userId) ?? ''
  })));
};
export default /*#__PURE__*/React.memo(AmitySocialHomePage);
//# sourceMappingURL=index.js.map