import { useNavigation } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import AppText from 'components/AppText';
import React from 'react';
import { useTranslation } from 'react-i18next';
import {
  Linking,
  ScrollView,
  StyleSheet,
  TouchableOpacity,
  View,
} from 'react-native';
import AppLink from 'react-native-app-link';
import { SafeAreaView } from 'react-native-safe-area-context';
import ArrowLeft from 'svg/ArrowLeft';
import { RootStackParamList } from 'types/types';

type TermsScreenNavigationProp = NativeStackNavigationProp<
  RootStackParamList,
  'TermsAndConditions'
>;

const TermsAndConditions = () => {
  const navigation = useNavigation<TermsScreenNavigationProp>();
  const { t } = useTranslation();
  const handleAgree = () => {
    navigation.goBack();
  };
  const openTelegram = React.useCallback(async () => {
    try {
      await AppLink.maybeOpenURL('tg://resolve?domain=cpost_admin', {
        appName: 'Telegram',
        appStoreId: 686449807,
        appStoreLocale: 'us',
        playStoreId: 'org.telegram.messenger',
      });
    } catch (err) {
      Linking.openURL('https://t.me/cpost_admin');
    }
  }, []);
  return (
    <SafeAreaView style={styles.container}>
      <View style={styles.header}>
        <TouchableOpacity onPress={() => navigation.goBack()}>
          <ArrowLeft color="#000" />
        </TouchableOpacity>
        <AppText style={styles.headerTitle}>
          {t('Foydalanish shartlari')}
        </AppText>
        <View style={{ width: 20 }} />
      </View>

      <ScrollView style={styles.content} showsVerticalScrollIndicator={false}>
        <AppText style={styles.title}>
          {t('Foydalanish shartlari va qoidalari')}
        </AppText>

        <AppText style={styles.text}>
          {t(
            "Biz sizdan Xitoy xalq Respublikasi Davlatidan sotib olingan tovarlarni olib kelishda quyidagi tovarlarni jo‘natmaslikka rozilik so'raymiz.",
          )}
        </AppText>

        <AppText style={styles.sectionTitle}>1. {t('Umumiy qoidalar')}</AppText>
        <AppText style={styles.text}>{t('Taqiqlangan tovarlar matni')}</AppText>

        <AppText style={styles.text}>{t('Tovarlar')}</AppText>

        <AppText style={styles.sectionTitle}>
          {t('foydalanuvchi_majburiyatlari')}
        </AppText>
        <AppText style={[styles.text, { textAlign: 'left' }]}>
          {t('foydalanuvchi_majburiyatlari_text')}
        </AppText>

        <AppText style={styles.sectionTitle}>{t('maxfiylik_siyosati')}</AppText>
        <AppText style={styles.text}>{t('maxfiylik_siyosati_text')}</AppText>

        <AppText style={styles.sectionTitle}>{t('javobgarlik')}</AppText>
        <AppText style={styles.text}>{t('javobgarlik_text')}</AppText>

        <AppText style={styles.sectionTitle}>
          {t('shartlarni_ozgartirish')}
        </AppText>
        <AppText style={styles.text}>
          {t('shartlarni_ozgartirish_text')}
        </AppText>

        <AppText style={styles.sectionTitle}>{t('aloqa')}</AppText>
        <AppText style={styles.text}>{t('aloqa_text')}</AppText>
        <TouchableOpacity
          onPress={() => Linking.openURL('mailto:info@cpost.uz')}
        >
          <AppText style={styles.text}>{t('Email')}: info@cpost.uz</AppText>
        </TouchableOpacity>
        <TouchableOpacity onPress={() => Linking.openURL('tel:+998951264477')}>
          <AppText style={styles.text}>
            {t('Telefon')}: +998 (95) 126 44 77
          </AppText>
        </TouchableOpacity>
        <TouchableOpacity onPress={openTelegram}>
          <AppText style={styles.text}>{t('Telegram')}: @cpost_admin</AppText>
        </TouchableOpacity>

        <View style={styles.footer}>
          <AppText style={styles.footerText}>
            {t('oxirgi_yangilanish')} 01/09/2025
          </AppText>
        </View>
      </ScrollView>

      <View style={styles.bottomContainer}>
        <TouchableOpacity style={styles.agreeButton} onPress={handleAgree}>
          <AppText style={styles.agreeButtonText}>{t('Roziman')}</AppText>
        </TouchableOpacity>
      </View>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
  },
  header: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    paddingHorizontal: 20,
    paddingVertical: 15,
    borderBottomWidth: 1,
    borderBottomColor: '#E5E5E5',
  },
  headerTitle: {
    fontSize: 18,
    fontFamily: 'GolosText-Bold',
    color: '#000',
  },
  content: {
    flex: 1,
    paddingHorizontal: 20,
  },
  title: {
    fontSize: 24,
    fontWeight: 'bold',
    color: '#000',
    marginVertical: 20,
    textAlign: 'center',
  },
  sectionTitle: {
    fontSize: 18,
    fontFamily: 'GolosText-Bold',
    color: '#000',
    marginTop: 20,
    marginBottom: 10,
  },
  text: {
    fontSize: 14,
    lineHeight: 22,
    color: '#333',
    marginBottom: 15,
    textAlign: 'justify',
  },
  footer: {
    marginTop: 30,
    marginBottom: 20,
    alignItems: 'center',
  },
  footerText: {
    fontSize: 12,
    color: '#666',
    fontStyle: 'italic',
  },
  bottomContainer: {
    paddingHorizontal: 20,
    paddingVertical: 15,
    borderTopWidth: 1,
    borderTopColor: '#E5E5E5',
  },
  agreeButton: {
    backgroundColor: '#28A7E8',
    paddingVertical: 15,
    borderRadius: 8,
    alignItems: 'center',
  },
  agreeButtonText: {
    color: '#fff',
    fontSize: 16,
    fontFamily: 'GolosText-Bold',
  },
});

export default TermsAndConditions;
