// 初始化状态应用注解
const initState = {
  // 三个模块的表格信息
  tableList: {
    list: [] as any,
    total: 0,
  },
  // 角色管理的角色权限弹窗信息
  roleInfo: {} as any,
  roleArr: [
    {
      id: 100,
      name: "藏品登记",
      authority: false,
      children: [
        { name: "编辑", authority: false, id: 102 },
        { name: "删除", authority: false, id: 103 },
        { name: "审核", authority: false, id: 105 },
      ],
    },
    {
      id: 200,
      name: "臧品总账",
      authority: false,
      children: [
        { name: "编辑", authority: false, id: 202 },
        { name: "移库", authority: false, id: 205 },
      ],
    },
    {
      id: 300,
      name: "入库管理",
      authority: false,
      children: [
        { name: "编辑", authority: false, id: 302 },
        { name: "删除", authority: false, id: 303 },
        { name: "审核", authority: false, id: 305 },
      ],
    },
    {
      id: 400,
      name: "出库管理",
      authority: false,
      children: [
        { name: "编辑", authority: false, id: 402 },
        { name: "删除", authority: false, id: 403 },
        { name: "审核", authority: false, id: 405 },
        { name: "归还", authority: false, id: 406 },
      ],
    },
    {
      id: 500,
      name: "臧品修改",
      authority: false,
      children: [
        { name: "删除", authority: false, id: 503 },
        { name: "审核", authority: false, id: 505 },
      ],
    },
    {
      id: 600,
      name: "臧品注销",
      authority: false,
      children: [
        { name: "编辑", authority: false, id: 602 },
        { name: "删除", authority: false, id: 603 },
        { name: "审核", authority: false, id: 605 },
      ],
    },
    {
      id: 700,
      name: "库房设置",
      authority: false,
      children: [
        { name: "编辑", authority: false, id: 702 },
        { name: "删除", authority: false, id: 703 },
      ],
    },
    {
      id: 800,
      name: "臧品移库",
      authority: false,
      children: [
        { name: "删除", authority: false, id: 803 },
        { name: "审核", authority: false, id: 805 },
      ],
    },
  ],
  // 所有角色的下拉框
  roleSelect: [] as any,
};

type ActionType =
  | { type: "system/getTableList"; payload: any }
  | { type: "system/getRoleInfo"; payload: any }
  | { type: "system/getRoleArr"; payload: any }
  | { type: "system/getRoleSelect"; payload: any };

export default function systemReducer(state = initState, action: ActionType) {
  switch (action.type) {
    // 用户管理表格信息
    case "system/getTableList":
      return { ...state, tableList: action.payload };
    // 角色管理的角色权限弹窗信息
    case "system/getRoleInfo":
      return { ...state, roleInfo: action.payload };
    case "system/getRoleArr":
      return { ...state, roleArr: action.payload };
    // 所有角色的下拉框
    case "system/getRoleSelect":
      return { ...state, roleSelect: action.payload };

    default:
      return state;
  }
}
