import React from 'react';
import {observer, inject} from 'mobx-react';
import bind from 'bind-decorator';
import {
  Card,
  CardActions,
  CardHeader,
  CardMedia,
  CardTitle,
  AutoComplete,
  CardText,
  FlatButton,
  Divider,
  RaisedButton,
  Toolbar,
  DatePicker,
  FontIcon,
  SelectField,
  MenuItem,
  ToolbarGroup,
  FloatingActionButton,
  ToolbarSeparator,
  IconButton,
  ToolbarTitle,
  RadioButton, RadioButtonGroup, DropDownMenu,
  Tabs, Tab,
} from 'material-ui';
import {withRouter} from 'react-router';
import {BrowserRouter as Router, Route} from 'react-router-dom';
import StarBorder from 'material-ui/svg-icons/toggle/star-border';
import ContentAdd from 'material-ui/svg-icons/content/add';
import ListTrain from './ListTrain';
import FormTrain from './FormTrain';
import FormTrainCustomers from './FormTrainCustomers';
import TrainConfirmation from './TrainConfirmation';
import FormTrainSeat from './FormTrainSeat';
import SnackbarMessage from '../SnackbarMessage';

import '../style.scss';
import {appConfig} from "../../../config/app";

@inject('appstate')
@observer
export default class Train extends React.Component {
  constructor(props) {
    super(props);
    this.props = props;
    this.state = {
      value: 0,
      openSnackbar: false
    };
    this.defaultState = Object.assign({}, this.state);
    this.http = props.appstate.http;
    this.authStore = props.appstate.auth;
  }

  componentDidMount() {
    console.log('Profile loaded!');

  }

  handleClickFind = () => {
    this.setState({
      value: 1
    })
  };

  handleClickBack = () => {
    this.setState({
      value: 0
    })
  };

  handleClickConfirmation = () => {
    this.setState({
      value: 2
    })
  };

  handleClickBackConfirmation = () => {
    this.setState({
      value: 3
    })
  };

  handleClickConfirmCustomers = () => {
    this.setState({
      value: 3
    })
  };

  handleBackConfirmCustomers = () => {
    this.setState({
      value: 1
    })
  };

  handleBackFormSeat = () => {
    this.setState({
      value: 2
    })
  };

  handleClickFormSeat = () => {
    this.setState({
      value: 4
    })
  };

  handleCloseSnackbar = () => {
    this.setState({
      openSnackbar: false
    })
  };

  handleBookedSeat = () => {
    this.setState({
      value: 0,
      openSnackbar: true,
    })
  }

  render() {
    return (
      <div className="row">
        <div className="col s12">
          {(this.state.value == 0) ? <FormTrain onClickFind={this.handleClickFind}/> : ''}
          {(this.state.value == 1) ?
            <ListTrain onClickBack={this.handleClickBack} onClickBuy={this.handleClickConfirmation}/> : ''}
          {(this.state.value == 2) ? <FormTrainCustomers onClickBack={this.handleBackConfirmCustomers}
                                                         onConfirm={this.handleClickConfirmCustomers}/> : ''}
          {(this.state.value == 3) ?
            <FormTrainSeat onClickBack={this.handleBackFormSeat} onConfirm={this.handleClickFormSeat}/> : ''}
          {(this.state.value == 4) ? <TrainConfirmation onClickBack={this.handleClickBackConfirmation}
                                                        onSuccessModal={this.handleBookedSeat}/> : ''}
          <SnackbarMessage message='Booking Succeed' open={this.state.openSnackbar}
                           closeSnackbar={this.handleCloseSnackbar}/>
        </div>
      </div>
    )
  }
}
