import { B1tableAreaType, B1tableType } from "@/types";

// 初始化状态
const initState = {
  // 列表数据
  B1TableList: {
    list: [] as B1tableType[],
    total: 0,
  },
  B1TableListArea: {
    list: [] as B1tableAreaType[],
    total: 0,
  },
};

// 定义 action 类型
type Props =
  | {
      type: "B1/getList";
      payload: { list: B1tableType[]; total: number };
    }
  | {
      type: "B1/getListArea";
      payload: { list: B1tableAreaType[]; total: number };
    };

// reducer
export default function Reducer(state = initState, action: Props) {
  switch (action.type) {
    // 获取列表数据
    case "B1/getList":
      return { ...state, B1TableList: action.payload };
    case "B1/getListArea":
      return { ...state, B1TableListArea: action.payload };
    default:
      return state;
  }
}
