import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import AppText from 'components/AppText';
import React from 'react';
import {
  Image,
  ScrollView,
  StyleSheet,
  TouchableOpacity,
  useWindowDimensions,
  View,
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import RU from 'screens/../../assets/bootsplash/RU.png';
import UZ from 'screens/../../assets/bootsplash/UZ.png';
import Logo from 'screens/../../assets/bootsplash/logo_512.png';
import { RootStackParamList } from 'types/types';

type NavigationProp = NativeStackNavigationProp<RootStackParamList>;
const SelectLangPage = ({
  onSelectLang,
}: {
  onSelectLang: (lang: 'uz' | 'ru') => void;
}) => {
  const { width } = useWindowDimensions();
  const isSmallScreen = width < 380;

  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: 180,
                    height: 150,
                    marginLeft: 35,
                  },
                ]}
              />
              <AppText
                style={[styles.logoText, { fontSize: 42, fontWeight: '700' }]}
              >
                CPOST
              </AppText>
            </View>

            <AppText style={[styles.title, { fontSize: 24 }]}>
              Tilni tanlang{' '}
              <AppText style={[styles.title, { fontSize: 18 }]}>
                (Выберите язык)
              </AppText>
            </AppText>

            <View style={styles.btnContainer}>
              <TouchableOpacity
                onPress={() => onSelectLang('uz')}
                style={[
                  styles.button,
                  {
                    backgroundColor: 'none',
                    borderWidth: 1,
                    borderColor: '#28A7E8',
                  },
                ]}
              >
                <Image source={UZ} style={styles.flag} />
                <AppText style={[styles.btnText, { color: '#28A7E8' }]}>
                  O'zbek tili
                </AppText>
              </TouchableOpacity>

              <TouchableOpacity
                onPress={() => onSelectLang('ru')}
                style={styles.button}
              >
                <Image source={RU} style={styles.flag} />
                <AppText style={styles.btnText}>Русский язык</AppText>
              </TouchableOpacity>
            </View>
          </View>
        </ScrollView>
      </View>
    </SafeAreaView>
  );
};

export default SelectLangPage;

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