var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var SwcAppMod_exports = {};
__export(SwcAppMod_exports, {
  SwcAppMod: () => SwcAppMod
});
module.exports = __toCommonJS(SwcAppMod_exports);
var import_SwcHTMLModElementBase = require("../elements/base/SwcHTMLModElementBase");
var import_elementDefine = require("../decorators/elementDefine");
var import_SimpleApplication = require("@dooboostore/simple-boot/SimpleApplication");
var import_PathRouter = require("@dooboostore/core-web/routers/PathRouter");
var import_HashRouter = require("@dooboostore/core-web/routers/HashRouter");
var import_SimOption = require("@dooboostore/simple-boot/SimOption");
var import_Router = require("@dooboostore/core-web/routers/Router");
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);
};
let SwcAppMod = class SwcAppMod2 extends import_SwcHTMLModElementBase.SwcHTMLModElementBase {
  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 import_PathRouter.PathRouter({ window: _config.window }) : new import_HashRouter.HashRouter({ window: _config.window });
          this.routerSubscription = this._router.observable.subscribe((route) => {
            if (route.triggerPoint === "end") {
              this.routingProcess(route.path);
            }
          });
          const option = new import_SimOption.SimOption({
            excludeProxys: [Node],
            rootRouter: _config.rootRouter
          });
          this.simpleApplication = new import_SimpleApplication.SimpleApplication(option);
          const otherInstanceSim = /* @__PURE__ */ new Map();
          if (this._router) {
            otherInstanceSim.set(import_Router.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);
  }
};
SwcAppMod = __decorate([
  (0, import_elementDefine.elementDefine)({ name: "swc-app-del", extends: "del" }),
  __metadata("design:paramtypes", [])
], SwcAppMod);
//# sourceMappingURL=SwcAppMod.js.map
