import React,{Component} from 'react';
import {windowEventHandler,getWindowInnerHeight} from '@utils/tools';
import {connect} from 'react-redux';
import $ from 'jquery';

class PushEmbed extends Component{
  constructor(props){
    super(props);
    this.state={
      height:100,
      width:'100%'
    }
  }
  componentDidMount() {
    const height = getWindowInnerHeight() - 190;
    this.setState({height:height});
    windowEventHandler('resize', ()=>{
        const height = getWindowInnerHeight() - 190;
        this.setState({height:height});
    });
  }
  componentWillReceiveProps(next){
    if(next.update!=this.props.update){
      //window.frames['embedPage'].contentWindow.location.reload();
      //console.log(window.frames['embedPage'].contentWindow)
    }
  }
  render(){
    const {width,height}=this.state;
    const {mrId} = this.props;
    const url = "http://192.168.2.241:5448/index.html?mrId="+mrId+"&plan=1";
    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;