"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.watchUnit = watchUnit;
const Graph_1 = require("../Class/Graph");
const Stateful_1 = require("../Class/Stateful");
const GRAPH_DEFAULT_EVENTS_1 = require("../constant/GRAPH_DEFAULT_EVENTS");
const callAll_1 = require("../util/call/callAll");
const watchGraphInternal_1 = require("./graph/watchGraphInternal");
const watchUnitEvent_1 = require("./watchUnitEvent");
const watchUnitIO_1 = require("./watchUnitIO");
function watchUnit(unit, callback, events = GRAPH_DEFAULT_EVENTS_1.GRAPH_DEFAULT_EVENTS) {
    const all = [];
    all.push((0, watchUnitIO_1.watchUnitIO)(unit, events, callback));
    if (unit instanceof Stateful_1.Stateful) {
        if (events.includes('set')) {
            all.push((0, watchUnitEvent_1.watchStatefulSetEvent)('set', unit, callback));
        }
    }
    if (unit.isElement()) {
        if (events.includes('call')) {
            // @ts-ignore
            all.push((0, watchUnitEvent_1.watchElementCallEvent)('call', unit, callback));
        }
    }
    if (events.includes('play')) {
        all.push((0, watchUnitEvent_1.watchUnitEvent)('play', unit, callback));
    }
    if (events.includes('pause')) {
        all.push((0, watchUnitEvent_1.watchUnitEvent)('pause', unit, callback));
    }
    if (events.includes('listen')) {
        all.push((0, watchUnitEvent_1.watchUnitEvent)('listen', unit, callback));
    }
    if (events.includes('unlisten')) {
        all.push((0, watchUnitEvent_1.watchUnitEvent)('unlisten', unit, callback));
    }
    if (events.includes('register')) {
        all.push((0, watchUnitEvent_1.watchUnitEvent)('register', unit, callback));
    }
    if (events.includes('unregister')) {
        all.push((0, watchUnitEvent_1.watchUnitEvent)('unregister', unit, callback));
    }
    if (events.includes('restore')) {
        all.push((0, watchUnitEvent_1.watchUnitEvent)('restore', unit, callback));
    }
    if (unit instanceof Graph_1.Graph) {
        all.push((0, watchGraphInternal_1.watchGraphInternal)(unit, events, callback));
    }
    let unlisten = (0, callAll_1.callAll)(all);
    return unlisten;
}
//# sourceMappingURL=watchUnit.js.map