import { useState, useEffect } from 'react';
import {
  View,
  Text,
  TextInput,
  TouchableOpacity,
  Image,
  StyleSheet,
  Alert,
  StatusBar
} from 'react-native';

import { Toast, Button } from '@ant-design/react-native';
import { useContextHook } from '@/components/AuthContext/index';

import AsyncStorage from '@/storage/index';
import { useRouter } from '@/hooks/useRouter';

import {
  statusBarHeight,
  paddingTopStatusBarHeight,
  flexRow,
  flexColumn,
  flexSub,
  flexShrink,
  flexWrap,
  flexnoWrap,
  justifyStart,
  justifyEnd,
  justifyCenter,
  justifyBetween,
  justifyAround,
  justifyEvenly,
  alignItemsStart,
  alignItemsEnd,
  alignItemsCenter,
  alignItemsStretch,
  positionRelative,
  positionAbsolute,
  useStyles,
} from '@/assets/styles/css';

const Index = () => {
  const { themeColor } = useContextHook();
  const { linkTo, resetAllRoutes, isFocused } = useRouter();
  useEffect(() => {
    const user = AsyncStorage.getItemAsync('user');
    // 这里请求配置后，再跳转
    setTimeout(() => {
      console.log('user', user);
      if (user && user.token) {
        resetAllRoutes('Home');
      } else {
        resetAllRoutes('AccountInfo');
      }
    }, 1000);
  }, [isFocused]);

  return (
    <View style={[flexSub, {}]}>
      <View
        style={[
          flexSub,
          justifyCenter,
          alignItemsCenter,
          flexRow
        ]}>
        <Image
          source={require('@/assets/images/logo.png')}
          style={[
            {
              width: 52,
              height: 52,
              resizeMode: 'contain',
            },
          ]}
        />
        <Text
          style={{
            fontSize: 32,
            fontWeight: 'bold',
            marginLeft: 10,
            color: themeColor.color_text_base,
          }}>
          Finix
        </Text>
      </View>
    </View>
  );
};
export default Index;
