"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useReactiveBaseProps = exports.replaceDocCountWithParent = void 0;
const react_1 = __importDefault(require("react"));
const hooks_1 = require("../../hooks");
const props_1 = require("../../utility/props");
const replaceDocCountWithParent = (response) => {
    Object.entries(response)
        .filter(([key]) => key !== "doc_count")
        .forEach(([key, value]) => {
        var _a;
        (_a = value.buckets) === null || _a === void 0 ? void 0 : _a.forEach((bucket) => {
            if (bucket.parent_docs) {
                bucket.doc_count = bucket.parent_docs.doc_count;
                delete bucket.parent_docs;
            }
        });
    });
    return response;
};
exports.replaceDocCountWithParent = replaceDocCountWithParent;
const useReactiveBaseProps = () => {
    var _a;
    const { options, config } = (0, hooks_1.useReactifySearchContext)();
    const reactiveBasePropsShared = (0, props_1.getPropsBase)({
        provider: options,
        config: config,
        query: options.query,
    });
    const reactiveBaseProps = react_1.default.useMemo(() => {
        var _a;
        return (Object.assign(Object.assign({}, reactiveBasePropsShared), { initialState: (_a = options.preload) === null || _a === void 0 ? void 0 : _a.state, headers: Object.assign(Object.assign({}, reactiveBasePropsShared.headers), { "x-reactify-ga": (0, hooks_1.getCookie)("_rs_ga") }) }));
    }, [options.index, config.endpoint, options.credentials, options.theme, (_a = options.preload) === null || _a === void 0 ? void 0 : _a.state]);
    return reactiveBaseProps;
};
exports.useReactiveBaseProps = useReactiveBaseProps;
//# sourceMappingURL=useReactiveBaseProps.js.map