import { __read } from "tslib";
import { getDefaultExtractor, applyOnPidChange, applyReportPageview, applyOnUrlChange, isManualMode } from './util';
export var pvGetterWithRouteObserver = function (report, tearDownGroup, _a, config) {
    var _b = __read(_a, 1), routeObserver = _b[0];
    var sendInitFlag = config.sendInit, initPid = config.initPid, routeMode = config.routeMode, extractPid = config.extractPid, onPidUpdate = config.onPidUpdate;
    var extractPidFromUrl = isManualMode(routeMode) ? function () { return ''; } : getDefaultExtractor(routeMode);
    var customPidFromUrl = extractPid || (function () { return undefined; });
    var getFinalPid = function (url) { var _a; return (_a = customPidFromUrl(url)) !== null && _a !== void 0 ? _a : extractPidFromUrl(url); };
    var _c = __read(applyOnPidChange(applyReportPageview(report), initPid || getFinalPid(location.href), extractPidFromUrl(location.href), onPidUpdate), 2), onPidChange = _c[0], sendInit = _c[1];
    if (!isManualMode(routeMode)) {
        var _d = __read(applyOnUrlChange(function (sources, url) { return onPidChange(sources, extractPidFromUrl(url), customPidFromUrl(url)); }, ''), 1), onUrlChange_1 = _d[0];
        routeObserver &&
            tearDownGroup.push(routeObserver[0](function (value) { return onUrlChange_1(routeMode, value); }));
    }
    if (sendInitFlag) {
        sendInit();
    }
    return [onPidChange.bind(null, "user_set" /* user_set */)];
};
//# sourceMappingURL=index.js.map