import { Typetable } from '@/pages/Zother/data'

// 初始化状态
const initState = {
  // 列表数据
  tableInfo: {
    list: [] as Typetable[],
    total: 0
  },
  // 导入数据分页数据
  importExcelTableInfo: {
    list: [] as Typetable[],
    total: 0
  },
  // 导入图片分页数据
  importZipTableInfo: {
    list: [] as Typetable[],
    total: 0
  }
}

// 定义 action 类型
type Props =
  | {
      type: 'C1/getList'
      payload: { list: Typetable[]; total: number }
    }
  | {
      type: 'C1/getImportExcelList'
      payload: { list: Typetable[]; total: number }
    }
  | {
      type: 'C1/getImportZipList'
      payload: { list: Typetable[]; total: number }
    }

// reducer
export default function Reducer(state = initState, action: Props) {
  switch (action.type) {
    // 获取列表数据
    case 'C1/getList':
      return { ...state, tableInfo: action.payload }
    // 获取导入数据分页数据
    case 'C1/getImportExcelList':
      return { ...state, importExcelTableInfo: action.payload }
    // 获取导入图片分页数据
    case 'C1/getImportZipList':
      return { ...state, importZipTableInfo: action.payload }
    default:
      return state
  }
}
