fix this code.
// components/PDFGenerator.js

import React, { useContext, useState } from 'react';
import {
  StyleSheet,
  View,
  Button,
  Alert,
  TouchableOpacity,
  Text,
  Platform,
} from 'react-native';
import * as Print from 'expo-print';
import * as FileSystem from 'expo-file-system';
import * as Sharing from 'expo-sharing'; // Import Sharing
import { MediaContext } from '../context/MediaContext';
import { Ionicons } from '@expo/vector-icons'; // For icons

const PDFGenerator = () => {
  const { media } = useContext(MediaContext);
  const [pdfUri, setPdfUri] = useState(null); // State to store PDF URI

  const generatePDF = async () => {
    // Create HTML content for PDF
    let mediaHtml = '';

    if (media.photo) {
      mediaHtml += `<h2>Captured Photo</h2><img src="${media.photo}" style="width:100%; height:auto;" />`;
    }

    if (media.video) {
      // Note: Embedding video in PDF is not widely supported
      mediaHtml += `<h2>Recorded Video</h2>
                    <p>Video recorded at: <a href="${media.video}">Download Video</a></p>`;
    }

    if (media.audio) {
      // Note: Embedding audio in PDF is not widely supported
      mediaHtml += `<h2>Recorded Voice</h2>
                    <p>Audio recorded at: <a href="${media.audio}">Download Audio</a></p>`;
    }

    const htmlContent = `
      <html>
        <head>
          <style>
            body { font-family: Arial, sans-serif; padding: 20px; }
            h1 { text-align: center; }
            img { max-width: 100%; height: auto; }
            a { color: blue; text-decoration: none; }
          </style>
        </head>
        <body>
          <h1>Consent Document</h1>
          <p>${legalText}</p>
          ${mediaHtml}
        </body>
      </html>
    `;

    try {
      // Generate PDF from HTML
      const { uri } = await Print.printToFileAsync({ html: htmlContent });
      console.log('PDF generated at:', uri);

      let destinationPath;

      if (Platform.OS === 'android') {
        if (FileSystem.downloadDirectory) {
          destinationPath = `${FileSystem.downloadDirectory}ConsentDocument_${Date.now()}.pdf`;
        } else {
          // Fallback to documentDirectory if downloadDirectory is undefined
          destinationPath = `${FileSystem.documentDirectory}ConsentDocument_${Date.now()}.pdf`;
          console.warn('Download Directory is undefined. Falling back to documentDirectory.');
        }
      } else {
        // For iOS, use documentDirectory
        destinationPath = `${FileSystem.documentDirectory}ConsentDocument_${Date.now()}.pdf`;
      }

      console.log('Destination Path:', destinationPath);

      // Verify if the destination directory exists or is writable
      const dirInfo = await FileSystem.getInfoAsync(
        Platform.OS === 'android' ? FileSystem.downloadDirectory : FileSystem.documentDirectory
      );

      if (!dirInfo.exists) {
        console.warn('Destination directory does not exist. Attempting to create it.');
        await FileSystem.makeDirectoryAsync(
          Platform.OS === 'android' ? FileSystem.downloadDirectory : FileSystem.documentDirectory,
          { intermediates: true }
        );
      }

      // Move the PDF to the desired location
      await FileSystem.moveAsync({
        from: uri,
        to: destinationPath,
      });

      // Update state with the new PDF URI
      setPdfUri(destinationPath);

      if (Platform.OS === 'android') {
        if (FileSystem.downloadDirectory) {
          Alert.alert(
            'Success',
            'PDF has been downloaded successfully and saved to your Downloads folder!'
          );
        } else {
          Alert.alert(
            'Success',
            'PDF has been saved to your Documents folder.'
          );
        }
      } else if (Platform.OS === 'ios') {
        if (await Sharing.isAvailableAsync()) {
          await Sharing.shareAsync(destinationPath);
        } else {
          Alert.alert(
            'Success',
            'PDF has been saved to your Documents folder.'
          );
        }
      }
    } catch (error) {
      Alert.alert('Error', 'Failed to generate PDF: ' + error.message);
      console.error('Error generating PDF:', error);
    }
  };

  const openDownloadLocation = async () => {
    if (!pdfUri) {
      Alert.alert('No PDF', 'Please generate the PDF first.');
      return;
    }

    try {
      if (Platform.OS === 'android') {
        if (FileSystem.downloadDirectory) {
          // Inform the user to check the Downloads folder
          Alert.alert(
            'Download Complete',
            'The PDF has been saved to your Downloads folder. You can access it using any file manager app.'
          );
        } else {
          Alert.alert(
            'Download Complete',
            'The PDF has been saved to your Documents folder. You can access it using any file manager app.'
          );
        }
      } else if (Platform.OS === 'ios') {
        // Use the sharing sheet to open the PDF
        if (await Sharing.isAvailableAsync()) {
          await Sharing.shareAsync(pdfUri);
        } else {
          Alert.alert(
            'Sharing Not Available',
            'Cannot share the PDF on this device.'
          );
        }
      } else {
        Alert.alert('Unsupported Platform', 'This feature is not supported on your device.');
      }
    } catch (error) {
      Alert.alert('Error', 'Cannot open the PDF. Please try again.');
      console.error('Error opening PDF:', error);
    }
  };

  return (
    <View style={styles.container}>
      <View style={styles.section}>
        <Button title="Download PDF" onPress={generatePDF} />
      </View>
      {pdfUri && (
        <TouchableOpacity style={styles.iconContainer} onPress={openDownloadLocation}>
          <Ionicons name="folder-open" size={40} color="#4CAF50" />
          <Text style={styles.iconText}>Open Download Location</Text>
        </TouchableOpacity>
      )}
    </View>
  );
};

// --- Legal Text (Should be imported or passed as a prop) ---
const legalText = `YOUR LEGAL TEXT GOES HERE...

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vel turpis at quam aliquet lobortis. Integer sit amet ligula vitae justo commodo fermentum. Donec vitae massa a augue blandit porttitor. Proin id purus nec justo mollis finibus sit amet at justo. Mauris ac sem vitae nisl interdum interdum.`;

const styles = StyleSheet.create({
  container: {
    padding: 20,
  },
  section: {
    marginBottom: 30,
    backgroundColor: '#ffffff',
    padding: 15,
    borderRadius: 10,
    elevation: 2, // For Android
    shadowColor: '#000', // For iOS
    shadowOffset: { width: 0, height: 2 }, // For iOS
    shadowOpacity: 0.25, // For iOS
    shadowRadius: 3.84, // For iOS
    alignItems: 'center',
  },
  iconContainer: {
    flexDirection: 'row',
    alignItems: 'center',
    marginTop: 10,
    padding: 10,
    backgroundColor: '#e0f7fa',
    borderRadius: 10,
  },
  iconText: {
    marginLeft: 10,
    fontSize: 16,
    color: '#00796b',
  },
});

export default PDFGenerator;
 LOG  PDF generated at: file:///data/user/0/host.exp.exponent/cache/Print/903592f1-2783-4b3c-910e-1cdaad3aead3.pdf
 WARN  Download Directory is undefined. Falling back to documentDirectory.
 LOG  Destination Path: file:///data/user/0/host.exp.exponent/files/ConsentDocument_1728593151655.pdf
 ERROR  Error generating PDF: [Error: Call to function 'ExponentFileSystem.getInfoAsync' has been rejected.
→ Caused by: The 1st argument cannot be cast to type kotlin.String (received null)
→ Caused by: Cannot assigned null to not nullable type.]