/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { Rectangle } from "@vertexvis/geometry";
import { getMouseClientPosition } from "../../lib/dom";
import { MarkupInteractionHandler, } from "../../lib/markup/interactions";
import { getMarkupBoundingClientRect } from "../viewer-markup/dom";
import { transformRectangle, translatePointToRelative, } from "../viewer-markup/markup-utils";
export class CircleMarkupInteractionHandler extends MarkupInteractionHandler {
    constructor(markupEl, interactionBegin, interactionEnd, scalingOptions) {
        super(scalingOptions);
        this.markupEl = markupEl;
        this.interactionBegin = interactionBegin;
        this.interactionEnd = interactionEnd;
        this.anchor = 'bottom-right';
    }
    editAnchor(anchor, event) {
        if (this.markupEl.mode === 'edit') {
            this.anchor = anchor;
            this.resizeBounds = this.markupEl.bounds;
            this.startInteraction(event);
        }
    }
    startInteraction(event) {
        this.handleInteractionAttempt(event);
    }
    computeBoundingRect() {
        return getMarkupBoundingClientRect(this.markupEl);
    }
    handleInteractionAttempt(event) {
        var _a;
        if (this.markupEl.mode !== '' &&
            this.pointerId == null &&
            this.elementBounds != null) {
            const position = translatePointToRelative(getMouseClientPosition(event, this.elementBounds), this.elementBounds, this.scalingOptions.originatingViewport, this.scalingOptions.centeringBehavior, this.scalingOptions.scale, this.scalingOptions.offset);
            this.pointerId = event.pointerId;
            this.startPosition = position;
            this.markupEl.bounds =
                (_a = this.markupEl.bounds) !== null && _a !== void 0 ? _a : Rectangle.create(position.x, position.y, 0, 0);
            this.resizeBounds = this.markupEl.bounds;
            this.interactionBegin.emit();
            this.acceptInteraction();
        }
    }
    handleInteractionMove(event) {
        var _a;
        if (this.markupEl.bounds != null &&
            this.startPosition != null &&
            this.elementBounds != null &&
            this.pointerId === event.pointerId) {
            const position = translatePointToRelative(getMouseClientPosition(event, this.elementBounds), this.elementBounds, this.scalingOptions.originatingViewport, this.scalingOptions.centeringBehavior, this.scalingOptions.scale, this.scalingOptions.offset);
            this.markupEl.bounds = transformRectangle((_a = this.resizeBounds) !== null && _a !== void 0 ? _a : this.markupEl.bounds, this.startPosition, position, this.anchor, event.shiftKey);
        }
    }
    handleInteractionEnd(event) {
        var _a, _b;
        if (this.pointerId === event.pointerId) {
            if (this.markupEl.mode !== '' &&
                this.markupEl.bounds != null &&
                ((_a = this.markupEl.bounds) === null || _a === void 0 ? void 0 : _a.width) > 0 &&
                ((_b = this.markupEl.bounds) === null || _b === void 0 ? void 0 : _b.height) > 0) {
                this.anchor = 'bottom-right';
                const newlyCreatedMarkup = this.markupEl.mode !== 'edit';
                this.interactionEnd.emit({ markup: this.markupEl, newlyCreatedMarkup });
            }
            else {
                this.markupEl.bounds = undefined;
            }
            this.pointerId = undefined;
        }
    }
}
//# sourceMappingURL=interactions.js.map
