import { FourTableType } from '@/pages/B_enterTibet/B1collect/type'
import { FourKeyType } from '../action/FourAll'

// 初始化状态
const initState = {
  // 列表数据
  listObj: {
    1: {
      list: [] as FourTableType[],
      total: 0
    },
    2: {
      list: [] as FourTableType[],
      total: 0
    },
    3: {
      list: [] as FourTableType[],
      total: 0
    },
    4: {
      list: [] as FourTableType[],
      total: 0
    }
  }
}

// 定义 action 类型
type Props = {
  type: 'Four/getList'
  payload: { key: FourKeyType; value: { list: FourTableType[]; total: number } }
}

// reducer
export default function userReducer(state = initState, action: Props) {
  switch (action.type) {
    // 获取列表数据
    case 'Four/getList':
      return {
        ...state,
        listObj: {
          ...state.listObj,
          [action.payload.key]: action.payload.value
        }
      }

    default:
      return state
  }
}
