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

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

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

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