//Programa nacional de convivivencia escolar

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

const ProtocolosZacPDF = ({onClose}) => {
  const RecursoPDF = {uri: 'https://firebasestorage.googleapis.com/v0/b/eyesapp-3638d.appspot.com/o/Protocolo%20Zacatecas..pdf?alt=media&token=e1639dcd-054d-4a02-a5fc-f9a905675ddc', cache: true};



  const controlDescargaPDF = () => {
    Linking.openURL('https://firebasestorage.googleapis.com/v0/b/eyesapp-3638d.appspot.com/o/Protocolo%20Zacatecas..pdf?alt=media&token=e1639dcd-054d-4a02-a5fc-f9a905675ddc')
      .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.btnCerrar} 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: {
    position: "relative",
    height: Dimensions.get("window").height,
    zIndex: 9999,
    right:-35,
    top:18
  },
  PdfUno: {
    flex: 1,
    width: Dimensions.get("window").width,
    height: Dimensions.get("window").height,
    right: 20,
  },
  btnCerrar: {
    position: 'absolute',
    top: 20,
    left: 0,
    padding: 10,
    backgroundColor: "#62acac",
    borderRadius: 5,
  },
  btnDescargarPDF: {
    position: 'absolute',
    top: 20,
    right: 60,
    padding: 10,
    backgroundColor: "#62acac",
    borderRadius: 5,
  },
  TextModal: {
    color: 'white',
    textAlign: 'center',
  },
});

export default ProtocolosZacPDF;
