/**
 * @license
 * Copyright 2025-2026 Open Home Foundation
 * SPDX-License-Identifier: Apache-2.0
 */
import { MatterClient } from "@matter-server/ws-client";
import "../util/theme-service.js";
async function main() {
  import("../pages/matter-dashboard-app.js");
  let url = "";
  const isProductionServer = window.__MATTERJS_PRODUCTION_MODE__ === true || location.origin.includes(":5580") || location.href.includes("hassio_ingress") || location.href.includes("/api/ingress/");
  if (!isProductionServer) {
    let storageUrl = localStorage.getItem("matterURL");
    if (!storageUrl) {
      const urlParams = new URLSearchParams(window.location.search);
      const suggestedUrl = urlParams.get("url");
      storageUrl = prompt(
        "Enter Websocket URL to a running Matter Server",
        suggestedUrl ?? "ws://localhost:5580/ws"
      );
      if (!storageUrl) {
        alert("Unable to connect without URL");
        return;
      }
      if (suggestedUrl) {
        history.pushState({}, "", window.location.pathname);
      }
      localStorage.setItem("matterURL", storageUrl);
    }
    url = storageUrl;
  } else {
    let baseUrl = window.location.origin + window.location.pathname;
    if (baseUrl.endsWith("/")) {
      baseUrl = baseUrl.slice(0, -1);
    }
    url = baseUrl.replace("http", "ws") + "/ws";
    console.log(`Connecting to Matter Server API using url: ${url}`);
  }
  const client = new MatterClient(url);
  client.isProduction = isProductionServer;
  const dashboard = document.createElement("matter-dashboard-app");
  dashboard.client = client;
  document.body.append(dashboard);
}
main();
//# sourceMappingURL=main.js.map
