var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
    return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
import { AcDbEllipse, AcGePoint3d } from '@mlightcad/data-model';
import { AcApDocManager } from '../app';
import { AcEdCommand, AcEdOpenMode, AcEdPreviewJig, AcEdPromptAngleOptions, AcEdPromptDoubleOptions, AcEdPromptPointOptions, AcEdPromptStatus, eventBus } from '../editor';
import { AcApI18n } from '../i18n';
import { AcApLineJig } from './AcApLineCmd';
var EPSILON = 1e-9;
var TAU = Math.PI * 2;
var POSITIVE_NORMAL = { x: 0, y: 0, z: 1 };
function distance2d(p1, p2) {
    return Math.hypot(p2.x - p1.x, p2.y - p1.y);
}
function midpoint2d(p1, p2) {
    return {
        x: (p1.x + p2.x) / 2,
        y: (p1.y + p2.y) / 2,
        z: 0
    };
}
function normalizeVector2d(x, y) {
    var length = Math.hypot(x, y);
    if (!Number.isFinite(length) || length <= EPSILON)
        return undefined;
    return { x: x / length, y: y / length, z: 0 };
}
function perpendicular2d(unit) {
    return { x: -unit.y, y: unit.x, z: 0 };
}
function degToRad(degree) {
    return (degree * Math.PI) / 180;
}
function radToDeg(rad) {
    return (rad * 180) / Math.PI;
}
function axisAngleDeg(axis) {
    return radToDeg(Math.atan2(axis.y, axis.x));
}
/**
 * Converts a geometric direction angle (from center, relative to major axis)
 * to ellipse parameter angle used by AcGeEllipseArc3d.
 *
 * Ellipse parameterization:
 *   x = a * cos(t), y = b * sin(t)
 * Geometric ray angle alpha satisfies:
 *   tan(alpha) = (b * sin(t)) / (a * cos(t))
 * so:
 *   t = atan2(a * sin(alpha), b * cos(alpha))
 */
function geometricAngleDegToEllipseParamRad(geometricAngleDeg, majorRadius, minorRadius) {
    var alpha = degToRad(geometricAngleDeg);
    return Math.atan2(majorRadius * Math.sin(alpha), minorRadius * Math.cos(alpha));
}
function axisUnitFromCenterToPoint(center, point) {
    return normalizeVector2d(point.x - center.x, point.y - center.y);
}
function buildEllipseDefinition(center, firstAxisUnit, firstAxisRadius, secondAxisRadius, startAngle, endAngle) {
    if (startAngle === void 0) { startAngle = 0; }
    if (endAngle === void 0) { endAngle = TAU; }
    if (!Number.isFinite(firstAxisRadius) ||
        !Number.isFinite(secondAxisRadius) ||
        firstAxisRadius <= EPSILON ||
        secondAxisRadius <= EPSILON) {
        return undefined;
    }
    if (firstAxisRadius >= secondAxisRadius) {
        return {
            center: { x: center.x, y: center.y, z: 0 },
            majorAxis: firstAxisUnit,
            majorRadius: firstAxisRadius,
            minorRadius: secondAxisRadius,
            startAngle: startAngle,
            endAngle: endAngle
        };
    }
    return {
        center: { x: center.x, y: center.y, z: 0 },
        majorAxis: perpendicular2d(firstAxisUnit),
        majorRadius: secondAxisRadius,
        minorRadius: firstAxisRadius,
        startAngle: startAngle,
        endAngle: endAngle
    };
}
function createFallbackEllipse(point) {
    return new AcDbEllipse(point, POSITIVE_NORMAL, { x: 1, y: 0, z: 0 }, 1e-6, 1e-6, 0, TAU);
}
function applyEllipseDefinition(entity, definition) {
    entity.center = definition.center;
    entity.normal = POSITIVE_NORMAL;
    entity.majorAxisRadius = definition.majorRadius;
    entity.minorAxisRadius = definition.minorRadius;
    entity.startAngle = definition.startAngle;
    entity.endAngle = definition.endAngle;
    var ellipseWithGeo = entity;
    if (ellipseWithGeo._geo) {
        ellipseWithGeo._geo.majorAxis = definition.majorAxis;
    }
}
/**
 * Dynamic point-driven ellipse preview jig.
 */
