import { a as __awaiter } from './tslib.es6-ab63fd84.js';
import { n as normalizeLinkSlash, c as getDiscoverApiDomain } from './normalizeLink-0bc93fbf.js';
import { g as getDataWithCache } from './core-0cf3a3a7.js';
import './constantsDomainLocales.js';
import './Locale-87b46912.js';
import './constantsIsProduction.js';

const formatHealthTool = (healthTool, locale) => {
    var _a, _b;
    if (!healthTool)
        return {};
    const prefix = locale === 'tl-PH' ? '/fil' : '';
    return {
        id: healthTool.id,
        isSubot: healthTool.is_subot,
        template: healthTool.template,
        icon: healthTool.icon,
        link: ((_a = healthTool.link) === null || _a === void 0 ? void 0 : _a.startsWith('http'))
            ? healthTool.link
            : `${prefix}/health-tools` +
                ((_b = healthTool.link) === null || _b === void 0 ? void 0 : _b.replace(`/${prefix}/`, '/').replace(`/health-tools/`, '/')),
        subtitle: healthTool.subtitle,
        title: healthTool.title,
    };
};
const getDynamicHealthTool = (locale) => __awaiter(void 0, void 0, void 0, function* () {
    var _a, _b;
    try {
        const customLang = locale === 'tl-PH' ? 'lang=fil' : '';
        let response = [];
        const isMarryBaby = locale.endsWith('_MB');
        try {
            const healthTools = yield fetch(normalizeLinkSlash(normalizeLinkSlash(`${getDiscoverApiDomain(locale)}/wp-json/api/${isMarryBaby ? 'health-tools' : 'healthtools'}?ismenu=0${customLang ? '&' + customLang : ''}`))).then((res) => res.json());
            response =
                ((_b = (_a = healthTools === null || healthTools === void 0 ? void 0 : healthTools.data) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, (healthTool) => formatHealthTool(healthTool, locale))) || [];
        }
        catch (_c) { }
        return response;
    }
    catch (e) {
        console.error(e);
    }
});
const getDynamicHealthToolWithCache = (locale) => __awaiter(void 0, void 0, void 0, function* () {
    return (yield getDataWithCache('all-health-tools', () => getDynamicHealthTool(locale || 'en-PH'), (res) => !!(res === null || res === void 0 ? void 0 : res.length), 1000 * 60)) || [];
});

export { formatHealthTool, getDynamicHealthTool, getDynamicHealthToolWithCache };
