import { domainLocales } from './constantsDomainLocales.js';
import { isProduction } from './constantsIsProduction.js';

const getCurrentBaseUrl = (locale, isMarryBaby) => {
    const isDev = process.env.NEXT_PUBLIC_DEPLOY_ENV === 'development';
    const isStaging = !isDev && !isProduction;
    // const isDev = false
    // const isStaging = false
    return isDev
        ? 'http://localhost:3000'
        : `https://${isStaging
            ? isMarryBaby
                ? 'fe.'
                : 'discover.'
            : isMarryBaby
                ? 'www.'
                : ''}${domainLocales[isMarryBaby ? 'vi-VN_MB' : locale]}`;
};
const getCurrentSsoUrl = (locale, isMarryBaby) => {
    return (process.env.UNIFY_SSO_API ||
        `https://${!isProduction ? 'staging-id.' : 'id.'}${domainLocales[isMarryBaby ? 'vi-VN_MB' : locale]}`);
};
const getTogetherApiDomain = () => {
    return (process.env.UNIFY_INTERNAL_TOGETHER_API ||
        process.env.UNIFY_TOGETHER_API ||
        `https://${!isProduction ? 'staging-together.' : 'together.'}hellohealthgroup.com`);
};
const getDiscoverApiDomain = (locale) => {
    const isMarryBaby = locale.endsWith('_MB');
    if (isMarryBaby)
        return `https://${!isProduction ? 'staging.' : 'wp.'}${domainLocales[locale]}`;
    return (process.env.UNIFY_INTERNAL_DISCOVER_API ||
        process.env.UNIFY_DISCOVER_API ||
        `https://${!isProduction ? 'staging.' : 'wp.'}${domainLocales[locale]}`);
};
const getCareApiDomain = () => {
    return (process.env.UNIFY_INTERNAL_CARE_API ||
        process.env.UNIFY_CARE_API ||
        `https://${!isProduction ? 'service-health-care.' : 'health-care.'}hellohealthgroup.com`);
};

// remove accidental double continuous slash in url
const normalizeLinkSlash = (link) => {
    return link.replace(/([^:]\/)\/+/g, '$1');
};
const forceEndSlash = (link) => {
    return link.replace(/\/?$/, '/');
};
const normalizeLink = (link) => {
    return normalizeLinkSlash(forceEndSlash(link));
};

export { getCurrentSsoUrl as a, getTogetherApiDomain as b, getDiscoverApiDomain as c, getCareApiDomain as d, normalizeLink as e, getCurrentBaseUrl as g, normalizeLinkSlash as n };
