var __decorate = function(decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = function(k, v) {
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { SwcHTMLSelectElementBase } from "../elements/base/SwcHTMLSelectElementBase.js";
import { elementDefine } from "../decorators/elementDefine.js";
import { SimpleApplication } from "@dooboostore/simple-boot/SimpleApplication";
import { PathRouter } from "@dooboostore/core-web/routers/PathRouter";
import { HashRouter } from "@dooboostore/core-web/routers/HashRouter";
import { SimOption } from "@dooboostore/simple-boot/SimOption";
import { Router } from "@dooboostore/core-web/routers/Router";
let SwcAppSelect = class SwcAppSelect2 extends SwcHTMLSelectElementBase {
  constructor() {
    super();
    this._isInitialized = false;
  }
  async connectedCallback() {
    if (this._isInitialized)
      return;
    this._isInitialized = true;
    await new Promise((resolve) => setTimeout(resolve, 0));
    const applicationConfigStr = this.getAttribute("swc-get-application-config");
    if (applicationConfigStr) {
      try {
        const userConfig = new Function(`return ${applicationConfigStr}`).apply(this);
        if (userConfig) {
          const _config = {
            routeType: "path",
            window,
            ...userConfig
          };
          this._router = _config.routeType === "path" ? new PathRouter({ window: _config.window }) : new HashRouter({ window: _config.window });
          this.routerSubscription = this._router.observable.subscribe((route) => {
            if (route.triggerPoint === "end") {
              this.routingProcess(route.path);
            }
          });
          const option = new SimOption({
            excludeProxys: [Node],
            rootRouter: _config.rootRouter
          });
          this.simpleApplication = new SimpleApplication(option);
          const otherInstanceSim = /* @__PURE__ */ new Map();
          if (this._router) {
            otherInstanceSim.set(Router, this._router);
          }
          this.simpleApplication.run(otherInstanceSim);
          const data = this.simpleApplication.sim(_config.rootRouter);
          if (data instanceof Node && !this.contains(data)) {
            this.replaceChildren(data);
          }
          if (_config.path) {
            await this._router?.go(_config.path);
          }
        }
      } catch (e) {
        console.error("[SWC-APP] Failed to execute swc-get-application-config script:", e);
      }
    }
  }
  disconnectedCallback() {
    this.routerSubscription?.unsubscribe();
  }
  async routing(path) {
    await this._router?.go(path);
  }
  async routingProcess(path) {
    await this.simpleApplication?.routing(path);
  }
};
SwcAppSelect = __decorate([
  elementDefine({ name: "swc-app-select", extends: "select" }),
  __metadata("design:paramtypes", [])
], SwcAppSelect);
export {
  SwcAppSelect
};
//# sourceMappingURL=SwcAppSelect.js.map
