export const setStorage = (key: string, value: object) => {
  window.localStorage.setItem(key, JSON.stringify(value));
};

export const getStorage = (key: string) => {
  if (typeof window === 'undefined') {
    return null;
  }

  const storedItems = window.localStorage.getItem(key);

  return storedItems ? JSON.parse(storedItems) : [];
};

export const removeStorage = (key: string) => {
  if (typeof window === 'undefined') {
    return null;
  }
  window.localStorage.removeItem(key);
};

export const setSStorage = (key: string, value: object) => {
  window.sessionStorage.setItem(key, JSON.stringify(value));
};

export const getSStorage = (key: string) => {
  if (typeof window === 'undefined') {
    return null;
  }

  const storedItems = window.sessionStorage.getItem(key);

  return storedItems ? JSON.parse(storedItems) : [];
};

export const removeSStorage = (key: string) => {
  if (typeof window === 'undefined') {
    return null;
  }
  window.sessionStorage.removeItem(key);
};
