"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useToast = exports.default = void 0;
var _toolkit = require("@reduxjs/toolkit");
var _store = require("../store");
var _errors = require("../../../social/utils/errors");
const initialState = {
  visible: false,
  message: '',
  type: 'loading',
  duration: 2500,
  bottomPosition: 16
};
const toastSlice = (0, _toolkit.createSlice)({
  name: 'toast',
  initialState,
  reducers: {
    showToast: (state, action) => {
      state.visible = true;
      state.message = action.payload.message;
      state.type = action.payload.type;
      state.duration = action.payload.duration ?? initialState.duration;
      state.bottomPosition = action.payload.bottomPosition ?? initialState.bottomPosition;
    },
    hideToast: state => {
      state.visible = false;
      state.message = '';
      state.type = 'loading';
      state.duration = 2500;
      state.bottomPosition = 16;
    }
  }
});
var _default = exports.default = toastSlice;
const useToast = () => {
  const dispatch = (0, _store.useUIKitDispatch)();
  const toast = (0, _store.useUIKitSelector)(state => state.toast);
  const {
    showToast: $showToast,
    hideToast: $hideToast
  } = toastSlice.actions;
  const hideToast = () => dispatch($hideToast());
  const showToast = payload => dispatch($showToast(payload));
  const showCommentErrorToast = error => {
    const errorMessage = (0, _errors.getCommentErrorMessage)(error);
    showToast({
      message: errorMessage,
      type: 'informative'
    });
  };
  return {
    toast,
    hideToast,
    showToast,
    showCommentErrorToast
  };
};
exports.useToast = useToast;
//# sourceMappingURL=toastSlice.js.map