import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  TextInput,
  View,
  ListView,
  Navigator,
  Image,
  TouchableHighlight,
  AsyncStorage,
  AlertIOS
} from 'react-native';

const styles = require('./style.js')
const REQUEST_URL ='http://localhost:3000/session/login'


class Login extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }
  componentDidMount() {
        AsyncStorage.getItem("userID").then((value) => {
          console.log('current.val '+ value);
            this.setState({"userID": value});
        }).done();
    }
  render() {
    return (
    <Image source={require('./Resources/0.jpg')} style={styles.bImage}>
      <View style={styles.topMargin}></View>
        <View style={styles.container}>
          <View style={styles.outterMargin}>
          </View>
            <View style={styles.content}>
        <Text style={styles.text}>
          Login
        </Text>
        <TextInput
          placeholder="Username"
          style={styles.input}
          value={this.state.username}
          onChangeText={(text) => this.setState({username: text})}
        />
        {
          //secureTextEntry={true} add this line on production
      }
        <TextInput
          placeholder="Password"
          style={styles.input}
          secureTextEntry={true}
          value={this.state.password}
          onChangeText={(text) => this.setState({password: text})}
        />
        <TouchableHighlight
          style={styles.button}
          onPress={this.loginPress.bind(this)}>
          <Text style={styles.buttonText}>
            Login
          </Text>
        </TouchableHighlight>

        </View>
      <View style={styles.outterMargin}>
    </View>
  </View>
  </Image>

    );
  }
  loginPress(){
    fetch(REQUEST_URL, {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        username: this.state.username,
        password: this.state.password,
      })
    })
    .then((response) => response.json())
      .then((responseData) => {
        console.log(responseData)
        if (responseData.success != false){
          this.makeSession(responseData)
        } else {
          AlertIOS.alert(
           'Something went wrong!'
          );
        }
      })
      .done();
    console.log(this.state.username);
  }

  makeSession(userID){
    console.log('state'+ this.state.userID);
    AsyncStorage.setItem("userID", String(userID));
    console.log('new-state'+ this.state.userID);
    //this.props.navigator.popToTop();
      // AsyncStorage.getItem("userID").then((value) => {
      //         this.setState({"userID": value});
      // }).done();
  }
}


module.exports = Login;

@@ -208,17 +208,50 @@
 ative';%0A
+import MapScene from './MapScene'
 %0A
-
 const st
@@ -337,16 +337,53 @@
 login'%0A%0A
+import MainScene from './MainScene';%0A
 %0Aclass L
@@ -470,15 +470,38 @@
  = %7B
+%0A      userID: 0,%0A    
 %7D;%0A  %7D%0A
+%0A
   co
@@ -520,20 +520,16 @@
 unt() %7B%0A
-    
     Asyn
@@ -575,28 +575,24 @@
  =%3E %7B%0A      
-    
 console.log(
@@ -619,28 +619,24 @@
 e);%0A        
-   
- 
 this.setStat
@@ -634,32 +634,30 @@
 s.setState(%7B
-%22
 userID
-%22
 : value%7D);%0A 
@@ -659,20 +659,16 @@
 %7D);%0A    
-  
-  
 %7D).done(
@@ -670,22 +670,21 @@
 done();%0A
-  
   %7D%0A
+%0A
   render
@@ -1210,32 +1210,96 @@
 ername: text%7D)%7D%0A
+          autoCapitalize=%7B'none'%7D%0A          autoCorrect=%7Bfalse%7D%0A
         /%3E%0A     
@@ -1587,32 +1587,96 @@
 ssword: text%7D)%7D%0A
+          autoCapitalize=%7B'none'%7D%0A          autoCorrect=%7Bfalse%7D%0A
         /%3E%0A     
@@ -2449,38 +2449,274 @@
     
-this.makeSession(responseData)
+//Login successfully%0A          this.props.navigator.push(%7B%0A            title: 'Puppy Playdate',%0A            component: MapScene,%0A            leftButtonTitle: ' '%0A          %7D)%0A          this.setState(%7B%0A            username: '',%0A            password: ''%0A          %7D);%0A
 %0A   

Add import statements for MapScene and MainScene; define userID in state; fix indentation for componentDidMount(); fix autoCapitalize to 'none' with quotes; add navigator push to MapScene after successful login