import { BarrageTableType } from "@/types";

// 初始化状态
const initState = {
  // 列表数据
  tableInfo: {
    list: [] as BarrageTableType[],
    total: 0,
  },
  // 弹幕未审核个数
  stateNum: 0,
};

// 定义 action 类型
type BarrageActionType =
  | {
      type: "barrage/getList";
      payload: { list: BarrageTableType[]; total: number };
    }
  | { type: "barrage/stateNum"; payload: number };

// 频道 reducer
export default function barrageReducer(
  state = initState,
  action: BarrageActionType
) {
  switch (action.type) {
    // 获取列表数据
    case "barrage/getList":
      return { ...state, tableInfo: action.payload };
    // 弹幕未审核个数
    case "barrage/stateNum":
      return { ...state, stateNum: action.payload };
    default:
      return state;
  }
}