var AcApEllipsePointJig = /** @class */ (function (_super) {
    __extends(AcApEllipsePointJig, _super);
    /**
     * Creates point-driven ellipse preview jig.
     *
     * @param view - Active editor view.
     * @param builder - Cursor point to ellipse definition resolver.
     * @param fallbackPoint - Fallback point used to create valid initial entity.
     */
    function AcApEllipsePointJig(view, builder, fallbackPoint) {
        var _this = _super.call(this, view) || this;
        _this._builder = builder;
        _this._ellipse = createFallbackEllipse(fallbackPoint);
        return _this;
    }
    Object.defineProperty(AcApEllipsePointJig.prototype, "entity", {
        /**
         * Gets transient ellipse entity displayed by this jig.
         */
        get: function () {
            return this._ellipse;
        },
        enumerable: false,
        configurable: true
    });
    /**
     * Recomputes preview ellipse from cursor point.
     *
     * @param point - Current cursor/input point.
     */
    AcApEllipsePointJig.prototype.update = function (point) {
        var definition = this._builder(point);
        if (!definition)
            return;
        applyEllipseDefinition(this._ellipse, definition);
    };
    return AcApEllipsePointJig;
}(AcEdPreviewJig));
/**
 * Dynamic numeric-input ellipse preview jig.
 */
var AcApEllipseDistanceJig = /** @class */ (function (_super) {
    __extends(AcApEllipseDistanceJig, _super);
    /**
     * Creates numeric-input ellipse preview jig.
     *
     * @param view - Active editor view.
     * @param builder - Numeric value to ellipse definition resolver.
     * @param fallbackPoint - Fallback point used to create valid initial entity.
     */
    function AcApEllipseDistanceJig(view, builder, fallbackPoint) {
        var _this = _super.call(this, view) || this;
        _this._builder = builder;
        _this._ellipse = createFallbackEllipse(fallbackPoint);
        return _this;
    }
    Object.defineProperty(AcApEllipseDistanceJig.prototype, "entity", {
        /**
         * Gets transient ellipse entity displayed by this jig.
         */
        get: function () {
            return this._ellipse;
        },
        enumerable: false,
        configurable: true
    });
    /**
     * Recomputes preview ellipse from numeric input value.
     *
     * @param value - Current numeric prompt value.
     */
    AcApEllipseDistanceJig.prototype.update = function (value) {
        var definition = this._builder(value);
        if (!definition)
            return;
        applyEllipseDefinition(this._ellipse, definition);
    };
    return AcApEllipseDistanceJig;
}(AcEdPreviewJig));
/**
 * Command to create one ellipse or ellipse arc.
 */
