import { createReport, deleteReport, isReportedByMe } from '@amityco/ts-sdk-react-native';
import { useMutation, useQuery } from '@tanstack/react-query';
import { useToast } from '../../../core/stores/slices/toastSlice';
import { TOAST } from '../../../core/constants';
export const useFlagPost = ({
  postId,
  enabled = true
}) => {
  const {
    showToast
  } = useToast();
  const {
    data: isFlaggedByMe,
    isLoading,
    refetch
  } = useQuery({
    queryKey: ['PostRepository', 'isPostFlaggedByMe', postId],
    queryFn: () => isReportedByMe('post', postId),
    enabled: enabled && !!postId
  });
  const {
    mutate: flagPostMutate
  } = useMutation({
    mutationFn: targetPostId => createReport('post', targetPostId)
  });
  const {
    mutate: unflagPostMutate
  } = useMutation({
    mutationFn: targetPostId => deleteReport('post', targetPostId)
  });
  const reportPost = targetPostId => {
    flagPostMutate(targetPostId, {
      onSuccess: () => {
        refetch();
        showToast({
          type: 'success',
          message: TOAST.POST.REPORT.SUCCESS
        });
      },
      onError: () => showToast({
        type: 'informative',
        message: TOAST.POST.REPORT.FAILED
      })
    });
  };
  const unreportPost = targetPostId => {
    unflagPostMutate(targetPostId, {
      onSuccess: () => {
        refetch();
        showToast({
          type: 'success',
          message: TOAST.POST.UNREPORT.SUCCESS
        });
      },
      onError: () => showToast({
        type: 'informative',
        message: TOAST.POST.UNREPORT.FAILED
      })
    });
  };
  return {
    isLoading,
    isFlaggedByMe,
    reportPost,
    unreportPost
  };
};
//# sourceMappingURL=useFlagPost.js.map