"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.delayWhen = void 0;
const concat_js_1 = require("../observable/concat.js");
const take_js_1 = require("./take.js");
const ignoreElements_js_1 = require("./ignoreElements.js");
const mergeMap_js_1 = require("./mergeMap.js");
const rx_js_1 = require("../util/rx.js");
const map_js_1 = require("./map.js");
function delayWhen(delayDurationSelector, subscriptionDelay) {
    if (subscriptionDelay) {
        return (source) => (0, concat_js_1.concat)((0, rx_js_1.rx)(subscriptionDelay, (0, take_js_1.take)(1), (0, ignoreElements_js_1.ignoreElements)()), (0, rx_js_1.rx)(source, delayWhen(delayDurationSelector)));
    }
    return (0, mergeMap_js_1.mergeMap)((value, index) => (0, rx_js_1.rx)(delayDurationSelector(value, index), (0, take_js_1.take)(1), (0, map_js_1.map)(() => value)));
}
exports.delayWhen = delayWhen;