"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useClosePoll = void 0;
var _tsSdkReactNative = require("@amityco/ts-sdk-react-native");
var _reactQuery = require("@tanstack/react-query");
var _reactNative = require("react-native");
var _toastSlice = require("../../../core/stores/slices/toastSlice");
var _constants = require("../../../core/constants");
const useClosePoll = () => {
  const {
    showToast
  } = (0, _toastSlice.useToast)();
  const {
    mutate: closePollMutate,
    isPending
  } = (0, _reactQuery.useMutation)({
    mutationFn: _tsSdkReactNative.PollRepository.closePoll
  });
  const closePoll = async pollId => {
    _reactNative.Alert.alert(_constants.ALERT.POLL.CLOSE.TITLE, _constants.ALERT.POLL.CLOSE.MESSAGE, [{
      text: _constants.ALERT.ACTION.CANCEL,
      style: 'cancel'
    }, {
      text: _constants.ALERT.POLL.CLOSE.ACTION,
      style: 'destructive',
      onPress: () => {
        if (!isPending) {
          closePollMutate(pollId, {
            onSuccess: () => {
              showToast({
                type: 'success',
                message: _constants.TOAST.POLL.CLOSE.SUCCESS
              });
            },
            onError: () => {
              showToast({
                type: 'failed',
                message: _constants.TOAST.POLL.CLOSE.FAILED
              });
            }
          });
        }
      }
    }]);
  };
  return {
    closePoll
  };
};
exports.useClosePoll = useClosePoll;
//# sourceMappingURL=useClosePoll.js.map