import { ScrollView, View } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { Feed, Action, TopBar, Header, ImageFeed, VideoFeed } from './components';
import { useUserProfile } from './hooks/useUserProfile';
import Tabs from '../../../../core/components/Tabs';
import { UserProfileTab } from './types';
import { feed, image, mediaIcon } from '../../../../core/assets/icons';
function UserProfile({
  userId,
  inline,
  stickyTab = true
}) {
  const {
    user,
    styles,
    isUserLoading,
    activeTab,
    setActiveTab,
    feedRef,
    headerHeight,
    setHeaderHeight,
    isTabSticky,
    setIsTabSticky,
    scrollRef,
    accessibilityId,
    feedTabId,
    imageTabId,
    videoTabId
  } = useUserProfile(userId);
  return /*#__PURE__*/React.createElement(SafeAreaView, {
    testID: accessibilityId,
    style: styles.container,
    edges: inline ? [] : undefined
  }, !inline && /*#__PURE__*/React.createElement(TopBar, {
    userId: userId,
    displayName: user === null || user === void 0 ? void 0 : user.displayName,
    isShownDisplayName: isTabSticky,
    inline: inline
  }), /*#__PURE__*/React.createElement(Tabs, {
    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(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(View, {
    onLayout: e => setHeaderHeight(e.nativeEvent.layout.height)
  }, isUserLoading || !user ? /*#__PURE__*/React.createElement(Header.Skeleton, null) : /*#__PURE__*/React.createElement(Header, {
    user: user,
    inline: inline
  })), /*#__PURE__*/React.createElement(Tabs.List, null, /*#__PURE__*/React.createElement(Tabs.Tab, {
    testID: feedTabId,
    "aria-label": "User Feed",
    value: UserProfileTab.Feed,
    iconProps: {
      xml: feed()
    }
  }), /*#__PURE__*/React.createElement(Tabs.Tab, {
    testID: imageTabId,
    "aria-label": "User Image Feed",
    value: UserProfileTab.Image,
    iconProps: {
      xml: image()
    }
  }), /*#__PURE__*/React.createElement(Tabs.Tab, {
    testID: videoTabId,
    "aria-label": "User Video Feed",
    value: UserProfileTab.Video,
    iconProps: {
      xml: mediaIcon()
    }
  })), /*#__PURE__*/React.createElement(Tabs.Content, {
    value: UserProfileTab.Feed
  }, /*#__PURE__*/React.createElement(Feed, {
    ref: feedRef,
    userId: userId,
    isBrand: user === null || user === void 0 ? void 0 : user.isBrand,
    isUserLoading: isUserLoading
  })), /*#__PURE__*/React.createElement(Tabs.Content, {
    value: UserProfileTab.Image
  }, /*#__PURE__*/React.createElement(ImageFeed, {
    ref: feedRef,
    userId: userId,
    isBrand: user === null || user === void 0 ? void 0 : user.isBrand,
    isUserLoading: isUserLoading
  })), /*#__PURE__*/React.createElement(Tabs.Content, {
    value: UserProfileTab.Video
  }, /*#__PURE__*/React.createElement(VideoFeed, {
    ref: feedRef,
    userId: userId,
    isBrand: user === null || user === void 0 ? void 0 : user.isBrand,
    isUserLoading: isUserLoading
  })))), !inline && /*#__PURE__*/React.createElement(Action, {
    userId: userId
  }));
}
export default UserProfile;
//# sourceMappingURL=Profile.js.map