import * as tslib_1 from "tslib";
import { AUDIO_GRAPHS } from '../globals';
import { getNativeContext } from '../helpers/get-native-context';
export var createAudioDestinationNodeConstructor = function (audioNodeConstructor, createAudioDestinationNodeRenderer, createIndexSizeError, createInvalidStateError, createNativeAudioDestinationNode, isNativeOfflineAudioContext) {
    return /** @class */ (function (_super) {
        tslib_1.__extends(AudioDestinationNode, _super);
        function AudioDestinationNode(context, channelCount) {
            var _this = this;
            var nativeContext = getNativeContext(context);
            var isOffline = isNativeOfflineAudioContext(nativeContext);
            var nativeAudioDestinationNode = createNativeAudioDestinationNode(nativeContext, channelCount, isOffline);
            var audioDestinationNodeRenderer = (isOffline) ? createAudioDestinationNodeRenderer() : null;
            var audioGraph = { nodes: new WeakMap(), params: new WeakMap() };
            AUDIO_GRAPHS.set(context, audioGraph);
            AUDIO_GRAPHS.set(nativeContext, audioGraph);
            _this = _super.call(this, context, nativeAudioDestinationNode, audioDestinationNodeRenderer) || this;
            _this._isNodeOfNativeOfflineAudioContext = isOffline;
            _this._nativeAudioDestinationNode = nativeAudioDestinationNode;
            return _this;
        }
        Object.defineProperty(AudioDestinationNode.prototype, "channelCount", {
            get: function () {
                return this._nativeAudioDestinationNode.channelCount;
            },
            set: function (value) {
                // Bug #52: Chrome, Edge, Opera & Safari do not throw an exception at all.
                // Bug #54: Firefox does throw an IndexSizeError.
                if (this._isNodeOfNativeOfflineAudioContext) {
                    throw createInvalidStateError();
                }
                // Bug #47: The AudioDestinationNode in Edge and Safari do not initialize the maxChannelCount property correctly.
                if (value > this._nativeAudioDestinationNode.maxChannelCount) {
                    throw createIndexSizeError();
                }
                this._nativeAudioDestinationNode.channelCount = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(AudioDestinationNode.prototype, "channelCountMode", {
            get: function () {
                return this._nativeAudioDestinationNode.channelCountMode;
            },
            set: function (value) {
                // Bug #53: No browser does throw an exception yet.
                if (this._isNodeOfNativeOfflineAudioContext) {
                    throw createInvalidStateError();
                }
                this._nativeAudioDestinationNode.channelCountMode = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(AudioDestinationNode.prototype, "maxChannelCount", {
            get: function () {
                return this._nativeAudioDestinationNode.maxChannelCount;
            },
            enumerable: true,
            configurable: true
        });
        return AudioDestinationNode;
    }(audioNodeConstructor));
};
//# sourceMappingURL=/build/es2015/factories/audio-destination-node-constructor.js.map