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

// 初始化状态应用注解
const initState = {
  // 所有下拉数据
  selectAll: {
    藏品编号名称: [],
    文物级别: [],
    文物来源: [],
    完残程度: [],
    保存状态: [],
    入藏时间范围: [],
    质量范围: [],
    文物类别: [],
    质地: [],
    年代: [],
  } as any,
  // 单个里面的藏品的附件信息
  fileData: {
    img: [],
    video: [],
    audio: [],
    model: [],
    doc: [],
  } as any,
  // 藏品的表格信息
  goodsTableList: [] as any,
  // 关于按钮的权限信息
  authButtonArr: [],
  // 外层页面的权限信息
  authPageArr: [],
  // 所有图片点击预览查看大图
  lookBigImg: {
    url: "",
    show: false,
  },
  // 加载请求的loding
  asyncLoding: false,
  // antd轻提示(兼容360浏览器)
  message: {
    txt: "",
    type: "info",
    duration: 3,
  } as MessageType,
};

type LoginActionType =
  | { type: "login/getSelectAll"; payload: any }
  | { type: "login/setFileData"; payload: any }
  | { type: "login/setGoodsSonList"; payload: any }
  | { type: "login/setAuthButtonArr"; payload: any }
  | { type: "login/setAuthPageArr"; payload: any }
  | { type: "login/lookBigImg"; payload: any }
  | { type: "login/asyncLoding"; payload: any }
  | { type: "login/message"; payload: MessageType };
// 频道 reducer
export default function loginReducer(
  state = initState,
  action: LoginActionType
) {
  switch (action.type) {
    // 所有的下拉列表数据
    case "login/getSelectAll":
      return { ...state, selectAll: action.payload };
    // 新增编辑藏品的附件数据（弹窗里面的附件）
    case "login/setFileData":
      return { ...state, fileData: action.payload };
    // 新增编辑藏品 的外层 表格信息（新增编辑页面下面的表格）
    case "login/setGoodsSonList":
      return { ...state, goodsTableList: action.payload };
    // 关于按钮的权限信息
    case "login/setAuthButtonArr":
      return { ...state, authButtonArr: action.payload };
    // 关于外层页面的权限信息
    case "login/setAuthPageArr":
      return { ...state, authPageArr: action.payload };
    // 所有图片点击预览查看大图
    case "login/lookBigImg":
      return { ...state, lookBigImg: action.payload };
    // 加载请求的loding
    case "login/asyncLoding":
      return { ...state, asyncLoding: action.payload };
    // antd轻提示(兼容360浏览器)
    case "login/message":
      return { ...state, message: action.payload };
    default:
      return state;
  }
}
