// src/store/slices/authSlice.ts
import { createSlice } from "@reduxjs/toolkit";
// Initial state for the auth slice
const initialState = {
  clientSource: "default",
  mode: "",
  user: {
    data: {},
    isLoading: false,
    errors: "",
    platform: "ios"
  },
  isUserLoggedIn: false
};

// Define the auth slice
const authSlice = createSlice({
  name: "auth",
  initialState,
  reducers: {
    authenticateUserRequest: (state, action) => {
      state.user.isLoading = true;
      state.user.errors = "";
    },
    authenticateUserSuccess: (state, action) => {
      state.user.isLoading = false;
      state.user.data = action.payload.data;
      // setUserAttributes(action.payload.data);
      // localStorage.setItem(
      //   LOCAL_STORAGE.AUTH_TOKEN,
      //   action.payload.data?.token
      // );
      // localStorage.setItem(
      //   LOCAL_STORAGE.USER_INFO,
      //   JSON.stringify(action.payload.data)
      // );
      state.isUserLoggedIn = true;
    },
    authenticateUserError: (state, {
      payload: error
    }) => {
      state.user.isLoading = false;
      state.user.errors = error;
    },
    setClientSource: (state, action) => {
      let clientSource = action.payload ||
      // localStorage.getItem(LOCAL_STORAGE.CLIENT_SOURCE) ||
      "default";
      state.clientSource = clientSource;
    },
    setMode: (state, action) => {
      // let mode =
      //   action.payload || localStorage.getItem(LOCAL_STORAGE.MODE) || "";
      // state.mode = mode;
    }
  }
});

// Export actions and reducer
export const {
  authenticateUserRequest,
  authenticateUserSuccess,
  authenticateUserError,
  setClientSource,
  setMode
} = authSlice.actions;
export default authSlice.reducer;
//# sourceMappingURL=authSlice.js.map