import React, { Fragment, Component } from 'react';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import Shell from '@/baseComponent/Shell';
import ButtonDiy from '@/baseComponent/ButtonDiy';
import router from 'umi/router';
import { getToken, setToken } from '@/utils/authority';
import config from '@/config/config';
import { getOneStopConfig } from '@/webPublic/zyd_public/utils/utils';

const getUrlInfo = (param) => {
	let url = window.document.location.href.toString();
	let u = url.split('?');
	if (typeof u[1] == 'string') {
		u = u[1].split('&');
		let get = {};
		for (let i in u) {
			let j = u[i].split('=');
			get[j[0]] = decodeURIComponent(j[1]);
		}
		return get;
	} else {
		return {};
	}
};

export default class Detail extends Component {
	constructor(props) {
		super(props);
		const { state, pathname } = this.props.location;
		let id = '';
    id = getOneStopConfig(pathname);
    if (!id) {
			id = getUrlInfo()?.id;
		}

    let token = getUrlInfo().token;
    if(token){
      setToken(token);
    }
    if(id && getToken()){
      localStorage.setItem('wisdom-school-token', getToken());
    }
    this.state = {
			id,
		};
	}

	componentDidMount() {
		// window.addEventListener(
		// 	'message',
		// 	(event) => {
		// 		if (event.data && event.data.indexOf && event.data.indexOf('iframeDetailHeight') > -1) {
		// 			const height = Number(event.data.split('-')[1]);
		// 			document.getElementById('detailIframeId').height = height;
		// 		}
		// 	},
		// 	false,
		// );
	}

	showAll = () => {
		this.setState({
			showAll: true,
		});
	};

	render() {
		const { id, showAll } = this.state;
		const iframeUrl = `${config.gateWayPort}/portal/#/showSmartFormOnly?id=${id}&token=${getToken()}&isShow=true`;
		return (
			<PageHeaderWrapper title="">
				<Shell>
					<iframe
						src={iframeUrl}
						frameBorder={0}
						id="detailIframeId"
						name="applyIframe"
						marginWidth="0"
						marginHeight="0"
						onLoad={this.showAll}
						allowtransparency="yes"
						seamless
						scrolling={'no'}
						style={{
							width: '100%',
							overflowY: 'hidden',
							minHeight: '900px',
						}}
					/>
				</Shell>
			</PageHeaderWrapper>
		);
	}
}
