import { getUrlParam } from '@velofex/utils';

const windowBridge = {
  getUrlParam
} as const;

const WINDOW_BRIDGE_MOUNTED_KEY = '__WEB_VELOFEX_B_WINDOW_BRIDGE_MOUNTED__';

export function mountWindowBridge() {
  if (typeof window === 'undefined') {
    return;
  }

  const target = window as Window & {
    [WINDOW_BRIDGE_MOUNTED_KEY]?: boolean;
  };

  if (target[WINDOW_BRIDGE_MOUNTED_KEY]) {
    return;
  }

  Object.assign(window, windowBridge);

  Object.defineProperty(window, WINDOW_BRIDGE_MOUNTED_KEY, {
    configurable: false,
    enumerable: false,
    value: true,
    writable: false,
  });
}

