/*
 * Creater:     柿子
 * CreateDate:  2023/07/05
 * Describe：   Iframe外链界面弹窗展示
 * */
import React, { Component } from 'react';
import { Modal } from 'antd';

class IframeModal extends Component {
  constructor(props) {
    super(props);
    this.state = {
      visible: false,
      url: '', // 外链地址
    };
  }

  componentDidMount() {
    this.props.onRef && this.props.onRef(this);
  }

  // 修改弹窗状态
  modifyVisible = (visible, url = '') => {
    this.setState({ visible, url })
  }

  render() {
    let { title, width, height, maskClosable = false, bodyPadding, topResetFlag } = this.props;
    let { visible, url } = this.state;
    return (
      <Modal
        visible={visible}
        footer={null}
        width={width || '80vw'}
        title={title && title !== 'none' && title !== 'hide' ? title : ''}
        bodyStyle={{ padding: bodyPadding ? bodyPadding : 0 }}
        className={topResetFlag === 'Y' ? 'common-modal-top-60' : ''}
        closable={!!(title && title !== 'none' && title !== 'hide')} // 不存在描述的清空不展示xx关闭按钮，但是点击模板可以关闭
        maskClosable={title && title !== 'none' && title !== 'hide' ? maskClosable : true}
        onCancel={() => this.modifyVisible(false)}
      >
        <iframe
          style={{ width: '100%', height: height || '70vh' }}
          allowFullScreen={true}
          scrolling={'no'}
          src={url}
        />
      </Modal>
    )
  }
};

export default IframeModal;