"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/bf249e6efb5b097f23d7e21d7283429f0760b740/node_modules/rxjs/dist/cjs/internal/operators/switchMap.js.map