"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
var _components = require("./components");
var _useUserProfile = require("./hooks/useUserProfile");
var _Tabs = _interopRequireDefault(require("../../../../core/components/Tabs"));
var _types = require("./types");
var _icons = require("../../../../core/assets/icons");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function UserProfile({
  userId,
  inline,
  stickyTab = true
}) {
  const {
    user,
    styles,
    isUserLoading,
    activeTab,
    setActiveTab,
    feedRef,
    headerHeight,
    setHeaderHeight,
    isTabSticky,
    setIsTabSticky,
    scrollRef,
    accessibilityId,
    feedTabId,
    imageTabId,
    videoTabId
  } = (0, _useUserProfile.useUserProfile)(userId);
  return /*#__PURE__*/React.createElement(_reactNativeSafeAreaContext.SafeAreaView, {
    testID: accessibilityId,
    style: styles.container,
    edges: inline ? [] : undefined
  }, !inline && /*#__PURE__*/React.createElement(_components.TopBar, {
    userId: userId,
    displayName: user === null || user === void 0 ? void 0 : user.displayName,
    isShownDisplayName: isTabSticky,
    inline: inline
  }), /*#__PURE__*/React.createElement(_Tabs.default, {
    variant: "icon",
    activeTab: activeTab,
    onChangeTab: tab => {
      var _scrollRef$current;
      setActiveTab(tab);
      setIsTabSticky(false);
      (_scrollRef$current = scrollRef.current) === null || _scrollRef$current === void 0 || _scrollRef$current.scrollTo({
        y: 0,
        animated: false
      });
    }
  }, /*#__PURE__*/React.createElement(_reactNative.ScrollView, {
    ref: scrollRef,
    scrollEventThrottle: 50,
    stickyHeaderIndices: stickyTab ? [1] : [],
    onScroll: e => {
      var _feedRef$current;
      const {
        contentOffset,
        layoutMeasurement,
        contentSize
      } = e.nativeEvent;
      setIsTabSticky(contentOffset.y >= headerHeight);
      const isNearBottom = layoutMeasurement.height + contentOffset.y >= contentSize.height - 200;
      if (isNearBottom) (_feedRef$current = feedRef.current) === null || _feedRef$current === void 0 || _feedRef$current.loadMore();
    }
  }, /*#__PURE__*/React.createElement(_reactNative.View, {
    onLayout: e => setHeaderHeight(e.nativeEvent.layout.height)
  }, isUserLoading || !user ? /*#__PURE__*/React.createElement(_components.Header.Skeleton, null) : /*#__PURE__*/React.createElement(_components.Header, {
    user: user,
    inline: inline
  })), /*#__PURE__*/React.createElement(_Tabs.default.List, null, /*#__PURE__*/React.createElement(_Tabs.default.Tab, {
    testID: feedTabId,
    "aria-label": "User Feed",
    value: _types.UserProfileTab.Feed,
    iconProps: {
      xml: (0, _icons.feed)()
    }
  }), /*#__PURE__*/React.createElement(_Tabs.default.Tab, {
    testID: imageTabId,
    "aria-label": "User Image Feed",
    value: _types.UserProfileTab.Image,
    iconProps: {
      xml: (0, _icons.image)()
    }
  }), /*#__PURE__*/React.createElement(_Tabs.default.Tab, {
    testID: videoTabId,
    "aria-label": "User Video Feed",
    value: _types.UserProfileTab.Video,
    iconProps: {
      xml: (0, _icons.mediaIcon)()
    }
  })), /*#__PURE__*/React.createElement(_Tabs.default.Content, {
    value: _types.UserProfileTab.Feed
  }, /*#__PURE__*/React.createElement(_components.Feed, {
    ref: feedRef,
    userId: userId,
    isBrand: user === null || user === void 0 ? void 0 : user.isBrand,
    isUserLoading: isUserLoading
  })), /*#__PURE__*/React.createElement(_Tabs.default.Content, {
    value: _types.UserProfileTab.Image
  }, /*#__PURE__*/React.createElement(_components.ImageFeed, {
    ref: feedRef,
    userId: userId,
    isBrand: user === null || user === void 0 ? void 0 : user.isBrand,
    isUserLoading: isUserLoading
  })), /*#__PURE__*/React.createElement(_Tabs.default.Content, {
    value: _types.UserProfileTab.Video
  }, /*#__PURE__*/React.createElement(_components.VideoFeed, {
    ref: feedRef,
    userId: userId,
    isBrand: user === null || user === void 0 ? void 0 : user.isBrand,
    isUserLoading: isUserLoading
  })))), !inline && /*#__PURE__*/React.createElement(_components.Action, {
    userId: userId
  }));
}
var _default = exports.default = UserProfile;
//# sourceMappingURL=Profile.js.map