"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../../../Class/Functional");
const AudioNode_1 = require("../../../../../../wrap/AudioNode");
const _ids_1 = require("../../../../../_ids");
class AnalyserNode_ extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['node', 'opt'],
            o: ['node'],
        }, {}, system, _ids_1.ID_ANALYSER_NODE);
        this.addListener('destroy', () => {
            this.d();
        });
    }
    f({ node: sourceNode, opt }, done) {
        let _node;
        const { api: { window: { AnalyserNode }, }, } = this.__system;
        if (sourceNode.__.includes('AC')) {
            sourceNode = sourceNode;
            _node = sourceNode.createAnalyser(opt);
        }
        else {
            sourceNode = sourceNode;
            const context = sourceNode.getContext();
            // @ts-ignore
            _node = new AnalyserNode(context, opt);
            sourceNode.connect(_node);
        }
        this._source = sourceNode;
        this._node = _node;
        const node = (0, AudioNode_1.wrapAudioAnalyserNode)(_node, this.__system);
        done({
            node,
        });
    }
    d() {
        if (this._node) {
            this._source.disconnect(this._node);
            this._source = undefined;
            this._node = undefined;
        }
    }
}
exports.default = AnalyserNode_;
//# sourceMappingURL=index.js.map