import buildModuleUrl from"../../Core/buildModuleUrl.js";import Check from"../../Core/Check.js";import Color from"../../Core/Color.js";import defined from"../../Core/defined.js";import destroyObject from"../../Core/destroyObject.js";import knockout from"../../ThirdParty/knockout.js";import getElement from"../getElement.js";import subscribeAndEvaluate from"../subscribeAndEvaluate.js";import InfoBoxViewModel from"./InfoBoxViewModel.js";function InfoBox(e){Check.defined("container",e),e=getElement(e);const t=document.createElement("div");t.className="cesium-infoBox",t.setAttribute("data-bind",'css: { "cesium-infoBox-visible" : showInfo, "cesium-infoBox-bodyless" : _bodyless }'),e.appendChild(t);const o=document.createElement("div");o.className="cesium-infoBox-title",o.setAttribute("data-bind","text: titleText"),t.appendChild(o);const i=document.createElement("button");i.type="button",i.className="cesium-button cesium-infoBox-camera",i.setAttribute("data-bind",'attr: { title: "Focus camera on object" },click: function () { cameraClicked.raiseEvent(this); },enable: enableCamera,cesiumSvgPath: { path: cameraIconPath, width: 32, height: 32 }'),t.appendChild(i);const n=document.createElement("button");n.type="button",n.className="cesium-infoBox-close",n.setAttribute("data-bind","click: function () { closeClicked.raiseEvent(this); }"),n.innerHTML="×",t.appendChild(n);const s=document.createElement("iframe");s.className="cesium-infoBox-iframe",s.setAttribute("sandbox","allow-same-origin allow-popups allow-forms"),s.setAttribute("data-bind","style : { maxHeight : maxHeightOffset(40) }"),s.setAttribute("allowfullscreen",!0),t.appendChild(s);const r=new InfoBoxViewModel;knockout.applyBindings(r,t),this._container=e,this._element=t,this._frame=s,this._viewModel=r,this._descriptionSubscription=void 0;const c=this;s.addEventListener("load",(function(){const e=s.contentDocument,o=e.createElement("link");o.href=buildModuleUrl("Widgets/InfoBox/InfoBoxDescription.css"),o.rel="stylesheet",o.type="text/css";const i=e.createElement("div");i.className="cesium-infoBox-description",e.head.appendChild(o),e.body.appendChild(i),c._descriptionSubscription=subscribeAndEvaluate(r,"description",(function(e){s.style.height="5px",i.innerHTML=e;let o=null;const n=i.firstElementChild;if(null!==n&&1===i.childNodes.length){const e=window.getComputedStyle(n);if(null!==e){const t=e["background-color"],i=Color.fromCssColorString(t);defined(i)&&0!==i.alpha&&(o=e["background-color"])}}t.style["background-color"]=o;const r=i.getBoundingClientRect().height;s.style.height=`${r}px`}))})),s.setAttribute("src","about:blank")}Object.defineProperties(InfoBox.prototype,{container:{get:function(){return this._container}},viewModel:{get:function(){return this._viewModel}},frame:{get:function(){return this._frame}}}),InfoBox.prototype.isDestroyed=function(){return!1},InfoBox.prototype.destroy=function(){const e=this._container;return knockout.cleanNode(this._element),e.removeChild(this._element),defined(this._descriptionSubscription)&&this._descriptionSubscription.dispose(),destroyObject(this)};export default InfoBox;