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'
        })
    }
    return <View  className="container">
        {
            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>
        }
        
    </View>
}