"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.watchRefPinEvent = exports.specGlobalRef = void 0;
const stringify_1 = require("../spec/stringify");
function specGlobalRef(_data) {
    const globalId = _data.getGlobalId();
    const __ = _data.getInterface();
    const data = { globalId, __, _: undefined };
    return data;
}
exports.specGlobalRef = specGlobalRef;
function watchRefPinEvent(event, type, pinType, pinId, pin, callback) {
    // console.log(event, type, pin)
    const listener = (_data) => {
        const data = _data instanceof Function ? (0, stringify_1.stringify)(_data) : specGlobalRef(_data);
        callback({
            type,
            event,
            data: { type: pinType, pinId, data },
        });
    };
    if (event === 'data') {
        if (pin.active()) {
            const _data = pin.peak();
            listener(_data);
        }
    }
    pin.prependListener(event, listener);
    return () => {
        pin.removeListener(event, listener);
    };
}
exports.watchRefPinEvent = watchRefPinEvent;
//# sourceMappingURL=watchRefPinEvent.js.map