// lib/debugger/types.ts
import { CheckpointStore } from "../index.js";
export class DebuggerState {
    mode = "stepping";
    checkpoints;
    callDepth = 0;
    stepTarget = null;
    constructor(rewindSize) {
        this.checkpoints = new CheckpointStore(100, rewindSize);
    }
    stepping() {
        this.mode = "stepping";
        this.stepTarget = null;
    }
    running() {
        this.mode = "running";
        this.stepTarget = null;
    }
    isStepping() {
        return this.mode === "stepping";
    }
    isRunning() {
        return this.mode === "running";
    }
    isAtTargetDepth() {
        if (!this.stepTarget)
            return true;
        return this.callDepth === this.stepTarget.targetDepth;
    }
    isAtOrBelowTargetDepth() {
        if (!this.stepTarget)
            return true;
        return this.callDepth <= this.stepTarget.targetDepth;
    }
    enterCall() {
        this.callDepth++;
    }
    exitCall() {
        if (this.callDepth > 0) {
            this.callDepth--;
        }
    }
    resetCallDepth() {
        this.callDepth = 0;
    }
    reset() {
        this.resetCallDepth();
        this.stepping();
    }
    getMode() {
        return this.mode;
    }
    stepIn() {
        this.stepping();
        this.stepTarget = {
            type: "stepIn",
            targetDepth: this.callDepth + 1,
        };
    }
    stepNext() {
        this.stepping();
        this.stepTarget = {
            type: "next",
            targetDepth: this.callDepth,
        };
    }
    stepOut() {
        this.stepping();
        this.stepTarget = {
            type: "stepOut",
            targetDepth: this.callDepth - 1,
        };
    }
    loadCheckpoints(checkpoints) {
        for (const cp of checkpoints) {
            this.checkpoints.add(cp);
        }
    }
    pinCheckpoint(checkpointId, label) {
        this.checkpoints.pin(checkpointId, label);
    }
    cloneCheckpoint(checkpoint, opts = {}) {
        return this.checkpoints.cloneCheckpoint(checkpoint, opts);
    }
    createRollingCheckpoint(ctx, opts) {
        return this.checkpoints.createRolling(ctx, opts);
    }
    createPinnedCheckpoint(ctx, opts) {
        return this.checkpoints.createPinned(ctx.stateStack, ctx, opts);
    }
    getCheckpoint(id) {
        return this.checkpoints.get(id);
    }
    getCheckpoints() {
        return this.checkpoints.getSorted();
    }
    findCheckpoint(location) {
        return this.checkpoints.findCheckpoint(location);
    }
    findBefore(checkpoint) {
        return this.checkpoints.findBefore(checkpoint);
    }
    prettyPrint() {
        return this.checkpoints.prettyPrint();
    }
    deleteAfterCheckpoint(checkpointId) {
        this.checkpoints.deleteAfterCheckpoint(checkpointId);
    }
}
