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 '../style.scss';
import {appConfig} from "../../../config/app";
import ListPackage from "./ListPackage";
import DetailPackage from "./DetailPackage";

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

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

  }

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

  getData = (object) => {
    this.setState({
      value: 2,
      packageData: object
    })
    this.packageStore.packageData = object;
    this.packageStore.packageId = object.id;
    // console.log(object);
  };

  toList = () => {
    this.setState({
      value: ''
    });
  };


  render() {

    return (
      <div className="animated fadeIn">
        {(this.state.value == 0) ?
          <ListPackage onClickNew={this.handleClickAddPackage} onClickView={this.getData}/> : ''}
        {(this.state.value == 2) ? <DetailPackage onClickBack={this.toList} packageData={this.state.packageData}/> : ''}
      </div>
    )
  }
}
