import { WeaTools,WeaLocaleProvider,WeaDialog } from 'ecCom';
import isEmpty from 'lodash/isEmpty';
import ReactDOM from 'react-dom';
import {Button} from 'antd';

const getLabel = WeaLocaleProvider.getLabel;

(function () {
    WeaTools.callApi('/api/doc/console/multi/openWin/getOpenDocs', 'GET', {}).then(result => {
        if(result.api_status){
            const docs = result.docs || [];
            Array.isArray(docs) && !isEmpty(docs) && docs.forEach(v => {
                const div = document.createElement('div');
                document.body.appendChild(div);
                ReactDOM.render(
                <WeaDialog
                icon="icon-coms-doc"
                iconBgcolor="#f14a2d"
                style={{ width: v.pop_width+"px",height: v.pop_hight+"px"}}
                maskClosable={false}
                visible={true}
                parentClassName={"docPropDialog_"+v.id}
                onCancel={() => {

                    const _ob = document.getElementsByClassName("docPropDialog_" + v.id);

                    if(_ob){
                        try {
                            _ob[0].remove();
                        } catch(Err){
                            try {
                                _ob[0].parentNode.removeNode(true);
                            }catch(e) {

                            }
                        }
                    }
                }}
            >
            <div style={{height: '100%'}}>
            <iframe
                key="iframe"
                id="mainiframe"
                src={v.link}
                frameBorder="0"
                style={{height: '100%', width: '100%'}}
            >
            </iframe>
                </div>
                </WeaDialog>

                    , div);
            })
        }
    });
})();