import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import i18next from "i18next";
import cookies from "js-cookie";


interface LanguageState {
  currentLang: string;
}

const initialState: LanguageState = {
  currentLang: cookies.get("i18next"),
};

export const languageSlice = createSlice({
  name: "language",
  initialState,
  reducers: {
    handleChangeLanguage(state, action: PayloadAction<string>) {
      i18next.changeLanguage(action.payload);
      state.currentLang = action.payload;
    },
  },
});


export default languageSlice.reducer;

