import { __awaiter, __extends, __generator } from "tslib";
import { throttle } from 'lodash';
import { Cartesian3 } from '@taotieh/cesium_extend';
import { TIMESPAN_INSTANT } from '../../../core/Constant';
import Clip from './Clip';
var State;
(function (State) {
    State[State["READY"] = 0] = "READY";
    State[State["POINT_ORIGIN_SELECTED"] = 1] = "POINT_ORIGIN_SELECTED";
    State[State["POINT_ORIGIN_CHANGED"] = 2] = "POINT_ORIGIN_CHANGED";
    State[State["DONE"] = 3] = "DONE";
})(State || (State = {}));
/** ****************************************************************
 *  盒裁剪, 实际是六个通用面裁剪的叠加状态
 *******************************************************************/
var ClipWithBox = /** @class */ (function (_super) {
    __extends(ClipWithBox, _super);
    function ClipWithBox(viewer, instance) {
        var _this = _super.call(this, viewer, instance) || this;
        _this._state = State.READY;
        _this._origin = new Cartesian3();
        _this._modsClipPlans = [];
        _this._onMove = throttle(function (evt) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
            return [2 /*return*/];
        }); }); }, TIMESPAN_INSTANT);
        _this._onPointerDown = function (evt) { return __awaiter(_this, void 0, void 0, function () {
            var button;
            return __generator(this, function (_a) {
                button = evt.button;
                if (button === 2) {
                    this.stop();
                }
                return [2 /*return*/];
            });
        }); };
        _this._toReset();
        return _this;
    }
    /**
     * 使用原点来更新平面
     * @param origin 平面上一点
     */
    ClipWithBox.prototype._updateClipingBoxOriginWithOrigin = function (origin) {
        /** **********************************************
         *  TODO 这个函数负责更新裁剪面和更新渲染器中的可视实体绘图
         *************************************************/
        var mCPs = this._modsClipPlans;
    };
    ClipWithBox.prototype._updateClipingPlane = function (origin) {
        /** **********************************************
         *  TODO 这个函数负责更新裁剪面和更新渲染器中的可视实体绘图
         *************************************************/
        var mCPs = this._modsClipPlans;
    };
    ClipWithBox.prototype._toSelectOrigin = function () {
        return __awaiter(this, void 0, void 0, function () {
            var origin;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        origin = this._origin;
                        console.log('选一个基准点, 用于生成水平面');
                        return [4 /*yield*/, this._selectPoint(origin)];
                    case 1:
                        _a.sent();
                        console.log('选中原点', origin);
                        this._updateClipingBoxOriginWithOrigin(origin);
                        this._state = State.POINT_ORIGIN_SELECTED;
                        this.next();
                        return [2 /*return*/];
                }
            });
        });
    };
    ClipWithBox.prototype._toChangeOrigin = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    ClipWithBox.prototype._toReset = function () {
        var origin = this._origin;
        // TODO 重置逻辑
        this._state = State.READY;
    };
    ClipWithBox.prototype._installSubEvents = function () {
        return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
            return [2 /*return*/];
        }); });
    };
    ClipWithBox.prototype._uninstallSubEvents = function () {
        return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
            return [2 /*return*/];
        }); });
    };
    ClipWithBox.prototype.start = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        _super.prototype.start.call(this);
                        this._toReset();
                        return [4 /*yield*/, this._installSubEvents()];
                    case 1:
                        _a.sent();
                        this.next();
                        return [2 /*return*/];
                }
            });
        });
    };
    ClipWithBox.prototype.next = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = this._state;
                        switch (_a) {
                            case State.READY: return [3 /*break*/, 1];
                            case State.POINT_ORIGIN_SELECTED: return [3 /*break*/, 3];
                            case State.POINT_ORIGIN_CHANGED: return [3 /*break*/, 3];
                        }
                        return [3 /*break*/, 5];
                    case 1: return [4 /*yield*/, this._toSelectOrigin()];
                    case 2:
                        _b.sent();
                        return [3 /*break*/, 7];
                    case 3: return [4 /*yield*/, this._toChangeOrigin()];
                    case 4:
                        _b.sent();
                        return [3 /*break*/, 7];
                    case 5: return [4 /*yield*/, this._toReset()];
                    case 6:
                        _b.sent();
                        _b.label = 7;
                    case 7: return [2 /*return*/];
                }
            });
        });
    };
    ClipWithBox.prototype.stop = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this._toReset()];
                    case 1:
                        _a.sent();
                        _super.prototype.stop.call(this);
                        return [4 /*yield*/, this._uninstallSubEvents()];
                    case 2:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    return ClipWithBox;
}(Clip));
export default ClipWithBox;
