import WuhuBase from "./class/WuhuBase";
import WuHuTornHelper from "./class/WuhuTornHelper";
import { Common } from "./class/Common";
import UrlRouter from "./class/UrlRouter";
import translateMain from "./func/translate/translateMain";
import CommonUtils from "./class/utils/CommonUtils";
import LocalConfigWrapper from "./class/LocalConfigWrapper";
import ClassName from "./container/ClassName";
import { Injectable } from "./container/Injectable";

@ClassName('Application')
@Injectable()
export default class App {
    constructor(
        // private readonly icon: ZhongIcon,
        private readonly wuhuBase: WuhuBase,
        private readonly tornHelper: WuHuTornHelper,
        private readonly common: Common,
        private readonly urlRouter: UrlRouter,
        private readonly configWrapper: LocalConfigWrapper,
        private readonly utils: CommonUtils,
    ) {
    }

    public run() {

        this.wuhuBase.conditionInterrupt();

        // 初始化
        this.tornHelper.init();

        // 插件图标和设置菜单
        // this.icon.init();

        let tmp = () => {
            // 所有页面通用
            try {
                // this.common.resolve.apply(this.common, this.run);
                this.common.resolve(() => this.run());
            } catch (e) {
            }

            // URL匹配
            this.urlRouter.resolve();

            // 翻译
            if (this.configWrapper.config.transEnable)
                translateMain(window.location.href);
        };
        // TODO 临时检测jquery
        if (typeof $ === "function") {
            tmp();
        } else {
            this.utils.jQueryReady().then(() => tmp());
        }
    }
}
