import log from '../../Logger';
import { METHODS, WS_FEATURE_FLAG_FILE } from '../constants';
export const WEBRTC_CALLING_OVER_WS_FEATURE_KEY = 'webrtc-calling-over-ws-CALL-219562';
const ALLOWED_ORIGINS = ['localhost', '127.0.0.1', 'web-sdk.webex.com'];
function samplesPageToggleValue() {
    if (typeof window === 'undefined' || !window.localStorage) {
        return null;
    }
    const hostname = window.location.hostname;
    const isAllowedOrigin = ALLOWED_ORIGINS.some((origin) => hostname === origin || hostname.endsWith(`.${origin}`));
    if (!isAllowedOrigin) {
        return null;
    }
    const localStorageValue = localStorage.getItem('mobius-wss-enabled');
    if (localStorageValue === 'true') {
        log.trace(`Mobius WSS force-enabled via samples page localStorage override on ${hostname}`, {
            file: WS_FEATURE_FLAG_FILE,
            method: METHODS.IS_MOBIUS_WSS_ENABLED,
        });
        return true;
    }
    if (localStorageValue === 'false') {
        log.trace(`Mobius WSS force-disabled via samples page localStorage override on ${hostname}`, {
            file: WS_FEATURE_FLAG_FILE,
            method: METHODS.IS_MOBIUS_WSS_ENABLED,
        });
        return false;
    }
    return null;
}
export function isMobiusWssEnabled(webex) {
    const enabled = webex.internal?.device?.features?.developer?.get(WEBRTC_CALLING_OVER_WS_FEATURE_KEY)?.value ===
        true;
    const localStorageOverride = samplesPageToggleValue();
    const finalValue = localStorageOverride !== null ? localStorageOverride : enabled;
    log.trace(`Mobius WSS feature flag '${WEBRTC_CALLING_OVER_WS_FEATURE_KEY}' resolved to: ${finalValue} (backend: ${enabled}, localStorage: ${localStorageOverride})`, {
        file: WS_FEATURE_FLAG_FILE,
        method: METHODS.IS_MOBIUS_WSS_ENABLED,
    });
    return finalValue;
}
