import { createSlice } from '@reduxjs/toolkit';

interface IDEContainerState {
  info: any;
  menuData: any;
  flowData: any;
  canvasDataMap: any;
  projectComponentData: any;
  currentAppData: any;
  logBarStatus?: boolean;
}

const initialState: IDEContainerState = {
  info: {}, // 项目信息
  menuData: {}, // 菜单数据
  flowData: {}, // 编排数据，即流程图的渲染数据
  canvasDataMap: {}, // 每个画布的缓存信息
  projectComponentData: {}, // 工程下的组件列表
  currentAppData: {}, // 当前选中的应用数据
  logBarStatus: false
};

const ideContainerSlice = createSlice({
  name: 'ideContainer',
  initialState,
  reducers: {
    updateInfo(state, action) {
      state.info = action.payload;
    },
    updateMenuData(state, action) {
      state.menuData = action.payload;
    },
    updateFlowData(state, action) {
      state.flowData = { ...state.flowData, ...action.payload };
    },
    updateCanvasDataMap(state, action) {
      state.canvasDataMap = { ...state.canvasDataMap, ...action.payload };
    },
    updateProjectComponentData(state, action) {
      state.projectComponentData = { ...state.projectComponentData, ...action.payload };
    },
    updateCurrentAppData(state, action) {
      state.currentAppData = action.payload;
    },
    updateLogBarStatus(state, action) {
      state.logBarStatus = action.payload;
    }
  }
});

export const {
  updateInfo,
  updateMenuData,
  updateFlowData,
  updateCanvasDataMap,
  updateProjectComponentData,
  updateCurrentAppData,
  updateLogBarStatus
} = ideContainerSlice.actions;

export default ideContainerSlice.reducer;