import { DataAllType } from "@/types";
import { MessageType } from "@/utils/message";

// 初始化状态
const initState = {
  // antd轻提示(兼容360浏览器)
  message: {
    txt: "",
    type: "info",
    duration: 3,
  } as MessageType,

  // 所有数据
  dataAll: {} as DataAllType,
};

// 定义 action 类型
type LayoutActionType =
  | { type: "layout/message"; payload: MessageType }
  | { type: "layout/setDataAll"; payload: DataAllType };

// 频道 reducer
export default function layoutReducer(
  state = initState,
  action: LayoutActionType
) {
  switch (action.type) {
    // antd轻提示(兼容360浏览器)
    case "layout/message":
      return { ...state, message: action.payload };

    // 设置所有数据
    case "layout/setDataAll":
      return { ...state, dataAll: action.payload };

    default:
      return state;
  }
}
