import { isFunction } from "../util/isFunction.mjs";
import { identity } from "../util/identity.mjs";
import { operate } from "../util/lift.mjs";
import { createOperatorSubscriber } from "./OperatorSubscriber.mjs";

//#region ../../node_modules/.pnpm/rxjs@7.8.2/node_modules/rxjs/dist/esm5/internal/operators/tap.js
function tap(observerOrNext, error, complete) {
	var tapObserver = isFunction(observerOrNext) || error || complete ? {
		next: observerOrNext,
		error,
		complete
	} : observerOrNext;
	return tapObserver ? operate(function(source, subscriber) {
		var _a;
		(_a = tapObserver.subscribe) === null || _a === void 0 || _a.call(tapObserver);
		var isUnsub = true;
		source.subscribe(createOperatorSubscriber(subscriber, function(value) {
			var _a$1;
			(_a$1 = tapObserver.next) === null || _a$1 === void 0 || _a$1.call(tapObserver, value);
			subscriber.next(value);
		}, function() {
			var _a$1;
			isUnsub = false;
			(_a$1 = tapObserver.complete) === null || _a$1 === void 0 || _a$1.call(tapObserver);
			subscriber.complete();
		}, function(err) {
			var _a$1;
			isUnsub = false;
			(_a$1 = tapObserver.error) === null || _a$1 === void 0 || _a$1.call(tapObserver, err);
			subscriber.error(err);
		}, function() {
			var _a$1, _b;
			if (isUnsub) (_a$1 = tapObserver.unsubscribe) === null || _a$1 === void 0 || _a$1.call(tapObserver);
			(_b = tapObserver.finalize) === null || _b === void 0 || _b.call(tapObserver);
		}));
	}) : identity;
}

//#endregion
export { tap };
//# sourceMappingURL=tap.mjs.map