import { useCallback, useEffect, useState } from 'react';
import { View } from 'react-native';
import { useStyles } from './styles';
import useAuth from '../../../../core/hooks/useAuth';
import AmityStory from '../../StoryKit';
import { useStory } from '../../../../core/hooks/useStory';
import ContentLoader, { Circle } from 'react-content-loader/native';
import { useFocusEffect } from '@react-navigation/native';
export default function CommunityStories({
  communityId
}) {
  const styles = useStyles();
  const {
    apiRegion
  } = useAuth();
  const {
    getStories,
    stories,
    loading
  } = useStory();
  useFocusEffect(useCallback(() => {
    getStories({
      targetId: communityId,
      targetType: 'community'
    });
  }, [communityId, getStories]));
  const [communityStories, setCommunityStories] = useState([]);
  const getStory = useCallback(() => {
    const storyData = stories.map(item => {
      var _item$data, _item$data2, _item$creator;
      return {
        story_id: item.storyId,
        story_image: `https://api.${apiRegion}.amity.co/api/v3/files/${item === null || item === void 0 || (_item$data = item.data) === null || _item$data === void 0 ? void 0 : _item$data.fileId}/download?size=full`,
        swipeText: '',
        onPress: () => console.log('story 1 swiped'),
        story_type: item === null || item === void 0 ? void 0 : item.dataType,
        story_video: `https://api.${apiRegion}.amity.co/api/v3/files/${item === null || item === void 0 || (_item$data2 = item.data) === null || _item$data2 === void 0 || (_item$data2 = _item$data2.videoFileId) === null || _item$data2 === void 0 ? void 0 : _item$data2.original}/download`,
        story_page: 0,
        creatorName: (item === null || item === void 0 || (_item$creator = item.creator) === null || _item$creator === void 0 ? void 0 : _item$creator.displayName) ?? '',
        createdAt: item.createdAt,
        items: item.items,
        reactionCounts: item.reactionsCount,
        comments: item.comments,
        viewer: item.impression,
        myReactions: item.myReactions
      };
    });
    if (storyData.length > 0) {
      var _stories$;
      const mappedStories = [{
        user_id: stories[0].community.communityId,
        user_image: `https://api.${apiRegion}.amity.co/api/v3/files/${(_stories$ = stories[0]) === null || _stories$ === void 0 || (_stories$ = _stories$.community) === null || _stories$ === void 0 ? void 0 : _stories$.avatarFileId}/download?size=full`,
        user_name: stories[0].community.displayName,
        stories: storyData ?? [],
        isOfficial: true,
        isPublic: true
      }];
      setCommunityStories(mappedStories);
    }
  }, [apiRegion, stories]);
  useEffect(() => {
    getStory();
  }, [getStory]);
  return /*#__PURE__*/React.createElement(View, {
    style: styles.container
  }, loading ? /*#__PURE__*/React.createElement(ContentLoader, {
    height: 70,
    speed: 1,
    width: 100,
    backgroundColor: '#d2d2d2',
    foregroundColor: '#eee',
    viewBox: "-10 7 100 30"
  }, /*#__PURE__*/React.createElement(Circle, {
    cx: "25",
    cy: "25",
    r: "25"
  })) : communityStories.length > 0 ? /*#__PURE__*/React.createElement(AmityStory, {
    data: communityStories,
    duration: 7,
    isCommunityStory: true
  }) : null);
}
//# sourceMappingURL=index.js.map