console.log("🔥 当前 App.tsx 已加载");
import * as React from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";

import HomeScreen from "./src/HomeScreen";
import ScanScreen from "./src/ScanScreen";
import ScanScreen2 from "./src/ScanScreen2";
import ScanScreen3 from "./src/ScanScreen3";
import InfoScreen from "./src/InfoScreen";
import DfuScreen from "./src/DfuScreen";
import PrivacyScreen from "./src/PrivacyScreen";
import SplashScreen from "./src/SplashScreen"; // ✅ 新增启动页
import SettingScreen from "./src/SettingScreen";
import './src/i18n'
import InfoScreen2 from "./src/InfoScreen2";
import InfoScreen3 from "./src/InfoScreen3";
import SpindownScreen from "./src/SpindownScreen";
import { decode } from "base-64";


// 不要 global.atob
// 不要 atob

const base64ToBytes = (base64: string): number[] => {
  const binary = decode(base64);
  const bytes: number[] = [];

  for (let i = 0; i < binary.length; i++) {
    bytes.push(binary.charCodeAt(i));
  }

  return bytes;
};

export type RootStackParamList = {
  Splash: undefined;
  Home: undefined;
  Scan: undefined;
  ScanScreen2: undefined;
  ScanScreen3: undefined;
  Info: { peripheral: any };
  Info2: { peripheral: any };
  Info3: { peripheral: any };
  Spindown: { peripheral: any };
  Dfu: {
  deviceId: string;
  systemId?: string;
  address?: string | number;
  name: string;
  firmware: string;
};
  Privacy: undefined;
  Setting: undefined;
};

const Stack = createNativeStackNavigator<RootStackParamList>();

export default function App() {

  //linshi
  React.useEffect(() => {
  const test = async () => {
    try {
      console.log("🔥 App.tsx fetch test start");
      const resp = await fetch("https://www.baidu.com");
      console.log("🔥 App.tsx fetch status =", resp.status);
      const text = await resp.text();
      console.log("🔥 App.tsx fetch text length =", text.length);
    } catch (e) {
      console.log("❌ App.tsx fetch error =", e);
    }
  };

  test();
}, []);
  return (
    <NavigationContainer>
      <Stack.Navigator
        initialRouteName="Splash"
        screenOptions={{
          animation : 'slide_from_right'
        }}>
        <Stack.Screen
          name="Info2"
          component={InfoScreen2}
          options={{ headerShown: false }}
        />
        {/* 启动页（无标题） */}
        <Stack.Screen
          name="Splash"
          component={SplashScreen}
          options={{ headerShown: false }}
        />
 
        {/* 首页(标题栏无文字) */}
        <Stack.Screen
          name="Home"
          component={HomeScreen}
          options={{ headerShown: false }}
        />

        {/* 其他页面默认显示标题栏 */}
        <Stack.Screen
          name="Scan"
          component={ScanScreen}
          // options={{ title: "搜索设备" }}
          options={{ headerShown: false }}
        />
        <Stack.Screen
          name="ScanScreen2"
          component={ScanScreen2}
          // options={{ title: "搜索设备" }}
          options={{ headerShown: false }}
        />
        <Stack.Screen
          name="ScanScreen3"
          component={ScanScreen3}
          // options={{ title: "搜索设备" }}
          options={{ headerShown: false }}
        />
        <Stack.Screen
          name="Info"
          component={InfoScreen}
          // options={{ title: "设备详情" }}
          options={{ headerShown: false }}
        />
        <Stack.Screen
          name="Info3"
          component={InfoScreen3}
          // options={{ title: "设备详情" }}
          options={{ headerShown: false }}
        />
        <Stack.Screen
          name="Spindown"
          component={SpindownScreen}
          options={{ headerShown: false }}
        />
        <Stack.Screen
          name="Dfu"
          component={DfuScreen}
          // options={{ title: "固件升级" }}
          options={{ headerShown: false }}
        />
        <Stack.Screen
          name="Privacy"
          component={PrivacyScreen}
          // options={{ title: "隐私协议" }}
          options={{ headerShown: false }}
        />
        <Stack.Screen
          name="Setting"
          component={SettingScreen}
          // options={{ title: "隐私协议" }}
          options={{ headerShown: false }}
        />
      </Stack.Navigator>
    </NavigationContainer>
  );
}
