import { View, Text, Image,ScrollView} from 'react-native'
import React,{useState,useEffect} from 'react'
import Container from '../components/container';
import { useRoute } from '@react-navigation/native';
import { globalStyles,customStyles,GetPageTheme } from "../styles/Global";
import DrawerHeader from '../components/drawerHeader';
import CustomLoader from '../components/CustomLoader';
import LinearGradient from 'react-native-linear-gradient';
import {WebView} from 'react-native-webview'  

// 

import { mapStateToProps,mapDispatchToProps } from '../reducers/contextProvider';
import {connect} from 'react-redux'
import CustomHeader from '../components/customHeader';

function Bannerdetail(props) {
    const route = useRoute();
   
    const [currentItem, setcurrentItem] = useState({});
    
    const PageTheme=GetPageTheme(props.DarkMode,route.name);
    
  const customStyle=customStyles(props.DarkMode,route.name);
  let showwebview=false;


  useEffect(() => { 
    let params = props.route.params !=null?props.route.params:{};
    console.log("params",params);
    let currentitem1 = params.imagedesc!=null?params.imagedesc:{};
    console.log('onrender bannaer ',currentitem1);
    // let type='';
    let ext = currentitem1.NoticeLink_FullPage.split('.').pop();
    console.log('ext',ext)
  
     if(ext=='html'){
      showwebview=true;
          
    }
     else{
      
      showwebview=false;
    
     }
     setcurrentItem(currentitem1)
   // 
  }, []);
 
  return (
    <Container {...props} pt={0} avoidSafeArea={(Platform.OS=='ios'?true:false)}>
      
      <CustomHeader {...props} title={'Banner Detail'}/>

    <LinearGradient colors={[PageTheme.$gradient1,PageTheme.$primary_color]} start={{ x: 0, y: 0 }} end={{ x: 1, y: 0 }} style={customStyle.roundScrollWrapper}>
    
    <View style={customStyle.noticeboard_customstylewrapper}>
    <ScrollView contentContainerStyle = {{width:'100%', flex:1}}>
      {
         !showwebview &&
    <WebView
    style= {{height:'97%', width:'95%', borderRadius:20, marginLeft:10, marginTop:10}}source = {{uri:currentItem.NoticeLink_FullPage}}
    />
      }


    </ScrollView>
    </View>
    
  </LinearGradient>
  </Container>
  )
}
export default connect(mapStateToProps, mapDispatchToProps)(Bannerdetail)