import { A1ListType, NumListType } from '@/pages/A1record/data'

// 初始化状态
const initState = {
  // 列表数据
  tableInfo: {
    list: [] as A1ListType[],
    total: 0
  },
  // 牺牲时所在单位列表数据
  numList: [] as NumListType[]
}

// 定义 action 类型
type Props =
  | {
      type: 'A1/getList'
      payload: { list: A1ListType[]; total: number }
    }
  | {
      type: 'A1/getNumList'
      payload: NumListType[]
    }

// reducer
export default function userReducer(state = initState, action: Props) {
  switch (action.type) {
    // 获取列表数据
    case 'A1/getList':
      return { ...state, tableInfo: action.payload }
    case 'A1/getNumList':
      return { ...state, numList: action.payload }

    default:
      return state
  }
}
