import Buttons from "@/components/Buttons";
import { clear, logout } from "@/services/user";
import { View,Text } from "@tarojs/components";
import Taro from "@tarojs/taro";
import { useDispatch, useSelector } from "react-redux";

export default function Page(){
    const dispatch = useDispatch();
    const user = useSelector((state: any) => state.user);
    
    function logoutF(){
        dispatch(logout() as any);
    }

    function clearF(){
        dispatch(clear() as any);
    }

    function tapLogin(){
        Taro.navigateTo({
            url: '/pages/ChooseAuth'
        })
    }

    function reset(){
        Taro.login({
            
        })
    }

    return <View  className="container">
        {
            user.isLogin&&<Text>用户名：{user.nickname}</Text>
        }
        {
            user.isLogin&&<Text>id：{user.id}</Text>
        }
        {
            user.isLogin?<Buttons title='退出登录' onClick={logoutF} style={{ width: 289, marginBottom: 30 }} />:
            <Text onClick={tapLogin}>请登录</Text>
        }
        {
            user.isLogin?<Buttons title='注销账号' onClick={clearF} style={{ width: 289, marginBottom: 30 }} />:
            <Text></Text>
        }
        {
            user.isLogin&& <Buttons title='重置session' onClick={reset} style={{ width: 289, marginBottom: 30 }} />
        }
        
    </View>
}