import React from 'react';
import Header from '../../components/CommonComponent/HeaderComponent/HeaderComponent';
import LeftContainer from '../LeftContainer/LeftContainer';
import RightContainer from '../RightContainer/RightContainer';
import ReplenishHomePage from '../../components/ReplenishComponent/ReplenishHomePage/ReplenishHomePage'
import ReplenishSkuPage from '../../components/ReplenishComponent/ReplenishSkuPage/ReplenishSkuPage'
import ReplenishScanPage from '../../components/ReplenishComponent/ReplenishScanPage/ReplenishScanPage'
import WeChatUtil from '../../util/WeChatUtil'
require('./index.css');

const replenishPageIndex = {
    1 : 'getHomePage',
    2 : 'getSkuPage',
    3 : 'getScanPage',
}

export default class ReplenishContainer extends React.Component{
    constructor(props){
        super(props);
        this.beginScan = this.beginScan.bind(this)
        this.goBack = this.goBack.bind(this)
        this.state = {
            pageType : 1,
            showScanQrcode : false
        }

    }

    componentWillMount(){

    }

    componentWillReceiveProps(nextProps){
    }

    getPage(type){
        return (props)=>this[replenishPageIndex[type]](props)
    }

    beginScan(){
        this.setState({
            pageType : 3,
            showScanQrcode : true,
        })
    }


    getHomePage(props){
        let {headerInfo} = props;
        return(
            <ReplenishHomePage headerInfo={headerInfo}
                               scanQrcode={()=>this.beginScan()}
            />
        )
    }

    getSkuPage(props){
        return <ReplenishSkuPage {...props} beginScan={this.beginScan}/>
    }

    getScanPage(props){
        return <ReplenishScanPage {...props}/>
    }

    goBack(type){
        this.setState({
            showScanQrcode : false,
            pageType : type
        })
    }




    render(){
        let props = this.props;
        let {pageType}=this.state;
        pageType = WeChatUtil.getUrlParam().pageType?WeChatUtil.getUrlParam().pageType:pageType;
        return (
            <div className={"replenishContainer page"}>
                {
                    this.state.showScanQrcode ?
                        <ReplenishScanPage {...props} goBack={this.goBack}/> :
                        <div style={{width:'100%',height:'100%'}}>
                            {
                                props.headerInfo && props.headerInfo.storeInfo ?
                                    <Header headerInfo={props.headerInfo}/> : null
                            }

                            <LeftContainer leftInfo={props.headerInfo}/>
                            <RightContainer>
                                {this.getPage(pageType)(props)}
                            </RightContainer>
                        </div>
                }

            </div>
        )
    }
}