const CozeBotSDK=function(){let e="https://stat2-ans.chaoxing.com",t="",n="",o=!1,i=!1,r="",a="",s=!1,d="",l="",c=!1;function u(){document.querySelectorAll(".closeComlilation, .slideUp").forEach((e=>{e.addEventListener("click",(()=>{document.getElementById("cozeBx").style="display:none"}))}))}return{init:function(m){!function(e){if(!e.appId)throw new Error("Invalid configuration: appId is required.");if(!e.botId)throw new Error("Invalid configuration: botId is required.");if(!e.rootElementId)throw new Error("Invalid configuration: rootElementId is required.");if(!e.upload)throw new Error("Invalid configuration: upload is required.")}(m),c=m.showKnowledgeSvg,t=m.appId,n=m.botId,o=m.bogColorNone,a=m.rootElementId,i=m.isFullScreen,r=m.skipUrl,s=m.upload,m.custom_variables&&""!==m.custom_variables.trim()&&(d=m.custom_variables),m.sourceInfo&&""!==m.sourceInfo.trim()&&(l=m.sourceInfo);let f=m.target;void 0!==f&&""!==f&&(console.log("target: "+f),e=f),function(){const t=document.createElement("link");t.type="text/css",t.rel="stylesheet",t.href=e+"/stat2/style/cozebot/style.css",document.head.appendChild(t)}(),function(o){if(document.querySelector(".cozeBx"))return;const i=document.createElement("div");i.className="cozeBx",i.id="cozeBx",i.style="display:none";const r=document.createElement("span");r.className="slideUp";const u=document.createElement("div");u.className="compil_tit_option";const m=document.createElement("span");m.className="fullScreenBtn",m.style="display:none";const f=document.createElement("a");f.id="fullScreenBtn",f.href="",f.target="_blank",f.style="display:block;height:16px",m.appendChild(f);const p=document.createElement("span");p.className="splitLine",p.style="display:none";const g=document.createElement("span");g.className="closeComlilation",u.appendChild(m),u.appendChild(p),u.appendChild(g),o.isHideRetractBtn||i.appendChild(r),i.appendChild(u);const I=document.createElement("iframe");I.frameBorder="0",I.style.position="relative",I.style.width="100%",I.style.height="100%",I.src=e+"/bot/index?bgColorNone=true&bot_id="+n+"&app_id="+t+"&upload="+s+"&sdkFlag=true&sdkCustomVariables="+d+"&sourceInfo="+l+"&showKnowledgeSvg="+c,I.id="cozeIframe",i.appendChild(I),document.getElementById(a).appendChild(i)}(m),function(){if(i){let e=document.getElementById("fullScreenBtn");e.href=r,e.parentNode.style="display:block",document.getElementById("fullScreenBtn").parentNode.nextElementSibling.style="display:block"}}(),u()},sendToIframeMessage:function(e){if(void 0===e.eventName||""===e.eventName)throw new Error("Invalid configuration: eventName is required.");this.sendPostMessage(e),document.getElementById("cozeBx").style="display:block"},sendToIframeImage:function(n){const o=n.fileInputId,i=document.getElementById(o).files[0];if(void 0===i)throw new Error("Invalid configuration: file is required.");const r=i.name,a=i.type;return n.fileName=r,n.fileType=a,n.appId=t,new Promise(((t,o)=>{const r=new FileReader;r.onload=function(o){const i=o.target.result;n.arrayBuffer=i;document.getElementById("cozeIframe").contentWindow.postMessage(n,e),t(i)},r.onerror=function(e){o(new Error("File could not be read: "+e.target.error.code))},r.readAsArrayBuffer(i)}))},sendToIframeImageBase64:function(e){if(!e.imageBase64)throw new Error("Invalid configuration: base64 data is required.");this.sendPostMessage(e)},additionalMessages:function(e){if(void 0===e.eventName||""===e.eventName)throw new Error("Invalid configuration: eventName is required.");this.sendPostMessage(e)},sendPostMessage:function(t){document.getElementById("cozeIframe").contentWindow.postMessage(t,e)}}}();window.CozeBotSDK=CozeBotSDK;