import Button from '@/components/Button';
import { InformationContext } from '@/contexts/InformationContext';
import { InformationContext2 } from '@/contexts/InformationContext2';
import React, { useContext } from 'react';
import { View, Modal, Dimensions, Image } from 'react-native';
import AppText from '../AppText';
import { getIconPath } from '@/constants/constants';

interface PopupProps {
  isVisible: boolean;
  isPopUpone: boolean;
  onClose: () => void;
}

const Popup: React.FC<PopupProps> = ({ isVisible, isPopUpone, onClose }) => {
  const screenHeight = Dimensions.get('window').height;
  const popupHeight = screenHeight * 0.8;

  const { infoText } = useContext(InformationContext);
  const { infoText2 } = useContext(InformationContext2);

  // 🔥 Maintenant infoText = nom de fichier image
  const imageName = isPopUpone ? infoText : infoText2;

  return (
    <Modal visible={isVisible} transparent>
      <View
        style={{
          flex: 1,
          justifyContent: 'center',
          alignItems: 'center',
          backgroundColor: 'rgba(0, 0, 0, 0.5)',
        }}
      >
        <View
          style={{
            height: popupHeight,
            width: '80%',
            backgroundColor: 'white',
            borderRadius: 10,
            padding: 16,
            justifyContent: 'flex-start',
            alignItems: 'center',
          }}
        >
          {/* 🔹 Texte du haut */}
          <AppText
            text={'Version du 05 Juin 2026'}
            style={{ fontSize: 14, fontWeight: 'bold', marginBottom: 20 }}
          />

          {/* 🔹 Image en dessous */}
          {imageName ? (
            <Image
              source={getIconPath(imageName)}
              style={{
                width: '100%',
                height: '70%',
                resizeMode: 'contain',
                marginBottom: 20,
              }}
            />
          ) : null}

          {/* 🔹 Bouton */}
          <Button text={'Lu'} isSelected onPress={onClose} />
        </View>
      </View>
    </Modal>
  );
};

export default Popup;
