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_Subject$1 = require('../Subject.js');
const require_innerFrom$1 = require('../observable/innerFrom.js');

//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/cjs/internal/operators/windowToggle.js
var require_windowToggle = /* @__PURE__ */ require_rolldown_runtime.__commonJS({ "../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/cjs/internal/operators/windowToggle.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 Subject_1 = require_Subject$1.require_Subject();
	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 windowToggle(openings, closingSelector) {
		return lift_1.operate(function(source, subscriber) {
			var windows = [];
			var handleError = function(err) {
				while (0 < windows.length) windows.shift().error(err);
				subscriber.error(err);
			};
			innerFrom_1.innerFrom(openings).subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function(openValue) {
				var window = new Subject_1.Subject();
				windows.push(window);
				var closingSubscription = new Subscription_1.Subscription();
				var closeWindow = function() {
					arrRemove_1.arrRemove(windows, window);
					window.complete();
					closingSubscription.unsubscribe();
				};
				var closingNotifier;
				try {
					closingNotifier = innerFrom_1.innerFrom(closingSelector(openValue));
				} catch (err) {
					handleError(err);
					return;
				}
				subscriber.next(window.asObservable());
				closingSubscription.add(closingNotifier.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, closeWindow, noop_1.noop, handleError)));
			}, noop_1.noop));
			source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function(value) {
				var e_1, _a;
				var windowsCopy = windows.slice();
				try {
					for (var windowsCopy_1 = __values(windowsCopy), windowsCopy_1_1 = windowsCopy_1.next(); !windowsCopy_1_1.done; windowsCopy_1_1 = windowsCopy_1.next()) windowsCopy_1_1.value.next(value);
				} catch (e_1_1) {
					e_1 = { error: e_1_1 };
				} finally {
					try {
						if (windowsCopy_1_1 && !windowsCopy_1_1.done && (_a = windowsCopy_1.return)) _a.call(windowsCopy_1);
					} finally {
						if (e_1) throw e_1.error;
					}
				}
			}, function() {
				while (0 < windows.length) windows.shift().complete();
				subscriber.complete();
			}, handleError, function() {
				while (0 < windows.length) windows.shift().unsubscribe();
			}));
		});
	}
	exports.windowToggle = windowToggle;
}) });

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