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,
  Tabs, Tab,
  Table,
  TableBody,
  TableHeader,
  TableHeaderColumn,
  TableRow,
  TableRowColumn,
} 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 WarningIcon from 'material-ui/svg-icons/alert/warning';

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

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

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

  handleFlightDetail = (key)=>{
    if(key == this.state.flight_detail){
      this.setState({
        flight_detail : 'x-0!',
        price_detail:'',
      })  
    }
    else if(this.state.flight_detail == null){
        this.setState({
        flight_detail : key,
        price_detail:'',
      })
    }
    else{
      
      this.setState({
        flight_detail : key,
        price_detail:'',
      })
    }
  };


  render() {
    const listData = [
      {
        'key' : 1,
        'image' : 'http://akuntiket.com/img/logo_railink.png',
        'desc' : {
          name: 'ARS (U2)',
          depature : {
            station:'MEDAN (MDN)',
            time : '03:30'
          },
          destination : {
            station:'KUALA NAMU (KLN)',
            time:'04:00' 
          },
          date : '22 Sep 2017',
          },
        seat: [
          {
            class: 'Executive Class (A)',
            adult: '100.000 IDR',
            child: '100.000 IDR',
            available: '130'
          },
        ]
      },
      {
        'key' : 2,
        'image' : 'http://akuntiket.com/img/logo_railink.png',
        'desc' : {
          name: 'ARS (U4)',
          depature : {
            station:'MEDAN (MDN)',
            time : '04:00'
          },
          destination : {
            station:'KUALA NAMU (KLN)',
            time:'04:30' 
          },
          date : '22 Sep 2017',
          },
        seat: [
          {
            class: 'Executive Class (A)',
            adult: '100.000 IDR',
            child: '100.000 IDR',
            available: '130'
          },
        ]
      },
      {
        'key' : 3,
        'image' : 'http://akuntiket.com/img/logo_railink.png',
        'desc' : {
          name: 'ARS (U6)',
          depature : {
            station:'MEDAN (MDN)',
            time : '04:30'
          },
          destination : {
            station:'KUALA NAMU (KLN)',
            time:'05:00' 
          },
          date : '22 Sep 2017',
          },
        seat: [
          {
            class: 'Executive Class (A)',
            adult: '100.000 IDR',
            child: '100.000 IDR',
            available: '130'
          },
        ]
      },
      {
        'key' : 4,
        'image' : 'http://akuntiket.com/img/logo_railink.pngg',
        'desc' : {
          name: 'ARS (U8)',
          depature : {
            station:'MEDAN (MDN)',
            time : '05:00'
          },
          destination : {
            station:'KUALA NAMU (KLN)',
            time:'05:30' 
          },
          date : '22 Sep 2017',
          },
        seat: [
          {
            class: 'Executive Class (A)',
            adult: '100.000 IDR',
            child: '100.000 IDR',
            available: '130'
          },
        ]
      },
      {
        'key' : 5,
        'image' : 'http://akuntiket.com/img/logo_railink.png',
        'desc' : {
          name: 'ARS (U10)',
          depature : {
            station:'MEDAN (MDN)',
            time : '05:30'
          },
          destination : {
            station:'KUALA NAMU (KLN)',
            time:'06:00' 
          },
          date : '22 Sep 2017',
          },
        seat: [
          {
            class: 'Executive Class (A)',
            adult: '100.000 IDR',
            child: '100.000 IDR',
            available: '130'
          },
        ]
      },
      {
        'key' : 6,
        'image' : 'http://akuntiket.com/img/logo_railink.png',
        'desc' : {
          name: 'ARS (U12)',
          depature : {
            station:'MEDAN (MDN)',
            time : '06:00'
          },
          destination : {
            station:'KUALA NAMU (KLN)',
            time:'06:30' 
          },
          date : '22 Sep 2017',
          },
        seat: [
          {
            class: 'Executive Class (A)',
            adult: '100.000 IDR',
            child: '100.000 IDR',
            available: '130'
          },
        ]
      },
    ]

    return (
      <Card className="animated fadeIn">
        <Toolbar className="toolbarCard" style={{backgroundColor: '#fff'}}>
          <ToolbarGroup>
                <IconButton
                  iconClassName="material-icons"
                  tooltip="Back"
                  style={{marginLeft:'0px'}}
                  onClick={this.props.onClickBack}
                >
                  arrow_back
                </IconButton>
            <ToolbarTitle style={{fontSize: 14, fontWeight: 500, color: '#32325d'}} text="Find Schedule"/>
          </ToolbarGroup>
        </Toolbar>
        <Divider/>
        <div className="col m3" style={{padding:'10px'}}>
          <img src="http://akuntiket.com/img/logo_railink.png" className="img-responsive" />
        </div>
        <div className="col m9">
        <div style={{padding: '14px'}}>
          <div className="row">
            <p style={{marginLeft: '25px', marginTop: '5px'}}>
            MEDAN (MDN) - KUALA NAMU (KLN)
            </p>
          </div>
          <div className="row" style={{marginTop: '10px', marginBottom: '-10px'}}>
            <div className="col m6">
              <div className="row">
                <div className="col m6">
                  <div className="row">
                    <div className="col m2">
                      <FontIcon className="material-icons" style={{color:'#B7B7B7'}}>access_time</FontIcon>
                    </div>
                    <div className="col m10">
                      <p style={{marginTop: '5px'}}>
                        22 Sep 2017
                      </p>
                    </div>
                  </div>
                </div>
                <div className="col m6">
                  <div className="row">
                    <div className="col m2">
                      <FontIcon className="material-icons" style={{color:'#B7B7B7'}}>people_outline</FontIcon>
                    </div>
                    <div className="col m10">
                      <p style={{marginTop: '5px'}}>
                        Adult : 1 |  Child: 0
                      </p>
                    </div>
                  </div>
                </div>
                <div className="col m6"></div>
              </div>
            </div>
          </div>
        </div>
        </div>
        <Divider />
        <div>
            {(listData.slice(0, listData.length)).map(item => {
            return (
            <div>
            <div style={{padding: '20px 14px 14px 27px'}}>
                <div className="row">
                  <div className="col s12 l12">
                    <p className="detail-flight-top">{item.desc.name.toUpperCase()}</p>
                  </div>
                </div>
                <div className="row">
                  <div className="col s12 l2">
                    <p className="detail-flight-top">{item.desc.depature.time}</p>
                    <p>{item.desc.depature.station}</p>
                  </div>
                  <div className="col s12 l1">
                    <p><FontIcon className="material-icons" style={{color:'#B7B7B7', lineHeight: '50px'}}>directions_railway</FontIcon><FontIcon className="material-icons" style={{color:'#B7B7B7', lineHeight: '50px'}}>arrow_forward</FontIcon></p>
                  </div>
                  <div className="col s12 l2">
                    <p className="detail-flight-top">{item.desc.destination.time}</p>
                    <p>{item.desc.destination.station}</p>
                  </div>
                  <div className="col s12 l2">
                    <p className="detail-flight-top">30 minute</p>
                    <p>Direct</p>
                  </div>
                  <div className="col s12 l3">
                  {(this.state.flight_detail !== item.key) ? <RaisedButton primary={true} label="Detail" onClick={()=>this.handleFlightDetail(item.key)} style={{width: '100px'}}/> : <RaisedButton primary={false} label="Detail" onClick={()=>this.handleFlightDetail(item.key)} style={{marginRight:'10px'}}/>}
                  </div>
                </div>
                <div className="row">
                  <Card expanded={this.state.expanded} onExpandChange={this.handleFlightDetail} style={{boxShadow : 'none'}}>
                    <CardText expandable={this.state.flight_detail !== item.key} className="detail-flight">
                          <Table>
                            <TableHeader adjustForCheckbox={false} displaySelectAll={false}>
                              <TableRow>
                                <TableHeaderColumn><p style={{textAlign: 'center'}}>Class</p></TableHeaderColumn>
                                <TableHeaderColumn><p style={{textAlign: 'center'}}>Adult Price</p></TableHeaderColumn>
                                <TableHeaderColumn><p style={{textAlign: 'center'}}>Child Price</p></TableHeaderColumn>
                                <TableHeaderColumn><p style={{textAlign: 'center'}}>Available</p></TableHeaderColumn>
                                <TableHeaderColumn><p style={{textAlign: 'center'}}>Action</p></TableHeaderColumn>
                              </TableRow>
                            </TableHeader>
                            <TableBody displayRowCheckbox={false} showRowHover={true}>
                            {(item.seat.slice(0, listData.length)).map(items => {
                              return (
                                    <TableRow>
                                      <TableRowColumn><p style={{textAlign: 'center'}}>{items.class}</p></TableRowColumn>
                                      <TableRowColumn><p style={{textAlign: 'center'}}>{items.adult}</p></TableRowColumn>
                                      <TableRowColumn><p style={{textAlign: 'center'}}>{items.child}</p></TableRowColumn>
                                      <TableRowColumn><p style={{textAlign: 'center'}}>{items.available}</p></TableRowColumn>
                                      <TableRowColumn>{(items.available > 0) ? <div style={{textAlign: 'center'}}><RaisedButton primary={true} onClick={this.props.onClickBuy} label="Choose" /></div> : <p style={{color: '#F44336', textAlign: 'center'}}>N/A</p>}</TableRowColumn>
                                    </TableRow>
                              );
                            })}
                            </TableBody>
                          </Table>
                    </CardText>
                  </Card>
                </div>
            </div>
            <Divider/>
          </div>
          )
          })}
        </div>
      </Card>
    )
  }
}
