import { A2GoodsType, A2SelectType, Tab5ListType } from "@/types";

// 初始化状态
const initState = {
  // 文物列表数据
  goodsList: {
    list: [] as A2GoodsType[],
    total: 0,
  },
  // 下拉框数据
  selectData: {
    texture: [],
    age: [],
  } as A2SelectType,

  // 知识的列表数据（带分页）
  tab5List: {
    list: [] as Tab5ListType[],
    total: 0,
  },
};

// 定义 action 类型
type Props =
  | { type: "main/goodsList"; payload: { list: A2GoodsType[]; total: number } }
  | { type: "main/goodsSelect"; payload: A2SelectType }
  | { type: "main/tab5List"; payload: { list: Tab5ListType[]; total: number } };
// 频道 reducer
export default function loginReducer(state = initState, action: Props) {
  switch (action.type) {
    // 文物列表数据
    case "main/goodsList":
      return { ...state, goodsList: action.payload };
    // 下拉框数据
    case "main/goodsSelect":
      return { ...state, selectData: action.payload };
    // 知识列表数据
    case "main/tab5List":
      return { ...state, tab5List: action.payload };
    default:
      return state;
  }
}
