const hasMultipleBrandsKey = "hmb";
const isPrimaryBrandKey = "ipb";
const isSelfKey = "islf";
const corpBrandCodeKey = "cbc";
export const getAccessToken = () => {
  return sessionStorage.getItem("token");
};

export const setAccessToken = (AccessToken) => {
  sessionStorage.setItem("token", AccessToken);
};

export const removeAccessToken = () => {
  //sessionStorage.removeItem("token");
  sessionStorage.setItem("token", null);
};

export const setHasMultipleBrands = (value) => {
  sessionStorage.removeItem(hasMultipleBrandsKey);
  value = value === undefined || value === null || value?.length === 0 ? "0" : value?.toString();
  sessionStorage.setItem(hasMultipleBrandsKey, value);
};
export const setIsSelf = (value) => {
  sessionStorage.removeItem(isSelfKey);
  value = value === undefined || value === null || value?.length === 0 ? "1" : value?.toString();
  sessionStorage.setItem(isSelfKey, value);
};
export const setCorpBrandCode = (value) => {
  sessionStorage.removeItem(corpBrandCodeKey);
  value = value === undefined || value === null || value?.length === 0 ? "" : value?.toString();
  sessionStorage.setItem(corpBrandCodeKey, value);
};

export const getHasMultipleBrands = () => {
  let value = sessionStorage.getItem(hasMultipleBrandsKey);
  if (value === null || value === undefined) {
    return false;
  }
  if (value?.toString() === "1") {
    return true;
  }
  return false;
};

export const setIsPrimaryBrand = (value) => {
  sessionStorage.removeItem(isPrimaryBrandKey);
  value = value === undefined || value === null || value?.length === 0 ? "0" : value?.toString();
  sessionStorage.setItem(isPrimaryBrandKey, value);
};

export const getIsPrimaryBrand = () => {
  let value = sessionStorage.getItem(isPrimaryBrandKey);
  if (value === null || value === undefined) {
    return false;
  }
  if (value?.toString() === "1") {
    return true;    
  }
  return false;
};

export const getIsSelf = () => {
  let value = sessionStorage.getItem(isSelfKey);
  if (value === null || value === undefined) {
    return true;
  }
  if (value?.toString() === "0") {
    return false;    
  }
  return true;
};
export const getCorpBrandCode = () => {
  let value = sessionStorage.getItem(corpBrandCodeKey);
  if (value === null || value === undefined) {
    return "";
  }
  return value?.toString();
};

export const removeHasMultipleBrands = () => {
  sessionStorage.removeItem(hasMultipleBrandsKey);
};
export const removeIsPrimaryBrand = () => {
  sessionStorage.removeItem(isPrimaryBrandKey);
};
export const removeIsSelf = () => {
  sessionStorage.removeItem(isSelfKey);
};
export const removeCorpBrandCode = () => {
  sessionStorage.removeItem(corpBrandCodeKey);
};

export const getIsLoaderVisible = () => {
  let v = sessionStorage.getItem("showLoader");
  if (v === null || v === undefined) {
    return false;
  }
  if (v.length && v.length === 0) {
    return false;
  }
  if (v.toString().toUpperCase() === "TRUE") {
    return true;
  }
  return false;
};

export const setIsLoaderVisible = (value) => {
  sessionStorage.setItem("showLoader", value);
};


