import { createSlice, PayloadAction } from '@reduxjs/toolkit';

interface UIState {
  networkOnline: boolean;
  globalLoading: boolean;
  toastMessage: string | null;
}

const initialState: UIState = {
  networkOnline: true,
  globalLoading: false,
  toastMessage: null,
};

const uiSlice = createSlice({
  name: 'ui',
  initialState,
  reducers: {
    setNetworkOnline: (state, action: PayloadAction<boolean>) => {
      state.networkOnline = action.payload;
    },
    setGlobalLoading: (state, action: PayloadAction<boolean>) => {
      state.globalLoading = action.payload;
    },
    showToast: (state, action: PayloadAction<string>) => {
      state.toastMessage = action.payload;
    },
    clearToast: state => {
      state.toastMessage = null;
    },
  },
});

export const { setNetworkOnline, setGlobalLoading, showToast, clearToast } = uiSlice.actions;
export default uiSlice;


