// Initial state
const initialState = {
  role: null,
  clinicStatus: null,
};

// Action types
const SET_USER_ROLE = 'userRole/SET_USER_ROLE';

// Action creators
export const setUserRole = (role, clinicStatus) => ({
  type: SET_USER_ROLE,
  payload: role,
  clinicStatus: clinicStatus,
});

// Selector to get user role
export const selectUserRole = (state) => state.userRole.role;
export const selectClinicStatus = (state) => state.userRole.clinicStatus;

// Reducer
export default function userRoleReducer(state = initialState, action) {
  switch (action.type) {
    case SET_USER_ROLE:
      return {
        ...state,
        role: action.payload,
        clinicStatus: action.clinicStatus,
      };
    default:
      return state;
  }
}
