import { createContext, useEffect, useReducer } from "react"
import {useLocation} from 'react-router-dom'

const data ={
    device:'',
    layouts:{
        currentPage:'',
        pageIndex:1
    },
    theme:{

    },
    links:{
        shangliancha:'https://www.8n.cn/home',
        shangliangou:'https://www.8n.cn/mall',
        lianzhengbao:'https://lianzb.cn/home/index'
    }
}
export const AppContext = createContext<{data:typeof data,dispatch:any}>({
    data:data,
    dispatch:()=>null
})

interface Actions {
    type: string
    payload: any
}
const AppReducer = (state:typeof data,action:Actions)=>{
    const {type,payload} = action
    // switch(type){
    //     case
    // }
    return state
}

export const AppProvider = (props: any)=>{
    const [state,dispatch] = useReducer(AppReducer,data)
    const location = useLocation()

    return(
        <AppContext.Provider value={{data:state,dispatch}}>
            {props.children}
        </AppContext.Provider>
    )
}