const TokenKey = 'GCLS_Token';

export function getSessionID() {
  const token = localStorage.getItem(TokenKey);
  const _token = token ? JSON.parse(token) : null;
  return _token ? _token.session_id ?? '' : '';
}

export function getToken() {
  const token = localStorage.getItem(TokenKey);
  return token ? JSON.parse(token) : null;
}

export function setToken(token) {
  const _token = typeof token === 'object' ? JSON.stringify(token) : '';
  localStorage.setItem(TokenKey, _token);
}

export function removeToken() {
  localStorage.removeItem(TokenKey);
}

const ConfigKey = 'GCLS_Config';

export function getConfig() {
  const config = localStorage.getItem(ConfigKey);
  return config ? JSON.parse(config) : null;
}

export function setConfig(value) {
  let _val = typeof value === 'object' ? JSON.stringify(value) : '';
  localStorage.setItem(ConfigKey, _val);
}

export function removeConfig() {
  localStorage.removeItem(ConfigKey);
}
