import React,{useState,useEffect,useRef} from 'react';
import Container from '../components/container';
import { useRoute } from '@react-navigation/native';
import { globalStyles,customStyles,GetPageTheme } from "../styles/Global";
import {StatusBar,Image,TextInput,View,Text,ScrollView,TouchableOpacity,Platform,PermissionsAndroid,FlatList, Alert, Animated} from 'react-native';
import { ReactReduxContext,connect,useSelector, useDispatch  } from 'react-redux';
import { mapStateToProps,mapDispatchToProps } from '../reducers/contextProvider';
import {notify} from '../components/notify';
import moment from 'moment';
import CustomCamera from '../components/Camera';

function CameraScreen(props) { 
    const route = useRoute();
  
    // get all theme styles acc to current theme set 
    const PageTheme=GetPageTheme(props.DarkMode,route.name);
    const customStyle=customStyles(props.DarkMode,route.name);
    
    const [processing, setProcessing] = useState(false);
    const [loaderTitle, setLoaderTitle] = useState('loading...');
    const [params, setParams] = useState({'cameraType':'back'});
    const [showCamera, setShowCamera] = useState(true);
    const [hasUnsavedChanges,setHasUnsavedChanges] = useState(false);

    const d1=new Date();
    const d2=moment(d1).format('MM/DD/YYYY');
    
  
    useEffect(() => {
        let params1=props.route.params? props.route.params:{};
        setParams(params1);
    }, []);

    function closeCamera(){
        console.log('closeCamera');
        // setShowCamera(false);
        props.navigation.goBack();
    }

    async function onImageCaptured(imgData){
        console.log('onImageCaptured');
        if(params.getImage!=null){
            await params.getImage(imgData);
        }
    }
  
    return ( 
    <Container {...props} pt={0} avoidSafeArea={(Platform.OS=='ios'?true:false)}>
        {/* {processing && <CustomLoader fullHeight={true} title={loaderTitle}/>} */}
        <CustomCamera cameraType={(params.cameraType!=null?params.cameraType:'back')} onImageCaptured={(imgData)=>{onImageCaptured(imgData)}} showCamera={showCamera} onHideCamera={()=>{closeCamera()}}/>   
    </Container>   
    ); 
}
  
  

export default connect(mapStateToProps, mapDispatchToProps)(CameraScreen);