/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 */

import {
  Button,
  StatusBar,
  StyleSheet,
  Text,
  useColorScheme,
  View,
} from 'react-native';
import { showMessage } from '@common/ToastHelper.ts';
import Toast from 'react-native-toast-message';
import Alert from '@common/components/Alert.tsx';
import { NavigationPop } from '@common/NavigationHelper.ts';
import { versionName } from '@ywx/ywq.ts';
import { useEffect, useState } from 'react';
import { downloadToFile } from '@common/UpdateHelper.ts';

function YwqMain() {
  const isDarkMode = useColorScheme() === 'dark';
  const [progress, setProgress] = useState('');
  useEffect(() => {
    downloadToFile(
      'https://download-api.51trust.com/ywx-android-sdk/buz2.android.zip',
      'buz2.android.zip',
      (bytesWritten, contentLength) => {
        setProgress(
          `进度: ${((bytesWritten / contentLength) * 100).toFixed(2)}%`,
        );
      },
    );
  }, []);

  return (
    <View style={styles.container}>
      <StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
      <View style={{ height: 100 }} />
      <Text>
        医网签{versionName}(${progress})
      </Text>
      <Button
        title={'onConfirm'}
        onPress={() => {
          Alert.show('hello Alert', undefined, {
            action: () => {
              NavigationPop();
            },
          });
        }}
      />
      <View style={{ height: 15 }} />
      <Button
        title={'Toast'}
        onPress={() => {
          showMessage('医网签弹出toast-error', 'error');
        }}
      />
      <Toast />
      {/*<Alert ref={ref => Alert.setRef(ref)} />*/}
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

export default YwqMain;
