import { createSlice } from "@reduxjs/toolkit";
import { getUserInfoAsync } from "./operations";
import type { HeaderState } from "./state";

const initialState: HeaderState = {
  domain: {
    getUserInfo: undefined,
  },
};

export const headerSlice = createSlice({
  name: "header",
  initialState,
  reducers: {
    clearUserInfo: (state) => {
      state.domain.getUserInfo = undefined;
    },
  },
  extraReducers: (builder) => {
    builder.addCase(getUserInfoAsync.fulfilled, (state, action) => {
      state.domain.getUserInfo = action.payload;
    });
  },
});

export const { clearUserInfo } = headerSlice.actions;
export const headerReducer = headerSlice.reducer;
export default headerReducer;
