"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.setMode = exports.setClientSource = exports.default = exports.authenticateUserSuccess = exports.authenticateUserRequest = exports.authenticateUserError = void 0;
var _toolkit = require("@reduxjs/toolkit");
// src/store/slices/authSlice.ts

// 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 = (0, _toolkit.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
const {
  authenticateUserRequest,
  authenticateUserSuccess,
  authenticateUserError,
  setClientSource,
  setMode
} = authSlice.actions;
exports.setMode = setMode;
exports.setClientSource = setClientSource;
exports.authenticateUserError = authenticateUserError;
exports.authenticateUserSuccess = authenticateUserSuccess;
exports.authenticateUserRequest = authenticateUserRequest;
var _default = exports.default = authSlice.reducer;
//# sourceMappingURL=authSlice.js.map