"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useCommunityNotificationSettingsQuery = useCommunityNotificationSettingsQuery;
var _tsSdkReactNative = require("@amityco/ts-sdk-react-native");
var _reactQuery = require("@tanstack/react-query");
function useCommunityNotificationSettingsQuery({
  communityId
}) {
  const queryClient = (0, _reactQuery.useQueryClient)();
  const queryKey = ['communityNotificationSettings', communityId];
  const invalidate = () => {
    queryClient.invalidateQueries({
      queryKey
    });
  };
  const {
    data,
    isLoading
  } = (0, _reactQuery.useQuery)({
    queryKey,
    queryFn: () => _tsSdkReactNative.Client.notifications().community(communityId).getSettings(),
    enabled: !!communityId
  });
  const {
    mutateAsync: enableMutate,
    isPending: isEnablePending
  } = (0, _reactQuery.useMutation)({
    mutationFn: ({
      communityId: id,
      events
    }) => _tsSdkReactNative.Client.notifications().community(id).enable(events),
    onSuccess: invalidate
  });
  const {
    mutateAsync: disableMutate,
    isPending: isDisablePending
  } = (0, _reactQuery.useMutation)({
    mutationFn: ({
      communityId: id
    }) => _tsSdkReactNative.Client.notifications().community(id).disable(),
    onSuccess: invalidate
  });
  return {
    data,
    isLoading,
    enableNotifications: enableMutate,
    disableNotifications: disableMutate,
    isPending: isEnablePending || isDisablePending
  };
}
//# sourceMappingURL=useCommunityNotificationSettingsQuery.js.map