import { F as FlowGraphBlock } from './KHR_interactivity-VqtS29i9.esm.js';
import { R as RichTypeAny } from './declarationMapper-CZ6AxirO.esm.js';
import { f as RegisterClass } from './index-Cl9U4nB-.esm.js';
import './objectModelMapping-ghOGfUOh.esm.js';

/**
 * Maximum number of log entries stored by the debug block.
 */
// eslint-disable-next-line @typescript-eslint/naming-convention
const MAX_LOG_ENTRIES = 100;
/**
 * A passthrough block used to debug data values flowing through connections.
 * Spliced into a data connection to observe the value passing through it.
 */
class FlowGraphDebugBlock extends FlowGraphBlock {
    constructor(config) {
        super(config);
        /**
         * Log of values that have passed through this block.
         * Each entry is a [displayString, tooltipString] tuple.
         */
        this.log = [];
        /**
         * Whether this block is a debug block.
         * Used by the editor to identify debug blocks.
         */
        this._isDebug = true;
        this.input = this.registerDataInput("input", RichTypeAny);
        this.output = this.registerDataOutput("output", RichTypeAny);
    }
    /**
     * @internal
     */
    _updateOutputs(context) {
        const value = this.input.getValue(context);
        this.output.setValue(value, context);
        this._logValue(value);
    }
    /**
     * Format and store a value in the log.
     * @param value
     */
    _logValue(value) {
        if (value === null || value === undefined) {
            this.log.push(["null", "null"]);
        }
        else {
            const formatted = FlowGraphDebugBlock._FormatValue(value);
            this.log.push([formatted, String(value)]);
        }
        if (this.log.length > MAX_LOG_ENTRIES) {
            this.log.shift();
        }
    }
    /**
     * Type-aware value formatting.
     * @param value the value to format
     * @returns a human-readable string
     */
    static _FormatValue(value) {
        if (typeof value === "number") {
            return Number.isInteger(value) ? value.toString() : value.toFixed(4);
        }
        if (typeof value === "boolean" || typeof value === "string") {
            return String(value);
        }
        // Vector-like objects with x, y, z, w
        if (value && typeof value === "object") {
            if ("w" in value && "x" in value && "y" in value && "z" in value) {
                return `(${value.x.toFixed(3)}, ${value.y.toFixed(3)}, ${value.z.toFixed(3)}, ${value.w.toFixed(3)})`;
            }
            if ("z" in value && "x" in value && "y" in value) {
                return `(${value.x.toFixed(3)}, ${value.y.toFixed(3)}, ${value.z.toFixed(3)})`;
            }
            if ("x" in value && "y" in value) {
                return `(${value.x.toFixed(3)}, ${value.y.toFixed(3)})`;
            }
            // Color3/Color4 with r, g, b
            if ("r" in value && "g" in value && "b" in value) {
                const a = "a" in value ? `, ${value.a.toFixed(3)}` : "";
                return `(${value.r.toFixed(3)}, ${value.g.toFixed(3)}, ${value.b.toFixed(3)}${a})`;
            }
            if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) {
                return value.toString();
            }
        }
        try {
            const str = JSON.stringify(value);
            return str.length > 64 ? str.substring(0, 61) + "..." : str;
        }
        catch {
            return String(value);
        }
    }
    getClassName() {
        return "FlowGraphDebugBlock" /* FlowGraphBlockNames.DebugBlock */;
    }
}
RegisterClass("FlowGraphDebugBlock" /* FlowGraphBlockNames.DebugBlock */, FlowGraphDebugBlock);

export { FlowGraphDebugBlock };
//# sourceMappingURL=flowGraphDebugBlock-D4DDMrJS.esm.js.map
