import React, {useEffect} from 'react';
import { Modal, Text, View, TouchableOpacity, StyleSheet } from 'react-native';

const AlertaEM = ({ visible, message, onClose }) => {
    useEffect(() => {
        if (visible) {
          const timer = setTimeout(() => {
            onClose();
          }, 300000);
    
          return () => clearTimeout(timer);
        }
      }, [visible, onClose]);
  return (
    <Modal
      transparent={true}
      animationType = "fade"
      visible={visible}
      onRequestClose={onClose}>
        
      <View style={styles.modalContainer}>
        <View style={styles.alertContainer}>
          <Text style={styles.alertText}>{message}</Text>
          <TouchableOpacity onPress={onClose} style={styles.closeButton}>
            <Text style={styles.closeButtonText}>Cerrar</Text>
          </TouchableOpacity>
        </View>
      </View>
    </Modal>
  );
};

const styles = StyleSheet.create({
  modalContainer: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'rgba(0, 0, 0, 0.0)',
  },
  alertContainer: {
    width: 300,
    padding: 20,
    backgroundColor: "#469594",
    borderRadius: 10,
    alignItems: 'center',
  },
  alertText: {
    fontSize: 18,
    marginBottom: 20,
    color: "#D9D9D9"
  },
  closeButton: {
    backgroundColor: "#6ea9a8",
    padding: 10,
    borderRadius: 5,
  },
  closeButtonText: {
    color: "#D9D9D9",
    fontSize: 16,
  },
});

export default AlertaEM;