import { __awaiter, __extends, __generator } from "tslib";
import Instance from './core/Instance';
import { EventEmitter } from 'events';
var M3CesiumConstruction = /** @class */ (function () {
    function M3CesiumConstruction() {
    }
    return M3CesiumConstruction;
}());
export { M3CesiumConstruction };
var M3Cesium = /** @class */ (function (_super) {
    __extends(M3Cesium, _super);
    function M3Cesium(option) {
        var _this = _super.call(this) || this;
        _this.Instance = Instance;
        _this._container = option.container;
        (function () { return __awaiter(_this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this._cesiumLauncher()];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        }); })();
        return _this;
    }
    M3Cesium.prototype._cesiumLauncher = function () {
        return __awaiter(this, void 0, void 0, function () {
            var container, cCl, cSW, cLp, cAn, cSt, cCe, cCa, cSc, cPo, cStg, cMeu, cVP, cWo, cCp, cMe, cBiz;
            var _this = this;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        container = this._container;
                        return [4 /*yield*/, Instance.getInstanceClock()];
                    case 1:
                        cCl = _a.sent();
                        return [4 /*yield*/, Instance.getInstanceSWControl()];
                    case 2:
                        cSW = _a.sent();
                        return [4 /*yield*/, Instance.getInstanceLoopControl()];
                    case 3:
                        cLp = _a.sent();
                        return [4 /*yield*/, Instance.getInstanceAnimaControl()];
                    case 4:
                        cAn = _a.sent();
                        return [4 /*yield*/, Instance.getInstanceStateControl()];
                    case 5:
                        cSt = _a.sent();
                        return [4 /*yield*/, Instance.getInstanceCesiumControl(container)];
                    case 6:
                        cCe = _a.sent();
                        return [4 /*yield*/, Instance.getInstanceCameraControl(cCe.viewer)];
                    case 7:
                        cCa = _a.sent();
                        return [4 /*yield*/, Instance.getInstanceSceneControl(cCe.viewer)];
                    case 8:
                        cSc = _a.sent();
                        return [4 /*yield*/, Instance.getInstancePointerControl(cCe.viewer)];
                    case 9:
                        cPo = _a.sent();
                        return [4 /*yield*/, Instance.getInstanceStageControl(cCe.viewer)];
                    case 10:
                        cStg = _a.sent();
                        return [4 /*yield*/, Instance.getInstanceMenuControl(cCe.viewer)];
                    case 11:
                        cMeu = _a.sent();
                        return [4 /*yield*/, Instance.getInstanceVPointControl(cCe.viewer)];
                    case 12:
                        cVP = _a.sent();
                        return [4 /*yield*/, Instance.getInstanceWorkerControl()];
                    case 13:
                        cWo = _a.sent();
                        return [4 /*yield*/, Instance.getInstanceClipControl(cCe.viewer)];
                    case 14:
                        cCp = _a.sent();
                        return [4 /*yield*/, Instance.getInstanceMeasureControl(cCe.viewer)];
                    case 15:
                        cMe = _a.sent();
                        return [4 /*yield*/, Instance.getInstanceBizControl()];
                    case 16:
                        cBiz = _a.sent();
                        /** **********************************************
                         *  绑定一些基础鼠标操作
                         *
                         *  激活右键菜单功能
                         *************************************************/
                        // cPo.on('up', async (evt: PointerEvent) => {
                        //   const { button } = evt;
                        //
                        //   // 鼠标点击交互后强制刷新一小会儿
                        //   const cSc = await Instance.getInstanceSceneControl();
                        //   cSc.forceRender();
                        //
                        //   // console.log(evt);
                        //   if (button !== MOUSE.RIGHT) {
                        //     cMeu.close();
                        //     return;
                        //   }
                        //   cMeu.open(evt);
                        // });
                        cPo.on('moveEnd', function () { return __awaiter(_this, void 0, void 0, function () {
                            return __generator(this, function (_a) {
                                switch (_a.label) {
                                    case 0: 
                                    // 实时保存最后视点
                                    return [4 /*yield*/, cVP.create('latest')];
                                    case 1:
                                        // 实时保存最后视点
                                        _a.sent();
                                        return [2 /*return*/];
                                }
                            });
                        }); });
                        /** ******************************
                         *  Debug
                         */
                        if (process.env.NODE_ENV != 'production' || true) {
                            window['Instance'] = Instance;
                            window['cAn'] = cAn;
                            window['cCa'] = cCa;
                            window['cCe'] = cCe;
                            window['cCl'] = cCl;
                            window['cLp'] = cLp;
                            window['cPo'] = cPo;
                            window['cSc'] = cSc;
                            window['cStg'] = cStg;
                            window['cSW'] = cSW;
                            window['cVP'] = cVP;
                            window['cWo'] = cWo;
                            window['cCp'] = cCp;
                            window['cMe'] = cMe;
                            window['cBiz'] = cBiz;
                            window['cSt'] = cSt;
                        }
                        this.emit('ready', this);
                        /** ******************************
                         *  初始化一些设置
                         */
                        // 爆炸速度加载模式启动!
                        return [4 /*yield*/, cAn.sleep(1000)];
                    case 17:
                        /** ******************************
                         *  初始化一些设置
                         */
                        // 爆炸速度加载模式启动!
                        _a.sent();
                        cCe.bustMode(true);
                        cSc.isEarthVisible = false;
                        return [4 /*yield*/, cAn.sleep(1000)];
                    case 18:
                        _a.sent();
                        cSc.isEarthVisible = true;
                        return [2 /*return*/];
                }
            });
        });
    };
    M3Cesium.constructorAsync = function (option) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, new Promise(function (resolve) {
                        var m3Cesium = new M3Cesium(option);
                        m3Cesium.once('ready', resolve);
                    })];
            });
        });
    };
    return M3Cesium;
}(EventEmitter));
export default M3Cesium;
