"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _types = require("../../../../types");
var _MyStories = _interopRequireDefault(require("../../../../components/MyStories"));
var _CommunityStories = _interopRequireDefault(require("../../../../components/CommunityStories"));
var _tsSdkReactNative = require("@amityco/ts-sdk-react-native");
var _useConfig = _interopRequireDefault(require("../../../../hooks/useConfig"));
var _enums = require("../../../../enums");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const AmityStoryTabComponent = ({
  type,
  targetId
}) => {
  const [communityData, setCommunityData] = (0, _react.useState)(null);
  const {
    excludes
  } = (0, _useConfig.default)();
  (0, _react.useEffect)(() => {
    if (type === _types.AmityStoryTabComponentEnum.communityFeed && targetId) {
      _tsSdkReactNative.CommunityRepository.getCommunity(targetId, ({
        error,
        loading,
        data
      }) => {
        if (error) return;
        if (!loading) {
          setCommunityData(data);
        }
      });
    }
  }, [targetId, type]);
  if (excludes.includes(`*/${_enums.ComponentID.StoryTab}/*`)) return null;
  if (type === _types.AmityStoryTabComponentEnum.globalFeed) {
    return /*#__PURE__*/React.createElement(_MyStories.default, null);
  }
  if (type === _types.AmityStoryTabComponentEnum.communityFeed) {
    return /*#__PURE__*/React.createElement(_CommunityStories.default, {
      community: communityData,
      communityId: targetId
    });
  }
  return null;
};
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(AmityStoryTabComponent);
//# sourceMappingURL=Tab.js.map