const require_rolldown_runtime = require('../../../../../../../../../_virtual/rolldown_runtime.js');
const require_arrRemove$1 = require('../util/arrRemove.js');
const require_Subscription$1 = require('../Subscription.js');
const require_noop$1 = require('../util/noop.js');
const require_lift$1 = require('../util/lift.js');
const require_OperatorSubscriber$1 = require('./OperatorSubscriber.js');
const require_innerFrom$1 = require('../observable/innerFrom.js');

//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/cjs/internal/operators/bufferToggle.js
var require_bufferToggle = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/cjs/internal/operators/bufferToggle.js": ((exports) => {
	var __values = exports && exports.__values || function(o) {
		var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
		if (m) return m.call(o);
		if (o && typeof o.length === "number") return { next: function() {
			if (o && i >= o.length) o = void 0;
			return {
				value: o && o[i++],
				done: !o
			};
		} };
		throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
	};
	Object.defineProperty(exports, "__esModule", { value: true });
	var Subscription_1 = require_Subscription$1.require_Subscription();
	var lift_1 = require_lift$1.require_lift();
	var innerFrom_1 = require_innerFrom$1.require_innerFrom();
	var OperatorSubscriber_1 = require_OperatorSubscriber$1.require_OperatorSubscriber();
	var noop_1 = require_noop$1.require_noop();
	var arrRemove_1 = require_arrRemove$1.require_arrRemove();
	function bufferToggle(openings, closingSelector) {
		return lift_1.operate(function(source, subscriber) {
			var buffers = [];
			innerFrom_1.innerFrom(openings).subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function(openValue) {
				var buffer = [];
				buffers.push(buffer);
				var closingSubscription = new Subscription_1.Subscription();
				var emitBuffer = function() {
					arrRemove_1.arrRemove(buffers, buffer);
					subscriber.next(buffer);
					closingSubscription.unsubscribe();
				};
				closingSubscription.add(innerFrom_1.innerFrom(closingSelector(openValue)).subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, emitBuffer, noop_1.noop)));
			}, noop_1.noop));
			source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function(value) {
				var e_1, _a;
				try {
					for (var buffers_1 = __values(buffers), buffers_1_1 = buffers_1.next(); !buffers_1_1.done; buffers_1_1 = buffers_1.next()) buffers_1_1.value.push(value);
				} catch (e_1_1) {
					e_1 = { error: e_1_1 };
				} finally {
					try {
						if (buffers_1_1 && !buffers_1_1.done && (_a = buffers_1.return)) _a.call(buffers_1);
					} finally {
						if (e_1) throw e_1.error;
					}
				}
			}, function() {
				while (buffers.length > 0) subscriber.next(buffers.shift());
				subscriber.complete();
			}));
		});
	}
	exports.bufferToggle = bufferToggle;
}) });

//#endregion
Object.defineProperty(exports, 'default', {
  enumerable: true,
  get: function () {
    return require_bufferToggle();
  }
});