"use strict";
import {util} from "../../util/util.js";
import {httpUtil} from "../../util/httpUtil.js";
import {fullMap} from "../../fullMap.js";
import {khcToastr} from "../alert/khcToastr.js";
import {config} from "../../config.js";

class openLink{
    constructor(data) {
        this.eleID = util.getUUID();
        this.objID = util.getUUID() + 'div';
        this.parentObjID = data.parentObjID;
        this.code=data.openLinkCode.code;
        this.openLinkCode=data.openLinkCode;
        this.openURL = this.code.openURL;
        this.componentName = this.code.componentName;
    }
    init(){
        return new Promise((resolve, reject) => {
            let that=this;
            that.componentMap = new Map();//存储组件信息
            // 检查是否成功获取了元素
            let htmlTemplate=`
                    <div class="container d-flex justify-content-center align-items-center" style="height: 100vh;">
                        <div class="text-center p-5 bg-white shadow rounded">
                            <h2 class="mb-4">${this.componentName} - 已在新窗口打开</h2>
                            <p class="lead">如需再次访问，请点击下方按钮：</p>
                            <a id="openWindowBtn" href="${that.openURL}" target="_blank" class="btn btn-primary btn-lg mt-3">点击这里重新打开</a>
                            
                            <!-- 提示窗口被拦截 -->
                            <div class="alert alert-warning mt-4" role="alert">
                                <strong>注意！</strong> 如果新窗口未能打开，可能是浏览器拦截了弹出窗口。请检查浏览器的弹出窗口设置，或者点击上面按钮重新尝试。
                            </div>
                        </div>
                    </div>`;
            document.getElementById(that.parentObjID).insertAdjacentHTML("beforeEnd", htmlTemplate);
            window.open(that.openURL)
            resolve();
        })
    }
    render(){
        let that=this;
        that.init().then(()=>{
        })
    }
}
export {openLink}