"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractSetUnitPinConstantEventData = extractSetUnitPinConstantEventData;
exports.stringifySetUnitPinConstantEventData = stringifySetUnitPinConstantEventData;
exports.watchGraphSetUnitPinConstant = watchGraphSetUnitPinConstant;
const _1 = require("../../Class/$");
const stringify_1 = require("../../spec/stringify");
function extractSetUnitPinConstantEventData(...[unitId, type, pinId, constant, data, path]) {
    return {
        unitId,
        type,
        pinId,
        constant,
        data,
        path,
    };
}
function stringifySetUnitPinConstantEventData(data) {
    let data_;
    if (data instanceof _1.$) {
        data = null;
    }
    if (data !== undefined) {
        data_ = (0, stringify_1.stringify)(data);
    }
    return {
        ...data,
        data: data_,
    };
}
function watchGraphSetUnitPinConstant(event, graph, callback) {
    const listener = (...args) => {
        const data = stringifySetUnitPinConstantEventData(extractSetUnitPinConstantEventData(...args));
        callback({
            type: 'graph',
            event,
            data,
        });
    };
    graph.prependListener(event, listener);
    return () => {
        graph.removeListener(event, listener);
    };
}
//# sourceMappingURL=watchGraphSetUnitPinConstantEvent.js.map