import { createSlice } from '@reduxjs/toolkit';
import { useUIKitDispatch, useUIKitSelector } from '../store';
import { getCommentErrorMessage } from '../../../social/utils/errors';
const initialState = {
  visible: false,
  message: '',
  type: 'loading',
  duration: 2500,
  bottomPosition: 16
};
const toastSlice = 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;
    }
  }
});
export default toastSlice;
export const useToast = () => {
  const dispatch = useUIKitDispatch();
  const toast = 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 = getCommentErrorMessage(error);
    showToast({
      message: errorMessage,
      type: 'informative'
    });
  };
  return {
    toast,
    hideToast,
    showToast,
    showCommentErrorToast
  };
};
//# sourceMappingURL=toastSlice.js.map