import React,{Component} from 'react';
import {windowEventHandler,getWindowInnerHeight} from '@utils/tools';
import {connect} from 'react-redux';
import {pushPage} from '@utils/config';
import store from '@store';

class PushEmbed extends Component{
  constructor(props){
    super(props);
    this.state={
      height:100,
      width:'100%',
      hashNum:0
    }
  }
  componentDidMount() {
    const height = getWindowInnerHeight() - 119;
    this.setState({height:height});
    windowEventHandler('resize', ()=>{
        const height = getWindowInnerHeight() - 119;
        this.setState({height:height});
    });
  }
  componentWillReceiveProps(next){
    if(next.update!=this.props.update){
      this.setState({
        hashNum:Math.random()
      });
    }
  }
  render(){

    const {width,height,hashNum}=this.state;
    const {mrId} = this.props;
    let baseList = store.getState();
    console.log(1111111111111111);
    // console.log(baseList,'baseList');
    const url = pushPage+"?mrId="+mrId+"&plan=1&data="+hashNum;
    return <iframe id='embedPage' width={width} height={height} src={url} frameborder="0"></iframe>;
  }
}

function mapStateToProps(state){
  const {mrId,update} = state.print.mrInfo;
  //console.log(state);
  return {mrId,update};
};

const PushEmbedContainer = connect(
  mapStateToProps
)(PushEmbed);

export default PushEmbedContainer;