import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { View, Image, StyleSheet, Text, Button, ScrollView } from 'react-native';
import data from './transfer.json' 



var information = ""

function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
         information = this.responseText;
  }
  };
  xhttp.open("GET", "https://api.census.gov/data/2020/acs/acs5/profile?get=group(DP02PR)&for=county:127&in=state:72", true);
  xhttp.send();
  
}

//change this to an external css file later
const styles = StyleSheet.create({
	
  buttons: {
	  flexDirection: 'row',
	  justifyContent: 'center',
	  marginTop: 30,
	  marginBottom: 30,
	  margin: "4px",
	  borderColor: "grey",
  },
  container: {
    flexDirection: 'column',
	justifyContent: 'center',
    backgroundColor: 'black',
    alignItems: 'center',
    justifyContent: 'center',
	marginTop: 20,
	marginBottom: 500
  },
  containerbackground:{
	
    backgroundColor: '#063970',
	padding: "40px"
  },
  intro: {
	  fontWeight: "bold",
      color:"#beb2c8",
	  fontSize: 30,
	 
  },
  sub: {
      color:"#D7D6D6",
	  
	  fontSize: 20,
  },
  scrollView:{
	  marginHorizontal: 20
  }
});

//default button press

const handlePress = () => false


//data parsing goes here

function importJSON() {
	var stuff = JSON.stringify(data)
	return stuff
}

//states

let states = {
	
		welcome:
		  

		<View style = {styles.containerbackground}>
		  <View style = {styles.container}>
		  
		  
			<Text style={styles.intro}>BIENVENIDO!!!!</Text>
		
			<Text style={styles.sub}>Aqui podra mantenerse al tanto con las 
			ultimas noticias relacionadas al censo</Text>
			 
			<Image source={require('./testimg.gif')} />
			
		  </View>
		</View>,
		  
		dataView:
		
		<View style = {styles.containerbackground}>
		<ScrollView style={styles.scrollView}>
		 <View style = {styles.container}>
		  
		  
			<Text style={styles.intro}>DATADATADATADATADATA</Text>
		
			<Text style={styles.sub}>{information}</Text>
			 
			<Image source={require('./testimg.gif')} />
			
		 </View>
		</ScrollView></View>,


		newsView:
		<View style = {styles.containerbackground}>
		<ScrollView style={styles.scrollView}>
		 <View style = {styles.container}>
		  
		  
			<Text style={styles.intro}>Noticias</Text>
			 
			<Image source={require('./testimg.gif')} />
			
		 </View>
		</ScrollView></View>

		
	}




class App extends React.Component {

//current state
state = {current: states.welcome}

//state changing functions
setHome = () => this.setState({ current: states.welcome })
setData = () => {loadDoc(); this.setState({ current: states.dataView })}
setNews = () => this.setState({ current: states.newsView })
	
	
	//render app
   render() {
      return (
	  <View>
		
			<View style = {styles.containerbackground}>
				<View style = {styles.container}>
					<Text style={styles.sub}> Navegador</Text>
						<View style = {styles.buttons}>
			 		 			<Button
								onPress = {this.setNews}
				 				title = "Noticias"
				 				color = "blue"
			  					/>
			  
			  					<Button
								 onPress = {this.setData}
								 title = "Datos"
								 color = "black"
			  					/>

						</View>
		  				{this.state.current}
						</View>
			</View>
		</View>
      );
   }
}


export default App
