import React from "react";
import firebase from "firebase";
import { Component } from "react";
import { TouchableWithoutFeedback, ImageBackground, Text } from "react-native";
import { styles } from "../../config/styles";
import CustomButton from "../../components/CustomButton";

export default class Time extends Component{
  constructor(props){
    super(props);
    this.state = {
      Appointment : this.props.route.params.Appointment_Date,
    }
    this.time_assignment = this.time_assignment.bind(this);
  }


 time_assignment(desired_time, selectedTime){
   
  if(desired_time == 1){
    selectedTime = "8:00am-9:00am"
  }

  console.log(this.props.route.params)
  const user = firebase.auth().currentUser
  const uid = user.uid
  const month = this.state.Appointment.month
  const day = this.state.Appointment.day
  const _time_ = selectedTime
  firebase.firestore()
  .collection('APPOINTMENTS')
  .add({ 
    uid1: uid, 
    Month : month,
    Day: day,
    Time: _time_})

    this.props.navigation.navigate('Home')
 } 


render(){
  return(
  <TouchableWithoutFeedback style={styles.stdcontainer}>
    <ImageBackground style={styles.regcontainer} source={require('../../assets/yellow-white.jpg')}>
    <Text style={styles.stdcontainer}> Please select a time frame for the appointment</Text>
    <CustomButton marginTop={25} title="8:00am-9:00am" onPress={() => this.time_assignment(1,)}/>
    
    </ImageBackground>
  </TouchableWithoutFeedback>
    );
  }
}

