import { getConfig } from "./utils";
export const configHelpers = {
    async configCtaSettings(params, callbacks) {
        const payload = {
            apiKey: params.apiKey,
            configId: params.configId,
            configType: "search",
        };
        try {
            const data = await getConfig(payload, params.dataMode);
            if (data) {
                this.setDefaultSettings(data);
                callbacks.onConfigLoaded(data);
                if (data.customCSS) {
                    callbacks.insertCustomCSS(data.customCSS);
                }
                if (data.customJS) {
                    callbacks.insertCustomJS(data.customJS);
                }
            }
        }
        catch (error) {
            console.error("error", error);
            callbacks.onError(error);
        }
    },
    setDefaultSettings(settings) {
        if ((settings === null || settings === void 0 ? void 0 : settings.autoSearch) === undefined) {
            settings.autoSearch = true;
        }
        if ((settings === null || settings === void 0 ? void 0 : settings.allowClose) === undefined) {
            settings.allowClose = true;
        }
        if ((settings === null || settings === void 0 ? void 0 : settings.clearMemory) === undefined) {
            settings.clearMemory = true;
        }
        if ((settings === null || settings === void 0 ? void 0 : settings.enableMobileView) === undefined) {
            settings.enableMobileView = true;
        }
        if ((settings === null || settings === void 0 ? void 0 : settings.categorize) === undefined) {
            settings.categorize = true;
        }
    },
};
