import { jsx } from "react/jsx-runtime";
import { LikeC4View as LikeC4View$1 } from "likec4:react";
import { createRoot } from "react-dom/client";
import { ComponentName } from "./const.js";
import { dq as object, dr as literal, ds as stringbool, dt as string, du as formatError } from "./vendors.js";
const propsSchema = object({
  viewId: string().default("index"),
  browser: stringbool().default(!0),
  dynamicViewVariant: literal(["diagram", "sequence"]).optional()
});
class LikeC4View extends HTMLElement {
  shadow;
  root;
  hostCss;
  lastHostCss = "";
  constructor() {
    super(), this.shadow = this.attachShadow({ mode: "open", delegatesFocus: !0 });
  }
  updateHostCss() {
    const hostCss = `
    :host {
      display: block;
      position: relative;
      background-color: transparent;
      width: 100%;
      height: 100%;
      box-sizing: border-box;
      overflow: hidden;
      border: 0px solid transparent;
      padding: 0;
    }`;
    hostCss !== this.lastHostCss && (this.hostCss?.replaceSync(hostCss), this.lastHostCss = hostCss);
  }
  connectedCallback() {
    this.lastHostCss = "", this.hostCss = new CSSStyleSheet(), this.updateHostCss(), this.shadow.adoptedStyleSheets = [
      this.hostCss
    ], this.render();
  }
  disconnectedCallback() {
    this.root?.unmount(), this.root = void 0, this.shadow.adoptedStyleSheets.length = 0, this.hostCss = void 0;
  }
  static observedAttributes = ["view-id", "browser", "dynamic-variant"];
  getProps() {
    const props = propsSchema.safeParse(
      {
        viewId: this.getAttribute("view-id"),
        browser: this.getAttribute("browser") ?? void 0,
        dynamicViewVariant: this.getAttribute("dynamic-variant") ?? void 0
      }
    );
    return props.success ? props.data : (console.error("Invalid props", formatError(props.error)), {
      viewId: "index"
    });
  }
  render() {
    const props = this.getProps();
    this.updateHostCss(), this.root ??= createRoot(this.shadow), this.root.render(
      /* @__PURE__ */ jsx(LikeC4View$1, { ...props })
    );
  }
  attributeChangedCallback(_name) {
    this.root && this.render();
  }
}
customElements.define(ComponentName.View, LikeC4View);
export {
  LikeC4View
};
