"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = CommunityStories;
var _react = require("react");
var _reactNative = require("react-native");
var _styles = require("./styles");
var _useAuth = _interopRequireDefault(require("../../../../core/hooks/useAuth"));
var _StoryKit = _interopRequireDefault(require("../../StoryKit"));
var _useStory = require("../../../../core/hooks/useStory");
var _native = _interopRequireWildcard(require("react-content-loader/native"));
var _native2 = require("@react-navigation/native");
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); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function CommunityStories({
  communityId
}) {
  const styles = (0, _styles.useStyles)();
  const {
    apiRegion
  } = (0, _useAuth.default)();
  const {
    getStories,
    stories,
    loading
  } = (0, _useStory.useStory)();
  (0, _native2.useFocusEffect)((0, _react.useCallback)(() => {
    getStories({
      targetId: communityId,
      targetType: 'community'
    });
  }, [communityId, getStories]));
  const [communityStories, setCommunityStories] = (0, _react.useState)([]);
  const getStory = (0, _react.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]);
  (0, _react.useEffect)(() => {
    getStory();
  }, [getStory]);
  return /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.container
  }, loading ? /*#__PURE__*/React.createElement(_native.default, {
    height: 70,
    speed: 1,
    width: 100,
    backgroundColor: '#d2d2d2',
    foregroundColor: '#eee',
    viewBox: "-10 7 100 30"
  }, /*#__PURE__*/React.createElement(_native.Circle, {
    cx: "25",
    cy: "25",
    r: "25"
  })) : communityStories.length > 0 ? /*#__PURE__*/React.createElement(_StoryKit.default, {
    data: communityStories,
    duration: 7,
    isCommunityStory: true
  }) : null);
}
//# sourceMappingURL=index.js.map