import { readLocalStorageValue } from '@mantine/hooks';

export function setLocalStorageUrl(url: string) {
  if (typeof document === 'undefined') return;

  localStorage.setItem('echo_url', url);
}

export function getLocalStorageUrl() {
  if (typeof document === 'undefined') return null;

  return readLocalStorageValue({ key: 'echo_url' });
}

export function getEchoHeaders(): any {
  const url = getLocalStorageUrl();
  if (!url) {
    return {};
  }

  return {
    'x-echo-url': url,
  };
}
