import { __awaiter, __generator } from "tslib";
import * as Cesium from '@msign/angularis';
import CesiumControl from '../controls/Cesium';
import LoopControl from '../controls/Loop';
import SceneControl from '../controls/Scene';
import PointerControl from '../controls/Pointer';
import CameraControl from '../controls/Camera';
import AnimaControl from '../controls/Anima';
import SWControl from '../controls/SWControl';
import StageControl from '../controls/Stage';
import MenuControl from '../controls/Menu';
import Clock from './Clock';
import VPointControl from '../controls/VPoint';
import WorkerControl from '../controls/Worker';
import ClipControl from '../controls/Clip';
import MeasureControl from '../controls/Measure';
import StateControl from '../controls/State';
import BizControl from '../controls/Biz/inedx';
import Bridge from '../bridge';
var cm = new Map();
var Instance = /** @class */ (function () {
    function Instance() {
    }
    Instance.resetInstance = function () {
        cm.clear();
    };
    Instance.getInstanceClock = function () {
        return __awaiter(this, void 0, void 0, function () {
            var cacheKey, con;
            return __generator(this, function (_a) {
                cacheKey = "Clock";
                con = cm.get(cacheKey);
                if (con) {
                    return [2 /*return*/, con];
                }
                // return cm.set(cacheKey, new CesiumControl(container)).get(cacheKey);
                return [2 /*return*/, cm.set(cacheKey, new Clock()).get(cacheKey)];
            });
        });
    };
    Instance.getInstanceSWControl = function () {
        return __awaiter(this, void 0, void 0, function () {
            var cacheKey, con;
            return __generator(this, function (_a) {
                cacheKey = "SWControl";
                con = cm.get(cacheKey);
                if (con) {
                    return [2 /*return*/, con];
                }
                // return cm.set(cacheKey, new CesiumControl(container)).get(cacheKey);
                return [2 /*return*/, cm.set(cacheKey, new SWControl()).get(cacheKey)];
            });
        });
    };
    Instance.getInstanceCesiumControl = function (container) {
        return __awaiter(this, void 0, void 0, function () {
            var cacheKey, con, cSt, bridge, _a, _b, _c;
            return __generator(this, function (_d) {
                switch (_d.label) {
                    case 0:
                        cacheKey = "CesiumControl";
                        con = cm.get(cacheKey);
                        if (con || !container) {
                            return [2 /*return*/, con];
                        }
                        return [4 /*yield*/, Instance.getInstanceStateControl()];
                    case 1:
                        cSt = _d.sent();
                        bridge = new Bridge(cSt.state);
                        Cesium.Expands.update(bridge);
                        _b = (_a = cm).set;
                        _c = [cacheKey];
                        return [4 /*yield*/, CesiumControl.constructorAsync(container)];
                    case 2: 
                    // return cm.set(cacheKey, new CesiumControl(container)).get(cacheKey);
                    return [2 /*return*/, _b.apply(_a, _c.concat([_d.sent()]))
                            .get(cacheKey)];
                }
            });
        });
    };
    Instance.getInstanceLoopControl = function () {
        return __awaiter(this, void 0, void 0, function () {
            var cacheKey, con;
            return __generator(this, function (_a) {
                cacheKey = "LoopControl";
                con = cm.get(cacheKey);
                if (con) {
                    return [2 /*return*/, con];
                }
                return [2 /*return*/, cm.set(cacheKey, new LoopControl()).get(cacheKey)];
            });
        });
    };
    Instance.getInstanceSceneControl = function (viewer) {
        return __awaiter(this, void 0, void 0, function () {
            var cacheKey, con;
            return __generator(this, function (_a) {
                cacheKey = "SceneControl";
                con = cm.get(cacheKey);
                if (con || !viewer) {
                    return [2 /*return*/, con];
                }
                return [2 /*return*/, cm.set(cacheKey, new SceneControl(viewer)).get(cacheKey)];
            });
        });
    };
    Instance.getInstancePointerControl = function (viewer) {
        return __awaiter(this, void 0, void 0, function () {
            var cacheKey, con;
            return __generator(this, function (_a) {
                cacheKey = "PointerControl";
                con = cm.get(cacheKey);
                if (con || !viewer) {
                    return [2 /*return*/, con];
                }
                return [2 /*return*/, cm.set(cacheKey, new PointerControl(viewer)).get(cacheKey)];
            });
        });
    };
    Instance.getInstanceCameraControl = function (viewer) {
        return __awaiter(this, void 0, void 0, function () {
            var cacheKey, con;
            return __generator(this, function (_a) {
                cacheKey = "CameraControl";
                con = cm.get(cacheKey);
                if (con || !viewer) {
                    return [2 /*return*/, con];
                }
                return [2 /*return*/, cm.set(cacheKey, new CameraControl(viewer)).get(cacheKey)];
            });
        });
    };
    Instance.getInstanceAnimaControl = function () {
        return __awaiter(this, void 0, void 0, function () {
            var cacheKey, con;
            return __generator(this, function (_a) {
                cacheKey = "AnimaControl";
                con = cm.get(cacheKey);
                if (con) {
                    return [2 /*return*/, con];
                }
                return [2 /*return*/, cm.set(cacheKey, new AnimaControl()).get(cacheKey)];
            });
        });
    };
    Instance.getInstanceStageControl = function (viewer) {
        return __awaiter(this, void 0, void 0, function () {
            var cacheKey, con;
            return __generator(this, function (_a) {
                cacheKey = "StageControl";
                con = cm.get(cacheKey);
                if (con || !viewer) {
                    return [2 /*return*/, con];
                }
                return [2 /*return*/, cm.set(cacheKey, new StageControl(viewer)).get(cacheKey)];
            });
        });
    };
    Instance.getInstanceMenuControl = function (viewer) {
        return __awaiter(this, void 0, void 0, function () {
            var cacheKey, con;
            return __generator(this, function (_a) {
                cacheKey = "MenuControl";
                con = cm.get(cacheKey);
                if (con || !viewer) {
                    return [2 /*return*/, con];
                }
                return [2 /*return*/, cm.set(cacheKey, new MenuControl(viewer)).get(cacheKey)];
            });
        });
    };
    Instance.getInstanceVPointControl = function (viewer) {
        return __awaiter(this, void 0, void 0, function () {
            var cacheKey, con;
            return __generator(this, function (_a) {
                cacheKey = "VPointControl";
                con = cm.get(cacheKey);
                if (con || !viewer) {
                    return [2 /*return*/, con];
                }
                return [2 /*return*/, cm.set(cacheKey, new VPointControl(viewer)).get(cacheKey)];
            });
        });
    };
    Instance.getInstanceWorkerControl = function () {
        return __awaiter(this, void 0, void 0, function () {
            var cacheKey, con;
            return __generator(this, function (_a) {
                cacheKey = "WorkerControl";
                con = cm.get(cacheKey);
                if (con) {
                    return [2 /*return*/, con];
                }
                return [2 /*return*/, cm.set(cacheKey, new WorkerControl()).get(cacheKey)];
            });
        });
    };
    Instance.getInstanceClipControl = function (viewer) {
        return __awaiter(this, void 0, void 0, function () {
            var cacheKey, con;
            return __generator(this, function (_a) {
                cacheKey = "ClipControl";
                con = cm.get(cacheKey);
                if (con || !viewer) {
                    return [2 /*return*/, con];
                }
                return [2 /*return*/, cm.set(cacheKey, new ClipControl(viewer)).get(cacheKey)];
            });
        });
    };
    Instance.getInstanceStateControl = function () {
        return __awaiter(this, void 0, void 0, function () {
            var con;
            return __generator(this, function (_a) {
                con = cm.get('StateControl');
                if (con) {
                    return [2 /*return*/, con];
                }
                return [2 /*return*/, cm.set('StateControl', new StateControl()).get('StateControl')];
            });
        });
    };
    Instance.getInstanceMeasureControl = function (viewer) {
        return __awaiter(this, void 0, void 0, function () {
            var cacheKey, con;
            return __generator(this, function (_a) {
                cacheKey = "MeasureControl";
                con = cm.get(cacheKey);
                if (con || !viewer) {
                    return [2 /*return*/, con];
                }
                return [2 /*return*/, cm.set(cacheKey, new MeasureControl(viewer)).get(cacheKey)];
            });
        });
    };
    Instance.getInstanceBizControl = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, BizControl];
            });
        });
    };
    return Instance;
}());
export default Instance;
