"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var React = _react;
var _reactNative = require("react-native");
var _CustomSocialTab = _interopRequireDefault(require("../../components/CustomSocialTab/CustomSocialTab"));
var _hooks = require("../../hooks");
var _enumUIKitID = require("../../enums/enumUIKitID");
var _reactNativePaper = require("react-native-paper");
var _BehaviourProvider = require("../../providers/BehaviourProvider");
var _TopNavigation = _interopRequireDefault(require("../../features/feed/components/TopNavigation"));
var _MyCommunities = _interopRequireDefault(require("../../features/feed/components/MyCommunities"));
var _NewsFeed = _interopRequireDefault(require("../../features/feed/components/NewsFeed"));
var _Explore = _interopRequireDefault(require("../../features/feed/components/Explore"));
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
var _Profile = _interopRequireDefault(require("../../features/user/Profile"));
var _useAuth = _interopRequireDefault(require("../../../core/hooks/useAuth"));
var _Divider = _interopRequireDefault(require("../../components/Divider"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const PROFILE_TAB = 'Profile';
const AmitySocialHomePage = () => {
  const theme = (0, _reactNativePaper.useTheme)();
  const {
    client
  } = (0, _useAuth.default)();
  const styles = _reactNative.StyleSheet.create({
    container: {
      flex: 1,
      backgroundColor: theme.colors.background
    }
  });
  const {
    AmitySocialHomePageBehaviour
  } = (0, _BehaviourProvider.useBehaviour)();
  const [newsFeedTab] = (0, _hooks.useUiKitConfig)({
    page: _enumUIKitID.PageID.social_home_page,
    component: _enumUIKitID.ComponentID.WildCardComponent,
    element: _enumUIKitID.ElementID.newsfeed_button,
    keys: ['text']
  });
  const [exploreTab] = (0, _hooks.useUiKitConfig)({
    page: _enumUIKitID.PageID.social_home_page,
    component: _enumUIKitID.ComponentID.WildCardComponent,
    element: _enumUIKitID.ElementID.explore_button,
    keys: ['text']
  });
  const [myCommunitiesTab] = (0, _hooks.useUiKitConfig)({
    page: _enumUIKitID.PageID.social_home_page,
    component: _enumUIKitID.ComponentID.WildCardComponent,
    element: _enumUIKitID.ElementID.my_communities_button,
    keys: ['text']
  });
  const [activeTab, setActiveTab] = (0, _react.useState)(newsFeedTab);
  const visitedTabs = (0, _react.useRef)(new Set([newsFeedTab]));
  const onTabChange = (0, _react.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 = (0, _react.useCallback)(() => {
    onTabChange(exploreTab);
  }, [exploreTab, onTabChange]);
  const tabStyle = tab => ({
    flex: 1,
    display: activeTab === tab ? 'flex' : 'none'
  });
  return /*#__PURE__*/React.createElement(_reactNativeSafeAreaContext.SafeAreaView, {
    testID: "social_home_page",
    accessibilityLabel: "social_home_page",
    id: "social_home_page",
    style: styles.container
  }, /*#__PURE__*/React.createElement(_TopNavigation.default, {
    activeTab: activeTab
  }), /*#__PURE__*/React.createElement(_CustomSocialTab.default, {
    activeTab: activeTab,
    onTabChange: onTabChange,
    tabNames: [newsFeedTab, exploreTab, myCommunitiesTab, PROFILE_TAB]
  }), /*#__PURE__*/React.createElement(_Divider.default, null), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: tabStyle(newsFeedTab)
  }, /*#__PURE__*/React.createElement(_NewsFeed.default, {
    pageId: _enumUIKitID.PageID.social_home_page,
    onPressExploreCommunity: onPressExploreCommunity
  })), visitedTabs.current.has(exploreTab) && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: tabStyle(exploreTab)
  }, /*#__PURE__*/React.createElement(_Explore.default, {
    pageId: _enumUIKitID.PageID.social_home_page
  })), visitedTabs.current.has(myCommunitiesTab) && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: tabStyle(myCommunitiesTab)
  }, /*#__PURE__*/React.createElement(_MyCommunities.default, {
    pageId: _enumUIKitID.PageID.social_home_page,
    componentId: _enumUIKitID.ComponentID.my_communities
  })), visitedTabs.current.has(PROFILE_TAB) && /*#__PURE__*/React.createElement(_reactNative.View, {
    style: tabStyle(PROFILE_TAB)
  }, /*#__PURE__*/React.createElement(_Profile.default, {
    inline: true,
    stickyTab: false,
    userId: (client === null || client === void 0 ? void 0 : client.userId) ?? ''
  })));
};
var _default = exports.default = /*#__PURE__*/React.memo(AmitySocialHomePage);
//# sourceMappingURL=index.js.map