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