/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { Point, Rectangle } from "@vertexvis/geometry";
import { EventDispatcher } from "@vertexvis/utils";
export class VolumeIntersectionQueryModel {
    constructor(mode) {
        this.mode = mode;
        this.dragStarted = new EventDispatcher();
        this.dragComplete = new EventDispatcher();
        this.dragCancelled = new EventDispatcher();
        this.screenBoundsChanged = new EventDispatcher();
    }
    setStartPoint(point) {
        this.startPoint = point;
        this.dragStarted.emit();
    }
    setEndPoint(point) {
        if (this.startPoint != null &&
            Point.distance(this.startPoint, point) >= 2) {
            this.endPoint = point;
            this.updateQueryType();
            this.screenBoundsChanged.emit(this.getQueryDetails());
        }
    }
    setMode(mode) {
        this.mode = mode;
    }
    complete() {
        if (this.startPoint != null && this.endPoint != null) {
            this.screenBoundsChanged.emit(undefined);
            this.dragComplete.emit(this.getQueryDetails());
            this.reset();
        }
    }
    cancel() {
        this.screenBoundsChanged.emit(undefined);
        this.dragCancelled.emit();
        this.reset();
    }
    reset() {
        this.startPoint = undefined;
        this.endPoint = undefined;
        this.type = undefined;
    }
    getScreenBounds() {
        return this.startPoint != null && this.endPoint != null
            ? Rectangle.fromPoints(this.startPoint, this.endPoint)
            : undefined;
    }
    getType() {
        return this.type;
    }
    onScreenBoundsChanged(listener) {
        return this.screenBoundsChanged.on(listener);
    }
    onDragStarted(listener) {
        return this.dragStarted.on(listener);
    }
    onDragComplete(listener) {
        return this.dragComplete.on(listener);
    }
    onDragCancelled(listener) {
        return this.dragCancelled.on(listener);
    }
    getQueryDetails() {
        if (this.startPoint != null && this.endPoint != null && this.type != null) {
            return {
                screenBounds: Rectangle.fromPoints(this.startPoint, this.endPoint),
                type: this.type,
            };
        }
        else {
            throw new Error('Failed to create query details, the start and end points must be set.');
        }
    }
    updateQueryType() {
        var _a;
        if (this.startPoint != null && this.endPoint != null) {
            const directionalType = Point.subtract(this.endPoint, this.startPoint).x > 0
                ? 'exclusive'
                : 'inclusive';
            this.type = (_a = this.mode) !== null && _a !== void 0 ? _a : directionalType;
        }
    }
}
//# sourceMappingURL=model.js.map
