"use strict";

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