import { MessageType } from '@/utils/message'

// 初始化状态
const initState = {
  // antd轻提示(兼容360浏览器)
  message: {
    txt: '',
    type: 'info',
    duration: 3
  } as MessageType,
  // 所有图片点击预览查看大图
  lookBigImg: {
    url: '',
    show: false
  },
  // 路由堆栈长度
  routerLength: 0
}

// 定义 action 类型
type LayoutActionType =
  | { type: 'layout/message'; payload: MessageType }
  | { type: 'layout/lookBigImg'; payload: { url: string; show: boolean } }
  | { type: 'layout/routerLength'; payload: number }

// 频道 reducer
export default function layoutReducer(state = initState, action: LayoutActionType) {
  switch (action.type) {
    // antd轻提示(兼容360浏览器)
    case 'layout/message':
      return { ...state, message: action.payload }
    // 所有图片点击预览查看大图
    case 'layout/lookBigImg':
      return { ...state, lookBigImg: action.payload }
    // 路由堆栈长度
    case 'layout/routerLength':
      return { ...state, routerLength: action.payload }
    default:
      return state
  }
}
