//Directorio de autoridades

import React from 'react';
import { View, Text, StyleSheet, Dimensions, TouchableOpacity, Linking } from 'react-native';
import Pdf from 'react-native-pdf';

const DirectorioPDF = ({onClose}) => {
  const RecursoPDF = {uri: 'https://firebasestorage.googleapis.com/v0/b/eyesapp-3638d.appspot.com/o/DIRECTORIO%20DE%20AUTORIDADES%20DE%20PRIMER%20CONTACTO%20PARA%20LA%20ATENCI%C3%93N%20DE%20NI%C3%91AS.pdf?alt=media&token=2262b5db-e44d-43bd-ae44-08bbcda33d5a', cache: true};



  const controlDescargaPDF = () => {
    Linking.openURL('https://firebasestorage.googleapis.com/v0/b/eyesapp-3638d.appspot.com/o/DIRECTORIO%20DE%20AUTORIDADES%20DE%20PRIMER%20CONTACTO%20PARA%20LA%20ATENCI%C3%93N%20DE%20NI%C3%91AS.pdf?alt=media&token=2262b5db-e44d-43bd-ae44-08bbcda33d5a')
      .then(result => {
        console.log('Enlace abierto con éxito:', result);
      })
      .catch(error => {
        console.error('Error al abrir el enlace:', error);
      });
  };



  return (
    <View style={styles.Contenedor}>
      <Pdf
        trustAllCerts = {false}
        source={RecursoPDF}
        style={styles.PdfUno}
        onLoadComplete={(numberOfPages, filePath) => {
          console.log(`Número de páginas: ${numberOfPages}`);
        }}
      />
      <TouchableOpacity  style={styles.btnCerrarPDF} onPress={onClose}>
        <Text style={styles.TextModal}>Cerrar PDF</Text>
      </TouchableOpacity>

      <TouchableOpacity style={styles.btnDescargarPDF} onPress={controlDescargaPDF}>
        <Text style={styles.TextModal}>Descargar PDF</Text>
      </TouchableOpacity>
    </View>
  );
};

const styles = StyleSheet.create({
  Contenedor: {
    height: Dimensions.get("window").height,
    zIndex: 9999,
    right: "-7.5%",
    top:"-73%"
  },
  PdfUno: {
    flex: 1,
    width: Dimensions.get("window").width,
    height: Dimensions.get("window").height,
    right:20
  },
  btnCerrarPDF: {
    alignSelf: "center",
    padding: 10,
    backgroundColor: "#62acac",
    borderRadius: 5,
    top: "-93.5%",
    left: "-40%"
  },
  btnDescargarPDF: {
    padding: 10,
    backgroundColor: "#62acac",
    borderRadius: 5,
    alignSelf: "center",
    top: "-98.1%",
    left: "22%"

  },
  TextModal: {
    color: 'white',
    textAlign: 'center',
  },
});

export default DirectorioPDF;
