"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.switchMap = void 0;
const Observable_js_1 = require("../Observable.js");
function switchMap(project) {
    return (source) => new Observable_js_1.Observable((destination) => {
        let innerSubscriber = null;
        let index = 0;
        let isComplete = false;
        const checkComplete = () => isComplete && !innerSubscriber && destination.complete();
        source.subscribe((0, Observable_js_1.operate)({
            destination,
            next: (value) => {
                innerSubscriber?.unsubscribe();
                const outerIndex = index++;
                (0, Observable_js_1.from)(project(value, outerIndex)).subscribe((innerSubscriber = (0, Observable_js_1.operate)({
                    destination,
                    complete: () => {
                        innerSubscriber = null;
                        checkComplete();
                    },
                })));
            },
            complete: () => {
                isComplete = true;
                checkComplete();
            },
        }));
    });
}
exports.switchMap = switchMap;//# sourceMappingURL=http://go/sourcemap/sourcemaps/63a2996a10d9e476b6c28e951dd7691d9c0cf480/node_modules/rxjs/dist/cjs/internal/operators/switchMap.js.map