import { Dict_Apis } from "@/dict";
import { UploadController } from "@queenjs/controllers";
import { ModuleRoot } from "queenjs";
import components from "../components";
import { CompUICtrl } from "../controllers/CompUICtrl";
import { HistoryCtrl } from "../controllers/HistoryCtrl";
import { ImagePickController } from "../controllers/ImagePickerController";
import { TransferCtrl } from "../controllers/TransferCtrl";
import { createProxy } from "../objects/ProxyStore/create";
import { editActions } from "./actions/edit";
import { ImgCompActions } from "./actions/image";
import { initActions } from "./actions/init";
import { helpers } from "./helpers";
import { https } from "./https";
import { store } from "./stores";
import { DragAddCtrl } from "../controllers/DragAddCtrl";
import { SelectCtrl } from "../controllers/SelectCtrl";
import { CompObject } from "../controllers/SelectCtrl/compObj";
import { manualActions } from "./actions/editWithManualHistory";
import { wxController } from "@/controllers/wxController";

export class EditorModule extends ModuleRoot {
  config = this.setConfig({
    httpConfig: {
      baseURL: Dict_Apis.promotion,
    },
  });
  components = this.useComponents(components);

  actions = this.createActions([
    initActions,
    editActions,
    ImgCompActions,
    manualActions,
  ]);
  https = this.createHttps(https);
  store = this.createStore(store, {
    transform: (state) => createProxy(state),
  });
  helper = this.createHelper(helpers);

  controls = {
    uploader: new UploadController({
      httpConfig: {
        baseURL: Dict_Apis.queentree,
      },
      dir: "queenshow",
    }),
    wxCtrl: new wxController({
      url: `${Dict_Apis.promotion}/wechat/share?`,
    }),
    transferCtrl: new TransferCtrl(this),
    dragAddCtrl: new DragAddCtrl(this),
    streamCardTransferCtrl: new TransferCtrl(this),
    historyCtrl: new HistoryCtrl(this),
    pickCtrl: new ImagePickController(),
    compUICtrl: new CompUICtrl(this),
    selectCtrl: new SelectCtrl(this),
  };
  compObjsMap = new Map<string, CompObject>();

  onReady() {
    this.actions.init();
  }

  jumpIndexHtml(route = "#/") {
    const _params = new URLSearchParams(decodeURIComponent(location.search));
    const host = _params.get("host");
    let link = `${location.origin}/index.html?host=${host}${route}`;
    // if (location.host == "www.infish.cn") {
    //   link = `${location.origin}/projects/queenshowv1/index.html?host=${host}${route}`;
    // }
    location.href = link;
  }
}
