import { useNavigation } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { useTranslation } from 'react-i18next';
import {
  Image,
  ScrollView,
  StyleSheet,
  Text,
  TouchableOpacity,
  View,
  useWindowDimensions,
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import Logo from 'screens/../../assets/bootsplash/logo_512.png';
import { RootStackParamList } from 'types/types';

type LoginScreenNavigationProp = NativeStackNavigationProp<
  RootStackParamList,
  'Login'
>;

const SelectAuth = () => {
  const { t } = useTranslation();
  const navigation = useNavigation<LoginScreenNavigationProp>();
  const { width } = useWindowDimensions();

  const isSmallScreen = width < 360;

  return (
    <SafeAreaView style={{ flex: 1 }}>
      <View style={styles.container}>
        <ScrollView
          style={{ flex: 1 }}
          contentContainerStyle={styles.scrollContent}
          showsVerticalScrollIndicator={false}
        >
          <View style={[styles.innerContainer, { maxWidth: 500 }]}>
            <View style={styles.logoWrapper}>
              <Image
                source={Logo}
                style={[
                  styles.logoImage,
                  {
                    width: isSmallScreen ? 120 : 250,
                    height: isSmallScreen ? 120 : 200,
                    borderRadius: 20000,
                  },
                ]}
              />
              <Text
                style={[styles.logoText, { fontSize: isSmallScreen ? 22 : 50 }]}
              >
                CPOST
              </Text>
            </View>

            <Text style={[styles.title, { fontSize: isSmallScreen ? 20 : 24 }]}>
              {t('Ro’yxatdan o’tganmisz')}
            </Text>

            <View style={styles.btnContainer}>
              <View style={{ gap: 4 }}>
                <Text style={styles.helperText}>
                  {t("Botdan ro'yxatdan o’tganmisiz")}
                </Text>
                <TouchableOpacity
                  onPress={() => navigation.navigate('Login')}
                  style={styles.button}
                >
                  <Text style={styles.btnText}>{t('Tizimga kirish')}</Text>
                </TouchableOpacity>
              </View>

              <View style={{ gap: 4 }}>
                <Text style={styles.helperText}>
                  {t("Yangi ro’yxatdan o'tmoqchimisiz")}
                </Text>
                <TouchableOpacity
                  onPress={() => navigation.navigate('Register')}
                  style={styles.button}
                >
                  <Text style={styles.btnText}>{t('Ro’yxatdan o’tish')}</Text>
                </TouchableOpacity>
              </View>
            </View>
          </View>
        </ScrollView>
      </View>
    </SafeAreaView>
  );
};

export default SelectAuth;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    paddingHorizontal: 20,
    margin: 5,
    borderRadius: 12,
  },
  scrollContent: {
    flexGrow: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  innerContainer: {
    width: '100%',
    paddingHorizontal: 10,
  },
  logoWrapper: {
    alignItems: 'center',
    marginBottom: 40,
  },
  logoImage: {
    resizeMode: 'stretch',
  },
  logoText: {
    fontWeight: '700',
    color: '#28A7E8',
  },
  title: {
    fontWeight: '600',
    textAlign: 'center',
    color: '#28A7E8',
    marginBottom: 20,
  },
  helperText: {
    color: '#28A7E8',
    fontSize: 16,
  },
  button: {
    backgroundColor: '#28A7E8',
    height: 56,
    borderRadius: 6,
    justifyContent: 'center',
  },
  btnText: {
    color: '#fff',
    fontSize: 18,
    textAlign: 'center',
  },
  btnContainer: {
    gap: 16,
  },
});