var AcApEllipseCmd = /** @class */ (function (_super) {
    __extends(AcApEllipseCmd, _super);
    /**
     * Creates ELLIPSE command instance.
     */
    function AcApEllipseCmd() {
        var _this = _super.call(this) || this;
        _this.mode = AcEdOpenMode.Write;
        return _this;
    }
    /**
     * Command entry point.
     *
     * Supported branches:
     * - Axis endpoint workflow
     * - Center-first workflow
     * - Arc-prefixed variants for ellipse arc creation
     *
     * @param context - Current application/document context.
     */
    AcApEllipseCmd.prototype.execute = function (context) {
        return __awaiter(this, void 0, void 0, function () {
            var entryPrompt, entryResult, keyword;
            var _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        entryPrompt = new AcEdPromptPointOptions(AcApI18n.t('jig.ellipse.axisEndpointOrOptions'));
                        this.addKeyword(entryPrompt, 'arc');
                        this.addKeyword(entryPrompt, 'center');
                        return [4 /*yield*/, AcApDocManager.instance.editor.getPoint(entryPrompt)];
                    case 1:
                        entryResult = _b.sent();
                        if (!(entryResult.status === AcEdPromptStatus.Keyword)) return [3 /*break*/, 6];
                        keyword = (_a = entryResult.stringResult) !== null && _a !== void 0 ? _a : '';
                        if (!(keyword === 'Center')) return [3 /*break*/, 3];
                        return [4 /*yield*/, this.runCenterFlow(context, false)];
                    case 2:
                        _b.sent();
                        return [3 /*break*/, 5];
                    case 3:
                        if (!(keyword === 'Arc')) return [3 /*break*/, 5];
                        return [4 /*yield*/, this.runArcEntryFlow(context)];
                    case 4:
                        _b.sent();
                        _b.label = 5;
                    case 5: return [2 /*return*/];
                    case 6:
                        if (entryResult.status !== AcEdPromptStatus.OK)
                            return [2 /*return*/];
                        return [4 /*yield*/, this.runAxisEndFlow(context, entryResult.value, false)];
                    case 7:
                        _b.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Adds one localized keyword to a point prompt.
     *
     * @param prompt - Target point prompt.
     * @param key - Keyword i18n key suffix.
     */
    AcApEllipseCmd.prototype.addKeyword = function (prompt, key) {
        prompt.keywords.add(AcApI18n.t("jig.ellipse.keywords.".concat(key, ".display")), AcApI18n.t("jig.ellipse.keywords.".concat(key, ".global")), AcApI18n.t("jig.ellipse.keywords.".concat(key, ".local")));
    };
    /**
     * Appends final ellipse entity to model space.
     *
     * @param context - Current application/document context.
     * @param definition - Ellipse geometric definition to append.
     */
    AcApEllipseCmd.prototype.appendEllipse = function (context, definition) {
        var ellipse = new AcDbEllipse(definition.center, POSITIVE_NORMAL, definition.majorAxis, definition.majorRadius, definition.minorRadius, definition.startAngle, definition.endAngle);
        context.doc.database.tables.blockTable.modelSpace.appendEntity(ellipse);
    };
    /**
     * Emits one warning message for invalid ellipse input.
     *
     * @param key - Invalid-input category key.
     */
    AcApEllipseCmd.prototype.warnInvalidInput = function (key) {
        eventBus.emit('message', {
            message: AcApI18n.t("jig.ellipse.invalid.".concat(key)),
            type: 'warning'
        });
    };
    /**
     * Runs `Arc` entry branch where user can provide axis endpoints or center.
     *
     * @param context - Current application/document context.
     */
    AcApEllipseCmd.prototype.runArcEntryFlow = function (context) {
        return __awaiter(this, void 0, void 0, function () {
            var prompt, result;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        prompt = new AcEdPromptPointOptions(AcApI18n.t('jig.ellipse.arcAxisEndpointOrCenter'));
                        this.addKeyword(prompt, 'center');
                        return [4 /*yield*/, AcApDocManager.instance.editor.getPoint(prompt)];
                    case 1:
                        result = _a.sent();
                        if (!(result.status === AcEdPromptStatus.Keyword)) return [3 /*break*/, 4];
                        if (!(result.stringResult === 'Center')) return [3 /*break*/, 3];
                        return [4 /*yield*/, this.runCenterFlow(context, true)];
                    case 2:
                        _a.sent();
                        _a.label = 3;
                    case 3: return [2 /*return*/];
                    case 4:
                        if (result.status !== AcEdPromptStatus.OK)
                            return [2 /*return*/];
                        return [4 /*yield*/, this.runAxisEndFlow(context, result.value, true)];
                    case 5:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Runs center-first workflow:
     * center -> first axis endpoint -> other axis/rotation -> optional arc angles.
     *
     * @param context - Current application/document context.
     * @param arcMode - Whether to continue into arc-angle prompts.
     */
    AcApEllipseCmd.prototype.runCenterFlow = function (context, arcMode) {
        return __awaiter(this, void 0, void 0, function () {
            var centerPrompt, centerResult, center, axisEndPrompt, axisEndResult, axisUnit, axisRadius, definition;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        centerPrompt = new AcEdPromptPointOptions(AcApI18n.t('jig.ellipse.center'));
                        return [4 /*yield*/, AcApDocManager.instance.editor.getPoint(centerPrompt)];
                    case 1:
                        centerResult = _a.sent();
                        if (centerResult.status !== AcEdPromptStatus.OK)
                            return [2 /*return*/];
                        center = centerResult.value;
                        axisEndPrompt = new AcEdPromptPointOptions(AcApI18n.t('jig.ellipse.firstAxisEndpoint'));
                        axisEndPrompt.useDashedLine = true;
                        axisEndPrompt.useBasePoint = true;
                        axisEndPrompt.basePoint = new AcGePoint3d(center);
                        axisEndPrompt.jig = new AcApLineJig(context.view, center);
                        return [4 /*yield*/, AcApDocManager.instance.editor.getPoint(axisEndPrompt)];
                    case 2:
                        axisEndResult = _a.sent();
                        if (axisEndResult.status !== AcEdPromptStatus.OK)
                            return [2 /*return*/];
                        axisUnit = axisUnitFromCenterToPoint(center, axisEndResult.value);
                        if (!axisUnit) {
                            this.warnInvalidInput('axis');
                            return [2 /*return*/];
                        }
                        axisRadius = distance2d(center, axisEndResult.value);
                        return [4 /*yield*/, this.promptOtherAxis(context, center, axisUnit, axisRadius, arcMode)];
                    case 3:
                        definition = _a.sent();
                        if (!definition)
                            return [2 /*return*/];
                        this.appendEllipse(context, definition);
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Runs axis-endpoint workflow:
     * first axis endpoint -> second axis endpoint -> other axis/rotation.
     *
     * @param context - Current application/document context.
     * @param firstAxisEndpoint - First endpoint of major/minor axis line.
     * @param arcMode - Whether to continue into arc-angle prompts.
     */
    AcApEllipseCmd.prototype.runAxisEndFlow = function (context, firstAxisEndpoint, arcMode) {
        return __awaiter(this, void 0, void 0, function () {
            var secondAxisPrompt, secondAxisResult, secondAxisEndpoint, axisVectorX, axisVectorY, axisUnit, center, axisRadius, definition;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        secondAxisPrompt = new AcEdPromptPointOptions(AcApI18n.t('jig.ellipse.secondAxisEndpoint'));
                        secondAxisPrompt.useDashedLine = true;
                        secondAxisPrompt.useBasePoint = true;
                        secondAxisPrompt.basePoint = new AcGePoint3d(firstAxisEndpoint);
                        secondAxisPrompt.jig = new AcApLineJig(context.view, firstAxisEndpoint);
                        return [4 /*yield*/, AcApDocManager.instance.editor.getPoint(secondAxisPrompt)];
                    case 1:
                        secondAxisResult = _a.sent();
                        if (secondAxisResult.status !== AcEdPromptStatus.OK)
                            return [2 /*return*/];
                        secondAxisEndpoint = secondAxisResult.value;
                        axisVectorX = secondAxisEndpoint.x - firstAxisEndpoint.x;
                        axisVectorY = secondAxisEndpoint.y - firstAxisEndpoint.y;
                        axisUnit = normalizeVector2d(axisVectorX, axisVectorY);
                        if (!axisUnit) {
                            this.warnInvalidInput('axis');
                            return [2 /*return*/];
                        }
                        center = midpoint2d(firstAxisEndpoint, secondAxisEndpoint);
                        axisRadius = distance2d(firstAxisEndpoint, secondAxisEndpoint) / 2;
                        return [4 /*yield*/, this.promptOtherAxis(context, center, axisUnit, axisRadius, arcMode)];
                    case 2:
                        definition = _a.sent();
                        if (!definition)
                            return [2 /*return*/];
                        this.appendEllipse(context, definition);
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Prompts for the second axis radius by point or rotation angle option.
     *
     * In arc mode, this method also continues into arc start/end angle prompts.
     *
     * @param context - Current application/document context.
     * @param center - Ellipse center point.
     * @param firstAxisUnit - Unit direction of first specified axis.
     * @param firstAxisRadius - Radius length along first specified axis.
     * @param arcMode - Whether to return an ellipse arc definition.
     * @returns Final ellipse definition, or `undefined` on cancel/invalid.
     */
    AcApEllipseCmd.prototype.promptOtherAxis = function (context, center, firstAxisUnit, firstAxisRadius, arcMode) {
        return __awaiter(this, void 0, void 0, function () {
            var otherAxisPrompt, otherAxisResult, rotationPrompt, rotationResult, secondAxisRadius, definition_1, otherAxisRadius, definition;
            var _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        if (!true) return [3 /*break*/, 6];
                        otherAxisPrompt = new AcEdPromptPointOptions(AcApI18n.t('jig.ellipse.otherAxisOrRotation'));
                        this.addKeyword(otherAxisPrompt, 'rotation');
                        otherAxisPrompt.useDashedLine = true;
                        otherAxisPrompt.useBasePoint = true;
                        otherAxisPrompt.basePoint = new AcGePoint3d(center);
                        otherAxisPrompt.jig = new AcApEllipsePointJig(context.view, function (point) {
                            var otherAxisRadius = distance2d(center, point);
                            return buildEllipseDefinition(center, firstAxisUnit, firstAxisRadius, otherAxisRadius);
                        }, center);
                        return [4 /*yield*/, AcApDocManager.instance.editor.getPoint(otherAxisPrompt)];
                    case 1:
                        otherAxisResult = _b.sent();
                        if (!(otherAxisResult.status === AcEdPromptStatus.Keyword)) return [3 /*break*/, 4];
                        if (otherAxisResult.stringResult !== 'Rotation')
                            return [2 /*return*/, undefined];
                        rotationPrompt = new AcEdPromptDoubleOptions(AcApI18n.t('jig.ellipse.rotationAngle'));
                        rotationPrompt.allowNegative = false;
                        rotationPrompt.allowZero = true;
                        rotationPrompt.jig = new AcApEllipseDistanceJig(context.view, function (degreeValue) {
                            var secondAxisRadius = firstAxisRadius * Math.abs(Math.cos(degToRad(degreeValue)));
                            return buildEllipseDefinition(center, firstAxisUnit, firstAxisRadius, secondAxisRadius);
                        }, center);
                        return [4 /*yield*/, AcApDocManager.instance.editor.getDouble(rotationPrompt)];
                    case 2:
                        rotationResult = _b.sent();
                        if (rotationResult.status !== AcEdPromptStatus.OK)
                            return [2 /*return*/, undefined];
                        secondAxisRadius = firstAxisRadius *
                            Math.abs(Math.cos(degToRad((_a = rotationResult.value) !== null && _a !== void 0 ? _a : 0)));
                        definition_1 = buildEllipseDefinition(center, firstAxisUnit, firstAxisRadius, secondAxisRadius);
                        if (!definition_1) {
                            this.warnInvalidInput('rotation');
                            return [3 /*break*/, 0];
                        }
                        if (!arcMode)
                            return [2 /*return*/, definition_1];
                        return [4 /*yield*/, this.promptArcAngles(context, definition_1)];
                    case 3: return [2 /*return*/, _b.sent()];
                    case 4:
                        if (otherAxisResult.status !== AcEdPromptStatus.OK)
                            return [2 /*return*/, undefined];
                        otherAxisRadius = distance2d(center, otherAxisResult.value);
                        definition = buildEllipseDefinition(center, firstAxisUnit, firstAxisRadius, otherAxisRadius);
                        if (!definition) {
                            this.warnInvalidInput('otherAxis');
                            return [3 /*break*/, 0];
                        }
                        if (!arcMode)
                            return [2 /*return*/, definition];
                        return [4 /*yield*/, this.promptArcAngles(context, definition)];
                    case 5: return [2 /*return*/, _b.sent()];
                    case 6: return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Prompts start and end angles for ellipse-arc creation.
     *
     * @param context - Current application/document context.
     * @param baseEllipse - Base full-ellipse definition before arc trimming.
     * @returns Arc ellipse definition, or `undefined` when canceled.
     */
    AcApEllipseCmd.prototype.promptArcAngles = function (context, baseEllipse) {
        return __awaiter(this, void 0, void 0, function () {
            var majorAxisBaseAngle, startPrompt, startResult, startAngle, endPrompt, endResult;
            var _a, _b;
            return __generator(this, function (_c) {
                switch (_c.label) {
                    case 0:
                        majorAxisBaseAngle = axisAngleDeg(baseEllipse.majorAxis);
                        startPrompt = new AcEdPromptAngleOptions(AcApI18n.t('jig.ellipse.arcStartAngle'));
                        startPrompt.allowNegative = true;
                        startPrompt.useBasePoint = true;
                        startPrompt.useDashedLine = true;
                        startPrompt.basePoint = new AcGePoint3d(baseEllipse.center);
                        startPrompt.baseAngle = majorAxisBaseAngle;
                        startPrompt.jig = new AcApEllipseDistanceJig(context.view, function (degreeValue) { return (__assign(__assign({}, baseEllipse), { startAngle: geometricAngleDegToEllipseParamRad(degreeValue, baseEllipse.majorRadius, baseEllipse.minorRadius), endAngle: TAU })); }, baseEllipse.center);
                        return [4 /*yield*/, AcApDocManager.instance.editor.getAngle(startPrompt)];
                    case 1:
                        startResult = _c.sent();
                        if (startResult.status !== AcEdPromptStatus.OK)
                            return [2 /*return*/, undefined];
                        startAngle = geometricAngleDegToEllipseParamRad((_a = startResult.value) !== null && _a !== void 0 ? _a : 0, baseEllipse.majorRadius, baseEllipse.minorRadius);
                        endPrompt = new AcEdPromptAngleOptions(AcApI18n.t('jig.ellipse.arcEndAngle'));
                        endPrompt.allowNegative = true;
                        endPrompt.useBasePoint = true;
                        endPrompt.useDashedLine = true;
                        endPrompt.basePoint = new AcGePoint3d(baseEllipse.center);
                        endPrompt.baseAngle = majorAxisBaseAngle;
                        endPrompt.jig = new AcApEllipseDistanceJig(context.view, function (degreeValue) { return (__assign(__assign({}, baseEllipse), { startAngle: startAngle, endAngle: geometricAngleDegToEllipseParamRad(degreeValue, baseEllipse.majorRadius, baseEllipse.minorRadius) })); }, baseEllipse.center);
                        return [4 /*yield*/, AcApDocManager.instance.editor.getAngle(endPrompt)];
                    case 2:
                        endResult = _c.sent();
                        if (endResult.status !== AcEdPromptStatus.OK)
                            return [2 /*return*/, undefined];
                        return [2 /*return*/, __assign(__assign({}, baseEllipse), { startAngle: startAngle, endAngle: geometricAngleDegToEllipseParamRad((_b = endResult.value) !== null && _b !== void 0 ? _b : 0, baseEllipse.majorRadius, baseEllipse.minorRadius) })];
                }
            });
        });
    };
    return AcApEllipseCmd;
}(AcEdCommand));
export { AcApEllipseCmd };
//# sourceMappingURL=AcApEllipseCmd.js.map