import React from 'react';
import {StyleProp, ViewStyle} from 'react-native';
import {PostMetadata} from '@modules/post/interfaces';
import SharedGroupPost from '@modules/group/components/SharedGroupPost';
import SharedFeedPost from '@modules/post/components/SharedFeedPost';

interface Props {
  metadata: PostMetadata;
  withFooter?: boolean;
  style?: StyleProp<ViewStyle>;
}

export function SharedPost({metadata, withFooter, style}: Props) {
  const {postId, groupId} =
    'SHARE_POST_ID' in metadata
      ? {postId: metadata.SHARE_POST_ID.id, groupId: undefined}
      : {
          postId: metadata.SHARE_GROUP_POST_ID.id,
          groupId: metadata.SHARE_GROUP_POST_ID.groupId,
        };

  return groupId ? (
    <SharedGroupPost
      postId={postId}
      groupId={groupId}
      withFooter={withFooter}
      style={style}
    />
  ) : (
    <SharedFeedPost postId={postId} withFooter={withFooter} style={style} />
  );
}
