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

type CloseUpFileType = {
  fu: () => void;
  state: boolean;
};

// 初始化状态
const initState = {
  message: {
    txt: "",
    type: "info",
    duration: 3,
  } as MessageType,
  // 上传文件点击取消
  closeUpFile: {
    fu: () => {},
    state: false,
  },
};

// 定义 action 类型
type Props =
  | { type: "layout/message"; payload: MessageType }
  | { type: "layout/closeUpFile"; payload: CloseUpFileType };

// 频道 reducer
export default function layoutReducer(state = initState, action: Props) {
  switch (action.type) {
    // antd轻提示(兼容360浏览器)
    case "layout/message":
      return { ...state, message: action.payload };
    // 上传文件点击取消
    case "layout/closeUpFile":
      return { ...state, closeUpFile: action.payload };
    default:
      return state;
  }
}
